-// $Id$
/**
* Copyright (C) 2015 EDIT
* European Distributed Institute of Taxonomy
import java.io.InputStream;
import java.net.URI;
import java.util.Date;
+import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import eu.etaxonomy.cdm.api.application.ICdmRepository;
+import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
+import eu.etaxonomy.cdm.persistence.query.MatchMode;
+
/**
* @author pplitzner
- * @date 16.06.2015
- *
+ * @since 16.06.2015
*/
public class AbcdParseUtility {
private static final Logger logger = Logger.getLogger(AbcdParseUtility.class);
-
- public static URI parseFirstUri(NodeList nodeList, Abcd206ImportReport report){
+ public static URI parseFirstUri(NodeList nodeList, SpecimenImportReport report){
URI uri = null;
String textContent = parseFirstTextContent(nodeList);
if(textContent!=null){
public static String parseFirstTextContent(NodeList nodeList, boolean cleanUpWhiteSpaces){
String string = null;
- if(nodeList.getLength()>0){
+ if(nodeList!=null && nodeList.getLength()>0){
string = nodeList.item(0).getTextContent();
if(cleanUpWhiteSpaces){
string = string.replace("\n", "").replaceAll("( )+", " ").trim();
return string;
}
- public static Double parseFirstDouble(NodeList nodeList, Abcd206ImportReport report){
+ public static Double parseFirstDouble(NodeList nodeList, SpecimenImportReport report){
if(nodeList.getLength()>0){
return parseDouble(nodeList.item(0), report);
}
return null;
}
- public static Double parseDouble(Node node, Abcd206ImportReport report){
+ public static Double parseDouble(Node node, SpecimenImportReport report){
String message = "Could not parse double value for node " + node.getNodeName();
Double doubleValue = null;
try{
textContent = textContent.replace(".","");
//convert commmas
textContent = textContent.replace(",",".");
- doubleValue = Double.parseDouble(textContent);
+ if (!CdmUtils.isBlank(textContent)){
+ doubleValue = Double.parseDouble(textContent);
+ }
} catch (NullPointerException npe){
logger.error(message, npe);
if(report!=null){
return date;
}
+ public static Reference parseFirstReference(NodeList referenceNodeList, ICdmRepository cdmAppController){
+ String referenceCitation = AbcdParseUtility.parseFirstTextContent(referenceNodeList);
+ //check if reference already exists
+ List<Reference> matchingReferences = cdmAppController.getReferenceService().findByTitleWithRestrictions(Reference.class, referenceCitation, MatchMode.EXACT, null, null, null, null, null).getRecords();
+ Reference reference;
+ if(matchingReferences.size()==1){
+ reference = matchingReferences.iterator().next();
+ }
+ else{
+ reference = ReferenceFactory.newGeneric();
+ reference.setTitle(referenceCitation);
+ cdmAppController.getReferenceService().saveOrUpdate(reference);
+ }
+ return reference;
+ }
+
/**
* Return the wrapper with the list of root nodes for an ABCD XML file
* @param fileName: the file's location
* @return a wrapper with a list of root nodes ("Unit")
*/
- public static UnitAssociationWrapper parseUnitsNodeList(InputStream inputStream, Abcd206ImportReport report) {
+ public static UnitAssociationWrapper parseUnitsNodeList(InputStream inputStream, SpecimenImportReport report) {
UnitAssociationWrapper unitAssociationWrapper = new UnitAssociationWrapper();
NodeList unitList = null;
try {
}
return unitAssociationWrapper;
}
-
-}
+}
\ No newline at end of file