diff --git a/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/load/utility/IngestionNodegroupBuilder.java b/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/load/utility/IngestionNodegroupBuilder.java index 928f2d088..e0e9b4ef2 100644 --- a/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/load/utility/IngestionNodegroupBuilder.java +++ b/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/load/utility/IngestionNodegroupBuilder.java @@ -221,6 +221,7 @@ public void build() throws Exception { String measObjName = nItem.getKeyName() + "_" + measNItem.getKeyName(); // add yet another node off the Measurement + // no backwards compatibility: not checking the Enumerated type for idRegex // add to nodegroup Node measObjNode = nodegroup.addNode(measNItemRange, objNode, null, measNItem.getUriConnectBy()); @@ -265,45 +266,47 @@ public void build() throws Exception { csvTemplate.append(colName + ","); csvTypes.append("uri,"); - } else { - // set first data property matching ID_REGEX returned - boolean foundId = false; - for (PropertyItem pItem : objNode.getPropertyItems()) { - if (this.idRegex != null && Pattern.compile(this.idRegex).matcher(pItem.getKeyName()).find()) { - // set the lookup ID to be returned - // but not optional (link to node is optional instead) - nodegroup.setIsReturned(pItem, true); - - // give ID_REGEX property a meaningful sparqlID - String sparqlID; - if (nItem.getRangeUris().size() > 1) { - // complex range: include the class - sparqlID = nItem.getKeyName() + "_" + rangeKeyname + "_" + pItem.getKeyName(); - - } else { - // 'default' - sparqlID = nItem.getKeyName() + "_" + pItem.getKeyName(); - } - String propId = nodegroup.changeSparqlID(pItem, sparqlID); - - // add to importspec, using it to look up parent node - ispecBuilder.addProp(objNode.getSparqlID(), pItem.getUriRelationship()); - ispecBuilder.addURILookup(objNode.getSparqlID(), pItem.getUriRelationship(), objNode.getSparqlID()); - - // add the column and mapping to the importspec - String colName = buildColName(propId); - ispecBuilder.addColumn(colName); - ispecBuilder.addMapping(objNode.getSparqlID(), pItem.getUriRelationship(), ispecBuilder.buildMappingWithCol(colName, new String [] {transformId})); + } + // } else { is gone: for backwards compatibility we're also checking enumerated classes for ID_REGEX + + // set first data property matching ID_REGEX returned + boolean foundId = false; + for (PropertyItem pItem : objNode.getPropertyItems()) { + if (this.idRegex != null && Pattern.compile(this.idRegex).matcher(pItem.getKeyName()).find()) { + // set the lookup ID to be returned + // but not optional (link to node is optional instead) + nodegroup.setIsReturned(pItem, true); + + // give ID_REGEX property a meaningful sparqlID + String sparqlID; + if (nItem.getRangeUris().size() > 1) { + // complex range: include the class + sparqlID = nItem.getKeyName() + "_" + rangeKeyname + "_" + pItem.getKeyName(); - // add to csvTemplate and csvTypes - csvTemplate.append(colName + ","); - csvTypes.append(pItem.getValueTypesString(" ") + ","); - foundId = true; - break; + } else { + // 'default' + sparqlID = nItem.getKeyName() + "_" + pItem.getKeyName(); } + String propId = nodegroup.changeSparqlID(pItem, sparqlID); + + // add to importspec, using it to look up parent node + ispecBuilder.addProp(objNode.getSparqlID(), pItem.getUriRelationship()); + ispecBuilder.addURILookup(objNode.getSparqlID(), pItem.getUriRelationship(), objNode.getSparqlID()); + + // add the column and mapping to the importspec + String colName = buildColName(propId); + ispecBuilder.addColumn(colName); + ispecBuilder.addMapping(objNode.getSparqlID(), pItem.getUriRelationship(), ispecBuilder.buildMappingWithCol(colName, new String [] {transformId})); + + // add to csvTemplate and csvTypes + csvTemplate.append(colName + ","); + csvTypes.append(pItem.getValueTypesString(" ") + ","); + foundId = true; + break; } - if (!foundId) throw new Exception("Can't add " + nItem.getKeyName() + " " + rangeKeyname + " node: it must either match the data class regex, or contain a data property that matches id regex"); } + if (!this.oInfo.classIsEnumeration(rangeUri) && !foundId) throw new Exception("Can't add " + nItem.getKeyName() + " " + rangeKeyname + " node: it must either match the data class regex, or contain a data property that matches id regex"); + } } } diff --git a/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/nodegroupexecution/test/NodeGroupExecutionClientTest_IT.java b/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/nodegroupexecution/test/NodeGroupExecutionClientTest_IT.java index ee8c84d50..390009bd5 100755 --- a/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/nodegroupexecution/test/NodeGroupExecutionClientTest_IT.java +++ b/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/nodegroupexecution/test/NodeGroupExecutionClientTest_IT.java @@ -350,9 +350,8 @@ public void testClassTemplates() throws Exception { // ingest cells from template String res = nodeGroupExecutionClient.dispatchIngestFromCsvStringsByClassTemplateSync(CELL, "cellId", "cellId\ncell1a\ncell1b\n", TestGraph.getSparqlConn()); ArrayList warnings = nodeGroupExecutionClient.getWarnings(); - if (warnings != null && warnings.size() != 0) { - assertTrue("Unexpected ingest warnings on CELL: " + warnings, false); - } + assertEquals("Missing exactly one warning about color_Color", 1, warnings.size()); + assertTrue("Warning doesn't mention missing column color_Color", warnings.get(0).toLowerCase().contains("color_color")); // ingest batteries from template res = nodeGroupExecutionClient.dispatchIngestFromCsvStringsByClassTemplateSync(BATTERY, "name|cellId", "name,cell_cellId,extra\nbattery1,cell1a,extra1\nbattery1,cell1b,extra2\n", TestGraph.getSparqlConn());