Project

General

Profile

« Previous | Next » 

Revision 5b2db12a

Added by Andreas Müller about 3 years ago

cleanup

View differences:

cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/DozerBeanMapperFactoryBean.java
1 1
/**
2 2
 * Copyright (C) 2007 EDIT
3
 * European Distributed Institute of Taxonomy 
3
 * European Distributed Institute of Taxonomy
4 4
 * http://www.e-taxonomy.eu
5
 * 
5
 *
6 6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
 * See LICENSE.TXT at the top of this package for the full license terms.
8 8
 */
......
40 40

  
41 41
	  public final void setMappingFiles(final Resource[] mappingFiles) {
42 42
	    this.mappingFiles = mappingFiles;
43
	  }
43
	}
44 44

  
45
	  public final void setCustomConverters(final List<CustomConverter> customConverters) {
45
	public final void setCustomConverters(final List<CustomConverter> customConverters) {
46 46
	    this.customConverters = customConverters;
47
	  }
47
	}
48 48

  
49
	  public final void setEventListeners(final List<DozerEventListener> eventListeners) {
49
	public final void setEventListeners(final List<EventListener> eventListeners) {
50 50
	    this.eventListeners = eventListeners;
51
	  }
51
	}
52 52

  
53
	  public final void setFactories(final Map<String, BeanFactory> factories) {
53
	public final void setFactories(final Map<String, BeanFactory> factories) {
54 54
	    this.factories = factories;
55 55
	  }
56 56
	  
......
67 67
	  // ==================================================================================================================================
68 68
	  public final Object getObject() throws Exception {
69 69
	    return this.beanMapper;
70
	  }
71
	  public final Class<Mapper> getObjectType() {
70
	}
71

  
72
	@Override
73
    public final Class<Mapper> getObjectType() {
72 74
	    return Mapper.class;
73
	  }
74
	  public final boolean isSingleton() {
75
	}
76

  
77
	@Override
78
    public final boolean isSingleton() {
75 79
	    return true;
76
	  }
80
	}
81

  
82
	// ==================================================================================================================================
83
	// interface 'InitializingBean'
84
	// ==================================================================================================================================
85
	@Override
86
    public final void afterPropertiesSet() throws Exception {
87

  
88
        DozerBeanMapperBuilder beanMapperBuilder = DozerBeanMapperBuilder.create();
89

  
90
        final List<String> mappings = new ArrayList<>(this.mappingFiles.length);
91
        if (this.mappingFiles != null) {
92
            for (Resource mappingFile : this.mappingFiles) {
93
                mappings.add(mappingFile.getURL().toString());
94
            }
95
            beanMapperBuilder.withMappingFiles(mappings);
96
        }
77 97

  
78
	  // ==================================================================================================================================
79
	  // interface 'InitializingBean'
80
	  // ==================================================================================================================================
81
	  public final void afterPropertiesSet() throws Exception {
82
	    this.beanMapper = new DozerBeanMapper();
83

  
84
	    if (this.mappingFiles != null) {
85
	      final List<String> mappings = new ArrayList<String>(this.mappingFiles.length);
86
	      for (Resource mappingFile : this.mappingFiles) {
87
	        mappings.add(mappingFile.getURL().toString());
88
	      }
89
	      this.beanMapper.setMappingFiles(mappings);
90
	    }
91 98
	    if (this.customConverters != null) {
92
	      this.beanMapper.setCustomConverters(this.customConverters);
99
	        beanMapperBuilder.withCustomConverters(customConverters);
93 100
	    }
94 101
	    if (this.eventListeners != null) {
95
	      this.beanMapper.setEventListeners(this.eventListeners);
102
	        beanMapperBuilder.withEventListeners(eventListeners);
96 103
	    }
97 104
	    if (this.factories != null) {
98
	      this.beanMapper.setFactories(this.factories);
105
	        beanMapperBuilder.withBeanFactorys(factories);
99 106
	    }
100
	    
107

  
101 108
	    if(this.customFieldMapper != null) {
102
	    	this.beanMapper.setCustomFieldMapper(customFieldMapper);
109
	        beanMapperBuilder.withCustomFieldMapper(customFieldMapper);
103 110
	    }
104
	    
111

  
105 112
	    if(this.customConvertersWithId != null) {
106
	    	this.beanMapper.setCustomConvertersWithId(customConvertersWithId);
113
	        beanMapperBuilder.withCustomConvertersWithIds(customConvertersWithId);
107 114
	    }
108
	  }
109

  
110
	}
