Skip to content

Commit

Permalink
fixed some junits
Browse files Browse the repository at this point in the history
Added backwards compatibility with class templates with enumerated type node items.   Allow EITHER the enumeration URI or the identifier.
  • Loading branch information
Paul Cuddihy committed Jul 28, 2023
1 parent e2360af commit afd5cbe
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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");

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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());
Expand Down

0 comments on commit afd5cbe

Please sign in to comment.