diff --git a/components/pedigree/resources/src/main/resources/pedigree/model/import.js b/components/pedigree/resources/src/main/resources/pedigree/model/import.js old mode 100644 new mode 100755 index f904b07ddc..d71bb3b532 --- a/components/pedigree/resources/src/main/resources/pedigree/model/import.js +++ b/components/pedigree/resources/src/main/resources/pedigree/model/import.js @@ -1292,6 +1292,19 @@ define([ var relationshipTracker = new RelationshipTracker(newG, defaultEdgeWeight); + var createPersonNode = function(graph, attributes) { + return graph._addVertex( null, BaseGraph.TYPE.PERSON, attributes, graph.defaultPersonNodeWidth ); + }; + + var lookupNodeByReference = function(reference) { + // FIXME: some applications produce a GEDCOM file where links have incorrect IDs, + // where a correct reference "@Ixxx@" is replaced by "@xxx@". So as a quick fix an attemptis made to either look up + // the proper ID, or the ID with an "I" pefix attached before the numeric part of the ID. + return externalIDToID.hasOwnProperty(reference) + ? externalIDToID[reference] + : externalIDToID[reference.replace(/^@(\d+)/,"@I$1")]; + }; + // second pass (once all vertex IDs are known): process families & add edges for (var i = 0; i < gedcom.families.length; i++) { var nextFamily = gedcom.families[i]; @@ -1301,14 +1314,22 @@ define([ // create a virtual parent in case one of the parents is missing if (fatherLink == null) { - var fatherID = newG._addVertex( null, BaseGraph.TYPE.PERSON, {"gender": "M", "comments": "unknown"}, newG.defaultPersonNodeWidth ); + var fatherID = createPersonNode(newG, {"gender": "M", "comments": "unknown"}); } else { - var fatherID = externalIDToID[fatherLink]; + var fatherID = lookupNodeByReference(fatherLink); + + if (fatherID === undefined) { + throw "Unable to import pedigree: father link does not point to an existing individual: [" + fatherLink + "]"; + } } if (motherLink == null) { - var motherID = newG._addVertex( null, BaseGraph.TYPE.PERSON, {"gender": "F", "comments": "unknown"}, newG.defaultPersonNodeWidth ); + var motherID = createPersonNode(newG, {"gender": "F", "comments": "unknown"}); } else { - var motherID = externalIDToID[motherLink]; + var motherID = lookupNodeByReference(motherLink); + + if (motherID === undefined) { + throw "Unable to import pedigree: mother link does not point to an existing individual: [" + motherLink + "]"; + } } // both motherID and fatherID are now given and represent valid existing nodes in the pedigree @@ -1321,7 +1342,7 @@ define([ if (children == null) { // create a virtual child - var childID = newG._addVertex( null, BaseGraph.TYPE.PERSON, {"gender": "U", "placeholder": true}, newG.defaultPersonNodeWidth ); + var childID = createPersonNode(newG, {"gender": "U", "placeholder": true}); externalIDToID[childID] = childID; children = [{"value": childID}]; // TODO: add "infertile by choice" property to the relationship @@ -1329,10 +1350,9 @@ define([ for (var j = 0; j < children.length; j++) { var externalID = children[j].value; + var childID = lookupNodeByReference(externalID); - var childID = externalIDToID.hasOwnProperty(externalID) ? externalIDToID[externalID] : null; - - if (childID == null) { + if (childID === undefined) { throw "Unable to import pedigree: child link does not point to an existing individual: [" + externalID + "]"; }