115
	}
116
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/DateTimeConverter.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
9 9
package eu.etaxonomy.cdm.remote.dto.assembler.converter;
10 10

  
11

  
12 11
import javax.xml.datatype.DatatypeConfigurationException;
13 12
import javax.xml.datatype.DatatypeFactory;
14 13
import javax.xml.datatype.XMLGregorianCalendar;
......
19 18

  
20 19
public class DateTimeConverter implements CustomConverter {
21 20

  
22
	public Object convert(Object destination, Object source, Class destClass, Class sourceClass) {
21
	@Override
22
    public Object convert(Object destination, Object source, Class<?> destClass, Class<?> sourceClass) {
23 23
		if (source == null) {
24 24
			return null;
25 25
		}
26 26
		Object result = null;
27 27
		if (source instanceof DateTime) {
28 28
			if(destClass.equals(DateTime.class)){
29
				result =  new DateTime(((DateTime)source));
29
				result =  new DateTime((source));
30 30
			} else if(destClass.equals(XMLGregorianCalendar.class)){
31
				result = dataTypeFactory().newXMLGregorianCalendar(((DateTime)source).toGregorianCalendar()); //naive approach, may mot result in correct representation of partial datetime 
32
			} 
31
				result = dataTypeFactory().newXMLGregorianCalendar(((DateTime)source).toGregorianCalendar()); //naive approach, may mot result in correct representation of partial datetime
32
			}
33 33
		}
34
		
34

  
35 35
		if(result == null){
36 36
			throw new MappingException("Converter TestCustomConverter used incorrectly. Arguments passed in were:"
37 37
					+ destination + " and " + source);
38 38
		}
39 39
		return result;
40 40
	}
41
	
41

  
42 42
	  /**
43 43
	   * Cache the DatatypeFactory because newInstance is very expensive.
44 44
	   */
45 45
	  private static DatatypeFactory dataTypeFactory;
46
	  
46

  
47 47
	/**
48 48
	   * Returns a new instance of DatatypeFactory, or the cached one if previously created.
49 49
	   *
......
59 59
	    }
60 60
	    return dataTypeFactory;
61 61
	  }
62

  
63
}
62
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/DefaultRelatedPageConverter.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
1 9
package eu.etaxonomy.cdm.remote.dto.assembler.converter;
2 10

  
3 11
import java.net.URI;
......
31 39
	}
32 40

  
33 41
	@Override
34
    public Object convert(Object existingDestinationFieldValue,	Object sourceFieldValue, Class<?> destinationClass, Class<?> sourceClass) {
42
    public Object convert(Object existingDestinationFieldValue,	Object sourceFieldValue,
43
            Class<?> destinationClass, Class<?> sourceClass) {
35 44
		if(sourceFieldValue == null) {
36 45
			return null;
37 46
		}
......
51 60
		}
52 61
		return relation;
53 62
	}
54

  
55
}
63
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/HibernateProxyFieldMapper.java
19 19

  
20 20
public class HibernateProxyFieldMapper implements CustomFieldMapper {
21 21

  
22

  
23 22
	@Override
24 23
    public boolean mapField(Object source, Object destination, Object sourceFieldValue, ClassMap classMap, FieldMap fieldMapping) {
25 24

  
26 25
		if(sourceFieldValue instanceof CollectionProxy) {
27 26
			try {
28
				((CollectionProxy)sourceFieldValue).hashCode();
27
				((CollectionProxy<?,?>)sourceFieldValue).hashCode();
29 28
			} catch(SessionException se) { // currently no way to tell if is initialized
30 29
				return true;
31 30
			}
......
35 34
		}else {
36 35
			return true;
37 36
		}
38

  
39 37
	}
40
}
38
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/HibernateProxyNullSafeDeepConverter.java
47 47
		}
48 48
	}
49 49

  
50

  
51 50
	protected Mapper getMapper() {
52 51
		if(mapper == null) {
53 52
			this.setMapper(this.applicationContext.getBean("dozerMapper", Mapper.class));
......
79 78
			} catch (Exception e) {
80 79
				throw new MappingException("Converter HibernateProxyNullSafeDeepConverter used incorrectly. Arguments passed in were:"+ destination + " and " + source + " sourceClass " + sourceClass + " destClass " + destClass, e);
81 80
			}
82

  
83 81
		}
84 82
	}
85 83

  
......
104 102
			throws BeansException {
105 103
		this.applicationContext = applicationContext;
106 104
	}
107
}

105
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/LsidProxyConverter.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
17 17
public class LsidProxyConverter implements CustomConverter {
18 18

  
19 19
	private String lsidProxyServiceUrl;
20
	
20

  
21 21
	private String authorityPart;
22
	
22

  
23 23
	public void setLsidProxyServiceUrl(String lsidProxyServiceUrl) {
24 24
		this.lsidProxyServiceUrl = lsidProxyServiceUrl;
25 25
	}
26
	
26

  
27 27
	public void setAuthorityPart(String authorityPart) {
28 28
		this.authorityPart = authorityPart;
29 29
	}
30 30

  
31
	public Object convert(Object destination, Object source, Class destClass, Class sourceClass) {
31
	@Override
32
    public Object convert(Object destination, Object source, Class<?> destClass, Class<?> sourceClass) {
32 33
		if (source == null || ((LSID)source).toString() == null || ((LSID)source).toString().equals("")) {
33 34
			return null;
34 35
		}
......
43 44
					+ destination + " and " + source);
44 45
		}
45 46
	}
46

  
47
}
47
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/StripTagsConverter.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
18 18

  
19 19
public class StripTagsConverter implements CustomConverter {
20 20

  
21
	public Object convert(Object destination, Object source, Class<?> destClass, Class<?> sourceClass) {
21
	@Override
22
    public Object convert(Object destination, Object source, Class<?> destClass, Class<?> sourceClass) {
22 23
		if (source == null) {
23 24
			return null;
24 25
		}
25
		if (source instanceof String) {		      
26
		if (source instanceof String) {
26 27
			Reader reader = new RemoveHTMLReader(new StringReader((String)source));
27 28
			StringBuilder stringBuilder = new StringBuilder();
28 29
			int charValue;
......
30 31
				while ((charValue = reader.read()) != -1) {
31 32
				    stringBuilder.append((char)charValue);
32 33
				}
34
				reader.close();
33 35
			} catch (IOException e) {return e.toString();}
34 36
			return stringBuilder.toString();
35 37
		} else {
......
37 39
					+ destination + " and " + source);
38 40
		}
39 41
	}
40

  
41
}
42
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/TimePeriodConverter.java
38 38
			//convert from DateTime -> TimePeriod
39 39
			//FIXME implement
40 40
			return null;
41

  
42 41
		} else {
43 42

  
44 43
			throw new MappingException("Converter TestCustomConverter used incorrectly. Arguments passed in were:"
45 44
					+ existingDestinationFieldValue + " and " + source);
46 45
		}
47 46
	}
48

  
49
}
47
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/OaiPmhResponseView.java
22 22
 * @see com.ibm.lsid.MetadataResponse
23 23
 */
24 24
public abstract class OaiPmhResponseView extends AbstractView {
25
	
25

  
26 26
	private Marshaller marshaller;
27
	
27

  
28 28
	protected Mapper mapper;
29
	
29

  
30 30
	@Autowired
31 31
	@Qualifier("marshaller")
32 32
	public void setMarshaller(Marshaller marshaller) {
33 33
		this.marshaller = marshaller;
34 34
	}
35
	
35

  
36 36
	@Autowired
37 37
	public void setMapper(Mapper mapper) {
38 38
		this.mapper = mapper;
39 39
	}
40
	
40

  
41 41
    protected abstract void constructResponse(OAIPMH oaiPmh,Map<String,Object> model);
42 42

  
43 43
    @Override
cdmlib-remote/src/test/java/eu/etaxonomy/cdm/remote/view/JsonToCsvViewTest.java
52 52

  
53 53
    @Before
54 54
    public void setUp() throws Exception {
55
    
55

  
56 56
        model = new HashMap<String,Object>();
57 57
        identifyView = new IdentifyView();
58 58
        identifyView.setMarshaller(marshaller);
59
        
59

  
60 60
        metaDataRecord = new CsvDemoMetaDataRecord(true, "/tmp", "");
61 61
        config = CsvDemoExportConfigurator.NewInstance(null, null);
62 62

  
......
82 82
        demoRecord.setScientificName(taxon.getTitleCache());
83 83
        demoRecord.setAuthorName("Author");
84 84
        demoRecord.setDatasetName("Classification");
85
        
85

  
86 86
        ArrayList<CsvDemoRecord> recordList = new ArrayList<CsvDemoRecord>();
87 87
        logger.info(recordList.size());
88 88
        recordList.add(demoRecord);

Also available in: Unified diff