\r
package eu.etaxonomy.cdm.io.globis;\r
\r
+import java.io.IOException;\r
+import java.net.MalformedURLException;\r
+import java.net.URI;\r
import java.sql.ResultSet;\r
import java.sql.SQLException;\r
import java.util.HashMap;\r
import java.util.HashSet;\r
import java.util.Map;\r
import java.util.Set;\r
+import java.util.UUID;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
\r
-import org.apache.commons.lang.StringUtils;\r
+import org.apache.http.client.ClientProtocolException;\r
import org.apache.log4j.Logger;\r
import org.springframework.stereotype.Component;\r
\r
+import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;\r
+import eu.etaxonomy.cdm.common.UriUtils;\r
import eu.etaxonomy.cdm.io.common.IOValidator;\r
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;\r
-import eu.etaxonomy.cdm.io.globis.validation.GlobisCurrentSpeciesImportValidator;\r
+import eu.etaxonomy.cdm.io.globis.validation.GlobisImageImportValidator;\r
+import eu.etaxonomy.cdm.model.common.Annotation;\r
import eu.etaxonomy.cdm.model.common.CdmBase;\r
import eu.etaxonomy.cdm.model.common.Language;\r
+import eu.etaxonomy.cdm.model.common.Marker;\r
+import eu.etaxonomy.cdm.model.common.MarkerType;\r
+import eu.etaxonomy.cdm.model.common.OriginalSourceType;\r
import eu.etaxonomy.cdm.model.media.Media;\r
-import eu.etaxonomy.cdm.model.name.Rank;\r
import eu.etaxonomy.cdm.model.name.ZoologicalName;\r
+import eu.etaxonomy.cdm.model.occurrence.Collection;\r
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\r
+import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;\r
import eu.etaxonomy.cdm.model.reference.Reference;\r
-import eu.etaxonomy.cdm.model.taxon.Classification;\r
+import eu.etaxonomy.cdm.model.reference.ReferenceFactory;\r
import eu.etaxonomy.cdm.model.taxon.Taxon;\r
-import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
-import eu.etaxonomy.cdm.model.taxon.TaxonNode;\r
-import eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException;\r
-import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser;\r
-import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;\r
\r
\r
/**\r
public class GlobisImageImport extends GlobisImportBase<Taxon> {\r
private static final Logger logger = Logger.getLogger(GlobisImageImport.class);\r
\r
- private int modCount = 10000;\r
+ private int modCount = 1000;\r
+\r
+ private UUID uuidArtNonSpecTaxMarkerType = UUID.fromString("be362085-0f5b-4314-96d1-78b9b129ef6d") ;\r
private static final String pluralString = "images";\r
private static final String dbTableName = "Einzelbilder";\r
- private static final Class cdmTargetClass = Media\r
- .class; //not needed\r
+ private static final Class<?> cdmTargetClass = Media.class; //not needed\r
\r
- private static final String IMAGE_NAMESPACE = "Einzelbilder";\r
+ private static UUID uuidGartRef = UUID.fromString("af85470f-6e54-4304-9d29-fd117cd56161"); \r
\r
public GlobisImageImport(){\r
super(pluralString, dbTableName, cdmTargetClass);\r
protected String getRecordQuery(GlobisImportConfigurator config) {\r
String strRecordQuery = \r
" SELECT i.*, NULL as Created_When, NULL as Created_Who," +\r
- " NULL as Updated_who, NULL as Updated_When, NULL as Notes " + \r
+ " NULL as Updated_who, NULL as Updated_When, NULL as Notes, st.SpecCurrspecID " + \r
" FROM " + getTableName() + " i " +\r
+ " LEFT JOIN specTax st ON i.spectaxID = st.SpecTaxID " +\r
" WHERE ( i.BildId IN (" + ID_LIST_TOKEN + ") )";\r
return strRecordQuery;\r
}\r
public boolean doPartition(ResultSetPartitioner partitioner, GlobisImportState state) {\r
boolean success = true;\r
\r
- Set<TaxonBase> objectsToSave = new HashSet<TaxonBase>();\r
+ Set<Media> objectsToSave = new HashSet<Media>();\r
+ \r
+ Map<String, DerivedUnit> typeMap = (Map<String, DerivedUnit>) partitioner.getObjectMap(TYPE_NAMESPACE);\r
\r
Map<String, Taxon> taxonMap = (Map<String, Taxon>) partitioner.getObjectMap(TAXON_NAMESPACE);\r
-// Map<String, DerivedUnit> ecoFactDerivedUnitMap = (Map<String, DerivedUnit>) partitioner.getObjectMap(ECO_FACT_DERIVED_UNIT_NAMESPACE);\r
+ Map<String, ZoologicalName> specTaxNameMap = (Map<String, ZoologicalName>) partitioner.getObjectMap(SPEC_TAX_NAMESPACE);\r
\r
ResultSet rs = partitioner.getResultSet();\r
-\r
- Classification classification = getClassification(state);\r
+ \r
+ Reference<?> refGart = getReferenceService().find(uuidGartRef);\r
+ \r
\r
try {\r
\r
int i = 0;\r
\r
- //for each reference\r
+ //for each record\r
while (rs.next()){\r
\r
if ((i++ % modCount) == 0 && i!= 1 ){ logger.info(pluralString + " handled: " + (i-1));}\r
\r
- Integer taxonId = rs.getInt("IDcurrentspec");\r
+ Integer bildID = rs.getInt("BildID");\r
+ Integer spectaxID = nullSafeInt(rs, "spectaxID");\r
+ Integer taxonID = nullSafeInt(rs, "SpecCurrspecID");\r
+ String copyright = rs.getString("copyright");\r
+ String specimenId = rs.getString("specimenID");\r
+ String bemerkungen = rs.getString("Bemerkungen");\r
+ String artNotSpecTax = rs.getString("Art non spectax");\r
+ String motiv = rs.getString("Motiv");\r
\r
+ //ignore: \r
+ // [file lab2], same as Dateiname04 but less data\r
+ // Dateipfad\r
+\r
+ Set<Media> recordMedia = new HashSet<Media>();\r
\r
- //TODO\r
- //String dtSpcJahr,\r
- //dtSpcFamakt,dtSpcSubfamakt,dtSpcTribakt,\r
- //fiSpcLiteratur, fiSpcspcgrptax, dtSpcCountries,vernacularnames\r
- \r
- try {\r
+ try {\r
\r
- //source ref\r
- Reference<?> sourceRef = state.getTransactionalSourceReference();\r
- Taxon nextHigherTaxon = null;\r
+ makeAllMedia(state, rs, recordMedia, objectsToSave);\r
+ \r
+ String title = null;\r
+ \r
+ DerivedUnit specimen = null;\r
+ if (spectaxID != null){\r
+ //try to find type specimen\r
+ if (isNotBlank(motiv) && (motiv.startsWith("type specimen"))){\r
+ String collectionCode = transformCopyright2CollectionCode(copyright);\r
+ String id = GlobisSpecTaxImport.getTypeId(spectaxID, collectionCode);\r
+ specimen = typeMap.get(id);\r
+ }\r
+ \r
+ //try to find specTaxName\r
+ ZoologicalName specTaxTaxonName = specTaxNameMap.get(String.valueOf(spectaxID));\r
+ if (specTaxTaxonName != null){\r
+ title = " taxon name " + specTaxTaxonName.getTitleCache();\r
+ }else{\r
+ title = " spectaxID " + spectaxID;\r
+ }\r
+ }else{\r
+ title = " name " + getNameFromFileOs(rs) + (isBlank(specimenId)? "" : " (specimenId: " + specimenId + ")");\r
+ }\r
+ \r
+ //not type specimen\r
+ if (specimen == null){\r
+ specimen = DerivedUnit.NewPreservedSpecimenInstance();\r
+ specimen.setTitleCache("Specimen for " + title );\r
+ String collectionCode = transformCopyright2CollectionCode(copyright);\r
+ //TODO\r
+ Collection collection = getCollection(collectionCode);\r
+ specimen.setCollection(collection);\r
+ }\r
\r
- Taxon species = createObject(rs, state);\r
\r
- //subgenus\r
- String subGenusStr = rs.getString("dtSpcSubgenakt");\r
- String subGenusAuthorStr = rs.getString("dtSpcSubgenaktauthor");\r
- boolean hasSubgenus = StringUtils.isNotBlank(subGenusStr) || StringUtils.isNotBlank(subGenusAuthorStr);\r
- if (hasSubgenus){\r
- Taxon subGenus = getTaxon(state, rs, subGenusStr, Rank.SUBGENUS(), subGenusAuthorStr, taxonMap);\r
- classification.addParentChild(subGenus, species, sourceRef, null);\r
- nextHigherTaxon = getParent(subGenus, classification);\r
- }\r
+ //source\r
+ specimen.addSource(OriginalSourceType.Import, String.valueOf(bildID), IMAGE_NAMESPACE, state.getTransactionalSourceReference(), null);\r
\r
- //genus\r
- String genusStr = rs.getString("dtSpcGenusakt");\r
- String genusAuthorStr = rs.getString("dtSpcGenusaktauthor");\r
- Taxon genus = getTaxon(state, rs, genusStr, Rank.GENUS(), genusAuthorStr, taxonMap);\r
- if (nextHigherTaxon != null){\r
- if (! compareTaxa(genus, nextHigherTaxon)){\r
- logger.warn("Current genus and parent of subgenus are not equal: " + taxonId);\r
+ //GART id (specimenID)\r
+ if (isNotBlank(specimenId)){\r
+ specimen.addSource(OriginalSourceType.Lineage, specimenId, "specimenId", refGart, null);\r
+ }\r
+ //bemerkungen\r
+ if (isNotBlank(bemerkungen)){\r
+ Annotation annotation = Annotation.NewInstance(bemerkungen, null, null);\r
+ specimen.addAnnotation(annotation);\r
+ }\r
+ //media\r
+ DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(specimen);\r
+ for (Media media: recordMedia){\r
+ facade.addDerivedUnitMedia(media);\r
+ }\r
+ //art non spectax\r
+ if (isNotBlank(artNotSpecTax)){\r
+ if (artNotSpecTax.equalsIgnoreCase("ja")){\r
+ MarkerType artNotSpecTaxMarker = getMarkerType(state, uuidArtNonSpecTaxMarkerType , "Art non spectax", "This marker is true if in the orginal data the 'Art non spectax' was 'ja'", null) ;\r
+ specimen.addMarker(Marker.NewInstance(artNotSpecTaxMarker, true));\r
+ }else{\r
+ logger.warn(artNotSpecTax + " is not a valid value for 'Art non spectax' (BildID: " + bildID + ")" );\r
}\r
- }else{\r
- classification.addParentChild(genus, species, sourceRef, null);\r
- nextHigherTaxon = getParent(genus, classification);\r
}\r
- \r
- this.doIdCreatedUpdatedNotes(state, species, rs, taxonId, REFERENCE_NAMESPACE);\r
- \r
- objectsToSave.add(species); \r
- \r
+ \r
+ if (spectaxID != null){\r
+ \r
+ //add to image gallery (discuss if this is also needed if taxon is already added to type specimen\r
+// Taxon taxon = taxonMap.get(String.valueOf(taxonID));\r
+ ZoologicalName specTaxTaxonName = specTaxNameMap.get(String.valueOf(spectaxID));\r
+ \r
+// \r
+// if (taxon == null){\r
+//// taxon = specTaxMap.get(String.valueOf(spectaxID));\r
+//// specTaxName = specTaxMap.g\r
+// }\r
+// if (taxon == null){\r
+// logger.warn("No taxon available for specTaxID: " + spectaxID);\r
+// }else{\r
+// name = CdmBase.deproxy(taxon.getName(), ZoologicalName.class);\r
+// }\r
+ \r
+ //TODO FIXME\r
+ \r
+ if (specTaxTaxonName == null){\r
+ logger.warn("Name could not be found for spectaxID: " + spectaxID + " in BildID: " + bildID);\r
+ }else{\r
+ Taxon taxon = null;\r
+ for (Taxon specTaxTaxon: specTaxTaxonName.getTaxa()){\r
+ taxon = specTaxTaxon;\r
+ }\r
+ if (taxon == null){\r
+ //FIXME\r
+ Reference<?> undefinedSec = null;\r
+ taxon = Taxon.NewInstance(specTaxTaxonName, undefinedSec);\r
+ }\r
+ \r
+ DeterminationEvent.NewInstance(taxon, specimen);\r
\r
+ }\r
+ \r
+ \r
+\r
+ \r
+// if (taxon != null){\r
+// TaxonDescription taxonDescription = getTaxonDescription(taxon, true, true);\r
+// if (taxonDescription.getElements().size() == 0){\r
+// TextData textData = TextData.NewInstance(Feature.IMAGE());\r
+// taxonDescription.addElement(textData);\r
+// }\r
+// Set<DescriptionElementBase> elements = taxonDescription.getElements();\r
+// TextData textData = CdmBase.deproxy(elements.iterator().next(), TextData.class);\r
+// for (Media media: recordMedia){\r
+// textData.addMedia(media);\r
+// }\r
+// }\r
+ }\r
+ \r
} catch (Exception e) {\r
- logger.warn("Exception in current_species: IDcurrentspec " + taxonId + ". " + e.getMessage());\r
-// e.printStackTrace();\r
+ logger.warn("Exception in Einzelbilder: bildID " + bildID + ". " + e.getMessage());\r
+ e.printStackTrace();\r
} \r
\r
}\r
\r
-// logger.warn("Specimen: " + countSpecimen + ", Descriptions: " + countDescriptions );\r
-\r
- logger.warn(pluralString + " to save: " + objectsToSave.size());\r
- getTaxonService().save(objectsToSave); \r
+ logger.info(pluralString + " to save: " + objectsToSave.size());\r
+ getMediaService().save(objectsToSave); \r
\r
return success;\r
} catch (SQLException e) {\r
return false;\r
}\r
}\r
-\r
- /**\r
- * Compares 2 taxa, returns true of both taxa look similar\r
- * @param genus\r
- * @param nextHigherTaxon\r
- * @return\r
- */\r
- private boolean compareTaxa(Taxon taxon1, Taxon taxon2) {\r
- ZoologicalName name1 = CdmBase.deproxy(taxon1.getName(), ZoologicalName.class);\r
- ZoologicalName name2 = CdmBase.deproxy(taxon2.getName(), ZoologicalName.class);\r
- if (!name1.getRank().equals(name2.getRank())){\r
- return false;\r
- }\r
- if (! name1.getTitleCache().equals(name2.getTitleCache())){\r
- return false;\r
- }\r
- return true;\r
+ \r
+ private Collection getCollection(String collectionCode) {\r
+ //TODO\r
+ return null;\r
}\r
\r
\r
\r
\r
- private Taxon getParent(Taxon subgenus, Classification classification) {\r
- for (TaxonNode node : subgenus.getTaxonNodes()){\r
- if (node.getClassification().equals(classification)){\r
- return node.getParent().getTaxon();\r
- }\r
+ private String getNameFromFileOs(ResultSet rs) throws SQLException {\r
+ String fileOS = rs.getString("file OS");\r
+ Pattern pattern = Pattern.compile("(.+)(_.{4}(-.{1,3})?(_Nr\\d{3,4})?_.{2,3}\\.jpg)");\r
+ Matcher matcher = pattern.matcher(fileOS);\r
+ if (matcher.matches()){\r
+ String match = matcher.group(1);\r
+ return match;\r
+ }else{\r
+ logger.warn("FileOS does not match: " + fileOS);\r
+ return fileOS;\r
}\r
- return null;\r
}\r
\r
\r
\r
\r
- private Taxon getTaxon(GlobisImportState state, ResultSet rs, String subGenus, Rank rank, String author, Map<String, Taxon> taxonMap) {\r
- String key = subGenus + "@" + "subGenusAuthor" + "@" + rank.getTitleCache();\r
- Taxon taxon = taxonMap.get(key);\r
- if (taxon == null){\r
- ZoologicalName name = ZoologicalName.NewInstance(rank);\r
- taxon = Taxon.NewInstance(name, state.getTransactionalSourceReference());\r
- handleAuthor(author, name);\r
- getTaxonService().save(taxon);\r
- }\r
+ private void makeAllMedia(GlobisImportState state, ResultSet rs, Set<Media> recordMedia, Set<Media> objectsToSave) throws SQLException{\r
+ //make image path\r
+ String pathShort = rs.getString("Dateipfad_kurz");\r
+ String fileOS = rs.getString("file OS");\r
+ pathShort= pathShort.replace(fileOS, "");\r
+ String newPath = state.getConfig().getImageBaseUrl();\r
+ String path = pathShort.replace("image:Webversionen/", newPath);\r
\r
- return taxon;\r
- }\r
-\r
+ Media singleMedia = makeMedia(state, rs, "file OS", "Legende 1", path, objectsToSave );\r
+ recordMedia.add(singleMedia);\r
+ singleMedia = makeMedia(state, rs, "Dateinamen02", "Legende 2", path, objectsToSave );\r
+ recordMedia.add(singleMedia);\r
+ singleMedia = makeMedia(state, rs, "Dateinamen03", "Legende 3", path, objectsToSave );\r
+ recordMedia.add(singleMedia);\r
+ singleMedia = makeMedia(state, rs, "Dateinamen04", "Legende 4", path, objectsToSave );\r
+ recordMedia.add(singleMedia);\r
\r
- //fast and dirty is enough here\r
- private Classification classification;\r
- \r
- private Classification getClassification(GlobisImportState state) {\r
- if (this.classification == null){\r
- String name = state.getConfig().getClassificationName();\r
- Reference<?> reference = state.getTransactionalSourceReference();\r
- this.classification = Classification.NewInstance(name, reference, Language.DEFAULT());\r
- classification.setUuid(state.getConfig().getClassificationUuid());\r
- getClassificationService().save(classification);\r
- }\r
- return this.classification;\r
- \r
}\r
\r
- private INonViralNameParser parser = NonViralNameParserImpl.NewInstance();\r
- \r
-\r
- /* (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.io.common.mapping.IMappingImport#createObject(java.sql.ResultSet, eu.etaxonomy.cdm.io.common.ImportStateBase)\r
- */\r
- public Taxon createObject(ResultSet rs, GlobisImportState state)\r
- throws SQLException {\r
- String speciesEpi = rs.getString("dtSpcSpcakt");\r
- String subGenusEpi = rs.getString("dtSpcSubgenakt");\r
- String genusEpi = rs.getString("dtSpcGenusakt");\r
- String author = rs.getString("dtSpcAutor");\r
+ private Media makeMedia(GlobisImportState state, ResultSet rs, String fileNameAttr, String legendAttr, String path, Set<Media> objectsToSave) throws SQLException {\r
+ Media media = null;\r
+ String fileName = rs.getString(fileNameAttr);\r
+ String legend = rs.getString(legendAttr);\r
+ Integer bildID = rs.getInt("BildID");\r
\r
+ String uriStr = path+fileName;\r
+ uriStr = uriStr.replace(" ", "%20");\r
\r
- ZoologicalName zooName = ZoologicalName.NewInstance(Rank.SPECIES());\r
- zooName.setSpecificEpithet(speciesEpi);\r
- if (StringUtils.isNotBlank(subGenusEpi)){\r
- zooName.setInfraSpecificEpithet(subGenusEpi);\r
- }\r
- zooName.setGenusOrUninomial(genusEpi);\r
- handleAuthor(author, zooName);\r
+ URI uri = URI.create(uriStr); \r
\r
- Taxon taxon = Taxon.NewInstance(zooName, state.getTransactionalSourceReference());\r
+// Media media = ImageInfo.NewInstanceWithMetaData(uri, null);\r
\r
- return taxon;\r
+ try {\r
+ boolean readMediaData = state.getConfig().isDoReadMediaData();\r
+ if (isBlank(legend) && readMediaData){\r
+ if (UriUtils.isOk(UriUtils.getResponse(uri, null))){\r
+ logger.warn("Image exists but legend is null " + uri + ", bildID" + bildID );\r
+ }else{\r
+ return null;\r
+ }\r
+ }\r
+ \r
+ media = this.getImageMedia(uri.toString(), readMediaData, false);\r
+ media.putTitle(Language.ENGLISH(), legend);\r
+ this.doIdCreatedUpdatedNotes(state, media, rs, bildID, IMAGE_NAMESPACE);\r
+ \r
+ objectsToSave.add(media);\r
+ \r
+ \r
+ } catch (MalformedURLException e) {\r
+ e.printStackTrace();\r
+ } catch (ClientProtocolException e) {\r
+ e.printStackTrace();\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ return media;\r
}\r
+ \r
+ private String transformCopyright2CollectionCode(String copyright){\r
+ \r
+ if (isBlank(copyright)){\r
+ return "";\r
+ }else if(copyright.matches("Museum f.?r Naturkunde der Humboldt-Universit.?t, Berlin")){\r
+ return "MFNB";\r
+ }else if(copyright.matches("Staatliches Museum f.?r Tierkunde Dresden")){\r
+ return "SMTD";\r
+ }else if(copyright.equals("Natural History Museum, London")){\r
+ return "BMNH";\r
+ }else if(copyright.matches("Zoologische Staatssammlung M.?nchen")){\r
+ return "ZSSM";\r
+ }else if(copyright.matches("Staatliches Museum f.?r Naturkunde Karlsruhe")){\r
+ return "SMNK";\r
+ }else if(copyright.matches("Deutsches Entomologisches Institut M.?ncheberg")){\r
+ return "DEIE";\r
+ }else if(copyright.equals("Forschungsinstitut und Naturmuseum Senckenberg")){\r
+ return "SMFM";\r
+ }else if(copyright.matches("Mus.?um National d.?Histoire Naturelle, Paris")){\r
+ return "MNHN";\r
+ }else if(copyright.equals("Naturhistorisches Museum Wien")){\r
+ return "NHMW";\r
+ }else if(copyright.equals("Naturhistoriska Riksmuseet Stockholm")){\r
+ return "NRMS";\r
+ }else if(copyright.matches("Staatliches Museum f.?r Naturkunde Stuttgart")){\r
+ return "SMNS";\r
+ }else if(copyright.equals("United States National Museum of Natural History, Washington")){\r
+ return "USNM";\r
+ }else if(copyright.matches("Zentrum f.?r Biodokumentation des Saarlandes")){\r
+ return "ZFBS";\r
+ }else if(copyright.equals("Zoological Museum, University of Copenhagen")){\r
+ return "ZMUC";\r
+ }else if(copyright.equals("Zoologisches Forschungsinstitut und Museum \"Alexander Koenig\", Bonn")){\r
+ return "ZFMK";\r
+ }else if(copyright.equals("Zoologisches Forschungsmuseum \"Alexander Koenig\", Bonn")){\r
+ return "ZFMK";\r
+ }else if(copyright.matches("Zoologisches Institut der Martin-Luther-Universit.?t Halle-Wittenberg")){\r
+ return "ZIUH";\r
+ }else if(copyright.matches("Zoologisches Institut Universit.?t T.?bingen")){\r
+ return "ZIUT";\r
+ }else{\r
+ logger.warn("Unknown copyright entry: " + copyright);\r
+ return "";\r
+ }\r
\r
+ \r
+ }\r
\r
\r
\r
- /**\r
- * @param author\r
- * @param zooName\r
- */\r
- private void handleAuthor(String author, ZoologicalName zooName) {\r
- try {\r
- parser.parseAuthors(zooName, author);\r
- } catch (StringNotParsableException e) {\r
- logger.warn("Author could not be parsed: " + author);\r
- zooName.setAuthorshipCache(author, true);\r
- }\r
- }\r
-\r
/* (non-Javadoc)\r
* @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet)\r
*/\r
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs) {\r
+ String nameSpace;\r
+ Class cdmClass;\r
+ Set<String> idSet;\r
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();\r
- return result; //not needed\r
+ try{\r
+ Set<String> currSpecIdSet = new HashSet<String>();\r
+ Set<String> specTaxIdSet = new HashSet<String>();\r
+ Set<String> typeIdSet = new HashSet<String>();\r
+ \r
+ while (rs.next()){\r
+ handleForeignKey(rs, currSpecIdSet, "SpecCurrspecID");\r
+ handleForeignKey(rs, specTaxIdSet, "spectaxID");\r
+ handleTypeKey(rs, typeIdSet, "spectaxID", "copyright");\r
+ }\r
+ \r
+ //specTax map\r
+ nameSpace = SPEC_TAX_NAMESPACE;\r
+ cdmClass = ZoologicalName.class;\r
+ idSet = specTaxIdSet;\r
+ Map<String, ZoologicalName> specTaxNameMap = (Map<String, ZoologicalName>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);\r
+ result.put(nameSpace, specTaxNameMap);\r
+\r
+// //taxon map\r
+// nameSpace = TAXON_NAMESPACE;\r
+// cdmClass = Taxon.class;\r
+// idSet = currSpecIdSet;\r
+// Map<String, Taxon> taxonMap = (Map<String, Taxon>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);\r
+// result.put(nameSpace, taxonMap);\r
+\r
+ \r
+ //type map\r
+ nameSpace = GlobisSpecTaxImport.TYPE_NAMESPACE;\r
+ cdmClass = DerivedUnit.class;\r
+ idSet = typeIdSet;\r
+ Map<String, DerivedUnit> typeMap = (Map<String, DerivedUnit>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);\r
+ result.put(nameSpace, typeMap);\r
+ \r
+ \r
+ } catch (SQLException e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ return result;\r
+ }\r
+ \r
+ private void handleTypeKey(ResultSet rs, Set<String> idSet, String specTaxIdAttr, String copyrightAttr) throws SQLException {\r
+ Integer specTaxId = nullSafeInt(rs, specTaxIdAttr);\r
+ if (specTaxId != null){\r
+ String copyright = rs.getString(copyrightAttr);\r
+ if (isNotBlank(copyright)){\r
+ String id = GlobisSpecTaxImport.getTypeId(specTaxId, transformCopyright2CollectionCode(copyright));\r
+ idSet.add(id);\r
+ }\r
+ }\r
}\r
\r
/* (non-Javadoc)\r
*/\r
@Override\r
protected boolean doCheck(GlobisImportState state){\r
- IOValidator<GlobisImportState> validator = new GlobisCurrentSpeciesImportValidator();\r
+ IOValidator<GlobisImportState> validator = new GlobisImageImportValidator();\r
return validator.validate(state);\r
}\r
\r
\r
\r
\r
+ /* (non-Javadoc)\r
+ * @see eu.etaxonomy.cdm.io.globis.GlobisImportBase#doInvoke(eu.etaxonomy.cdm.io.globis.GlobisImportState)\r
+ */\r
+ @Override\r
+ protected void doInvoke(GlobisImportState state) {\r
+ Reference refGart = ReferenceFactory.newGeneric();\r
+ refGart.setTitleCache("GART");\r
+ refGart.setUuid(uuidGartRef);\r
+ getReferenceService().saveOrUpdate(refGart);\r
+ super.doInvoke(state);\r
+ }\r
+\r
+\r
+\r
+\r
\r
}\r