import java.io.IOException;
import java.io.InputStream;
+import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade.DerivedUnitType;
-import eu.etaxonomy.cdm.common.mediaMetaData.ImageMetaData;
import eu.etaxonomy.cdm.io.common.ICdmIO;
-import eu.etaxonomy.cdm.io.specimen.SpecimenIoBase;
+import eu.etaxonomy.cdm.io.specimen.SpecimenImportBase;
import eu.etaxonomy.cdm.io.specimen.UnitsGatheringArea;
import eu.etaxonomy.cdm.io.specimen.UnitsGatheringEvent;
import eu.etaxonomy.cdm.model.agent.Institution;
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
import eu.etaxonomy.cdm.model.description.TaxonDescription;
import eu.etaxonomy.cdm.model.location.NamedArea;
-import eu.etaxonomy.cdm.model.media.ImageFile;
import eu.etaxonomy.cdm.model.media.Media;
-import eu.etaxonomy.cdm.model.media.MediaRepresentation;
import eu.etaxonomy.cdm.model.name.BacterialName;
import eu.etaxonomy.cdm.model.name.BotanicalName;
import eu.etaxonomy.cdm.model.name.CultivarPlantName;
* @version 1.0
*/
@Component
-public class Abcd206Import extends SpecimenIoBase<Abcd206ImportConfigurator, Abcd206ImportState> implements ICdmIO<Abcd206ImportState> {
+public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator, Abcd206ImportState> implements ICdmIO<Abcd206ImportState> {
private static final Logger logger = Logger.getLogger(Abcd206Import.class);
logger.info("INVOKE Specimen Import from ABCD2.06 XML File");
boolean result = true;
//AbcdIO test = new AbcdIO();
- String sourceName = state.getConfig().getSource();
+ URI sourceName = state.getConfig().getSource();
NodeList unitsList = getUnitsNodeList(sourceName);
if (unitsList != null){
String message = "nb units to insert: "+unitsList.getLength();
// //add Multimedia URLs
if(dataHolder.multimediaObjects.size() > 0){
- MediaRepresentation representation;
- Media media;
- ImageMetaData imd ;
- URL url ;
- ImageFile imf;
for (String multimediaObject : dataHolder.multimediaObjects){
- if( multimediaObject != null){
- imd = ImageMetaData.newInstance();
- url = new URL(multimediaObject);
- try {
- imd.readMetaData(url.toURI(), 0);
- } catch (Exception e) {
- String message = "An error occurred when trying to read image meta data: " + e.getMessage();
- logger.warn(message);
- }
- //TODO do we really want to check the url?
- if (imd != null){
- imf = ImageFile.NewInstance(multimediaObject, null, imd);
- representation = MediaRepresentation.NewInstance();
- representation.addRepresentationPart(imf);
- media = Media.NewInstance();
- media.addRepresentation(representation);
-
- derivedUnitFacade.addFieldObjectMedia(media);
- }
- }
+ Media media = getImageMedia(multimediaObject, true);
+ derivedUnitFacade.addDerivedUnitMedia(media);
}
}
}
getTermService().saveLanguageData(unitsGatheringEvent.getLocality());//TODO needs to be saved ?? save it sooner
- getOccurrenceService().save(derivedUnitFacade.getDerivedUnit());
+ getOccurrenceService().save(derivedUnitFacade.innerDerivedUnit());
logger.info("saved ABCD specimen ...");
return result;
}
-
private void setCollectionData(Abcd206ImportConfigurator config,
Abcd206DataHolder dataHolder, DerivedUnitFacade derivedUnitFacade) {
//set catalogue number (unitID)
* @param fileName: the file's location
* @return the list of root nodes ("Unit")
*/
- private static NodeList getUnitsNodeList(String urlFileName){
+ private static NodeList getUnitsNodeList(URI urlFileName){
NodeList unitList = null;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
- URL url = new URL(urlFileName);
+ URL url = urlFileName.toURL();
Object o = url.getContent();
InputStream is = (InputStream)o;
Document document = builder.parse(is);
path="";
dataHolder.longitude = Double.valueOf(group.item(0).getTextContent());
} catch (NullPointerException e) {
- dataHolder.longitude=0.0;
+ dataHolder.longitude=null;
}
try {
group = root.getElementsByTagName("LatitudeDecimal");
path="";
dataHolder.latitude = Double.valueOf(group.item(0).getTextContent());
} catch (NullPointerException e) {
- dataHolder.latitude=0.0;
+ dataHolder.latitude=null;
}
try {
group = root.getElementsByTagName("Country");
if (config.isDoMatchTaxa()){
taxon = getTaxonService().findBestMatchingTaxon(scientificName);
}
+
if (taxon == null && config.isDoReUseTaxon()){
try{
names = getTaxonService().searchTaxaByName(scientificName, sec);
}
}
IndividualsAssociation individualsAssociation = IndividualsAssociation.NewInstance();
- individualsAssociation.setAssociatedSpecimenOrObservation(facade.getDerivedUnit());
+ individualsAssociation.setAssociatedSpecimenOrObservation(facade.innerDerivedUnit());
individualsAssociation.setFeature(Feature.INDIVIDUALS_ASSOCIATION());
for(ReferenceBase citation : determinationEvent.getReferences()){
individualsAssociation.addSource(DescriptionElementSource.NewInstance(null, null, citation, null));
return value;
}
- private void compareABCDtoCDM(String urlFileName, ArrayList<String> knownElts, Abcd206DataHolder dataHolder){
+ private void compareABCDtoCDM(URI urlFileName, ArrayList<String> knownElts, Abcd206DataHolder dataHolder){
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder constructeur = factory.newDocumentBuilder();
- URL url = new URL(urlFileName);
+ URL url = urlFileName.toURL();
Object o = url.getContent();
InputStream is = (InputStream)o;
Document document = constructeur.parse(is);