Fix missing inRef data
authorAndreas Müller <a.mueller@bgbm.org>
Mon, 20 Feb 2012 12:32:49 +0000 (12:32 +0000)
committerAndreas Müller <a.mueller@bgbm.org>
Mon, 20 Feb 2012 12:32:49 +0000 (12:32 +0000)
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelReferenceImport.java

index ba3e3ac1a33598ce1c882182092f9c725b2ea8b7..d13b39a59f131e7822308ee6211d336ea82b1001 100644 (file)
@@ -330,7 +330,7 @@ public class BerlinModelReferenceImport extends BerlinModelImportBase {
                        while (partitioner.nextPartition()){\r
                                partitioner.doPartition(this, state);\r
                        }\r
-                       logger.info("end make references with no in-references ... " + getSuccessString(success));\r
+                       logger.info("end make references without in-references ... " + getSuccessString(success));\r
                        state.setReferenceSecondPath(true);\r
 \r
 //                     if (config.getDoReferences() == ALL || config.getDoReferences() == NOMENCLATURAL){\r
@@ -420,6 +420,12 @@ public class BerlinModelReferenceImport extends BerlinModelImportBase {
 \r
 \r
 \r
+       /**\r
+        * Adds the inReference to the according references.\r
+        * @param partitioner\r
+        * @param state\r
+        * @return\r
+        */\r
        private boolean doPartitionSecondPath(ResultSetPartitioner partitioner, BerlinModelImportState state) {\r
                boolean success = true;\r
 \r
@@ -439,35 +445,36 @@ public class BerlinModelReferenceImport extends BerlinModelImportBase {
                                        if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("References handled: " + (i-1) + " in round -" );}\r
                                \r
                                        Integer refId = rs.getInt("refId");\r
+                                       Integer inRefFk = rs.getInt("inRefFk");\r
                                        \r
-                                       Reference<?> thisNomRef = getReferenceOnlyFromMaps(relatedNomReferences, relatedBiblioReferences, String.valueOf(refId));\r
-                                       Reference<?> thisBiblioRef = getReferenceOnlyFromMaps(relatedNomReferences, relatedBiblioReferences, String.valueOf(refId));\r
-                                       \r
-                                       Reference<?> inReference = relatedNomReferences.get("inRefFk");\r
-                                       if (thisNomRef != null){\r
-                                               thisNomRef.setInReference(inReference);\r
-                                               nomRefToSave.put(refId, thisNomRef);\r
+                                       if (inRefFk != null){\r
+                                               Reference<?> thisNomRef = getReferenceOnlyFromMaps(relatedNomReferences, relatedBiblioReferences, String.valueOf(refId));\r
+                                               Reference<?> thisBiblioRef = getReferenceOnlyFromMaps(relatedNomReferences, relatedBiblioReferences, String.valueOf(refId));\r
+                                               \r
+                                               Reference<?> nomInReference = relatedNomReferences.get("inRefFk");\r
+                                               Reference<?> biblioInReference = relatedBiblioReferences.get("inRefFk");\r
+                                               boolean inRefExists = false;\r
+                                               if (thisNomRef != null){\r
+                                                       Reference<?> inRef = (nomInReference != null)? nomInReference : biblioInReference;\r
+                                                       thisNomRef.setInReference(inRef);\r
+                                                       nomRefToSave.put(refId, thisNomRef);\r
+                                                       //remember that an in reference exists\r
+                                                       inRefExists |= (inRef != null);\r
+                                               }\r
+                                               if (thisBiblioRef != null){\r
+                                                       Reference<?> inRef = (biblioInReference != null)? biblioInReference : nomInReference;\r
+                                                       thisBiblioRef.setInReference(inRef);\r
+                                                       biblioRefToSave.put(refId, thisBiblioRef);\r
+                                                       //remember that an in reference exists\r
+                                                       inRefExists |= (inRef != null);\r
+                                               }\r
+                                               if (inRefExists == false){\r
+                                                       logger.warn("No in reference was saved though an 'inRefFk' is available. RefId " + refId);\r
+                                               }\r
                                        }\r
-                                       if (thisBiblioRef != null){\r
-                                               thisBiblioRef.setInReference(inReference);\r
-                                               biblioRefToSave.put(refId, thisBiblioRef);\r
-                                       }\r
-                                       \r
                                        \r
-//                                     success &= makeSingleReferenceRecord(rs, state, partitioner, biblioRefToSave, nomRefToSave, relatedBiblioReferences, relatedNomReferences, refCounter);\r
                                } // end resultSet\r
-                                                               \r
-                               //for the concept reference a fixed uuid may be needed -> change uuid\r
-                               Integer sourceSecId = (Integer) state.getConfig().getSourceSecId();\r
-                               Reference<?> sec = biblioRefToSave.get(sourceSecId);\r
-                               if (sec == null){\r
-                                       sec = nomRefToSave.get(sourceSecId);    \r
-                               }\r
-                               if (sec != null){\r
-                                       sec.setUuid(state.getConfig().getSecUuid());\r
-                                       logger.info("SecUuid changed to: " + state.getConfig().getSecUuid());\r
-                               }\r
-                               \r
+\r
                                //save and store in map\r
                                logger.info("Save nomenclatural references (" + refCounter.nomRefCount + ")");\r
                                getReferenceService().save(nomRefToSave.values());\r