-/**\r
-* Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy\r
-* http://www.e-taxonomy.eu\r
-*\r
-* The contents of this file are subject to the Mozilla Public License Version 1.1\r
-* See LICENSE.TXT at the top of this package for the full license terms.\r
-*/\r
-\r
-package eu.etaxonomy.cdm.io.common;\r
-\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.apache.log4j.Logger;\r
-import org.springframework.beans.BeansException;\r
-import org.springframework.context.ApplicationContext;\r
-import org.springframework.context.ApplicationContextAware;\r
-import org.springframework.security.authentication.AuthenticationManager;\r
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;\r
-import org.springframework.security.core.Authentication;\r
-import org.springframework.security.core.context.SecurityContext;\r
-import org.springframework.security.core.context.SecurityContextHolder;\r
-import org.springframework.stereotype.Component;\r
-\r
-import eu.etaxonomy.cdm.api.service.IService;\r
-import eu.etaxonomy.cdm.io.common.events.IIoObserver;\r
-import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;\r
-import eu.etaxonomy.cdm.model.common.CdmBase;\r
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\r
-import eu.etaxonomy.cdm.model.reference.Reference;\r
-import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
-import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmPermissionEvaluator;\r
-\r
-/**\r
- * @author a.mueller\r
- * @created 20.06.2008\r
- * @version 1.0\r
- */\r
-\r
-@Component("defaultImport")\r
-public class CdmApplicationAwareDefaultImport<T extends IImportConfigurator> implements ICdmImporter<T>, ApplicationContextAware {\r
- private static final Logger logger = Logger.getLogger(CdmApplicationAwareDefaultImport.class);\r
-\r
- protected ApplicationContext applicationContext;\r
-\r
-\r
- @Override\r
- public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {\r
- this.applicationContext = applicationContext;\r
- }\r
-\r
-\r
- //Constants\r
- final boolean OBLIGATORY = true;\r
- final boolean FACULTATIVE = false;\r
- final int modCount = 1000;\r
-\r
- IService<CdmBase> service = null;\r
-\r
- //different type of stores that are used by the known imports\r
- Map<String, MapWrapper<? extends CdmBase>> stores = new HashMap<String, MapWrapper<? extends CdmBase>>();\r
-\r
- public CdmApplicationAwareDefaultImport(){\r
-\r
- stores.put(ICdmIO.TEAM_STORE, new MapWrapper<TeamOrPersonBase<?>>(service));\r
- stores.put(ICdmIO.REFERENCE_STORE, new MapWrapper<Reference>(service));\r
- stores.put(ICdmIO.NOMREF_STORE, new MapWrapper<Reference>(service));\r
- stores.put(ICdmIO.TAXONNAME_STORE, new MapWrapper<TaxonNameBase<?,?>>(service));\r
- stores.put(ICdmIO.TAXON_STORE, new MapWrapper<TaxonBase>(service));\r
- stores.put(ICdmIO.SPECIMEN_STORE, new MapWrapper<DerivedUnit>(service));\r
- }\r
-\r
-\r
- @Override\r
- public boolean invoke(IImportConfigurator config){\r
- if (config.getCheck().equals(IImportConfigurator.CHECK.CHECK_ONLY)){\r
- return doCheck(config);\r
- }else if (config.getCheck().equals(IImportConfigurator.CHECK.CHECK_AND_IMPORT)){\r
- doCheck(config);\r
- return doImport(config);\r
- }else if (config.getCheck().equals(IImportConfigurator.CHECK.IMPORT_WITHOUT_CHECK)){\r
- return doImport(config);\r
- }else{\r
- logger.error("Unknown CHECK type");\r
- return false;\r
- }\r
- }\r
-\r
-\r
- public ImportResult execute(IImportConfigurator config){\r
- ImportResult result = new ImportResult();\r
- if (config.getCheck().equals(IImportConfigurator.CHECK.CHECK_ONLY)){\r
- result.setSuccess(doCheck(config));\r
- }else if (config.getCheck().equals(IImportConfigurator.CHECK.CHECK_AND_IMPORT)){\r
- boolean success = doCheck(config);\r
- if(success) {\r
- success = doImport(config, result);\r
- }\r
- result.setSuccess(success);\r
- } else if (config.getCheck().equals(IImportConfigurator.CHECK.IMPORT_WITHOUT_CHECK)){\r
- doImport(config, result);\r
- } else{\r
- logger.error("Unknown CHECK type");\r
- return null;\r
- }\r
- return result;\r
- }\r
-\r
-\r
- @SuppressWarnings("unchecked")\r
- protected <S extends IImportConfigurator> boolean doCheck(S config){\r
- boolean result = true;\r
-\r
- //check\r
- if (config == null){\r
- logger.warn("CdmImportConfiguration is null");\r
- return false;\r
- }\r
- System.out.println("Start checking Source ("+ config.getSourceNameString() + ") ...");\r
- if (! config.isValid()){\r
- logger.warn("CdmImportConfiguration is not valid");\r
- return false;\r
- }\r
-\r
- ImportStateBase state = config.getNewState();\r
- state.initialize(config);\r
-\r
- //do check for each class\r
- for (Class<ICdmImport> ioClass: config.getIoClassList()){\r
- try {\r
- String ioBeanName = getComponentBeanName(ioClass);\r
- ICdmIO cdmIo = applicationContext.getBean(ioBeanName, ICdmIO.class);\r
- if (cdmIo != null){\r
- registerObservers(config, cdmIo);\r
- state.setCurrentIO(cdmIo);\r
- result &= cdmIo.check(state);\r
- unRegisterObservers(config, cdmIo);\r
- }else{\r
- logger.error("cdmIO was null");\r
- result = false;\r
- }\r
- } catch (Exception e) {\r
- logger.error(e);\r
- e.printStackTrace();\r
- result = false;\r
- }\r
- }\r
-\r
- //return\r
- System.out.println("End checking Source ("+ config.getSourceNameString() + ") for import to Cdm");\r
- return result;\r
-\r
- }\r
-\r
- private void registerObservers(IImportConfigurator config, ICdmIO io){\r
- for (IIoObserver observer : config.getObservers()){\r
- io.addObserver(observer);\r
- }\r
- }\r
-\r
- private void unRegisterObservers(IImportConfigurator config, ICdmIO io){\r
- for (IIoObserver observer : config.getObservers()){\r
- io.removeObserver(observer);\r
- }\r
- }\r
-\r
- protected <S extends IImportConfigurator> boolean doImport(S config){\r
- ImportResult result = new ImportResult();\r
- return doImport(config, result);\r
- }\r
-\r
- /**\r
- * Executes the whole\r
- */\r
- protected <S extends IImportConfigurator> boolean doImport(S config, ImportResult importResult){\r
- boolean result = true;\r
- //validate\r
- if (config == null){\r
- logger.warn("Configuration is null");\r
- importResult.setSuccess(false);\r
- return false;\r
- }else if (! config.isValid()){\r
- logger.warn("Configuration is not valid");\r
- importResult.setSuccess(false);\r
- return false;\r
- }\r
-\r
- config.getSourceReference();\r
- logger.info("Start import from Source '"+ config.getSourceNameString() + "' to destination '" + config.getDestinationNameString() + "'");\r
-\r
- ImportStateBase state = config.getNewState();\r
- state.initialize(config);\r
-\r
- CdmPermissionEvaluator permissionEval = applicationContext.getBean("cdmPermissionEvaluator", CdmPermissionEvaluator.class);\r
-\r
- state.setSuccess(true);\r
- //do invoke for each class\r
- for (Class<ICdmImport> ioClass: config.getIoClassList()){\r
- try {\r
- String ioBeanName = getComponentBeanName(ioClass);\r
- ICdmImport cdmIo = applicationContext.getBean(ioBeanName, ICdmImport.class);\r
- if (cdmIo != null){\r
- registerObservers(config, cdmIo);\r
- state.setCurrentIO(cdmIo);\r
- result &= cdmIo.invoke(state);\r
- importResult.addReport(cdmIo.getByteArray());\r
- unRegisterObservers(config, cdmIo);\r
- }else{\r
- logger.error("cdmIO was null");\r
- result = false;\r
- }\r
- } catch (Exception e) {\r
- logger.error(e);\r
- e.printStackTrace();\r
- result = false;\r
- }\r
- }\r
-\r
- //do invoke for each class\r
-// for (String ioBean: config.getIoBeans()){\r
-// try {\r
-// ICdmIO<S> cdmIo = (ICdmIO<S>)applicationContext.getBean(ioBean, ICdmIO.class);\r
-// if (cdmIo != null){\r
-// result &= cdmIo.invoke(config, stores);\r
-// }else{\r
-// logger.error("cdmIO was null");\r
-// result = false;\r
-// }\r
-// } catch (Exception e) {\r
-// logger.error(e);\r
-// e.printStackTrace();\r
-// result = false;\r
-// }\r
-//\r
-// }\r
-\r
- logger.info("End import from source '" + config.getSourceNameString()\r
- + "' to destination '" + config.getDestinationNameString() + "'"+\r
- (result? "(successful)":"(with errors)")) ;\r
- importResult.setSuccess(result);\r
- return result;\r
- }\r
-\r
- /**\r
- * Returns the name of a component bean. If the name is defined in the Component annotation this name is returned.\r
- * Otherwise the class name is returned with starting lower case.\r
- * @param ioClass\r
- * @return\r
- * @throws IllegalArgumentException if the class does not have a "Component" annotation\r
- */\r
- public static String getComponentBeanName(Class<ICdmImport> ioClass) throws IllegalArgumentException {\r
- Component component = ioClass.getAnnotation(Component.class);\r
- if (component == null){\r
- throw new IllegalArgumentException("Class " + ioClass.getName() + " is missing a @Component annotation." );\r
- }\r
- String ioBean = component.value();\r
- if ("".equals(ioBean)){\r
- ioBean = ioClass.getSimpleName();\r
- ioBean = ioBean.substring(0, 1).toLowerCase() + ioBean.substring(1); //make camelcase\r
- }\r
- return ioBean;\r
- }\r
-\r
- public void authenticate(IImportConfigurator config) {\r
- UsernamePasswordAuthenticationToken token = config.getAuthenticationToken();\r
- if (token != null){\r
- SecurityContext context = SecurityContextHolder.getContext();\r
-\r
- AuthenticationManager authenticationManager = applicationContext.getBean("authenticationManager", AuthenticationManager.class);;\r
- Authentication authentication = authenticationManager.authenticate(token);\r
- context.setAuthentication(authentication);\r
- }else{\r
- logger.warn("No authentication token available");\r
- }\r
-\r
- }\r
-\r
-}\r
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.cdm.io.common;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContext;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.stereotype.Component;
+
+import eu.etaxonomy.cdm.api.service.IService;
+import eu.etaxonomy.cdm.io.common.events.IIoObserver;
+import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
+import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmPermissionEvaluator;
+
+/**
+ * @author a.mueller
+ * @created 20.06.2008
+ * @version 1.0
+ */
+
+@Component("defaultImport")
+public class CdmApplicationAwareDefaultImport<T extends IImportConfigurator> implements ICdmImporter<T>, ApplicationContextAware {
+ private static final Logger logger = Logger.getLogger(CdmApplicationAwareDefaultImport.class);
+
+ protected ApplicationContext applicationContext;
+
+
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+ this.applicationContext = applicationContext;
+ }
+
+
+ //Constants
+ final boolean OBLIGATORY = true;
+ final boolean FACULTATIVE = false;
+ final int modCount = 1000;
+
+ IService<CdmBase> service = null;
+
+ //different type of stores that are used by the known imports
+ Map<String, MapWrapper<? extends CdmBase>> stores = new HashMap<String, MapWrapper<? extends CdmBase>>();
+
+ public CdmApplicationAwareDefaultImport(){
+
+ stores.put(ICdmIO.TEAM_STORE, new MapWrapper<TeamOrPersonBase<?>>(service));
+ stores.put(ICdmIO.REFERENCE_STORE, new MapWrapper<Reference>(service));
+ stores.put(ICdmIO.NOMREF_STORE, new MapWrapper<Reference>(service));
+ stores.put(ICdmIO.TAXONNAME_STORE, new MapWrapper<TaxonNameBase<?,?>>(service));
+ stores.put(ICdmIO.TAXON_STORE, new MapWrapper<TaxonBase>(service));
+ stores.put(ICdmIO.SPECIMEN_STORE, new MapWrapper<DerivedUnit>(service));
+ }
+
+
+ @Override
+ public boolean invoke(IImportConfigurator config){
+ if (config.getCheck().equals(IImportConfigurator.CHECK.CHECK_ONLY)){
+ return doCheck(config);
+ }else if (config.getCheck().equals(IImportConfigurator.CHECK.CHECK_AND_IMPORT)){
+ doCheck(config);
+ return doImport(config);
+ }else if (config.getCheck().equals(IImportConfigurator.CHECK.IMPORT_WITHOUT_CHECK)){
+ return doImport(config);
+ }else{
+ logger.error("Unknown CHECK type");
+ return false;
+ }
+ }
+
+
+ public ImportResult execute(IImportConfigurator config){
+ ImportResult result = new ImportResult();
+ if (config.getCheck().equals(IImportConfigurator.CHECK.CHECK_ONLY)){
+ result.setSuccess(doCheck(config));
+ }else if (config.getCheck().equals(IImportConfigurator.CHECK.CHECK_AND_IMPORT)){
+ boolean success = doCheck(config);
+ if(success) {
+ success = doImport(config, result);
+ }
+ result.setSuccess(success);
+ } else if (config.getCheck().equals(IImportConfigurator.CHECK.IMPORT_WITHOUT_CHECK)){
+ doImport(config, result);
+ } else{
+ logger.error("Unknown CHECK type");
+ return null;
+ }
+ return result;
+ }
+
+
+ @SuppressWarnings("unchecked")
+ protected <S extends IImportConfigurator> boolean doCheck(S config){
+ boolean result = true;
+
+ //check
+ if (config == null){
+ logger.warn("CdmImportConfiguration is null");
+ return false;
+ }
+ System.out.println("Start checking Source ("+ config.getSourceNameString() + ") ...");
+ if (! config.isValid()){
+ logger.warn("CdmImportConfiguration is not valid");
+ return false;
+ }
+
+ ImportStateBase state = config.getNewState();
+ state.initialize(config);
+
+ //do check for each class
+ for (Class<ICdmImport> ioClass: config.getIoClassList()){
+ try {
+ String ioBeanName = getComponentBeanName(ioClass);
+ ICdmIO cdmIo = applicationContext.getBean(ioBeanName, ICdmIO.class);
+ if (cdmIo != null){
+ registerObservers(config, cdmIo);
+ state.setCurrentIO(cdmIo);
+ result &= cdmIo.check(state);
+ unRegisterObservers(config, cdmIo);
+ }else{
+ logger.error("cdmIO was null");
+ result = false;
+ }
+ } catch (Exception e) {
+ logger.error(e);
+ e.printStackTrace();
+ result = false;
+ }
+ }
+
+ //return
+ System.out.println("End checking Source ("+ config.getSourceNameString() + ") for import to Cdm");
+ return result;
+
+ }
+
+ private void registerObservers(IImportConfigurator config, ICdmIO io){
+ for (IIoObserver observer : config.getObservers()){
+ io.addObserver(observer);
+ }
+ }
+
+ private void unRegisterObservers(IImportConfigurator config, ICdmIO io){
+ for (IIoObserver observer : config.getObservers()){
+ io.removeObserver(observer);
+ }
+ }
+
+ protected <S extends IImportConfigurator> boolean doImport(S config){
+ ImportResult result = new ImportResult();
+ return doImport(config, result);
+ }
+
+ /**
+ * Executes the whole
+ */
+ protected <S extends IImportConfigurator> boolean doImport(S config, ImportResult importResult){
+ boolean result = true;
+ //validate
+ if (config == null){
+ logger.warn("Configuration is null");
+ importResult.setSuccess(false);
+ return false;
+ }else if (! config.isValid()){
+ logger.warn("Configuration is not valid");
+ importResult.setSuccess(false);
+ return false;
+ }
+
+ config.getSourceReference();
+ logger.info("Start import from Source '"+ config.getSourceNameString() + "' to destination '" + config.getDestinationNameString() + "'");
+
+ ImportStateBase state = config.getNewState();
+ state.initialize(config);
+
+ CdmPermissionEvaluator permissionEval = applicationContext.getBean("cdmPermissionEvaluator", CdmPermissionEvaluator.class);
+
+ state.setSuccess(true);
+ //do invoke for each class
+ for (Class<ICdmImport> ioClass: config.getIoClassList()){
+ try {
+ String ioBeanName = getComponentBeanName(ioClass);
+ ICdmImport cdmIo = applicationContext.getBean(ioBeanName, ICdmImport.class);
+ if (cdmIo != null){
+ registerObservers(config, cdmIo);
+ state.setCurrentIO(cdmIo);
+ result &= cdmIo.invoke(state);
+ importResult.addReport(state.getReportAsByteArray());
+ unRegisterObservers(config, cdmIo);
+ }else{
+ logger.error("cdmIO was null");
+ result = false;
+ }
+ } catch (Exception e) {
+ logger.error(e);
+ e.printStackTrace();
+ result = false;
+ }
+ }
+
+ //do invoke for each class
+// for (String ioBean: config.getIoBeans()){
+// try {
+// ICdmIO<S> cdmIo = (ICdmIO<S>)applicationContext.getBean(ioBean, ICdmIO.class);
+// if (cdmIo != null){
+// result &= cdmIo.invoke(config, stores);
+// }else{
+// logger.error("cdmIO was null");
+// result = false;
+// }
+// } catch (Exception e) {
+// logger.error(e);
+// e.printStackTrace();
+// result = false;
+// }
+//
+// }
+
+ logger.info("End import from source '" + config.getSourceNameString()
+ + "' to destination '" + config.getDestinationNameString() + "'"+
+ (result? "(successful)":"(with errors)")) ;
+ importResult.setSuccess(result);
+ return result;
+ }
+
+ /**
+ * Returns the name of a component bean. If the name is defined in the Component annotation this name is returned.
+ * Otherwise the class name is returned with starting lower case.
+ * @param ioClass
+ * @return
+ * @throws IllegalArgumentException if the class does not have a "Component" annotation
+ */
+ public static String getComponentBeanName(Class<ICdmImport> ioClass) throws IllegalArgumentException {
+ Component component = ioClass.getAnnotation(Component.class);
+ if (component == null){
+ throw new IllegalArgumentException("Class " + ioClass.getName() + " is missing a @Component annotation." );
+ }
+ String ioBean = component.value();
+ if ("".equals(ioBean)){
+ ioBean = ioClass.getSimpleName();
+ ioBean = ioBean.substring(0, 1).toLowerCase() + ioBean.substring(1); //make camelcase
+ }
+ return ioBean;
+ }
+
+ public void authenticate(IImportConfigurator config) {
+ UsernamePasswordAuthenticationToken token = config.getAuthenticationToken();
+ if (token != null){
+ SecurityContext context = SecurityContextHolder.getContext();
+
+ AuthenticationManager authenticationManager = applicationContext.getBean("authenticationManager", AuthenticationManager.class);;
+ Authentication authentication = authenticationManager.authenticate(token);
+ context.setAuthentication(authentication);
+ }else{
+ logger.warn("No authentication token available");
+ }
+
+ }
+
+}
-// $Id$\r
-/**\r
-* Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy \r
-* http://www.e-taxonomy.eu\r
-* \r
-* The contents of this file are subject to the Mozilla Public License Version 1.1\r
-* See LICENSE.TXT at the top of this package for the full license terms.\r
-*/\r
-\r
-package eu.etaxonomy.cdm.io.common;\r
-\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-import java.util.UUID;\r
-\r
-import org.apache.log4j.Logger;\r
-\r
-import eu.etaxonomy.cdm.api.service.IService;\r
-import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;\r
-import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;\r
-import eu.etaxonomy.cdm.model.common.AnnotationType;\r
-import eu.etaxonomy.cdm.model.common.CdmBase;\r
-import eu.etaxonomy.cdm.model.common.DefinedTerm;\r
-import eu.etaxonomy.cdm.model.common.DefinedTermBase;\r
-import eu.etaxonomy.cdm.model.common.ExtensionType;\r
-import eu.etaxonomy.cdm.model.common.Language;\r
-import eu.etaxonomy.cdm.model.common.MarkerType;\r
-import eu.etaxonomy.cdm.model.description.Feature;\r
-import eu.etaxonomy.cdm.model.description.MeasurementUnit;\r
-import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;\r
-import eu.etaxonomy.cdm.model.description.State;\r
-import eu.etaxonomy.cdm.model.description.StatisticalMeasure;\r
-import eu.etaxonomy.cdm.model.location.NamedArea;\r
-import eu.etaxonomy.cdm.model.location.NamedAreaLevel;\r
-import eu.etaxonomy.cdm.model.location.ReferenceSystem;\r
-import eu.etaxonomy.cdm.model.name.Rank;\r
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\r
-import eu.etaxonomy.cdm.model.reference.Reference;\r
-import eu.etaxonomy.cdm.model.taxon.Classification;\r
-import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
-import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;\r
-\r
-/**\r
- * @author a.mueller\r
- * @created 11.05.2009\r
- * @version 1.0\r
- */\r
-public abstract class ImportStateBase<CONFIG extends ImportConfiguratorBase, IO extends CdmImportBase> extends IoStateBase<CONFIG, IO> {\r
- @SuppressWarnings("unused")\r
- private static final Logger logger = Logger.getLogger(ImportStateBase.class);\r
- \r
- //States\r
- private boolean isCheck;\r
- \r
- private Map<Object,Classification> treeMap = new HashMap<Object,Classification>();\r
-\r
- private Map<Reference<?>,UUID> treeUuidMap = new HashMap<Reference<?>,UUID>();\r
-\r
- private Map<String,UUID> classificationKeyUuidMap = new HashMap<String,UUID>();\r
- \r
- private IInputTransformer inputTransformer;\r
-\r
- \r
- private Map<UUID, ExtensionType> extensionTypeMap = new HashMap<UUID, ExtensionType>();\r
- private Map<UUID, MarkerType> markerTypeMap = new HashMap<UUID, MarkerType>();\r
- private Map<UUID, AnnotationType> annotationTypeMap = new HashMap<UUID, AnnotationType>();\r
- private Map<UUID, DefinedTerm> identifierTypeMap = new HashMap<UUID, DefinedTerm>();\r
- \r
- private Map<UUID, NamedArea> namedAreaMap = new HashMap<UUID, NamedArea>();\r
- private Map<UUID, NamedAreaLevel> namedAreaLevelMap = new HashMap<UUID, NamedAreaLevel>();\r
- private Map<UUID, Feature> featureMap = new HashMap<UUID, Feature>();\r
- private Map<UUID, State> stateTermMap = new HashMap<UUID, State>();\r
- private Map<UUID, MeasurementUnit> measurementUnitMap = new HashMap<UUID, MeasurementUnit>();\r
- \r
- private Map<UUID, StatisticalMeasure> statisticalMeasureMap = new HashMap<UUID, StatisticalMeasure>();\r
- private Map<UUID, DefinedTerm> modifierMap = new HashMap<UUID, DefinedTerm>();\r
- \r
- private Map<UUID, PresenceAbsenceTerm> presenceTermMap = new HashMap<UUID, PresenceAbsenceTerm>();\r
- private Map<UUID, Language> languageMap = new HashMap<UUID, Language>();\r
- private Map<UUID, TaxonRelationshipType> taxonRelationshipTypeMap = new HashMap<UUID, TaxonRelationshipType>();\r
- \r
- private Map<UUID, ReferenceSystem> referenceSystemMap = new HashMap<UUID, ReferenceSystem>();\r
- private Map<UUID, Rank> rankMap = new HashMap<UUID, Rank>();\r
- private Map<UUID, DefinedTerm> kindOfUnitMap = new HashMap<UUID, DefinedTerm>();\r
- \r
- \r
- \r
- protected IService<CdmBase> service = null;\r
- \r
- protected ImportStateBase(CONFIG config){\r
- this.config = config;\r
- stores.put(ICdmIO.TEAM_STORE, new MapWrapper<TeamOrPersonBase<?>>(service));\r
- stores.put(ICdmIO.REFERENCE_STORE, new MapWrapper<Reference>(service));\r
- stores.put(ICdmIO.NOMREF_STORE, new MapWrapper<Reference>(service));\r
- stores.put(ICdmIO.TAXONNAME_STORE, new MapWrapper<TaxonNameBase<?,?>>(service));\r
- stores.put(ICdmIO.TAXON_STORE, new MapWrapper<TaxonBase>(service));\r
- stores.put(ICdmIO.SPECIMEN_STORE, new MapWrapper<DerivedUnit>(service));\r
- \r
- if (getTransformer() == null){\r
- IInputTransformer newTransformer = config.getTransformer();\r
-// if (newTransformer == null){\r
-// newTransformer = new DefaultTransf();\r
-// }\r
- setTransformer(newTransformer);\r
- }\r
- \r
- }\r
- \r
- \r
- \r
- /**\r
- * Resets (empties) all maps which map a uuid to a {@link DefinedTermBase term}.\r
- * This is usually needed when a a new transaction is opened and user defined terms are reused.\r
- */\r
- public void resetUuidTermMaps(){\r
- extensionTypeMap = new HashMap<UUID, ExtensionType>();\r
- markerTypeMap = new HashMap<UUID, MarkerType>();\r
- annotationTypeMap = new HashMap<UUID, AnnotationType>();\r
- \r
- namedAreaMap = new HashMap<UUID, NamedArea>();\r
- namedAreaLevelMap = new HashMap<UUID, NamedAreaLevel>();\r
- featureMap = new HashMap<UUID, Feature>();\r
- stateTermMap = new HashMap<UUID, State>();\r
- measurementUnitMap = new HashMap<UUID, MeasurementUnit>();\r
- statisticalMeasureMap = new HashMap<UUID, StatisticalMeasure>();\r
- modifierMap = new HashMap<UUID, DefinedTerm>();\r
- \r
- presenceTermMap = new HashMap<UUID, PresenceAbsenceTerm>();;\r
- languageMap = new HashMap<UUID, Language>();\r
- taxonRelationshipTypeMap = new HashMap<UUID, TaxonRelationshipType>();\r
- \r
- referenceSystemMap = new HashMap<UUID, ReferenceSystem>();\r
- rankMap = new HashMap<UUID, Rank>();\r
- }\r
- \r
- \r
- //different type of stores that are used by the known imports\r
- protected Map<String, MapWrapper<? extends CdmBase>> stores = new HashMap<String, MapWrapper<? extends CdmBase>>();\r
- \r
- \r
- /**\r
- * @return the stores\r
- */\r
- public Map<String, MapWrapper<? extends CdmBase>> getStores() {\r
- return stores;\r
- }\r
-\r
- /**\r
- * @param stores the stores to set\r
- */\r
- public void setStores(Map<String, MapWrapper<? extends CdmBase>> stores) {\r
- this.stores = stores;\r
- }\r
-\r
-\r
- public MapWrapper<? extends CdmBase> getStore(String storeLabel){\r
- return (MapWrapper<? extends CdmBase>) stores.get(storeLabel);\r
- }\r
- \r
-\r
- /**\r
- * @return the treeMap\r
- */\r
- public Classification getTree(Object ref) {\r
- return treeMap.get(ref);\r
- }\r
-\r
- /**\r
- * @param treeMap the treeMap to set\r
- */\r
- public void putTree(Object ref, Classification tree) {\r
- if (tree != null){\r
- this.treeMap.put(ref, tree);\r
- }\r
- }\r
- \r
- public int countTrees(){\r
- return treeUuidMap.size();\r
- }\r
- \r
- /**\r
- * @return the treeUuid\r
- */\r
- public UUID getTreeUuid(Reference ref) {\r
- return treeUuidMap.get(ref);\r
- }\r
-\r
- public void putTreeUuid(Reference ref, Classification tree) {\r
- if (tree != null && tree.getUuid() != null){\r
- this.treeUuidMap.put(ref, tree.getUuid());\r
- }\r
- }\r
-\r
- public int countTreeUuids(){\r
- return treeUuidMap.size();\r
- }\r
-\r
- \r
- /**\r
- * Adds a classification uuid to the classification uuid map,\r
- * which maps a key for the classification to its UUID in the CDM\r
- * @param classificationKeyId\r
- * @param classification\r
- */\r
- public void putClassificationUuidInt(int classificationKeyId, Classification classification) {\r
- putClassificationUuid(String.valueOf(classificationKeyId), classification);\r
- }\r
-\r
- public void putClassificationUuid(String treeKey, Classification tree) {\r
- if (tree != null && tree.getUuid() != null){\r
- this.classificationKeyUuidMap.put(treeKey, tree.getUuid());\r
- }\r
- }\r
- \r
- public UUID getTreeUuidByIntTreeKey(int treeKey) {\r
- return classificationKeyUuidMap.get(String.valueOf(treeKey));\r
- }\r
- \r
- public UUID getTreeUuidByTreeKey(String treeKey) {\r
- return classificationKeyUuidMap.get(treeKey);\r
- }\r
- \r
- \r
- public DefinedTerm getIdentifierType(UUID uuid){\r
- return identifierTypeMap.get(uuid);\r
- }\r
- \r
- public void putIdentifierType(DefinedTerm identifierType){\r
- identifierTypeMap.put(identifierType.getUuid(), identifierType);\r
- }\r
- \r
- public ExtensionType getExtensionType(UUID uuid){\r
- return extensionTypeMap.get(uuid);\r
- }\r
- \r
- public void putExtensionType(ExtensionType extensionType){\r
- extensionTypeMap.put(extensionType.getUuid(), extensionType);\r
- }\r
-\r
- public MarkerType getMarkerType(UUID uuid){\r
- return markerTypeMap.get(uuid);\r
- }\r
- \r
- public void putMarkerType(MarkerType markerType){\r
- markerTypeMap.put(markerType.getUuid(), markerType);\r
- }\r
- \r
- public AnnotationType getAnnotationType(UUID uuid){\r
- return annotationTypeMap.get(uuid);\r
- }\r
- \r
- public void putAnnotationType(AnnotationType annotationType){\r
- annotationTypeMap.put(annotationType.getUuid(), annotationType);\r
- }\r
- \r
- public NamedArea getNamedArea(UUID uuid){\r
- return namedAreaMap.get(uuid);\r
- }\r
- \r
- public void putNamedArea(NamedArea namedArea){\r
- namedAreaMap.put(namedArea.getUuid(), namedArea);\r
- }\r
- \r
- public NamedAreaLevel getNamedAreaLevel(UUID uuid){\r
- return namedAreaLevelMap.get(uuid);\r
- }\r
-\r
- \r
- public void putNamedAreaLevel(NamedAreaLevel namedAreaLevel){\r
- namedAreaLevelMap.put(namedAreaLevel.getUuid(), namedAreaLevel);\r
- }\r
- \r
- public Rank getRank(UUID uuid){\r
- return rankMap.get(uuid);\r
- }\r
-\r
- \r
- public void putRank(Rank rank){\r
- rankMap.put(rank.getUuid(), rank);\r
- }\r
-\r
- public State getStateTerm(UUID uuid){\r
- return stateTermMap.get(uuid);\r
- }\r
- \r
- public void putStateTerm(State stateTerm){\r
- stateTermMap.put(stateTerm.getUuid(), stateTerm);\r
- }\r
- \r
- public Feature getFeature(UUID uuid){\r
- return featureMap.get(uuid);\r
- }\r
- \r
- public void putFeature(Feature feature){\r
- featureMap.put(feature.getUuid(), feature);\r
- }\r
-\r
- public DefinedTerm getKindOfUnit(UUID uuid){\r
- return kindOfUnitMap.get(uuid);\r
- }\r
- \r
- public void putKindOfUnit(DefinedTerm unit){\r
- kindOfUnitMap.put(unit.getUuid(), unit);\r
- }\r
- \r
- public MeasurementUnit getMeasurementUnit(UUID uuid){\r
- return measurementUnitMap.get(uuid);\r
- }\r
- \r
- public void putMeasurementUnit(MeasurementUnit unit){\r
- measurementUnitMap.put(unit.getUuid(), unit);\r
- }\r
- \r
- public void putStatisticalMeasure(StatisticalMeasure unit){\r
- statisticalMeasureMap.put(unit.getUuid(), unit);\r
- }\r
- \r
- public StatisticalMeasure getStatisticalMeasure(UUID uuid){\r
- return statisticalMeasureMap.get(uuid);\r
- }\r
-\r
- \r
- public DefinedTerm getModifier(UUID uuid){\r
- return modifierMap.get(uuid);\r
- }\r
- \r
- public void putModifier(DefinedTerm unit){\r
- modifierMap.put(unit.getUuid(), unit);\r
- }\r
- \r
- public TaxonRelationshipType getTaxonRelationshipType(UUID uuid){\r
- return taxonRelationshipTypeMap.get(uuid);\r
- }\r
- \r
- public void putTaxonRelationshipType(TaxonRelationshipType relType){\r
- taxonRelationshipTypeMap.put(relType.getUuid(), relType);\r
- }\r
- \r
- \r
- public PresenceAbsenceTerm getPresenceAbsenceTerm(UUID uuid){\r
- return presenceTermMap.get(uuid);\r
- }\r
- \r
- public void putPresenceAbsenceTerm(PresenceAbsenceTerm presenceTerm){\r
- presenceTermMap.put(presenceTerm.getUuid(), presenceTerm);\r
- }\r
-\r
- public Language getLanguage(UUID uuid){\r
- return languageMap.get(uuid);\r
- }\r
- \r
- public void putLanguage(Language language){\r
- languageMap.put(language.getUuid(), language);\r
- }\r
- \r
- \r
- public ReferenceSystem getReferenceSystem(UUID uuid){\r
- return referenceSystemMap.get(uuid);\r
- }\r
- \r
- public void putReferenceSystem(ReferenceSystem referenceSystem){\r
- referenceSystemMap.put(referenceSystem.getUuid(), referenceSystem);\r
- }\r
- \r
- \r
- //TODO make this abstract or find another way to force that the\r
- //transformer exists\r
- public IInputTransformer getTransformer(){\r
- return inputTransformer;\r
- }\r
- \r
- public void setTransformer(IInputTransformer transformer){\r
- this.inputTransformer = transformer;\r
- }\r
-\r
- /**\r
- * Returns true, if this import is in validation state. Flase otherwise\r
- * @return\r
- */\r
- public boolean isCheck() {\r
- return isCheck;\r
- }\r
- \r
- /**\r
- * @see #isCheck\r
- * @param isCheck\r
- */\r
- public void setCheck(boolean isCheck) {\r
- this.isCheck = isCheck;\r
- }\r
-\r
- \r
-}\r
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.cdm.io.common;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.log4j.Logger;
+
+import eu.etaxonomy.cdm.api.service.IService;
+import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
+import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
+import eu.etaxonomy.cdm.model.common.AnnotationType;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.common.DefinedTerm;
+import eu.etaxonomy.cdm.model.common.DefinedTermBase;
+import eu.etaxonomy.cdm.model.common.ExtensionType;
+import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.common.MarkerType;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.MeasurementUnit;
+import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
+import eu.etaxonomy.cdm.model.description.State;
+import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
+import eu.etaxonomy.cdm.model.location.NamedArea;
+import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
+import eu.etaxonomy.cdm.model.location.ReferenceSystem;
+import eu.etaxonomy.cdm.model.name.Rank;
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
+import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
+
+/**
+ * @author a.mueller
+ * @created 11.05.2009
+ * @version 1.0
+ */
+public abstract class ImportStateBase<CONFIG extends ImportConfiguratorBase, IO extends CdmImportBase> extends IoStateBase<CONFIG, IO> {
+ @SuppressWarnings("unused")
+ private static final Logger logger = Logger.getLogger(ImportStateBase.class);
+
+ //States
+ private boolean isCheck;
+
+ private Map<Object,Classification> treeMap = new HashMap<Object,Classification>();
+
+ private Map<Reference<?>,UUID> treeUuidMap = new HashMap<Reference<?>,UUID>();
+
+ private Map<String,UUID> classificationKeyUuidMap = new HashMap<String,UUID>();
+
+ private IInputTransformer inputTransformer;
+
+
+ private Map<UUID, ExtensionType> extensionTypeMap = new HashMap<UUID, ExtensionType>();
+ private Map<UUID, MarkerType> markerTypeMap = new HashMap<UUID, MarkerType>();
+ private Map<UUID, AnnotationType> annotationTypeMap = new HashMap<UUID, AnnotationType>();
+ private Map<UUID, DefinedTerm> identifierTypeMap = new HashMap<UUID, DefinedTerm>();
+
+ private Map<UUID, NamedArea> namedAreaMap = new HashMap<UUID, NamedArea>();
+ private Map<UUID, NamedAreaLevel> namedAreaLevelMap = new HashMap<UUID, NamedAreaLevel>();
+ private Map<UUID, Feature> featureMap = new HashMap<UUID, Feature>();
+ private Map<UUID, State> stateTermMap = new HashMap<UUID, State>();
+ private Map<UUID, MeasurementUnit> measurementUnitMap = new HashMap<UUID, MeasurementUnit>();
+
+ private Map<UUID, StatisticalMeasure> statisticalMeasureMap = new HashMap<UUID, StatisticalMeasure>();
+ private Map<UUID, DefinedTerm> modifierMap = new HashMap<UUID, DefinedTerm>();
+
+ private Map<UUID, PresenceAbsenceTerm> presenceTermMap = new HashMap<UUID, PresenceAbsenceTerm>();
+ private Map<UUID, Language> languageMap = new HashMap<UUID, Language>();
+ private Map<UUID, TaxonRelationshipType> taxonRelationshipTypeMap = new HashMap<UUID, TaxonRelationshipType>();
+
+ private Map<UUID, ReferenceSystem> referenceSystemMap = new HashMap<UUID, ReferenceSystem>();
+ private Map<UUID, Rank> rankMap = new HashMap<UUID, Rank>();
+ private Map<UUID, DefinedTerm> kindOfUnitMap = new HashMap<UUID, DefinedTerm>();
+
+
+
+ protected IService<CdmBase> service = null;
+
+ protected ImportStateBase(CONFIG config){
+ this.config = config;
+ stores.put(ICdmIO.TEAM_STORE, new MapWrapper<TeamOrPersonBase<?>>(service));
+ stores.put(ICdmIO.REFERENCE_STORE, new MapWrapper<Reference>(service));
+ stores.put(ICdmIO.NOMREF_STORE, new MapWrapper<Reference>(service));
+ stores.put(ICdmIO.TAXONNAME_STORE, new MapWrapper<TaxonNameBase<?,?>>(service));
+ stores.put(ICdmIO.TAXON_STORE, new MapWrapper<TaxonBase>(service));
+ stores.put(ICdmIO.SPECIMEN_STORE, new MapWrapper<DerivedUnit>(service));
+
+ if (getTransformer() == null){
+ IInputTransformer newTransformer = config.getTransformer();
+// if (newTransformer == null){
+// newTransformer = new DefaultTransf();
+// }
+ setTransformer(newTransformer);
+ }
+
+ }
+
+
+
+ /**
+ * Resets (empties) all maps which map a uuid to a {@link DefinedTermBase term}.
+ * This is usually needed when a a new transaction is opened and user defined terms are reused.
+ */
+ public void resetUuidTermMaps(){
+ extensionTypeMap = new HashMap<UUID, ExtensionType>();
+ markerTypeMap = new HashMap<UUID, MarkerType>();
+ annotationTypeMap = new HashMap<UUID, AnnotationType>();
+
+ namedAreaMap = new HashMap<UUID, NamedArea>();
+ namedAreaLevelMap = new HashMap<UUID, NamedAreaLevel>();
+ featureMap = new HashMap<UUID, Feature>();
+ stateTermMap = new HashMap<UUID, State>();
+ measurementUnitMap = new HashMap<UUID, MeasurementUnit>();
+ statisticalMeasureMap = new HashMap<UUID, StatisticalMeasure>();
+ modifierMap = new HashMap<UUID, DefinedTerm>();
+
+ presenceTermMap = new HashMap<UUID, PresenceAbsenceTerm>();;
+ languageMap = new HashMap<UUID, Language>();
+ taxonRelationshipTypeMap = new HashMap<UUID, TaxonRelationshipType>();
+
+ referenceSystemMap = new HashMap<UUID, ReferenceSystem>();
+ rankMap = new HashMap<UUID, Rank>();
+ }
+
+
+ //different type of stores that are used by the known imports
+ protected Map<String, MapWrapper<? extends CdmBase>> stores = new HashMap<String, MapWrapper<? extends CdmBase>>();
+
+
+ /**
+ * @return the stores
+ */
+ public Map<String, MapWrapper<? extends CdmBase>> getStores() {
+ return stores;
+ }
+
+ /**
+ * @param stores the stores to set
+ */
+ public void setStores(Map<String, MapWrapper<? extends CdmBase>> stores) {
+ this.stores = stores;
+ }
+
+
+ public MapWrapper<? extends CdmBase> getStore(String storeLabel){
+ return stores.get(storeLabel);
+ }
+
+
+ /**
+ * @return the treeMap
+ */
+ public Classification getTree(Object ref) {
+ return treeMap.get(ref);
+ }
+
+ /**
+ * @param treeMap the treeMap to set
+ */
+ public void putTree(Object ref, Classification tree) {
+ if (tree != null){
+ this.treeMap.put(ref, tree);
+ }
+ }
+
+ public int countTrees(){
+ return treeUuidMap.size();
+ }
+
+ /**
+ * @return the treeUuid
+ */
+ public UUID getTreeUuid(Reference ref) {
+ return treeUuidMap.get(ref);
+ }
+
+ public void putTreeUuid(Reference ref, Classification tree) {
+ if (tree != null && tree.getUuid() != null){
+ this.treeUuidMap.put(ref, tree.getUuid());
+ }
+ }
+
+ public int countTreeUuids(){
+ return treeUuidMap.size();
+ }
+
+
+ /**
+ * Adds a classification uuid to the classification uuid map,
+ * which maps a key for the classification to its UUID in the CDM
+ * @param classificationKeyId
+ * @param classification
+ */
+ public void putClassificationUuidInt(int classificationKeyId, Classification classification) {
+ putClassificationUuid(String.valueOf(classificationKeyId), classification);
+ }
+
+ public void putClassificationUuid(String treeKey, Classification tree) {
+ if (tree != null && tree.getUuid() != null){
+ this.classificationKeyUuidMap.put(treeKey, tree.getUuid());
+ }
+ }
+
+ public UUID getTreeUuidByIntTreeKey(int treeKey) {
+ return classificationKeyUuidMap.get(String.valueOf(treeKey));
+ }
+
+ public UUID getTreeUuidByTreeKey(String treeKey) {
+ return classificationKeyUuidMap.get(treeKey);
+ }
+
+
+ public DefinedTerm getIdentifierType(UUID uuid){
+ return identifierTypeMap.get(uuid);
+ }
+
+ public void putIdentifierType(DefinedTerm identifierType){
+ identifierTypeMap.put(identifierType.getUuid(), identifierType);
+ }
+
+ public ExtensionType getExtensionType(UUID uuid){
+ return extensionTypeMap.get(uuid);
+ }
+
+ public void putExtensionType(ExtensionType extensionType){
+ extensionTypeMap.put(extensionType.getUuid(), extensionType);
+ }
+
+ public MarkerType getMarkerType(UUID uuid){
+ return markerTypeMap.get(uuid);
+ }
+
+ public void putMarkerType(MarkerType markerType){
+ markerTypeMap.put(markerType.getUuid(), markerType);
+ }
+
+ public AnnotationType getAnnotationType(UUID uuid){
+ return annotationTypeMap.get(uuid);
+ }
+
+ public void putAnnotationType(AnnotationType annotationType){
+ annotationTypeMap.put(annotationType.getUuid(), annotationType);
+ }
+
+ public NamedArea getNamedArea(UUID uuid){
+ return namedAreaMap.get(uuid);
+ }
+
+ public void putNamedArea(NamedArea namedArea){
+ namedAreaMap.put(namedArea.getUuid(), namedArea);
+ }
+
+ public NamedAreaLevel getNamedAreaLevel(UUID uuid){
+ return namedAreaLevelMap.get(uuid);
+ }
+
+
+ public void putNamedAreaLevel(NamedAreaLevel namedAreaLevel){
+ namedAreaLevelMap.put(namedAreaLevel.getUuid(), namedAreaLevel);
+ }
+
+ public Rank getRank(UUID uuid){
+ return rankMap.get(uuid);
+ }
+
+
+ public void putRank(Rank rank){
+ rankMap.put(rank.getUuid(), rank);
+ }
+
+ public State getStateTerm(UUID uuid){
+ return stateTermMap.get(uuid);
+ }
+
+ public void putStateTerm(State stateTerm){
+ stateTermMap.put(stateTerm.getUuid(), stateTerm);
+ }
+
+ public Feature getFeature(UUID uuid){
+ return featureMap.get(uuid);
+ }
+
+ public void putFeature(Feature feature){
+ featureMap.put(feature.getUuid(), feature);
+ }
+
+ public DefinedTerm getKindOfUnit(UUID uuid){
+ return kindOfUnitMap.get(uuid);
+ }
+
+ public void putKindOfUnit(DefinedTerm unit){
+ kindOfUnitMap.put(unit.getUuid(), unit);
+ }
+
+ public MeasurementUnit getMeasurementUnit(UUID uuid){
+ return measurementUnitMap.get(uuid);
+ }
+
+ public void putMeasurementUnit(MeasurementUnit unit){
+ measurementUnitMap.put(unit.getUuid(), unit);
+ }
+
+ public void putStatisticalMeasure(StatisticalMeasure unit){
+ statisticalMeasureMap.put(unit.getUuid(), unit);
+ }
+
+ public StatisticalMeasure getStatisticalMeasure(UUID uuid){
+ return statisticalMeasureMap.get(uuid);
+ }
+
+
+ public DefinedTerm getModifier(UUID uuid){
+ return modifierMap.get(uuid);
+ }
+
+ public void putModifier(DefinedTerm unit){
+ modifierMap.put(unit.getUuid(), unit);
+ }
+
+ public TaxonRelationshipType getTaxonRelationshipType(UUID uuid){
+ return taxonRelationshipTypeMap.get(uuid);
+ }
+
+ public void putTaxonRelationshipType(TaxonRelationshipType relType){
+ taxonRelationshipTypeMap.put(relType.getUuid(), relType);
+ }
+
+
+ public PresenceAbsenceTerm getPresenceAbsenceTerm(UUID uuid){
+ return presenceTermMap.get(uuid);
+ }
+
+ public void putPresenceAbsenceTerm(PresenceAbsenceTerm presenceTerm){
+ presenceTermMap.put(presenceTerm.getUuid(), presenceTerm);
+ }
+
+ public Language getLanguage(UUID uuid){
+ return languageMap.get(uuid);
+ }
+
+ public void putLanguage(Language language){
+ languageMap.put(language.getUuid(), language);
+ }
+
+
+ public ReferenceSystem getReferenceSystem(UUID uuid){
+ return referenceSystemMap.get(uuid);
+ }
+
+ public void putReferenceSystem(ReferenceSystem referenceSystem){
+ referenceSystemMap.put(referenceSystem.getUuid(), referenceSystem);
+ }
+
+
+ //TODO make this abstract or find another way to force that the
+ //transformer exists
+ public IInputTransformer getTransformer(){
+ return inputTransformer;
+ }
+
+ public void setTransformer(IInputTransformer transformer){
+ this.inputTransformer = transformer;
+ }
+
+ /**
+ * Returns true, if this import is in validation state. Flase otherwise
+ * @return
+ */
+ public boolean isCheck() {
+ return isCheck;
+ }
+
+ /**
+ * @see #isCheck
+ * @param isCheck
+ */
+ public void setCheck(boolean isCheck) {
+ this.isCheck = isCheck;
+ }
+
+ /**
+ * Returns the import report as a byte array
+ * @return
+ */
+ public byte[] getReportAsByteArray() {
+ return null;
+ }
+
+
+}
package eu.etaxonomy.cdm.io.specimen.abcd206.in;
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.HashMap;
private static final String COLON = ":";
- private Abcd206ImportReport report;
-
-
public Abcd206Import() {
super();
}
@Override
@SuppressWarnings("rawtypes")
public void doInvoke(Abcd206ImportState state) {
- report = new Abcd206ImportReport();
try{
state.setTx(startTransaction());
logger.info("INVOKE Specimen Import from ABCD2.06 XML ");
}
}
- UnitAssociationWrapper unitAssociationWrapper = AbcdParseUtility.parseUnitsNodeList(state.getConfig().getSource(), report);
+ UnitAssociationWrapper unitAssociationWrapper = AbcdParseUtility.parseUnitsNodeList(state.getConfig().getSource(), state.getReport());
NodeList unitsList = unitAssociationWrapper.getAssociatedUnits();
state.setPrefix(unitAssociationWrapper.getPrefix());
catch(Exception e){
String errorDuringImport = "Exception during import!";
logger.error(errorDuringImport, e);
- report.addException(errorDuringImport, e);
+ state.getReport().addException(errorDuringImport, e);
}
finally{
- report.printReport(state.getConfig().getReportUri());
+ state.getReport().printReport(state.getConfig().getReportUri());
}
return;
}
state.setDerivedUnitBase(derivedUnit);
derivedUnitFacade = DerivedUnitFacade.NewInstance(state.getDerivedUnitBase());
importAssociatedUnits(state, item, derivedUnitFacade);
- report.addAlreadyExistingSpecimen(AbcdImportUtility.getUnitID(derivedUnit, state.getConfig()), derivedUnit);
+ state.getReport().addAlreadyExistingSpecimen(AbcdImportUtility.getUnitID(derivedUnit, state.getConfig()), derivedUnit);
return;
}
}
// import DNA unit
if(state.getDataHolder().kindOfUnit!=null && state.getDataHolder().kindOfUnit.equalsIgnoreCase("dna")){
- AbcdDnaParser dnaParser = new AbcdDnaParser(state.getPrefix(), report, state.getCdmRepository());
+ AbcdDnaParser dnaParser = new AbcdDnaParser(state.getPrefix(), state.getReport(), state.getCdmRepository());
DnaSample dnaSample = dnaParser.parse(item, state);
save(dnaSample, state);
//set dna as derived unit to avoid creating an extra specimen for this dna sample (instead just the field unit will be created)
} catch (Exception e) {
String message = "Error when reading record!";
logger.warn(message);
- report.addException(message, e);
+ state.getReport().addException(message, e);
e.printStackTrace();
state.setUnsuccessfull();
}
for(int k=0;k<unitAssociationList.getLength();k++){
if(unitAssociationList.item(k) instanceof Element){
Element unitAssociation = (Element)unitAssociationList.item(k);
- UnitAssociationParser unitAssociationParser = new UnitAssociationParser(currentPrefix, report, state.getCdmRepository());
+ UnitAssociationParser unitAssociationParser = new UnitAssociationParser(currentPrefix, state.getReport(), state.getCdmRepository());
UnitAssociationWrapper associationWrapper = unitAssociationParser.parse(unitAssociation);
if(associationWrapper!=null){
NodeList associatedUnits = associationWrapper.getAssociatedUnits();
java.util.Collection<FieldUnit> associatedFieldUnits = state.getCdmRepository().getOccurrenceService().getFieldUnits(associatedUnit.getUuid());
//ignore field unit if associated unit has more than one
if(associatedFieldUnits.size()>1){
- report.addInfoMessage(String.format("%s has more than one field unit.", associatedUnit));
+ state.getReport().addInfoMessage(String.format("%s has more than one field unit.", associatedUnit));
}
else if(associatedFieldUnits.size()==1){
associatedFieldUnit = associatedFieldUnits.iterator().next();
//copy derivation event and connect parent and sub derivative
if(associationWrapper.getAssociationType().contains("individual")){
if(currentDerivedFrom==null){
- report.addInfoMessage(String.format("No derivation event found for unit %s. Defaulting to ACCESSIONING event.",AbcdImportUtility.getUnitID(currentUnit, state.getConfig())));
+ state.getReport().addInfoMessage(String.format("No derivation event found for unit %s. Defaulting to ACCESSIONING event.",AbcdImportUtility.getUnitID(currentUnit, state.getConfig())));
DerivationEvent.NewSimpleInstance(associatedUnit, currentUnit, DerivationEventType.ACCESSIONING());
}
else{
updatedDerivationEvent.setInstitution(currentDerivedFrom.getInstitution());
updatedDerivationEvent.setTimeperiod(currentDerivedFrom.getTimeperiod());
}
- report.addDerivate(associatedUnit, currentUnit, state.getConfig());
+ state.getReport().addDerivate(associatedUnit, currentUnit, state.getConfig());
}
//siblings relation
//connect current unit to field unit of associated unit
}
else{
if(currentDerivedFrom==null){
- report.addInfoMessage("No derivation event found for unit "+AbcdImportUtility.getUnitID(currentUnit, state.getConfig())+". Defaulting to ACCESIONING event.");
+ state.getReport().addInfoMessage("No derivation event found for unit "+AbcdImportUtility.getUnitID(currentUnit, state.getConfig())+". Defaulting to ACCESIONING event.");
DerivationEvent.NewSimpleInstance(associatedFieldUnit, currentUnit, DerivationEventType.ACCESSIONING());
}
if(currentDerivedFrom!=null && associatedFieldUnit!=currentFieldUnit){
save(taxonDescription, state);
save(taxon, state);
- report.addDerivate(state.getDerivedUnitBase(), state.getConfig());
- report.addIndividualAssociation(taxon, state.getDataHolder().unitID, state.getDerivedUnitBase());
+ state.getReport().addDerivate(state.getDerivedUnitBase(), state.getConfig());
+ state.getReport().addIndividualAssociation(taxon, state.getDataHolder().unitID, state.getDerivedUnitBase());
}
/**
if(config.isReuseExistingTaxaWhenPossible()){
NonViralName<?> parsedName = atomisedTaxonName;
if(parsedName==null){
- parsedName = parseScientificName(scientificName, state, report);
+ parsedName = parseScientificName(scientificName, state, state.getReport());
}
if(config.isIgnoreAuthorship() && parsedName!=null && preferredFlag){
// do not ignore authorship for non-preferred names because they need
// to be created for the determination history
String nameCache = parsedName.getNameCache();
List<NonViralName> names = getNameService().findNamesByNameCache(nameCache, MatchMode.EXACT, null);
- taxonName = getBestMatchingName(scientificName, new ArrayList<TaxonNameBase>(names));
+ taxonName = getBestMatchingName(scientificName, new ArrayList<TaxonNameBase>(names), state);
}
else {
//search for existing names
List<TaxonNameBase> names = getNameService().listByTitle(TaxonNameBase.class, scientificName, MatchMode.EXACT, null, null, null, null, null);
- taxonName = getBestMatchingName(scientificName, names);
+ taxonName = getBestMatchingName(scientificName, names, state);
//still nothing found -> try with the atomised name full title cache
if(taxonName==null && atomisedTaxonName!=null){
names = getNameService().listByTitle(TaxonNameBase.class, atomisedTaxonName.getFullTitleCache(), MatchMode.EXACT, null, null, null, null, null);
- taxonName = getBestMatchingName(atomisedTaxonName.getTitleCache(), names);
+ taxonName = getBestMatchingName(atomisedTaxonName.getTitleCache(), names, state);
//still nothing found -> try with the atomised name title cache
if(taxonName==null){
names = getNameService().listByTitle(TaxonNameBase.class, atomisedTaxonName.getTitleCache(), MatchMode.EXACT, null, null, null, null, null);
- taxonName = getBestMatchingName(atomisedTaxonName.getTitleCache(), names);
+ taxonName = getBestMatchingName(atomisedTaxonName.getTitleCache(), names, state);
}
}
}
if(taxonName==null && atomisedTaxonName!=null){
taxonName = atomisedTaxonName;
- report.addName(taxonName);
+ state.getReport().addName(taxonName);
logger.info("Created new taxon name "+taxonName);
if(taxonName.hasProblem()){
- report.addInfoMessage(String.format("Created %s with parsing problems", taxonName));
+ state.getReport().addInfoMessage(String.format("Created %s with parsing problems", taxonName));
}
if(!atomisedTaxonName.getTitleCache().equals(scientificName)){
- report.addInfoMessage(String.format("Taxon %s was parsed as %s", scientificName, atomisedTaxonName.getTitleCache()));
+ state.getReport().addInfoMessage(String.format("Taxon %s was parsed as %s", scientificName, atomisedTaxonName.getTitleCache()));
}
}
else if(taxonName==null){
taxonName = NonViralName.NewInstance(rank);
taxonName.setFullTitleCache(scientificName,true);
taxonName.setTitleCache(scientificName, true);
- report.addName(taxonName);
+ state.getReport().addName(taxonName);
logger.info("Created new taxon name "+taxonName);
}
save(taxonName, state);
return taxonName;
}
- private TaxonNameBase<?, ?> getBestMatchingName(String scientificName, java.util.Collection<TaxonNameBase> names){
+ private TaxonNameBase<?, ?> getBestMatchingName(String scientificName, java.util.Collection<TaxonNameBase> names, Abcd206ImportState state){
List<TaxonNameBase> namesWithAcceptedTaxa = new ArrayList<TaxonNameBase>();
for (TaxonNameBase name : names) {
if(!name.getTaxa().isEmpty()){
//check for names with accepted taxa
if(namesWithAcceptedTaxa.size()>0){
if(namesWithAcceptedTaxa.size()>1){
- report.addInfoMessage(message);
+ state.getReport().addInfoMessage(message);
logger.warn(message);
return null;
}
}
if(taxaFromSynonyms.size()>0){
if(taxaFromSynonyms.size()>1){
- report.addInfoMessage(message);
+ state.getReport().addInfoMessage(message);
logger.warn(message);
return null;
}
if(acceptedTaxa.size()>1){
String message = "More than one accepted taxon was found for taxon name: "
+ taxonNameBase.getTitleCache() + "!\n" + firstAcceptedTaxon + "was chosen for "+state.getDerivedUnitBase();
- report.addInfoMessage(message);
+ state.getReport().addInfoMessage(message);
logger.warn(message);
}
else{
String message = "No accepted taxa could be found for taxon name: "
+ taxonNameBase.getTitleCache()
+ "!\nEither it is a pro parte synonym or has no accepted taxa";
- report.addInfoMessage(message);
+ state.getReport().addInfoMessage(message);
logger.warn(message);
}
else{
}
Taxon taxon = Taxon.NewInstance(taxonNameBase, state.getRef());
save(taxon, state);
- report.addTaxon(taxon);
+ state.getReport().addTaxon(taxon);
logger.info("Created new taxon "+ taxon);
return taxon;
}
}
}
if(node!=null){
- report.addTaxonNode(node);
+ state.getReport().addTaxonNode(node);
return node.getTaxon();
}
String message = "Could not create taxon node for " +child;
- report.addInfoMessage(message);
+ state.getReport().addInfoMessage(message);
logger.warn(message);
return null;
}
}
}
else if (state.getDataHolder().nomenclatureCode.equals("Botanical")) {
- BotanicalName taxonName = (BotanicalName) parseScientificName(fullName, state, report);
+ BotanicalName taxonName = (BotanicalName) parseScientificName(fullName, state, state.getReport());
if (taxonName != null){
return taxonName;
}
return false;
}
- @Override
- public byte[] getByteArray() {
- ByteArrayOutputStream importStream = new ByteArrayOutputStream();
- report.printReport(new PrintStream(importStream));
- return importStream.toByteArray();
- }
-
}
\ No newline at end of file
package eu.etaxonomy.cdm.io.specimen.abcd206.in;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
private String prefix;
+ private Abcd206ImportReport report;
+
private Classification classification = null;
private Classification defaultClassification = null;
private Reference<?> ref = null;
public Abcd206ImportState(Abcd206ImportConfigurator config) {
super(config);
+ report = new Abcd206ImportReport();
}
//************************ GETTER / SETTER *****************************************/
return prefix;
}
+ public Abcd206ImportReport getReport(){
+ return report;
+ }
+
+ @Override
+ public byte[] getReportAsByteArray() {
+ ByteArrayOutputStream importStream = new ByteArrayOutputStream();
+ report.printReport(new PrintStream(importStream));
+ return importStream.toByteArray();
+ }
+
public void reset() {
getDataHolder().reset();
derivedUnitBase = null;