+ 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, SpecimenImportReport report) {
+ UnitAssociationWrapper unitAssociationWrapper = new UnitAssociationWrapper();
+ NodeList unitList = null;
+ try {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+
+ Document document = builder.parse(inputStream);
+ Element root = document.getDocumentElement();
+ unitList = root.getElementsByTagName("Unit");
+ if (unitList.getLength()>0) {
+ unitAssociationWrapper.setPrefix("");
+ unitAssociationWrapper.setAssociatedUnits(unitList);
+ return unitAssociationWrapper;
+ }
+ unitList = root.getElementsByTagName("abcd:Unit");
+ if (unitList.getLength()>0) {
+ unitAssociationWrapper.setPrefix("abcd:");
+ unitAssociationWrapper.setAssociatedUnits(unitList);
+ return unitAssociationWrapper;
+ }
+ unitList = root.getElementsByTagName("abcd21:Unit");
+ if (unitList.getLength()>0) {
+ unitAssociationWrapper.setPrefix("abcd21:");
+ unitAssociationWrapper.setAssociatedUnits(unitList);
+ }
+ } catch (Exception e) {
+ logger.warn(e);
+ if(report!=null){
+ report.addException("Exception during parsing of nodeList!", e);
+ }
+ }
+ return unitAssociationWrapper;
+ }
+}
\ No newline at end of file