cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/AnnotationAssembler.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/AssemblerBase.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/DescriptionAssembler.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/DozerBeanMapperFactoryBean.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/LocalisedTermAssembler.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/MediaAssembler.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/NameAssembler.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/SpecimenAssembler.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/TaxonAssembler.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/TypeDesignationAssembler.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/DateTimeConverter.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/HibernateProxyFieldMapper.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/HibernateProxyNullSafeDeepConverter.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/LsidConverter.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/LsidProxyConverter.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/PreferLsidToUriConverter.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/dc/Relation.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/package.html -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/tdwg/Actor.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/tdwg/BaseThing.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/tdwg/Concept.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/tdwg/DefinedTerm.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/tdwg/Name.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/tdwg/PublicationCitation.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/tdwg/package-info.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/tdwg/voc/LinkType.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/tdwg/voc/Person.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/tdwg/voc/PublicationCitation.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/tdwg/voc/Relationship.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/tdwg/voc/TaxonConcept.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/tdwg/voc/TaxonName.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/tdwg/voc/TaxonRelationshipTerm.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/tdwg/voc/Team.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/editor/LSIDAuthorityPropertyEditor.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/editor/LSIDPropertyEditor.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/exception/CdmExceptionResolver.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/service/AuthorityController.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/service/CdmObjectNonExisting.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/service/CdmServiceImpl.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/service/DataController.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/service/ICdmService.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/service/MetadataController.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/service/RestController.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/service/Utils.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/BaseView.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/DateTimeJSONValueProcessor.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/JsonView.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/RdfView.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/WsdlView.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/XmlView.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/processor/CalendarJSONValueProcessor.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/processor/DateTimeJSONValueProcessor.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/processor/InitializedHibernatePropertyFilter.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/processor/PartialJSONValueProcessor.java -text
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/processor/UUIDJSONValueProcessor.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/remote/dto/rdf/Rdf.java -text
+cdmlib-remote/src/main/resources/eu/etaxonomy/cdm/remote.xml -text
+cdmlib-remote/src/main/resources/eu/etaxonomy/cdm/remote/dto/tdwg/mappings-deep.xml -text
+cdmlib-remote/src/main/resources/eu/etaxonomy/cdm/remote/dto/tdwg/mappings-shallow.xml -text
+cdmlib-remote/src/main/resources/eu/etaxonomy/cdm/remote/dto/tdwg/mappings.xml -text
cdmlib-remote/src/main/resources/log4j.properties -text
cdmlib-remote/src/main/resources/spy.properties -text
cdmlib-remote/src/main/webapp/WEB-INF/applicationContext.xml -text
cdmlib-remote/src/test/java/eu/etaxonomy/cdm/remote/dto/ResultSetPageSTOTest.java -text
cdmlib-remote/src/test/java/eu/etaxonomy/cdm/remote/dto/assembler/AssemblerTestBase.java -text
cdmlib-remote/src/test/java/eu/etaxonomy/cdm/remote/dto/assembler/NameSTOAssemblerTest.java -text
+cdmlib-remote/src/test/java/eu/etaxonomy/cdm/remote/dto/assembler/lsid/AssemblerTest.java -text
+cdmlib-remote/src/test/java/eu/etaxonomy/cdm/remote/service/AuthorityControllerTest.java -text
cdmlib-remote/src/test/java/eu/etaxonomy/cdm/remote/service/CdmServiceImplTest.java -text
+cdmlib-remote/src/test/java/eu/etaxonomy/cdm/remote/service/DataControllerTest.java -text
+cdmlib-remote/src/test/java/eu/etaxonomy/cdm/remote/service/MetadataControllerTest.java -text
+cdmlib-remote/src/test/java/eu/etaxonomy/cdm/remote/view/RdfViewTest.java -text
+cdmlib-remote/src/test/java/eu/etaxonomy/cdm/test/util/LSIDArguementMatcher.java -text
+cdmlib-remote/src/test/java/eu/etaxonomy/cdm/test/util/LSIDAuthorityArguementMatcher.java -text
+cdmlib-remote/src/test/java/eu/etaxonomy/cdm/test/util/LSIDMatchers.java -text
cdmlib-remote/src/test/resources/applicationContext.xml -text
+cdmlib-remote/src/test/resources/eu/etaxonomy/cdm/applicationContext-test.xml -text
+cdmlib-remote/src/test/resources/eu/etaxonomy/cdm/override.properties -text
+cdmlib-remote/src/test/resources/eu/etaxonomy/cdm/remote/view/RdfViewTest.rdf -text
cdmlib-remote/src/test/resources/log4j.properties -text
cdmlib-services/LICENSE.TXT -text
cdmlib-services/README.TXT -text
<stringAttribute key="org.eclipse.debug.core.source_locator_id" value="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector"/>\r
<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <sourceLookupDirector> <sourceContainers duplicates="false"> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;javaProject name=&quot;cdmlib-commons&quot;/&gt;&#13;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;javaProject name=&quot;cdmlib-model&quot;/&gt;&#13;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;javaProject name=&quot;cdmlib-persistence&quot;/&gt;&#13;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;javaProject name=&quot;cdmlib-remote&quot;/&gt;&#13;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;javaProject name=&quot;cdmlib-services&quot;/&gt;&#13;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;default/&gt;&#13;&#10;" typeId="org.eclipse.debug.core.containerType.default"/> </sourceContainers> </sourceLookupDirector> "/>\r
<booleanAttribute key="org.eclipse.jdt.launching.ALLOW_TERMINATE" value="true"/>\r
+<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.classpathProvider"/>\r
<mapAttribute key="org.eclipse.jdt.launching.CONNECT_MAP">\r
<mapEntry key="port" value="4000"/>\r
<mapEntry key="hostname" value="localhost"/>\r
<mapEntry key="timeout" value="20000"/>\r
</mapAttribute>\r
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="cdmlib-remote"/>\r
+<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.sourcepathProvider"/>\r
<stringAttribute key="org.eclipse.jdt.launching.VM_CONNECTOR_ID" value="org.eclipse.jdt.launching.socketAttachConnector"/>\r
</launchConfiguration>\r
<groupId>eu.etaxonomy</groupId>
<artifactId>cdmlib-persistence</artifactId>
</dependency>
+ <dependency>
+ <groupId>eu.etaxonomy</groupId>
+ <artifactId>cdmlib-model</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>eu.etaxonomy</groupId>
+ <artifactId>cdmlib-services</artifactId>
+ </dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>com.ibm.lsid</groupId>
+ <artifactId>lsid-server</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.ibm.lsid</groupId>
+ <artifactId>lsid-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>xmlunit</groupId>
+ <artifactId>xmlunit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.dozer</groupId>
+ <artifactId>dozer</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>joda-time</groupId>
+ <artifactId>joda-time</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-cglib-repack</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ </dependency>
<!-- JsonView -->
<dependency>
<groupId>net.sf.json-lib</groupId>
<version>2.2.2</version>
<classifier>jdk15</classifier>
</dependency>
-
+ <dependency>
+ <groupId>org.springframework.ws</groupId>
+ <artifactId>spring-oxm-tiger</artifactId>
+ <version>1.5.0</version>
+ </dependency>
<!-- XmlView -->
<dependency>
- <groupId>xstream</groupId>
+ <groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3</artifactId>
</dependency>
+ <dependency>
+ <groupId>stax</groupId>
+ <artifactId>stax</artifactId>
+ </dependency>
<!-- JSP TAG LIBS -->
<dependency>
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.assembler;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import net.sf.dozer.util.mapping.CustomFieldMapperIF;\r
+import net.sf.dozer.util.mapping.DozerBeanMapper;\r
+import net.sf.dozer.util.mapping.MapperIF;\r
+import net.sf.dozer.util.mapping.converters.CustomConverter;\r
+import net.sf.dozer.util.mapping.converters.CustomConverterBase;\r
+import net.sf.dozer.util.mapping.event.DozerEventListener;\r
+\r
+import org.springframework.beans.factory.BeanFactory;\r
+import org.springframework.beans.factory.FactoryBean;\r
+import org.springframework.beans.factory.InitializingBean;\r
+import org.springframework.core.io.Resource;\r
+\r
+/**\r
+ * extended version of Sören Chittka's DozerBeanMapperFactoryBean, allowing other\r
+ * properties to be set.\r
+ * @author Sören Chittka\r
+ */\r
+public class DozerBeanMapperFactoryBean implements FactoryBean, InitializingBean {\r
+\r
+ private DozerBeanMapper beanMapper;\r
+ private Resource[] mappingFiles;\r
+ private List<CustomConverter> customConverters;\r
+ private Map<String,CustomConverterBase> customConvertersWithId;\r
+ private List<DozerEventListener> eventListeners;\r
+ private Map<String, BeanFactory> factories;\r
+ private CustomFieldMapperIF customFieldMapper;\r
+ \r
+\r
+ public final void setMappingFiles(final Resource[] mappingFiles) {\r
+ this.mappingFiles = mappingFiles;\r
+ }\r
+\r
+ public final void setCustomConverters(final List<CustomConverter> customConverters) {\r
+ this.customConverters = customConverters;\r
+ }\r
+\r
+ public final void setEventListeners(final List<DozerEventListener> eventListeners) {\r
+ this.eventListeners = eventListeners;\r
+ }\r
+\r
+ public final void setFactories(final Map<String, BeanFactory> factories) {\r
+ this.factories = factories;\r
+ }\r
+ \r
+ public final void setCustomFieldMapper(final CustomFieldMapperIF customFieldMapper) {\r
+ this.customFieldMapper = customFieldMapper;\r
+ }\r
+ \r
+ public final void setCustomConvertersWithId(final Map<String,CustomConverterBase> customConvertersWithId) {\r
+ this.customConvertersWithId = customConvertersWithId;\r
+ }\r
+\r
+ // ==================================================================================================================================\r
+ // interface 'FactoryBean'\r
+ // ==================================================================================================================================\r
+ public final Object getObject() throws Exception {\r
+ return this.beanMapper;\r
+ }\r
+ public final Class<MapperIF> getObjectType() {\r
+ return MapperIF.class;\r
+ }\r
+ public final boolean isSingleton() {\r
+ return true;\r
+ }\r
+\r
+ // ==================================================================================================================================\r
+ // interface 'InitializingBean'\r
+ // ==================================================================================================================================\r
+ public final void afterPropertiesSet() throws Exception {\r
+ this.beanMapper = new DozerBeanMapper();\r
+\r
+ if (this.mappingFiles != null) {\r
+ final List<String> mappings = new ArrayList<String>(this.mappingFiles.length);\r
+ for (Resource mappingFile : this.mappingFiles) {\r
+ mappings.add(mappingFile.getURL().toString());\r
+ }\r
+ this.beanMapper.setMappingFiles(mappings);\r
+ }\r
+ if (this.customConverters != null) {\r
+ this.beanMapper.setCustomConverters(this.customConverters);\r
+ }\r
+ if (this.eventListeners != null) {\r
+ this.beanMapper.setEventListeners(this.eventListeners);\r
+ }\r
+ if (this.factories != null) {\r
+ this.beanMapper.setFactories(this.factories);\r
+ }\r
+ \r
+ if(this.customFieldMapper != null) {\r
+ this.beanMapper.setCustomFieldMapper(customFieldMapper);\r
+ }\r
+ \r
+ if(this.customConvertersWithId != null) {\r
+ this.beanMapper.setCustomConvertersWithId(customConvertersWithId);\r
+ }\r
+ }\r
+\r
+ }
\ No newline at end of file
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.common.LanguageString;
import eu.etaxonomy.cdm.model.media.AudioFile;
import eu.etaxonomy.cdm.model.media.ImageFile;
import eu.etaxonomy.cdm.model.media.Media;
if (media !=null){
mediaSTO = new MediaSTO();
setVersionableEntity(media, mediaSTO);
- mediaSTO.setTitle(media.getTitle().get(languages));
+ mediaSTO.setTitle(getPreferredLanguageString(languages,media.getTitle()));
mediaSTO.setRepresentations(getMediaRepresentationSTOs(media.getRepresentations()));
}
return mediaSTO;
}
+
+ private LanguageString getPreferredLanguageString(List<Language> languages, Map<Language,LanguageString> multiLanguageSet){
+
+ LanguageString languageString = null;
+ for (Language language : languages) {
+ languageString = multiLanguageSet.get(language);
+ if(languageString != null){
+ return languageString;
+ }
+ }
+ return multiLanguageSet.get(Language.DEFAULT());
+ }
@Override
MediaTO getTO(Media media, Enumeration<Locale> locales) {
if (media !=null){
mediaTO = new MediaTO();
setVersionableEntity(media, mediaTO);
- mediaTO.setTitle(media.getTitle().get(languages));
- mediaTO.setDescription(media.getDescription().get(languages));
+ mediaTO.setTitle(getPreferredLanguageString(languages,media.getTitle()));
+ mediaTO.setDescription(getPreferredLanguageString(languages,media.getDescription()));
mediaTO.setRepresentations(getMediaRepresentationSTOs(media.getRepresentations()));
}
return name;
}
- public Set<DescriptionTO> getDescriptions(TaxonNameBase<TaxonNameBase, INameCacheStrategy> taxonNameBase, Enumeration<Locale> locales){
+ public Set<DescriptionTO> getDescriptions(TaxonNameBase taxonNameBase, Enumeration<Locale> locales){
Set<DescriptionTO> descriptions = new HashSet<DescriptionTO>();
for(TaxonNameDescription nameDescription : (Set<TaxonNameDescription>)taxonNameBase.getDescriptions()){
}
- public List<TaggedText> getTaggedName(TaxonNameBase<?, INameCacheStrategy> taxonNameBase){
+ public List<TaggedText> getTaggedName(TaxonNameBase taxonNameBase){
List<TaggedText> tags = new ArrayList<TaggedText>();
//FIXME rude hack:
if(!(taxonNameBase instanceof NonViralName)){
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.assembler.converter;
+
+import net.sf.dozer.util.mapping.MappingException;
+import net.sf.dozer.util.mapping.converters.CustomConverter;
+
+import org.joda.time.DateTime;
+
+public class DateTimeConverter implements CustomConverter {
+
+ public Object convert(Object destination, Object source, Class destClass, Class sourceClass) {
+ if (source == null) {
+ return null;
+ }
+ if (source instanceof DateTime) {
+ return new DateTime(((DateTime)source));
+ } else {
+ throw new MappingException("Converter TestCustomConverter used incorrectly. Arguments passed in were:"
+ + destination + " and " + source);
+ }
+ }
+
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.assembler.converter;\r
+\r
+import org.hibernate.Hibernate;\r
+\r
+import net.sf.dozer.util.mapping.CustomFieldMapperIF;\r
+import net.sf.dozer.util.mapping.classmap.ClassMap;\r
+import net.sf.dozer.util.mapping.fieldmap.FieldMap;\r
+\r
+public class HibernateProxyFieldMapper implements CustomFieldMapperIF {\r
+\r
+ public boolean mapField(Object source, Object destination, Object sourceFieldValue, ClassMap classMap, FieldMap fieldMapping) {\r
+ if(sourceFieldValue != null && Hibernate.isInitialized(sourceFieldValue)) {\r
+ return false;\r
+ } else {\r
+ fieldMapping.writeDestValue(destination, null);\r
+ return true;\r
+ }\r
+ \r
+ }\r
+}\r
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.assembler.converter;\r
+\r
+import java.beans.PropertyDescriptor;\r
+import java.lang.reflect.Method;\r
+\r
+import net.sf.dozer.util.mapping.MapperIF;\r
+import net.sf.dozer.util.mapping.MappingException;\r
+import net.sf.dozer.util.mapping.converters.ConfigurableCustomConverter;\r
+\r
+import org.hibernate.Hibernate;\r
+import org.springframework.beans.BeanUtils;\r
+import org.springframework.beans.BeansException;\r
+import org.springframework.context.ApplicationContext;\r
+import org.springframework.context.ApplicationContextAware;\r
+\r
+public class HibernateProxyNullSafeDeepConverter implements ConfigurableCustomConverter, ApplicationContextAware {\r
+ \r
+ private MapperIF mapper;\r
+ \r
+ private ApplicationContext applicationContext;\r
+ \r
+ protected MapperIF getMapper() {\r
+ if(mapper == null) {\r
+ this.setMapper((MapperIF)this.applicationContext.getBean("dozerMapper", MapperIF.class)); \r
+ }\r
+ return mapper;\r
+ }\r
+ \r
+ public void setMapper(MapperIF mapper) {\r
+ this.mapper = mapper;\r
+ }\r
+\r
+ public Object convert(Object destination, Object source, Class destClass, Class sourceClass, String arg) {\r
+ if (source == null || !Hibernate.isInitialized(source)) {\r
+ return null;\r
+ } else {\r
+ try {\r
+ PropertyDescriptor propertyDescriptor = BeanUtils.getPropertyDescriptor(sourceClass, arg);\r
+ Method method = propertyDescriptor.getReadMethod();\r
+ method.setAccessible(true); \r
+ assert method != null;\r
+ Object value = method.invoke(source);\r
+ if(value == null || !Hibernate.isInitialized(value)) {\r
+ return null;\r
+ } else {\r
+ return getMapper().map(value, destClass);\r
+ }\r
+ } catch (Exception e) {\r
+ throw new MappingException("Converter HibernateProxyNullSafeDeepConverter used incorrectly. Arguments passed in were:"+ destination + " and " + source + " sourceClass " + sourceClass + " destClass " + destClass, e);\r
+ } \r
+ } \r
+ }\r
+\r
+ public void setApplicationContext(ApplicationContext applicationContext)\r
+ throws BeansException {\r
+ this.applicationContext = applicationContext;\r
+ }\r
+}\r
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.assembler.converter;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import net.sf.dozer.util.mapping.MappingException;
+import net.sf.dozer.util.mapping.converters.CustomConverter;
+import eu.etaxonomy.cdm.model.common.LSID;
+
+public class LsidConverter implements CustomConverter {
+
+ public Object convert(Object destination, Object source, Class destClass, Class sourceClass) {
+ if (source == null) {
+ return null;
+ }
+ if (source instanceof LSID) {
+ try {
+ return new URI(((LSID)source).getLsid());
+ } catch (URISyntaxException e) {
+ throw new MappingException("Converter TestCustomConverter used incorrectly. Arguments passed in were:"
+ + destination + " and " + source);
+ }
+ } else {
+ throw new MappingException("Converter TestCustomConverter used incorrectly. Arguments passed in were:"
+ + destination + " and " + source);
+ }
+ }
+
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.assembler.converter;
+
+import net.sf.dozer.util.mapping.MappingException;
+import net.sf.dozer.util.mapping.converters.CustomConverter;
+import eu.etaxonomy.cdm.model.common.LSID;
+
+public class LsidProxyConverter implements CustomConverter {
+
+ private String lsidProxyServiceUrl;
+
+ public void setLsidProxyServiceUrl(String lsidProxyServiceUrl) {
+ this.lsidProxyServiceUrl = lsidProxyServiceUrl;
+ }
+
+ public Object convert(Object destination, Object source, Class destClass, Class sourceClass) {
+ if (source == null) {
+ return null;
+ }
+ String dest = null;
+ if (source instanceof LSID) {
+ dest = this.lsidProxyServiceUrl + ((LSID)source).getLsid();
+ return dest;
+ } else {
+ throw new MappingException("Converter TestCustomConverter used incorrectly. Arguments passed in were:"
+ + destination + " and " + source);
+ }
+ }
+
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.assembler.converter;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import net.sf.dozer.util.mapping.MappingException;
+import net.sf.dozer.util.mapping.converters.CustomConverter;
+
+public class PreferLsidToUriConverter implements CustomConverter {
+
+ public Object convert(Object destination, Object source, Class destClass, Class sourceClass) {
+ if (destination == null) {
+ if(source != null) {
+ try {
+ return new URI((String)source);
+ } catch (URISyntaxException e) {
+ throw new MappingException("Converter TestCustomConverter used incorrectly. Arguments passed in were:"
+ + destination + " and " + source);
+ }
+ } else {
+ return null;
+ }
+ } else {
+ return destination;
+ }
+ }
+
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.dc;\r
+\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+import javax.xml.bind.annotation.XmlType;\r
+\r
+import eu.etaxonomy.cdm.remote.dto.tdwg.voc.LinkType;\r
+\r
+@XmlAccessorType(XmlAccessType.FIELD)\r
+@XmlType(name = "Relation", propOrder = {})\r
+@XmlRootElement(name = "Relation", namespace = "http://purl.org/dc/elements/1.1/")\r
+public class Relation extends LinkType {\r
+\r
+}\r
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.tdwg;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+
+import javax.xml.bind.annotation.XmlType;
+
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "Actor", propOrder = {})
+public class Actor extends BaseThing {
+
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.tdwg;
+
+import java.io.Serializable;
+import java.net.URI;
+import java.util.Set;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+import org.joda.time.DateTime;
+
+import eu.etaxonomy.cdm.jaxb.DateTimeAdapter;
+import eu.etaxonomy.cdm.jaxb.LSIDAdapter;
+import eu.etaxonomy.cdm.model.common.LSID;
+import eu.etaxonomy.cdm.remote.dto.dc.Relation;
+import eu.etaxonomy.cdm.remote.dto.tdwg.voc.LinkType;
+import eu.etaxonomy.cdm.remote.dto.tdwg.voc.PublicationCitation;
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "BaseThing", propOrder = {
+ "title",
+ "sameAs",
+ "identifier",
+ "created",
+ "relations",
+ "abcdEquivalence",
+ "berlinModelEquivalence",
+ "darwinCoreEquivalence",
+ "deprecated",
+ "restricted",
+ "microReference",
+ "notes",
+ "publishedIn",
+ "taxonomicPlacementFormal",
+ "taxonomicPlacementInformal",
+ "tcsEquivalence",
+ "publishedInCitation"
+})
+public abstract class BaseThing {
+ @XmlElement(namespace = "http://purl.org/dc/elements/1.1/")
+ private String title;
+
+ @XmlElement(namespace = "http://www.w3.org/2002/07/owl#")
+ private String sameAs;
+
+ @XmlElement(namespace = "http://purl.org/dc/elements/1.1/")
+ private URI identifier;
+
+ @XmlElement(namespace = "http://purl.org/dc/terms/")
+ @XmlJavaTypeAdapter(DateTimeAdapter.class)
+ private DateTime created;
+
+ @XmlElement(name = "relation", namespace = "http://purl.org/dc/elements/1.1/")
+ private Set<Relation> relations;
+
+ @XmlElement
+ private String abcdEquivalence;
+
+ @XmlElement
+ private String berlinModelEquivalence;
+
+ @XmlElement
+ private String darwinCoreEquivalence;
+
+ @XmlElement(name = "isDeprecated")
+ private Boolean deprecated;
+
+ @XmlElement(name = "isRestricted")
+ private Boolean restricted;
+
+ @XmlElement
+ private String microReference;
+
+ @XmlElement
+ private Set<String> notes;
+
+ @XmlElement
+ private String publishedIn;
+
+ @XmlElement
+ private String taxonomicPlacementFormal;
+
+ @XmlElement
+ private String taxonomicPlacementInformal;
+
+ @XmlElement
+ private String tcsEquivalence;
+
+ @XmlElement(name = "publishedInCitation")
+ private PublishedInCitation publishedInCitation;
+
+ public String getAbcdEquivalence() {
+ return abcdEquivalence;
+ }
+
+ public String getBerlinModelEquivalence() {
+ return berlinModelEquivalence;
+ }
+
+ //dcterms:created
+ public DateTime getCreated() {
+ return created;
+ }
+
+ public String getDarwinCoreEquivalence() {
+ return darwinCoreEquivalence;
+ }
+
+ //dc:identifier
+ public URI getIdentifier() {
+ return identifier;
+ }
+
+ public String getMicroReference() {
+ return microReference;
+ }
+
+ public Set<String> getNotes() {
+ return notes;
+ }
+
+ public String getPublishedIn() {
+ return publishedIn;
+ }
+
+ //owl:sameAs
+ public String getSameAs() {
+ return sameAs;
+ }
+
+ public String getTaxonomicPlacementFormal() {
+ return taxonomicPlacementFormal;
+ }
+
+ public String getTaxonomicPlacementInformal() {
+ return taxonomicPlacementInformal;
+ }
+
+ public String getTcsEquivalence() {
+ return tcsEquivalence;
+ }
+
+ //dc:title
+ public String getTitle() {
+ return title;
+ }
+
+ public Boolean isDeprecated() {
+ return deprecated;
+ }
+
+ public Boolean isRestricted() {
+ return restricted;
+ }
+
+ public void setDeprecated(Boolean deprecated) {
+ this.deprecated = deprecated;
+ }
+
+ public void setIdentifier(URI identifier) {
+ this.identifier = identifier;
+ }
+
+ public void setMicroReference(String microReference) {
+ this.microReference = microReference;
+ }
+
+ public void setNotes(Set<String> notes) {
+ this.notes = notes;
+ }
+
+ public void setPublishedIn(String publishedIn) {
+ this.publishedIn = publishedIn;
+ }
+
+ public void setRestricted(Boolean restricted) {
+ this.restricted = restricted;
+ }
+
+ public void setSameAs(String sameAs) {
+ this.sameAs = sameAs;
+ }
+
+ public void setTaxonomicPlacementFormal(String taxonomicPlacementFormal) {
+ this.taxonomicPlacementFormal = taxonomicPlacementFormal;
+ }
+
+ public void setTaxonomicPlacementInformal(String taxonomicPlacementInformal) {
+ this.taxonomicPlacementInformal = taxonomicPlacementInformal;
+ }
+
+ public void setTcsEquivalence(String tcsEquivalence) {
+ this.tcsEquivalence = tcsEquivalence;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public void setCreated(DateTime created) {
+ this.created = created;
+ }
+
+ public void setPublishedInCitation(PublicationCitation publicationCitation) {
+ this.publishedInCitation = new PublishedInCitation(publicationCitation, false);
+ }
+
+ public PublicationCitation getPublishedInCitation() {
+ return publishedInCitation != null ? publishedInCitation.getPublicationCitation() : null;
+ }
+
+ public void setPublishedInCitationRelation(PublicationCitation publicationCitation) {
+ this.publishedInCitation = new PublishedInCitation(publicationCitation, true);
+ }
+
+ public PublicationCitation getPublishedInCitationRelation() {
+ return publishedInCitation != null ? publishedInCitation.getPublicationCitation() : null;
+ }
+
+ public void setRelations(Set<Relation> relations) {
+ this.relations = relations;
+ }
+
+ public Set<Relation> getRelations() {
+ return relations;
+ }
+
+ @XmlAccessorType(XmlAccessType.FIELD)
+ @XmlType(name = "", propOrder = {
+ "publicationCitation"
+ })
+ public static class PublishedInCitation extends LinkType {
+
+ @XmlElement(name = "PublicationCitation", namespace = "http://rs.tdwg.org/ontology/voc/PublicationCitation#")
+ private PublicationCitation publicationCitation;
+
+ protected PublishedInCitation() {}
+
+ protected PublishedInCitation(PublicationCitation publicationCitation, boolean useRelation) {
+ if(useRelation) {
+ if(publicationCitation != null && publicationCitation.getIdentifier() != null) {
+ this.setResource(publicationCitation.getIdentifier());
+ } else {
+ this.publicationCitation = publicationCitation;
+ }
+ } else {
+ this.publicationCitation = publicationCitation;
+ }
+ }
+
+ protected void setPublicationCitation(PublicationCitation publicationCitation) {
+ this.publicationCitation = publicationCitation;
+ }
+
+ protected PublicationCitation getPublicationCitation() {
+ return publicationCitation;
+ }
+
+ }
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.tdwg;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "Concept", propOrder = {})
+public abstract class Concept extends BaseThing {
+
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.tdwg;\r
+\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlType;\r
+\r
+@XmlAccessorType(XmlAccessType.FIELD)\r
+@XmlType(name = "DefinedTerm", propOrder = {})\r
+public class DefinedTerm extends BaseThing {\r
+\r
+}\r
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.tdwg;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "Name", propOrder = {})
+public abstract class Name extends BaseThing {
+
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.tdwg;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "PublicationCitation", propOrder = {})
+public abstract class PublicationCitation extends BaseThing {
+
+}
--- /dev/null
+/* Package Annotations*/\r
+\r
+@javax.xml.bind.annotation.XmlSchema(namespace = "http://rs.tdwg.org/ontology/voc/Common#", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)\r
+package eu.etaxonomy.cdm.remote.dto.tdwg;\r
+\r
+
\ No newline at end of file
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.tdwg.voc;\r
+\r
+import java.io.Serializable;\r
+import java.net.URI;\r
+\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlAttribute;\r
+import javax.xml.bind.annotation.XmlType;\r
+\r
+@XmlAccessorType(XmlAccessType.FIELD)\r
+@XmlType(name = "", propOrder = {})\r
+public abstract class LinkType {\r
+ \r
+ @XmlAttribute(namespace = "http://www.w3.org/1999/02/22-rdf-syntax-ns#")\r
+ protected URI resource;\r
+\r
+ public Serializable getResource() {\r
+ return resource;\r
+ }\r
+\r
+ public void setResource(URI resource) {\r
+ this.resource = resource;\r
+ }\r
+}\r
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.tdwg.voc;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import eu.etaxonomy.cdm.remote.dto.tdwg.Actor;
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "Person", propOrder = {})
+@XmlRootElement(name = "Person", namespace = "http://rs.tdwg.org/ontology/voc/Person#")
+public class Person extends Actor {
+
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.tdwg.voc;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "PublicationCitation", propOrder = {
+})
+@XmlRootElement(name = "PublicationCitation", namespace = "http://rs.tdwg.org/ontology/voc/PublicationCitation#")
+public class PublicationCitation extends eu.etaxonomy.cdm.remote.dto.tdwg.PublicationCitation {
+
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.tdwg.voc;\r
+\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlElement;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+import javax.xml.bind.annotation.XmlType;\r
+\r
+import eu.etaxonomy.cdm.remote.dto.tdwg.BaseThing;\r
+\r
+@XmlAccessorType(XmlAccessType.FIELD)\r
+@XmlType(name = "Relationship", propOrder = {\r
+ "fromTaxon",\r
+ "relationshipCategory",\r
+ "toTaxon"\r
+})\r
+@XmlRootElement(namespace = "http://rs.tdwg.org/ontology/voc/TaxonConcept#")\r
+public class Relationship extends BaseThing {\r
+ \r
+ @XmlElement(namespace = "http://rs.tdwg.org/ontology/voc/TaxonConcept#")\r
+ private FromTaxon fromTaxon;\r
+ \r
+ @XmlElement(namespace = "http://rs.tdwg.org/ontology/voc/TaxonConcept#")\r
+ private RelationshipCategory relationshipCategory;\r
+ \r
+ @XmlElement(namespace = "http://rs.tdwg.org/ontology/voc/TaxonConcept#")\r
+ private ToTaxon toTaxon;\r
+ \r
+ public TaxonConcept getFromTaxon() {\r
+ return fromTaxon != null ? fromTaxon.getTaxonConcept() : null;\r
+ }\r
+\r
+ public void setFromTaxon(TaxonConcept fromTaxon) {\r
+ this.fromTaxon = new FromTaxon(fromTaxon);\r
+ }\r
+\r
+ public TaxonRelationshipTerm getRelationshipCategory() {\r
+ return relationshipCategory != null ? relationshipCategory.getTaxonRelationshipTerm() : null;\r
+ }\r
+\r
+ public void setRelationshipCategory(TaxonRelationshipTerm relationshipCategory) {\r
+ this.relationshipCategory = new RelationshipCategory(relationshipCategory,false);\r
+ }\r
+ \r
+ public TaxonRelationshipTerm getRelationshipCategoryRelation() {\r
+ return relationshipCategory != null ? relationshipCategory.getTaxonRelationshipTerm() : null;\r
+ }\r
+\r
+ public void setRelationshipCategoryRelation(TaxonRelationshipTerm relationshipCategory) {\r
+ this.relationshipCategory = new RelationshipCategory(relationshipCategory,true);\r
+ }\r
+\r
+ public TaxonConcept getToTaxon() {\r
+ return toTaxon != null ? toTaxon.getTaxonConcept() : null;\r
+ }\r
+\r
+ public void setToTaxon(TaxonConcept toTaxon) {\r
+ this.toTaxon = new ToTaxon(toTaxon);\r
+ }\r
+\r
+ @XmlAccessorType(XmlAccessType.FIELD)\r
+ @XmlType(name = "", propOrder = {\r
+ "taxonConcept"\r
+ })\r
+ public static class FromTaxon extends LinkType {\r
+ \r
+ @XmlElement(name = "TaxonConcept", namespace = "http://rs.tdwg.org/ontology/voc/TaxonConcept#")\r
+ private TaxonConcept taxonConcept;\r
+\r
+ protected FromTaxon() {}\r
+ \r
+ protected FromTaxon(TaxonConcept taxonConcept) {\r
+ if(taxonConcept != null && taxonConcept.getIdentifier() != null) {\r
+ this.setResource(taxonConcept.getIdentifier());\r
+ }\r
+ }\r
+ \r
+ protected TaxonConcept getTaxonConcept() {\r
+ return taxonConcept;\r
+ }\r
+\r
+ protected void setTaxonConcept(TaxonConcept taxonConcept) {\r
+ this.taxonConcept = taxonConcept;\r
+ } \r
+ }\r
+ \r
+ @XmlAccessorType(XmlAccessType.FIELD)\r
+ @XmlType(name = "", propOrder = {\r
+ "taxonConcept"\r
+ })\r
+ public static class ToTaxon extends LinkType {\r
+ \r
+ @XmlElement(name = "TaxonConcept", namespace = "http://rs.tdwg.org/ontology/voc/TaxonConcept#")\r
+ private TaxonConcept taxonConcept;\r
+ \r
+ protected ToTaxon() {}\r
+ \r
+ protected ToTaxon(TaxonConcept taxonConcept) {\r
+ if(taxonConcept != null && taxonConcept.getIdentifier() != null) {\r
+ this.setResource(taxonConcept.getIdentifier());\r
+ } \r
+ }\r
+\r
+ protected TaxonConcept getTaxonConcept() {\r
+ return taxonConcept;\r
+ }\r
+\r
+ protected void setTaxonConcept(TaxonConcept taxonConcept) {\r
+ this.taxonConcept = taxonConcept;\r
+ }\r
+ \r
+ }\r
+ \r
+ @XmlAccessorType(XmlAccessType.FIELD)\r
+ @XmlType(name = "", propOrder = {\r
+ "taxonRelationshipTerm"\r
+ })\r
+ public static class RelationshipCategory extends LinkType {\r
+ \r
+ @XmlElement(name = "TaxonRelationshipTerm", namespace = "http://rs.tdwg.org/ontology/voc/TaxonConcept#")\r
+ private TaxonRelationshipTerm taxonRelationshipTerm;\r
+ \r
+ protected RelationshipCategory() {}\r
+ \r
+ protected RelationshipCategory(TaxonRelationshipTerm taxonRelationshipTerm, boolean useRelation) {\r
+ if(useRelation) {\r
+ if(taxonRelationshipTerm != null) {\r
+ if(taxonRelationshipTerm.getIdentifier() != null)\r
+ this.setResource(taxonRelationshipTerm.getIdentifier());\r
+ } else {\r
+ this.taxonRelationshipTerm = taxonRelationshipTerm;\r
+ }\r
+ } else {\r
+ this.taxonRelationshipTerm = taxonRelationshipTerm;\r
+ }\r
+ }\r
+\r
+ protected TaxonRelationshipTerm getTaxonRelationshipTerm() {\r
+ return taxonRelationshipTerm;\r
+ }\r
+\r
+ protected void setTaxonRelationshipTerm(TaxonRelationshipTerm taxonRelationshipTerm) {\r
+ this.taxonRelationshipTerm = taxonRelationshipTerm;\r
+ }\r
+\r
+ protected RelationshipCategory(TaxonRelationshipTerm taxonRelationshipTerm) {\r
+ this.taxonRelationshipTerm = taxonRelationshipTerm;\r
+ }\r
+ \r
+ }\r
+}\r
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.tdwg.voc;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import eu.etaxonomy.cdm.remote.dto.tdwg.Actor;
+import eu.etaxonomy.cdm.remote.dto.tdwg.Concept;
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "TaxonConcept", propOrder = {
+ "primary",
+ "accordingTo",
+ "hasName",
+ "hasRelationships"
+})
+@XmlRootElement(name = "TaxonConcept", namespace = "http://rs.tdwg.org/ontology/voc/TaxonConcept#")
+public class TaxonConcept extends Concept {
+
+ @XmlElement(namespace = "http://rs.tdwg.org/ontology/voc/TaxonConcept#")
+ private Boolean primary;
+
+ @XmlElement(namespace = "http://rs.tdwg.org/ontology/voc/TaxonConcept#")
+ private AccordingTo accordingTo;
+
+ @XmlElement(name = "hasName", namespace = "http://rs.tdwg.org/ontology/voc/TaxonConcept#")
+ private HasName hasName;
+
+ @XmlElement(name = "hasRelationship", namespace = "http://rs.tdwg.org/ontology/voc/TaxonConcept#")
+ private Set<HasRelationship> hasRelationships = null;
+
+ public Set<Relationship> getHasRelationship() {
+ if(hasRelationships != null) {
+ Set<Relationship> relationships = new HashSet<Relationship>();
+ for(HasRelationship hasRelationship : hasRelationships) {
+ relationships.add(hasRelationship.getRelationship());
+ }
+ return relationships;
+ } else {
+ return null;
+ }
+ }
+
+ public void setHasRelationship(Set<Relationship> relationships) {
+ if(relationships != null) {
+ this.hasRelationships = new HashSet<HasRelationship>();
+ for(Relationship relationship : relationships) {
+ hasRelationships.add( new HasRelationship(relationship));
+ }
+ } else {
+ hasRelationships = null;
+ }
+ }
+
+ public TaxonName getHasName() {
+ return hasName != null ? hasName.getTaxonName() : null;
+ }
+
+ public void setHasName(TaxonName taxonName) {
+ this.hasName = new HasName(taxonName, false);
+ }
+
+ public TaxonName getHasNameRelation() {
+ return hasName != null ? hasName.getTaxonName() : null;
+ }
+
+ public void setHasNameRelation(TaxonName taxonName) {
+ this.hasName = new HasName(taxonName, true);
+ }
+
+ public Boolean isPrimary() {
+ return primary;
+ }
+
+ public Actor getAccordingTo() {
+ return accordingTo != null ? accordingTo.getActor() : null;
+ }
+
+ public void setAccordingTo(Actor accordingTo) {
+ this.accordingTo = new AccordingTo(accordingTo, false);
+ }
+
+ public Actor getAccordingToRelation() {
+ return accordingTo != null ? accordingTo.getActor() : null;
+ }
+
+ public void setAccordingToRelation(Actor accordingTo) {
+ this.accordingTo = new AccordingTo(accordingTo, true);
+ }
+
+ public void setPrimary(Boolean primary) {
+ this.primary = primary;
+ }
+
+ @XmlAccessorType(XmlAccessType.FIELD)
+ @XmlType(name = "", propOrder = {
+ "taxonName"
+ })
+ public static class HasName extends LinkType {
+ @XmlElement(name = "TaxonName", namespace = "http://rs.tdwg.org/ontology/voc/TaxonName#")
+ private TaxonName taxonName;
+
+ protected HasName() {}
+
+ protected HasName(TaxonName taxonName, boolean useRelation) {
+ if(useRelation) {
+ if(taxonName != null && taxonName.getIdentifier() != null) {
+ this.setResource(taxonName.getIdentifier());
+ } else {
+ this.taxonName = taxonName;
+ }
+ } else {
+ this.taxonName = taxonName;
+ }
+ }
+
+ protected TaxonName getTaxonName() {
+ return taxonName;
+ }
+
+ protected void setTaxonName(TaxonName taxonName) {
+ this.taxonName = taxonName;
+ }
+ }
+
+ @XmlAccessorType(XmlAccessType.FIELD)
+ @XmlType(name = "", propOrder = {
+ "relationship"
+ })
+ public static class HasRelationship extends LinkType {
+
+ @XmlElement(name = "Relationship")
+ private Relationship relationship;
+
+ protected HasRelationship() {}
+
+ protected HasRelationship(Relationship relationship) {
+ this.relationship = relationship;
+ }
+
+ protected Relationship getRelationship() {
+ return relationship;
+ }
+
+ protected void setRelationship(Relationship relationship) {
+ this.relationship = relationship;
+ }
+ }
+
+ @XmlAccessorType(XmlAccessType.FIELD)
+ @XmlType(name = "", propOrder = {
+ "actor"
+ })
+ public static class AccordingTo extends LinkType {
+
+ @XmlElements({
+ @XmlElement(name = "Person", namespace = "http://rs.tdwg.org/ontology/voc/Person#", type = Person.class),
+ @XmlElement(name = "Team", namespace = "http://rs.tdwg.org/ontology/voc/Team#", type = Team.class)
+ })
+ private Actor actor;
+
+ protected AccordingTo() {}
+
+ protected AccordingTo(Actor actor, boolean useRelation) {
+ if(useRelation) {
+ if(actor != null && actor.getIdentifier() != null) {
+ this.setResource(actor.getIdentifier());
+ } else {
+ this.actor = actor;
+ }
+ } else {
+ this.actor = actor;
+ }
+ }
+
+ protected Actor getActor() {
+ return actor;
+ }
+
+ protected void setActor(Actor actor) {
+ this.actor = actor;
+ }
+ }
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.tdwg.voc;\r
+\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlElement;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+import javax.xml.bind.annotation.XmlType;\r
+\r
+import eu.etaxonomy.cdm.remote.dto.tdwg.Name;\r
+\r
+@XmlAccessorType(XmlAccessType.FIELD)\r
+@XmlType(name = "TaxonName", propOrder = {\r
+ "authorship",\r
+ "nameComplete"\r
+})\r
+@XmlRootElement(name = "TaxonName", namespace = "http://rs.tdwg.org/ontology/voc/TaxonName#")\r
+public class TaxonName extends Name {\r
+ \r
+ @XmlElement(namespace = "http://rs.tdwg.org/ontology/voc/TaxonName#")\r
+ private String authorship;\r
+ \r
+ @XmlElement(namespace = "http://rs.tdwg.org/ontology/voc/TaxonName#")\r
+ private String nameComplete;\r
+\r
+ public String getAuthorship() {\r
+ return authorship;\r
+ }\r
+\r
+ public void setAuthorship(String authorship) {\r
+ this.authorship = authorship;\r
+ }\r
+\r
+ public String getNameComplete() {\r
+ return nameComplete;\r
+ }\r
+\r
+ public void setNameComplete(String nameComplete) {\r
+ this.nameComplete = nameComplete;\r
+ }\r
+\r
+}\r
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.tdwg.voc;\r
+\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+import javax.xml.bind.annotation.XmlType;\r
+\r
+import eu.etaxonomy.cdm.remote.dto.tdwg.DefinedTerm;\r
+\r
+@XmlAccessorType(XmlAccessType.FIELD)\r
+@XmlType(name = "TaxonRelationshipTerm", propOrder = {})\r
+@XmlRootElement(name = "TaxonRelationshipTerm", namespace = "http://rs.tdwg.org/ontology/voc/TaxonConcept#")\r
+public class TaxonRelationshipTerm extends DefinedTerm {\r
+\r
+}\r
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.tdwg.voc;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import eu.etaxonomy.cdm.remote.dto.tdwg.Actor;
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "Team", propOrder = {
+})
+@XmlRootElement(name = "Team", namespace = "http://rs.tdwg.org/ontology/voc/Team#")
+public class Team extends Actor {
+
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.editor;
+
+import java.beans.PropertyEditorSupport;
+
+import eu.etaxonomy.cdm.model.common.LSIDAuthority;
+import com.ibm.lsid.MalformedLSIDException;
+
+public class LSIDAuthorityPropertyEditor extends PropertyEditorSupport {
+ public void setAsText(String text) {
+ try {
+ setValue(new LSIDAuthority(text));
+ } catch (MalformedLSIDException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.editor;
+
+import java.beans.PropertyEditorSupport;
+import eu.etaxonomy.cdm.model.common.LSID;
+
+import com.ibm.lsid.MalformedLSIDException;
+
+public class LSIDPropertyEditor extends PropertyEditorSupport {
+ public void setAsText(String text) {
+ try {
+ setValue(new LSID(text));
+ } catch (MalformedLSIDException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.exception;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.web.servlet.ModelAndView;
+import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
+
+import com.ibm.lsid.LSIDException;
+
+public class CdmExceptionResolver extends SimpleMappingExceptionResolver {
+ public static String LSID_ERROR_CODE_HEADER = "LSID-Error-Code";
+
+ @Override
+ protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception) {
+ if(exception instanceof LSIDException) {
+ LSIDException lsidException = (LSIDException) exception;
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ response.addHeader(CdmExceptionResolver.LSID_ERROR_CODE_HEADER,Integer.toString(lsidException.getErrorCode()));
+ }
+ return super.doResolveException(request, response, handler, exception);
+ }
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.service;
+
+import eu.etaxonomy.cdm.api.service.lsid.LSIDAuthorityService;
+import eu.etaxonomy.cdm.model.common.LSID;
+import eu.etaxonomy.cdm.model.common.LSIDAuthority;
+import eu.etaxonomy.cdm.remote.editor.LSIDAuthorityPropertyEditor;
+import eu.etaxonomy.cdm.remote.editor.LSIDPropertyEditor;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.WebDataBinder;
+import org.springframework.web.bind.annotation.InitBinder;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.servlet.ModelAndView;
+
+import com.ibm.lsid.ExpiringResponse;
+import com.ibm.lsid.LSIDException;
+
+import com.ibm.lsid.server.LSIDServerException;
+
+/**
+ * Controller which accepts incoming requests to the LSIDAuthorityService
+ * This controller has three methods. Using ControllerClassNameHandlerMapping means that
+ * any requests to /authority/ get handled by this controller.
+ *
+ * To allow the Spring DispatcherServlet to handle /authority/, /authority/notify/ and
+ * /authority/revoke/ directly, you need to add the following mappings to your web.xml
+ *
+ * <servlet-mapping>
+ * <servlet-name>${servlet.name}</servlet-name>
+ * <url-pattern>/authority/</url-pattern>
+ * </servlet-mapping>
+ * <servlet-mapping>
+ * <servlet-name>${servlet.name}</servlet-name>
+ * <url-pattern>/authority/revoke/</url-pattern>
+ * </servlet-mapping>
+ * <servlet-mapping>
+ * <servlet-name>${servlet.name}</servlet-name>
+ * <url-pattern>/authority/notify/</url-pattern>
+ * </servlet-mapping>
+ *
+ * You also need to use some kind of MethodNameResolver - AuthorityMethodNameResolver
+ * maps the request to the correct method using the request URL.
+ *
+ * @author ben
+ * @author Ben Szekely (<a href="mailto:bhszekel@us.ibm.com">bhszekel@us.ibm.com</a>)
+ * @see org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping
+ * @see org.cateproject.controller.interceptor.lsid.AuthorityMethodNameResolver
+ * @see com.ibm.lsid.server.servlet.AuthorityServlet
+ */
+@Controller
+public class AuthorityController {
+ private static Log log = LogFactory.getLog(AuthorityController.class);
+ private LSIDAuthorityService lsidAuthorityService;
+
+ @Autowired
+ public void setLsidAuthorityService(LSIDAuthorityService lsidAuthorityService) {
+ this.lsidAuthorityService = lsidAuthorityService;
+ }
+
+ @InitBinder
+ public void initBinder(WebDataBinder binder) {
+ binder.registerCustomEditor(LSID.class, new LSIDPropertyEditor());
+ binder.registerCustomEditor(LSIDAuthority.class, new LSIDAuthorityPropertyEditor());
+ }
+
+ /**
+ * Get the available services of this LSIDAuthority as a wsdl document
+ *
+ * @return ModelAndView containing the WSDL as a javax.xml.transform.Source, view name 'Authority.wsdl'
+ * @throws LSIDServerException
+ * @see javax.xml.transform.Source
+ */
+ @RequestMapping(value="/authority/",params="!lsid")
+ public ModelAndView getAvailableServices() throws LSIDServerException {
+ ExpiringResponse expiringResponse = lsidAuthorityService.getAuthorityWSDL();
+ return new ModelAndView("Authority.wsdl","source",expiringResponse.getValue());
+ }
+
+ /**
+ * Get the available services for a given lsid
+ *
+ * @return ModelAndView containing the WSDL as a javax.xml.transform.Source, view name 'Services.wsdl'
+ * @param LSID the lsid to query the service with
+ * @throws LSIDServerException
+ * @see javax.xml.transform.Source
+ */
+ @RequestMapping(value="/authority/",params="lsid")
+ public ModelAndView getAvailableServices(@RequestParam("lsid")LSID lsid) throws LSIDServerException {
+ ExpiringResponse expiringResponse = lsidAuthorityService.getAvailableServices(lsid);
+ return new ModelAndView("Services.wsdl","source",expiringResponse.getValue());
+ }
+
+ /**
+ * Notify the authority that another authority resolves the object with the given identifier
+ *
+ * @param lsid the LSID to notify the authority about
+ * @param authorityName the foreign authority
+ * @return ModelAndView (null)
+ * @throws LSIDServerException
+ */
+ @RequestMapping(value="/authority/notify/",params={"lsid","authorityName"})
+ public ModelAndView notifyForeignAuthority(@RequestParam("lsid")LSID lsid,
+ @RequestParam("authorityName")LSIDAuthority lsidAuthority) throws LSIDServerException {
+ lsidAuthorityService.notifyForeignAuthority(lsid,lsidAuthority);
+ return null;
+ }
+
+ /**
+ * Maps to the notify path without the required params
+ *
+ * @throws LSIDServerException
+ */
+ @RequestMapping(value="/authority/notify/")
+ public ModelAndView notifyForeignAuthority() throws LSIDException {
+ throw new LSIDException(LSIDException.INVALID_METHOD_CALL, "You must supply an lsid and an lsidAuthority");
+ }
+
+ /**
+ * Notify the authority that another authority no longer resolves the object with the given identifier
+ *
+ * @param lsid the LSID to notify the authority about
+ * @param authorityName the foreign authority
+ * @return ModelAndView (null)
+ * @throws LSIDServerException
+ */
+ @RequestMapping(value="/authority/revoke/",params={"lsid","authorityName"})
+ public ModelAndView revokeNotificationForeignAuthority(@RequestParam("lsid")LSID lsid,
+ @RequestParam("authorityName")LSIDAuthority lsidAuthority) throws LSIDServerException {
+ lsidAuthorityService.revokeNotificationForeignAuthority(lsid,lsidAuthority);
+ return null;
+ }
+
+ /**
+ * Maps to the revoke path without the required params
+ *
+ * @throws LSIDServerException
+ */
+ @RequestMapping(value="/authority/revoke/")
+ public ModelAndView revokeNotificationForeignAuthority() throws LSIDException {
+ throw new LSIDException(LSIDException.INVALID_METHOD_CALL, "You must supply an lsid and an lsidAuthority");
+ }
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.service;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.servlet.http.HttpServletResponse;
+
+import eu.etaxonomy.cdm.model.common.LSID;
+import eu.etaxonomy.cdm.remote.editor.LSIDPropertyEditor;
+import eu.etaxonomy.cdm.api.service.lsid.LSIDDataService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.WebDataBinder;
+import org.springframework.web.bind.annotation.InitBinder;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.servlet.ModelAndView;
+
+import com.ibm.lsid.LSIDException;
+import com.ibm.lsid.server.LSIDServerException;
+
+/**
+ * Controller which accepts requests for the data representation of an object
+ * with a given lsid. The response is written directly into the request, rather
+ * than being passed as part of the ModelAndView since data is supposed to be
+ * byte-identical and thus cannot be transformed by the view layer.
+ *
+ * @author ben
+ * @author Ben Szekely (<a href="mailto:bhszekel@us.ibm.com">bhszekel@us.ibm.com</a>)
+ * @see com.ibm.lsid.server.servlet.DataServlet
+ */
+@Controller
+public class DataController {
+
+ private LSIDDataService lsidDataService;
+
+ @Autowired
+ public void setLsidDataService(LSIDDataService lsidDataService) {
+ this.lsidDataService = lsidDataService;
+ }
+
+ @InitBinder
+ public void initBinder(WebDataBinder binder) {
+ binder.registerCustomEditor(LSID.class, new LSIDPropertyEditor());
+ }
+
+ /**
+ * Handle requests for the data representation of an object with a given lsid. Can return only part of the
+ * data if the length and offset are specified in the request as per the specification.
+ *
+ * @param LSID lsid the lsid to retrieve data for
+ * @param Integer start the offset in bytes to read from
+ * @param Integer length the number of bytes to return
+ * @return ModelAndView (null)
+ * @throws LSIDServerException
+ * @throws IOException
+ */
+ @RequestMapping(value = "/authority/data.do",params = {"lsid","start","length"})
+ public ModelAndView getData(@RequestParam("lsid") LSID lsid,
+ @RequestParam("start") Integer start,
+ @RequestParam("length") Integer length,
+ HttpServletResponse response) throws LSIDServerException, IOException {
+ OutputStream out = null;
+ InputStream data = null;
+ try {
+ data = lsidDataService.getDataByRange(lsid,start,length);
+ if(data != null) {
+ response.setContentType("application/octet-stream");
+ byte[] bytes = new byte[1024];
+ int numbytes = data.read(bytes);
+ while (numbytes != -1) {
+ out.write(bytes,0,numbytes);
+ numbytes = data.read(bytes);
+ }
+ out.flush();
+ }
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+
+ if (data != null) {
+ data.close();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Handle requests for the data representation of an object with a given lsid.
+ *
+ * @param LSID lsid the lsid to retrieve data for
+ * @return ModelAndView (null)
+ * @throws LSIDServerException
+ * @throws IOException
+ */
+ @RequestMapping(value = "/authority/data.do",params = {"lsid"})
+ public ModelAndView getData(@RequestParam("lsid")LSID lsid,
+ HttpServletResponse response) throws LSIDServerException, IOException {
+ OutputStream out = null;
+ InputStream data = null;
+ try {
+ data = lsidDataService.getData(lsid);
+ if(data != null) {
+ response.setContentType("application/octet-stream");
+ out = response.getOutputStream();
+ byte[] bytes = new byte[1024];
+ int numbytes = data.read(bytes);
+ while (numbytes != -1) {
+ out.write(bytes,0,numbytes);
+ numbytes = data.read(bytes);
+ }
+ out.flush();
+ }
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+
+ if (data != null) {
+ data.close();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Handle requests for the data representation of an object without an lsid.
+ *
+ * @throws LSIDServerException
+ */
+ @RequestMapping(value = "/authority/data.do")
+ public ModelAndView getData() throws LSIDException {
+ throw new LSIDException(LSIDException.INVALID_METHOD_CALL, "Must specify HTTP Parameter 'lsid'");
+ }
+
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.service;
+
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import eu.etaxonomy.cdm.api.service.lsid.LSIDMetadataService;
+import eu.etaxonomy.cdm.model.common.LSID;
+import eu.etaxonomy.cdm.remote.editor.LSIDPropertyEditor;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.WebDataBinder;
+import org.springframework.web.bind.annotation.InitBinder;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.servlet.ModelAndView;
+
+import com.ibm.lsid.LSIDException;
+import com.ibm.lsid.MetadataResponse;
+import com.ibm.lsid.server.LSIDServerException;
+
+/**
+ * Controller which accepts requests for the metadata representation of an object
+ * with a given lsid.
+ *
+ * @author ben
+ * @author Ben Szekely (<a href="mailto:bhszekel@us.ibm.com">bhszekel@us.ibm.com</a>)
+ * @see com.ibm.lsid.server.servlet.MetadataServlet
+ */
+@Controller
+public class MetadataController {
+
+ private LSIDMetadataService lsidMetadataService;
+
+ @Autowired
+ public void setLsidMetadataService(LSIDMetadataService lsidMetadataService) {
+ this.lsidMetadataService = lsidMetadataService;
+ }
+
+ @InitBinder
+ public void initBinder(WebDataBinder binder) {
+ binder.registerCustomEditor(LSID.class, new LSIDPropertyEditor());
+ }
+
+ /**
+ * Handle requests for the metadata representation of an object with a given lsid. Will return metadata in any format supported
+ * from a list of formats if specified.
+ *
+ * @param lsid the lsid to get metadata for
+ * @param formats a comma separated list of acceptable formats to the client
+ * @return ModelAndView containing the metadata response as an object with key 'metadataResponse', view name 'Metadata.rdf'
+ * @throws LSIDServerException
+ */
+ @RequestMapping(value = "/authority/metadata.do", params = "lsid")
+ public ModelAndView getMetadata(@RequestParam("lsid") LSID lsid,
+ @RequestParam(value = "acceptedFormats", required = false) String formats) throws LSIDServerException {
+ String[] acceptedFormats = null;
+ if (formats != null) {
+ StringTokenizer st = new StringTokenizer(formats,",",false);
+ Vector<String> v = new Vector<String>();
+ while (st.hasMoreTokens()) {
+ v.add(st.nextToken());
+ }
+ acceptedFormats = new String[v.size()];
+ v.toArray(acceptedFormats);
+ }
+
+ MetadataResponse metadataResponse = lsidMetadataService.getMetadata(lsid, acceptedFormats);
+
+ return new ModelAndView("Metadata.rdf","metadataResponse",metadataResponse);
+ }
+
+ @RequestMapping(value = "/authority/metadata.do", params = "!lsid")
+ public ModelAndView getMetadata() throws LSIDException {
+ throw new LSIDException(LSIDException.INVALID_METHOD_CALL, "Must specify HTTP Parameter 'lsid'");
+ }
+
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.view;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.transform.stream.StreamResult;
+
+import net.sf.dozer.util.mapping.MapperIF;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.oxm.Marshaller;
+import org.springframework.web.servlet.view.AbstractView;
+
+import com.ibm.lsid.MetadataResponse;
+import com.ibm.lsid.http.HTTPConstants;
+
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.remote.dto.tdwg.BaseThing;
+import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonConcept;
+import eu.etaxonomy.remote.dto.rdf.Rdf;
+
+/**
+ * View class which takes a MetadataResponse and returns the Source for serialization
+ * @author ben
+ * @see javax.xml.transform.Source
+ * @see com.ibm.lsid.MetadataResponse
+ */
+public class RdfView extends AbstractView {
+
+ private Marshaller marshaller;
+
+ private MapperIF mapper;
+
+ private Map<Class<? extends CdmBase>,Class<? extends BaseThing>> classMap = new HashMap<Class<? extends CdmBase>,Class<? extends BaseThing>>();
+
+ public RdfView() {
+ classMap.put(Taxon.class, TaxonConcept.class);
+ }
+
+ @Autowired
+ public void setMarshaller(Marshaller marshaller) {
+ this.marshaller = marshaller;
+ }
+
+ @Autowired
+ public void setMapper(MapperIF mapper) {
+ this.mapper = mapper;
+ }
+
+ @Override
+ protected void renderMergedOutputModel(Map model,HttpServletRequest request, HttpServletResponse response)
+ throws Exception {
+ MetadataResponse metadataResponse = (MetadataResponse)model.get("metadataResponse");
+ if(metadataResponse.getExpires() != null) {
+ response.setHeader(HTTPConstants.EXPIRES_HEADER, HTTPConstants.HTTP_DATE_FORMAT.format(metadataResponse.getExpires()));
+ }
+
+ CdmBase object = (CdmBase)metadataResponse.getValue();
+ Class clazz = classMap.get(object.getClass());
+ Rdf rdf = new Rdf();
+ rdf.addThing((BaseThing)mapper.map(object, clazz));
+ marshaller.marshal(rdf, new StreamResult(response.getOutputStream()));
+ }
+
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.view;
+
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.transform.Source;
+
+import org.springframework.web.servlet.view.xslt.AbstractXsltView;
+
+/**
+ * View class which returns the Source for serialization
+ * @author ben
+ * @see javax.xml.transform.Source
+ */
+public class WsdlView extends AbstractXsltView {
+ protected Source createXsltSource(Map model, String rootName, HttpServletRequest
+ request, HttpServletResponse response) throws Exception {
+ return (Source) model.get("source");
+ }
+
+}
--- /dev/null
+//\r
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.0.1-b01-fcs \r
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
+// Any modifications to this file will be lost upon recompilation of the source schema. \r
+// Generated on: 2007.08.01 at 10:51:47 AM BST \r
+//\r
+\r
+\r
+package eu.etaxonomy.remote.dto.rdf;\r
+\r
+import java.util.HashSet;\r
+import java.util.Set;\r
+\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlElement;\r
+import javax.xml.bind.annotation.XmlElements;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+import javax.xml.bind.annotation.XmlType;\r
+\r
+import eu.etaxonomy.cdm.remote.dto.tdwg.BaseThing;\r
+import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonConcept;\r
+\r
+\r
+@XmlAccessorType(XmlAccessType.FIELD)\r
+@XmlType(name = "", propOrder = {\r
+ "things"\r
+})\r
+@XmlRootElement(name = "RDF", namespace = "http://www.w3.org/1999/02/22-rdf-syntax-ns#")\r
+public class Rdf {\r
+\r
+ @XmlElements({\r
+ @XmlElement(name = "TaxonConcept", namespace = "http://rs.tdwg.org/ontology/voc/TaxonConcept#", type = TaxonConcept.class)\r
+ })\r
+ protected Set<BaseThing> things = new HashSet<BaseThing>();\r
+\r
+ public Set<BaseThing> getThings() {\r
+ return things;\r
+ }\r
+\r
+ public void addThing(BaseThing thing) {\r
+ this.things.add(thing);\r
+ }\r
+ \r
+ public void removeThing(BaseThing thing) {\r
+ this.things.remove(thing);\r
+ }\r
+}\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
+ ">
+
+ <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
+ <property name="classesToBeBound">
+ <list>
+ <value>eu.etaxonomy.remote.dto.rdf.Rdf</value>
+ <value>eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonConcept</value>
+ </list>
+ </property>
+ <property name="marshallerProperties">
+ <map>
+ <entry key="com.sun.xml.bind.namespacePrefixMapper">
+ <bean class="eu.etaxonomy.cdm.jaxb.TDWGNamespacePrefixMapper"/>
+ </entry>
+ </map>
+ </property>
+ </bean>
+
+ <bean id="dozerMapper" class="eu.etaxonomy.cdm.remote.dto.assembler.DozerBeanMapperFactoryBean">
+ <property name="mappingFiles">
+ <list>
+ <value>classpath:/eu/etaxonomy/cdm/remote/dto/tdwg/mappings.xml</value>
+ <value>classpath:/eu/etaxonomy/cdm/remote/dto/tdwg/mappings-deep.xml</value>
+ <!--
+ Substitute mappings-deep.xml to prefer relations in objects over embedded relations
+ <value>classpath:/eu/etaxonomy/cdm/remote/dto/tdwg/mappings-shallow.xml</value>-->
+ </list>
+ </property>
+ <property name="customFieldMapper">
+ <bean class="eu.etaxonomy.cdm.remote.dto.assembler.converter.HibernateProxyFieldMapper"/>
+ </property>
+ <property name="customConvertersWithId">
+ <map>
+ <entry key="lsidProxyConverter" value-ref="lsidProxyConverter"/>
+ <entry key="lsidConverter">
+ <bean class="eu.etaxonomy.cdm.remote.dto.assembler.converter.LsidConverter"/>
+ </entry>
+ <entry key="dateTimeConverter">
+ <bean class="eu.etaxonomy.cdm.remote.dto.assembler.converter.DateTimeConverter"/>
+ </entry>
+ <entry key="hibernateProxyDeepConverter">
+ <bean class="eu.etaxonomy.cdm.remote.dto.assembler.converter.HibernateProxyNullSafeDeepConverter"/>
+ </entry>
+ <entry key="preferLsidToUriConverter">
+ <bean class="eu.etaxonomy.cdm.remote.dto.assembler.converter.PreferLsidToUriConverter"/>
+ </entry>
+ </map>
+ </property>
+ </bean>
+
+ <bean name="lsidProxyConverter" class="eu.etaxonomy.cdm.remote.dto.assembler.converter.LsidProxyConverter"/>
+</beans>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mappings PUBLIC "-//DOZER//DTD MAPPINGS//EN"
+ "http://dozer.sourceforge.net/dtd/dozerbeanmapping.dtd">
+<mappings>
+ <!-- taxon package -->
+
+ <mapping>
+ <class-a>eu.etaxonomy.cdm.model.taxon.Taxon</class-a>
+ <class-b>eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonConcept</class-b>
+ <field>
+ <a>sec</a>
+ <b>publishedInCitation</b>
+ </field>
+ <field type="one-way" custom-converter-id="hibernateProxyDeepConverter" custom-converter-param="authorTeam">
+ <a>sec</a>
+ <b>accordingTo</b>
+ </field>
+ <field>
+ <a>name</a>
+ <b>hasName</b>
+ </field>
+ <field>
+ <a>relationsToThisTaxon</a>
+ <b>hasRelationship</b>
+ </field>
+ </mapping>
+
+ <mapping>
+ <class-a>eu.etaxonomy.cdm.model.taxon.TaxonRelationship</class-a>
+ <class-b>eu.etaxonomy.cdm.remote.dto.tdwg.voc.Relationship</class-b>
+ <field>
+ <a>type</a>
+ <b>relationshipCategory</b>
+ </field>
+ </mapping>
+
+</mappings>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mappings PUBLIC "-//DOZER//DTD MAPPINGS//EN"
+ "http://dozer.sourceforge.net/dtd/dozerbeanmapping.dtd">
+<mappings>
+
+ <!-- taxon package -->
+
+ <mapping>
+ <class-a>eu.etaxonomy.cdm.model.taxon.Taxon</class-a>
+ <class-b>eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonConcept</class-b>
+ <field>
+ <a>sec</a>
+ <b>publishedInCitationRelation</b>
+ </field>
+ <field type="one-way" custom-converter-id="hibernateProxyDeepConverter" custom-converter-param="authorTeam">
+ <a>sec</a>
+ <b>accordingToRelation</b>
+ </field>
+ <field>
+ <a>name</a>
+ <b>hasNameRelation</b>
+ </field>
+ <field>
+ <a>relationsToThisTaxon</a>
+ <b>hasRelationship</b>
+ </field>
+ </mapping>
+
+ <mapping>
+ <class-a>eu.etaxonomy.cdm.model.taxon.TaxonRelationship</class-a>
+ <class-b>eu.etaxonomy.cdm.remote.dto.tdwg.voc.Relationship</class-b>
+ <field>
+ <a>type</a>
+ <b>relationshipCategoryRelation</b>
+ </field>
+ </mapping>
+
+</mappings>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mappings PUBLIC "-//DOZER//DTD MAPPINGS//EN"
+ "http://dozer.sourceforge.net/dtd/dozerbeanmapping.dtd">
+<mappings>
+ <!-- agent package -->
+ <mapping>
+ <class-a>eu.etaxonomy.cdm.model.agent.Person</class-a>
+ <class-b>eu.etaxonomy.cdm.remote.dto.tdwg.voc.Person</class-b>
+ </mapping>
+
+ <mapping>
+ <class-a>eu.etaxonomy.cdm.model.agent.Team</class-a>
+ <class-b>eu.etaxonomy.cdm.remote.dto.tdwg.voc.Team</class-b>
+ </mapping>
+ <!-- common package -->
+ <mapping>
+ <class-a>eu.etaxonomy.cdm.model.common.DefinedTermBase</class-a>
+ <class-b>eu.etaxonomy.cdm.remote.dto.tdwg.DefinedTerm</class-b>
+ <field custom-converter-id="preferLsidToUriConverter">
+ <a>uri</a>
+ <b>identifier</b>
+ </field>
+ </mapping>
+
+ <mapping>
+ <class-a>eu.etaxonomy.cdm.model.common.IdentifiableEntity</class-a>
+ <class-b>eu.etaxonomy.cdm.remote.dto.tdwg.BaseThing</class-b>
+ <field>
+ <a>titleCache</a>
+ <b>title</b>
+ </field>
+ <field custom-converter-id="lsidConverter">
+ <a>lsid</a>
+ <b>identifier</b>
+ </field>
+ <field type="one-way" custom-converter-id="lsidProxyConverter">
+ <a>lsid</a>
+ <b>sameAs</b>
+ </field>
+ <field custom-converter-id="dateTimeConverter">
+ <a>created</a>
+ <b>created</b>
+ </field>
+ </mapping>
+ <!-- name package -->
+
+ <mapping>
+ <class-a>eu.etaxonomy.cdm.model.name.NonViralName</class-a>
+ <class-b>eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonName</class-b>
+ <field>
+ <a>authorshipCache</a>
+ <b>authorship</b>
+ </field>
+ <field>
+ <a>nameCache</a>
+ <b>nameComplete</b>
+ </field>
+ </mapping>
+
+</mappings>
--- /dev/null
+package eu.etaxonomy.cdm.remote.dto.assembler.lsid;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.Serializable;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+import net.sf.dozer.util.mapping.MapperIF;
+
+import org.hibernate.Hibernate;
+import org.hibernate.HibernateException;
+import org.hibernate.LazyInitializationException;
+import org.hibernate.collection.PersistentCollection;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.proxy.HibernateProxy;
+import org.hibernate.proxy.LazyInitializer;
+import org.joda.time.DateTime;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.unitils.UnitilsJUnit4;
+import org.unitils.spring.annotation.SpringApplicationContext;
+import org.unitils.spring.annotation.SpringBeanByType;
+
+import eu.etaxonomy.cdm.model.agent.Person;
+import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
+import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
+import eu.etaxonomy.cdm.model.common.LSID;
+import eu.etaxonomy.cdm.model.name.BotanicalName;
+import eu.etaxonomy.cdm.model.name.NonViralName;
+import eu.etaxonomy.cdm.model.reference.Book;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
+import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonConcept;
+
+@SpringApplicationContext("file:./target/test-classes/eu/etaxonomy/cdm/applicationContext-test.xml")
+public class AssemblerTest extends UnitilsJUnit4 {
+
+ @SpringBeanByType
+ private MapperIF mapper;
+
+ private Taxon taxon;
+ private Book sec;
+ private TeamOrPersonBase authorTeam;
+ private NonViralName name;
+ private LSID lsid;
+
+ @BeforeClass
+ public static void onSetUp() {
+ DefaultTermInitializer defaultTermInitializer = new DefaultTermInitializer();
+ defaultTermInitializer.initialize();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ lsid = new LSID("urn:lsid:example.org:taxonconcepts:1");
+
+ authorTeam = Person.NewInstance();
+ authorTeam.setTitleCache("authorTeam.titleCache");
+
+ name = BotanicalName.NewInstance(null);
+ name.setNameCache("nameCache");
+ name.setAuthorshipCache("authorshipCache");
+
+ sec = Book.NewInstance();
+ sec.setAuthorTeam(authorTeam);
+ sec.setTitleCache("sec.titleCache");
+ sec.setLsid(new LSID("urn:lsid:example.org:references:1"));
+
+ taxon = Taxon.NewInstance(name, sec);
+ taxon.setCreated(new DateTime(2004, 12, 25, 12, 0, 0, 0));
+ taxon.setTitleCache("titleCache");
+ taxon.setLsid(lsid);
+
+ for(int i = 0; i < 10; i++) {
+ Taxon child = Taxon.NewInstance(name, sec);
+ taxon.addTaxonomicChild(child, null,null);
+ }
+ }
+
+ @Test
+ public void testDeepMapping() {
+ TaxonConcept taxonConcept = (TaxonConcept)mapper.map(taxon, TaxonConcept.class);
+ assertNotNull("map() should return an object", taxonConcept);
+ assertTrue("map() should return a TaxonConcept",taxonConcept instanceof TaxonConcept);
+
+ assertEquals("IdentifiableEntity.titleCache should be copied into BaseThing.title",taxon.getTitleCache(),taxonConcept.getTitle());
+ assertEquals("IdentifiableEntity.lsid should be copied into BaseThing.identifier",taxon.getLsid().toString(),taxonConcept.getIdentifier().toString());
+ assertEquals("BaseThing.sameAs should refer to the proxy version of the lsid","http://lsid.example.org/" + taxon.getLsid().toString(),taxonConcept.getSameAs());
+ assertEquals("CdmBase.created should be copied into BaseThing.created",new DateTime(2004, 12, 25, 12, 0, 0, 0),taxonConcept.getCreated());
+ assertNotNull("TaxonBase.sec should be mapped into BaseThing.publishedInCitation",taxonConcept.getPublishedInCitation());
+ assertEquals("TaxonBase.sec.titleCache should be mapped into BaseThing.publishedInCitation.title",sec.getTitleCache(),taxonConcept.getPublishedInCitation().getTitle());
+ assertNotNull("TaxonBase.sec.authorTeam should be mapped into TaxonConcept.accordingTo",taxonConcept.getAccordingTo());
+ assertEquals("TaxonBase.sec.authorTeam.titleCache should be mapped into TaxonConcept.accordingTo.title",authorTeam.getTitleCache(),taxonConcept.getAccordingTo().getTitle());
+ assertNotNull("TaxonBase.name should be mapped to TaxonConcept.hasName",taxonConcept.getHasName());
+ assertEquals("NonViralName.nameCache should be mapped to TaxonName.nameComplete",name.getNameCache(),taxonConcept.getHasName().getNameComplete());
+ assertNotNull("Taxon.relationsToThisTaxon should be copied into TaxonConcept.hasRelationship",taxonConcept.getHasRelationship());
+ assertEquals("There should be 10 relations in TaxonConcept.hasRelationship",10,taxonConcept.getHasRelationship().size());
+ }
+
+ @Test
+ public void testLazyInitializationExceptionWithProxy() throws Exception {
+ Book proxy = getUninitializedDetachedProxy(Book.class,sec);
+ assert !Hibernate.isInitialized(proxy);
+ Field secField = TaxonBase.class.getDeclaredField("sec");
+ secField.setAccessible(true);
+ secField.set(taxon, proxy);
+
+ TaxonConcept taxonConcept = (TaxonConcept)mapper.map(taxon, TaxonConcept.class);
+ assertNull("TaxonBase.sec was uninitialized, so TaxonConcept.publishedInCitation should be null",taxonConcept.getPublishedInCitation());
+ assertNull("TaxonBase.sec was uninitialized, so TaxonConcept.accordingTo should be null",taxonConcept.getAccordingTo());
+ }
+
+ @Test
+ public void testLazyInitializationExceptionWithPersistentCollection() throws Exception {
+ Set<TaxonRelationship> proxy = (Set<TaxonRelationship>)getUninitializedPersistentCollection(HashSet.class,(HashSet<TaxonRelationship>)taxon.getRelationsToThisTaxon());
+ assert !Hibernate.isInitialized(proxy);
+ Field relationsToThisTaxonField = Taxon.class.getDeclaredField("relationsToThisTaxon");
+ relationsToThisTaxonField.setAccessible(true);
+ relationsToThisTaxonField.set(taxon, proxy);
+
+ TaxonConcept taxonConcept = (TaxonConcept)mapper.map(taxon, TaxonConcept.class);
+ assertNull("TaxonBase.relationsToThisTaxon was uninitialized, so TaxonConcept.hasRelationship should be null",taxonConcept.getHasRelationship());
+ }
+
+ private <T extends Collection> T getUninitializedPersistentCollection(final Class<T> clazz,final T wrappedCollection) {
+ final Enhancer enhancer = new Enhancer();
+ List<Class> interfaces = new ArrayList<Class>();
+ interfaces.addAll(Arrays.asList(clazz.getInterfaces()));
+ interfaces.add(PersistentCollection.class);
+ enhancer.setSuperclass(clazz);
+ enhancer.setInterfaces(interfaces.toArray(new Class[interfaces.size()]));
+ enhancer.setCallback( new MethodInterceptor() {
+ public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
+ if("wasInitialized".equals(method.getName())) {
+ return false;
+ } else if(clazz.getDeclaredConstructor().equals(method)){
+ return proxy.invoke(obj, args);
+ } else if("finalize".equals(method.getName())){
+ return proxy.invoke(obj, args);
+ } else if("toString".equals(method.getName())) {
+ return wrappedCollection.toString();
+ } else if("getClass".equals(method.getName())) {
+ return proxy.invoke(obj, args);
+ } else if("hashCode".equals(method.getName())) {
+ return wrappedCollection.hashCode();
+ } else {
+ throw new LazyInitializationException(null);
+ }
+
+ }
+ });
+
+ T proxy = (T)enhancer.create();
+ return proxy;
+ }
+
+ private <T> T getUninitializedDetachedProxy(final Class<T> clazz,final T wrappedClass) {
+ final Enhancer enhancer = new Enhancer();
+ List<Class> interfaces = new ArrayList<Class>();
+ interfaces.addAll(Arrays.asList(clazz.getInterfaces()));
+ interfaces.add(HibernateProxy.class);
+ enhancer.setSuperclass(clazz);
+ enhancer.setInterfaces(interfaces.toArray(new Class[interfaces.size()]));
+ enhancer.setCallback( new MethodInterceptor() {
+ public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
+ if("getHibernateLazyInitializer".equals(method.getName())) {
+ return new UninitializedLazyInitializer();
+ } else if(clazz.getDeclaredConstructor().equals(method)){
+ return proxy.invoke(obj, args);
+ } else if("finalize".equals(method.getName())){
+ return proxy.invoke(obj, args);
+ } else if("toString".equals(method.getName())) {
+ return wrappedClass.toString();
+ } else if("getClass".equals(method.getName())) {
+ return proxy.invoke(obj, args);
+ } else if("hashCode".equals(method.getName())) {
+ return wrappedClass.hashCode();
+ } else {
+ throw new LazyInitializationException(null);
+ }
+
+ }
+ });
+
+ T proxy = (T)enhancer.create();
+ return proxy;
+ }
+
+ class UninitializedLazyInitializer implements LazyInitializer {
+
+ public boolean isUninitialized() {
+ return true;
+ }
+
+ public String getEntityName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Serializable getIdentifier() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object getImplementation() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object getImplementation(SessionImplementor arg0)
+ throws HibernateException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Class getPersistentClass() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public SessionImplementor getSession() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void initialize() throws HibernateException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean isUnwrap() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void setIdentifier(Serializable arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setImplementation(Object arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setSession(SessionImplementor arg0)
+ throws HibernateException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setUnwrap(boolean arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ }
+
+
+
+
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.service;
+
+
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.test.web.ModelAndViewAssert;
+import org.springframework.web.servlet.ModelAndView;
+import org.unitils.UnitilsJUnit4;
+import org.unitils.easymock.annotation.Mock;
+import org.unitils.inject.annotation.InjectInto;
+import org.unitils.inject.annotation.TestedObject;
+
+import com.ibm.lsid.ExpiringResponse;
+import com.ibm.lsid.LSIDException;
+import com.ibm.lsid.MalformedLSIDException;
+
+import com.ibm.lsid.server.LSIDServerException;
+
+
+import eu.etaxonomy.cdm.api.service.lsid.LSIDAuthorityService;
+import eu.etaxonomy.cdm.model.common.LSID;
+import eu.etaxonomy.cdm.model.common.LSIDAuthority;
+import eu.etaxonomy.cdm.test.util.LSIDMatchers;
+
+public class AuthorityControllerTest extends UnitilsJUnit4 {
+
+ @Mock
+ @InjectInto(property = "lsidAuthorityService")
+ private LSIDAuthorityService authorityService;
+
+ @TestedObject
+ private AuthorityController authorityController;
+
+ private LSID lsid;
+ private LSIDAuthority lsidAuthority;
+ private Object source;
+ private ExpiringResponse expiringResponse;
+
+ @Before
+ public void setUp() {
+ try {
+ lsid = new LSID("urn:lsid:example.org:taxonconcept:1");
+ } catch (MalformedLSIDException e) { }
+
+ try {
+ lsidAuthority = new LSIDAuthority("fred.org");
+ } catch (MalformedLSIDException e) { }
+
+ authorityService = EasyMock.createMock(LSIDAuthorityService.class);
+ authorityController = new AuthorityController();
+ source = new Object();
+ expiringResponse = new ExpiringResponse(source, null);
+ }
+
+ @Test
+ public void testAuthorityWSDL() throws Exception {
+ EasyMock.expect(authorityService.getAuthorityWSDL()).andReturn(expiringResponse);
+ EasyMock.replay(authorityService);
+
+ ModelAndView modelAndView = authorityController.getAvailableServices();
+
+ EasyMock.verify(authorityService);
+ ModelAndViewAssert.assertViewName(modelAndView, "Authority.wsdl");
+ ModelAndViewAssert.assertModelAttributeValue(modelAndView, "source", source);
+ }
+
+ @Test
+ public void testGetServices() throws Exception {
+ EasyMock.expect(authorityService.getAvailableServices(LSIDMatchers.eqLSID(lsid))).andReturn(expiringResponse);
+ EasyMock.replay(authorityService);
+
+ ModelAndView modelAndView = authorityController.getAvailableServices(lsid);
+
+ EasyMock.verify(authorityService);
+ ModelAndViewAssert.assertViewName(modelAndView, "Services.wsdl");
+ ModelAndViewAssert.assertModelAttributeValue(modelAndView, "source",source);
+ }
+
+ @Test(expected = LSIDServerException.class)
+ public void testGetServicesWithUnknownLSID() throws Exception {
+ LSIDServerException lse = new LSIDServerException(LSIDException.UNKNOWN_LSID, "Unknown LSID");
+ EasyMock.expect(authorityService.getAvailableServices(LSIDMatchers.eqLSID(lsid))).andThrow(lse);
+ EasyMock.replay(authorityService);
+
+ authorityController.getAvailableServices(lsid);
+ }
+
+ @Test(expected = LSIDServerException.class)
+ public void testNotifyForeignAuthority() throws Exception {
+ LSIDServerException lse = new LSIDServerException(LSIDServerException.METHOD_NOT_IMPLEMENTED, "FAN service not available");
+
+ authorityService.notifyForeignAuthority(LSIDMatchers.eqLSID(lsid), LSIDMatchers.eqLSIDAuthority(lsidAuthority));
+ EasyMock.expectLastCall().andThrow(lse);
+
+ EasyMock.replay(authorityService);
+
+ authorityController.notifyForeignAuthority(lsid, lsidAuthority);
+ }
+
+ @Test(expected = LSIDServerException.class)
+ public void testRevokeForeignAuthority() throws Exception {
+ LSIDServerException lse = new LSIDServerException(LSIDServerException.METHOD_NOT_IMPLEMENTED, "FAN service not available");
+
+ authorityService.revokeNotificationForeignAuthority(LSIDMatchers.eqLSID(lsid), LSIDMatchers.eqLSIDAuthority(lsidAuthority));
+ EasyMock.expectLastCall().andThrow(lse);
+
+ EasyMock.replay(authorityService);
+ authorityController.revokeNotificationForeignAuthority(lsid, lsidAuthority);
+ }
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.service;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.web.servlet.ModelAndView;
+import org.unitils.UnitilsJUnit4;
+import org.unitils.easymock.annotation.Mock;
+import org.unitils.inject.annotation.InjectInto;
+import org.unitils.inject.annotation.TestedObject;
+
+import com.ibm.lsid.LSIDException;
+import com.ibm.lsid.MalformedLSIDException;
+import com.ibm.lsid.server.LSIDServerException;
+
+import eu.etaxonomy.cdm.api.service.lsid.LSIDDataService;
+import eu.etaxonomy.cdm.model.common.LSID;
+import eu.etaxonomy.cdm.test.util.LSIDMatchers;
+
+public class DataControllerTest extends UnitilsJUnit4 {
+
+ @Mock
+ @InjectInto(property = "lsidDataService")
+ LSIDDataService dataService;
+
+ @TestedObject
+ private DataController dataController;
+
+ private static String expectedData = "Acherontia Laspeyres 1809 sensu example.org 2007";
+ private InputStream inputStream;
+ private LSID lsid;
+ private MockHttpServletResponse response;
+
+
+ @Before
+ public void setUp() {
+ try {
+ lsid = new LSID("urn:lsid:example.org:taxonconcepts:1");
+ } catch (MalformedLSIDException e) { }
+
+ dataController = new DataController();
+ inputStream = new ByteArrayInputStream(expectedData.getBytes());
+ dataService = EasyMock.createMock(LSIDDataService.class);
+ response = new MockHttpServletResponse();
+ }
+
+ @Test
+ public void testGetData() throws Exception {
+ EasyMock.expect(dataService.getData(LSIDMatchers.eqLSID(lsid))).andReturn(inputStream);
+ EasyMock.replay(dataService);
+
+ ModelAndView modelAndView = dataController.getData(lsid,response);
+ EasyMock.verify(dataService);
+
+ Assert.assertNull(modelAndView);
+ Assert.assertEquals(response.getContentAsString(),expectedData);
+ }
+
+ @Test(expected = LSIDServerException.class)
+ public void testGetDataWithUnknownLSID() throws Exception {;
+ LSIDServerException lse = new LSIDServerException(LSIDException.UNKNOWN_LSID, "Unknown LSID");
+
+ EasyMock.expect(dataService.getData(LSIDMatchers.eqLSID(lsid))).andThrow(lse);
+ EasyMock.replay(dataService);
+
+ dataController.setLsidDataService(dataService);
+ dataController.getData(lsid, response);
+ }
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.service;
+
+
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.test.web.ModelAndViewAssert;
+import org.springframework.web.servlet.ModelAndView;
+import org.unitils.UnitilsJUnit4;
+import org.unitils.easymock.annotation.Mock;
+import org.unitils.inject.annotation.InjectInto;
+import org.unitils.inject.annotation.TestedObject;
+
+import com.ibm.lsid.LSIDException;
+import com.ibm.lsid.MalformedLSIDException;
+import com.ibm.lsid.MetadataResponse;
+import com.ibm.lsid.server.LSIDServerException;
+
+import eu.etaxonomy.cdm.api.service.lsid.LSIDMetadataService;
+import eu.etaxonomy.cdm.model.common.LSID;
+import eu.etaxonomy.cdm.test.util.LSIDMatchers;
+
+public class MetadataControllerTest extends UnitilsJUnit4 {
+
+ @Mock
+ @InjectInto(property = "lsidMetadataService")
+ private LSIDMetadataService metadataService;
+
+ @TestedObject
+ private MetadataController metadataController;
+
+ private LSID lsid;
+ private String[] acceptedFormats;
+
+ @Before
+ public void setUp() {
+ metadataController = new MetadataController();
+ metadataService = EasyMock.createMock(LSIDMetadataService.class);
+ try {
+ lsid = new LSID("urn:lsid:fred.org:dagg:1");
+ } catch (MalformedLSIDException e) { }
+ acceptedFormats = new String[]{MetadataResponse.RDF_FORMAT};
+ }
+
+ @Test
+ public void testGetMetadata() throws Exception {
+ MetadataResponse metadataResponse = new MetadataResponse(null, null);
+ EasyMock.expect(metadataService.getMetadata(LSIDMatchers.eqLSID(lsid), EasyMock.aryEq(acceptedFormats))).andReturn(metadataResponse);
+ EasyMock.replay(metadataService);
+
+
+ ModelAndView modelAndView = metadataController.getMetadata(lsid, "application/xml+rdf");
+
+ EasyMock.verify(metadataService);
+ ModelAndViewAssert.assertViewName(modelAndView, "Metadata.rdf");
+ ModelAndViewAssert.assertModelAttributeValue(modelAndView,"metadataResponse",metadataResponse);
+ }
+
+ @Test(expected = LSIDServerException.class)
+ public void testGetMetadataWithoutAcceptedFormat() throws Exception {
+ acceptedFormats = new String[]{MetadataResponse.N3_FORMAT,MetadataResponse.XMI_FORMAT};
+ LSIDServerException lse = new LSIDServerException(LSIDServerException.NO_METADATA_AVAILABLE_FOR_FORMATS,"No metadata found for given format");
+ EasyMock.expect(metadataService.getMetadata(LSIDMatchers.eqLSID(lsid), EasyMock.aryEq(acceptedFormats))).andThrow(lse);
+ EasyMock.replay(metadataService);
+
+ metadataController.getMetadata(lsid, "application/n3,application/xml+xmi");
+ }
+
+ @Test(expected = LSIDServerException.class)
+ public void testGetMetadataWithUnknownLSID() throws Exception {
+
+ LSIDServerException lse = new LSIDServerException(LSIDException.UNKNOWN_LSID, "Unknown LSID");
+ EasyMock.expect(metadataService.getMetadata(LSIDMatchers.eqLSID(lsid), EasyMock.aryEq(acceptedFormats))).andThrow(lse);
+ EasyMock.replay(metadataService);
+
+ metadataController.getMetadata(lsid, "application/xml+rdf");
+ }
+}
--- /dev/null
+package eu.etaxonomy.cdm.remote.view;\r
+\r
+import java.io.BufferedWriter;\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.InputStreamReader;\r
+import java.io.OutputStreamWriter;\r
+import java.io.StringReader;\r
+import java.io.Writer;\r
+import java.net.URI;\r
+import java.util.HashSet;\r
+import java.util.Set;\r
+\r
+import javax.xml.transform.Result;\r
+import javax.xml.transform.Source;\r
+import javax.xml.transform.Transformer;\r
+import javax.xml.transform.TransformerFactory;\r
+import javax.xml.transform.stream.StreamResult;\r
+\r
+import org.custommonkey.xmlunit.XMLAssert;\r
+import org.custommonkey.xmlunit.XMLUnit;\r
+import org.joda.time.DateTime;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.springframework.oxm.Marshaller;\r
+import org.unitils.UnitilsJUnit4;\r
+import org.unitils.spring.annotation.SpringApplicationContext;\r
+import org.unitils.spring.annotation.SpringBeanByType;\r
+\r
+import eu.etaxonomy.cdm.remote.dto.dc.Relation;\r
+import eu.etaxonomy.cdm.remote.dto.tdwg.voc.PublicationCitation;\r
+import eu.etaxonomy.cdm.remote.dto.tdwg.voc.Relationship;\r
+import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonConcept;\r
+import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonName;\r
+import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonRelationshipTerm;\r
+import eu.etaxonomy.cdm.remote.dto.tdwg.voc.Team;\r
+import eu.etaxonomy.remote.dto.rdf.Rdf;\r
+\r
+@SpringApplicationContext("file:./target/test-classes/eu/etaxonomy/cdm/applicationContext-test.xml")\r
+public class RdfViewTest extends UnitilsJUnit4 {\r
+ \r
+ @SpringBeanByType\r
+ private Marshaller marshaller;\r
+ \r
+ private Rdf rdf;\r
+ \r
+ @Before\r
+ public void setUp() throws Exception {\r
+ XMLUnit.setControlParser("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");\r
+ XMLUnit.setTestParser("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");\r
+ XMLUnit.setSAXParserFactory("org.apache.xerces.jaxp.SAXParserFactoryImpl");\r
+ XMLUnit.setIgnoreWhitespace(true);\r
+ \r
+ TaxonConcept taxonConcept = new TaxonConcept();\r
+\r
+ TaxonName taxonName = new TaxonName();\r
+ taxonName.setAuthorship("authorship");\r
+ taxonName.setNameComplete("Aus aus");\r
+ taxonName.setIdentifier(new URI("urn:lsid:example.org:names:1"));\r
+ taxonConcept.setHasName(taxonName);\r
+ taxonConcept.setIdentifier(new URI("urn:lsid:example.org:taxonconcepts:1"));\r
+ taxonConcept.setTitle("Lorem ipsum");\r
+ taxonConcept.setCreated(new DateTime(2004, 12, 25, 12, 0, 0, 0));\r
+ \r
+ Set<Relation> relations = new HashSet<Relation>();\r
+ Relation relation = new Relation();\r
+ relation.setResource(new URI("http://www.example.org/"));\r
+ relations.add(relation);\r
+ taxonConcept.setRelations(relations);\r
+ PublicationCitation publicationCitation = new PublicationCitation();\r
+ taxonConcept.setPublishedIn("Lorem ipsum dolor");\r
+ \r
+ Team team = new Team();\r
+ team.setTitle("team name");\r
+ \r
+ taxonConcept.setAccordingTo(team);\r
+ \r
+ TaxonRelationshipTerm taxonRelationshipTerm = new TaxonRelationshipTerm();\r
+ taxonRelationshipTerm.setIdentifier(new URI("http://rs.e-taxonomy.eu/voc/TaxonRelationshipTerm.rdf"));\r
+ Set<Relationship> relationships = new HashSet<Relationship>(); \r
+ Relationship relationship = new Relationship();\r
+ relationship.setRelationshipCategory(taxonRelationshipTerm);\r
+ TaxonConcept t = new TaxonConcept();\r
+ t.setIdentifier(new URI("urn:lsid:example.org:taxonconcepts:2"));\r
+ relationship.setToTaxon(t);\r
+ relationship.setFromTaxon(taxonConcept);\r
+ relationships.add(relationship);\r
+ \r
+ taxonConcept.setHasRelationship(relationships);\r
+ \r
+ rdf = new Rdf();\r
+ rdf.addThing(taxonConcept);\r
+ }\r
+ \r
+ @Test\r
+ public void testMarshalRdf() throws Exception { \r
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();\r
+ Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8" ));\r
+ marshaller.marshal(rdf, new StreamResult(writer));\r
+ writer.close();\r
+ \r
+ String resource = "/eu/etaxonomy/cdm/remote/view/RdfViewTest.rdf"; \r
+ XMLAssert.assertXMLEqual(new InputStreamReader(this.getClass().getResourceAsStream(resource)),new StringReader(new String(outputStream.toByteArray())));\r
+ }\r
+\r
+}\r
--- /dev/null
+package eu.etaxonomy.cdm.test.util;
+
+import org.easymock.IArgumentMatcher;
+
+import eu.etaxonomy.cdm.model.common.LSID;
+
+public class LSIDArguementMatcher implements IArgumentMatcher {
+
+ private LSID expected;
+
+ public LSIDArguementMatcher(LSID expected) {
+ super();
+ this.expected = expected;
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("LSID matches " + expected.toString());
+ }
+
+ public boolean matches(Object actual) {
+ return (actual instanceof LSID)
+ && ((LSID) actual).equals(expected);
+ }
+}
--- /dev/null
+package eu.etaxonomy.cdm.test.util;
+
+import org.easymock.IArgumentMatcher;
+
+import eu.etaxonomy.cdm.model.common.LSIDAuthority;
+
+public class LSIDAuthorityArguementMatcher implements IArgumentMatcher {
+
+ private LSIDAuthority expected;
+
+ public LSIDAuthorityArguementMatcher(LSIDAuthority expected) {
+ super();
+ this.expected = expected;
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("LSIDAuthority matches " + expected.toString());
+ }
+
+ public boolean matches(Object actual) {
+ return (actual instanceof LSIDAuthority)
+ && ((LSIDAuthority) actual).equals(expected);
+ }
+
+}
--- /dev/null
+package eu.etaxonomy.cdm.test.util;
+
+import org.easymock.EasyMock;
+
+import eu.etaxonomy.cdm.model.common.LSID;
+import eu.etaxonomy.cdm.model.common.LSIDAuthority;
+
+public class LSIDMatchers {
+ public static LSIDAuthority eqLSIDAuthority(LSIDAuthority lsidAuthority) {
+ EasyMock.reportMatcher(new LSIDAuthorityArguementMatcher(lsidAuthority));
+ return null;
+ }
+
+ public static LSID eqLSID(LSID lsid) {
+ EasyMock.reportMatcher(new LSIDArguementMatcher(lsid));
+ return null;
+ }
+
+}
<!-- Overwrites the component-scan in services.xml -->
<context:component-scan base-package="eu/etaxonomy/cdm">
<context:exclude-filter type="regex" expression="eu\.etaxonomy\.cdm\.api\.service\.UserService"/>
+ <context:exclude-filter type="regex" expression="eu\.etaxonomy\.cdm\.persistence\.dao\.hibernate\.taxon\.TaxonAlternativeSpellingSuggestionParser"/>
</context:component-scan>
<import resource="classpath:/eu/etaxonomy/cdm/h2-datasource.xml" />
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<beans xmlns="http://www.springframework.org/schema/beans"\r
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+ xmlns:context="http://www.springframework.org/schema/context"\r
+ xmlns:tx="http://www.springframework.org/schema/tx"\r
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-2.5.xsd\r
+ http://www.springframework.org/schema/tx \r
+ http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
+\r
+ <context:property-override location="classpath:eu/etaxonomy/cdm/override.properties"/>\r
+
+ <import resource="classpath:/eu/etaxonomy/cdm/remote.xml"/>
+</beans>
\ No newline at end of file
--- /dev/null
+lsidProxyConverter.lsidProxyServiceUrl=http://lsid.example.org/
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/" xmlns:tt="http://rs.tdwg.org/ontology/voc/Team#" xmlns:tpc="http://rs.tdwg.org/ontology/voc/PublicationCitation#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:tp="http://rs.tdwg.org/ontology/voc/Person#" xmlns:tn="http://rs.tdwg.org/ontology/voc/TaxonName#" xmlns:tcom="http://rs.tdwg.org/ontology/voc/Common#" xmlns:tc="http://rs.tdwg.org/ontology/voc/TaxonConcept#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:owl="http://www.w3.org/2002/07/owl#">
+ <tc:TaxonConcept>
+ <dc:title>Lorem ipsum</dc:title>
+ <dc:identifier>urn:lsid:example.org:taxonconcepts:1</dc:identifier>
+ <dcterms:created>2004-12-25T12:00:00.000Z</dcterms:created>
+ <dc:relation rdf:resource="http://www.example.org/"/>
+ <tcom:publishedIn>Lorem ipsum dolor</tcom:publishedIn>
+ <tc:accordingTo>
+ <tt:Team>
+ <dc:title>team name</dc:title>
+ </tt:Team>
+ </tc:accordingTo>
+ <tc:hasName>
+ <tn:TaxonName>
+ <dc:identifier>urn:lsid:example.org:names:1</dc:identifier>
+ <tn:authorship>authorship</tn:authorship>
+ <tn:nameComplete>Aus aus</tn:nameComplete>
+ </tn:TaxonName>
+ </tc:hasName>
+ <tc:hasRelationship>
+ <Relationship>
+ <tc:fromTaxon rdf:resource="urn:lsid:example.org:taxonconcepts:1"/>
+ <tc:relationshipCategory>
+ <tc:TaxonRelationshipTerm>
+ <dc:identifier>http://rs.e-taxonomy.eu/voc/TaxonRelationshipTerm.rdf</dc:identifier>
+ </tc:TaxonRelationshipTerm>
+ </tc:relationshipCategory>
+ <tc:toTaxon rdf:resource="urn:lsid:example.org:taxonconcepts:2"/>
+ </Relationship>
+ </tc:hasRelationship>
+ </tc:TaxonConcept>
+</rdf:RDF>
+
+
+