2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.io
;
13 import java
.net
.URISyntaxException
;
14 import java
.util
.ArrayList
;
15 import java
.util
.HashMap
;
16 import java
.util
.HashSet
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.springframework
.stereotype
.Component
;
22 import eu
.etaxonomy
.cdm
.app
.images
.AbstractImageImporter
;
23 import eu
.etaxonomy
.cdm
.app
.images
.ImageImportConfigurator
;
24 import eu
.etaxonomy
.cdm
.app
.images
.ImageImportState
;
25 import eu
.etaxonomy
.cdm
.common
.ExcelUtils
;
26 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
27 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
28 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
29 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
30 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
31 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentationPart
;
32 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
40 public class PalmaeProtologueImport
extends AbstractImageImporter
{
41 private static final Logger logger
= Logger
.getLogger(PalmaeProtologueImport
.class);
43 public static final String SPECIES
= "Species";
44 public static final String TAXONID
= "Taxon ID";
45 public static final String LINK_PROTO
= "Link proto";
48 * @see eu.etaxonomy.cdm.app.images.AbstractImageImporter#invokeImageImport(eu.etaxonomy.cdm.io.common.IImportConfigurator)
51 protected void invokeImageImport(ImageImportState state
) {
53 ArrayList
<HashMap
<String
, String
>> contents
;
55 contents
= ExcelUtils
.parseXLS(state
.getConfig().getSource());
56 } catch (/*FileNotFound*/Exception e
) {
57 logger
.error("FileNotFound: " + state
.getConfig().getSource().toString());
58 state
.setUnsuccessfull();
62 Set
<TaxonNameBase
> taxonNameStore
= new HashSet
<TaxonNameBase
>();
66 for (HashMap
<String
, String
> row
: contents
){
69 TaxonNameBase taxonNameBase
= null;
70 String species
= null;
71 String taxonId
= null;
72 String linkProto
= null;
74 species
= row
.get(PalmaeProtologueImport
.SPECIES
).trim();
75 taxonId
= row
.get(PalmaeProtologueImport
.TAXONID
);
76 linkProto
= row
.get(PalmaeProtologueImport
.LINK_PROTO
).trim();
77 taxonNameBase
= (TaxonNameBase
)getCommonService().getSourcedObjectByIdInSource(TaxonNameBase
.class, "palm_tn_" + taxonId
.replace(".0", ""), "TaxonName");
79 logger
.error("The row has errors: rowNumber: " +count
+ ", content: " + row
, e
);
84 if(taxonNameBase
== null){
85 logger
.warn("no taxon with this name found: " + species
+ ", idInSource: " + taxonId
);
90 uri
= new URI(linkProto
);
91 MediaRepresentationPart representationPart
= MediaRepresentationPart
.NewInstance(uri
, 0);
92 MediaRepresentation representation
= MediaRepresentation
.NewInstance("text/html", null);
93 representation
.addRepresentationPart(representationPart
);
95 Media media
= Media
.NewInstance();
96 media
.addRepresentation(representation
);
98 TaxonNameDescription description
= TaxonNameDescription
.NewInstance();
99 TextData protolog
= TextData
.NewInstance(Feature
.PROTOLOGUE());
100 protolog
.addMedia(media
);
101 description
.addElement(protolog
);
102 taxonNameBase
.addDescription(description
);
103 } catch (URISyntaxException e
) {
104 String message
= "URISyntaxException when trying to convert: " + linkProto
;
105 logger
.error(message
);
109 taxonNameStore
.add(taxonNameBase
);
111 logger
.info(count
+ " protologues processed.");
117 getNameService().save(taxonNameStore
);
118 logger
.info(count
+ " protologues imported to CDM store.");