Skip to content

Commit

Permalink
added "csvTypes" to /getClassTemplateAndCsv"
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Cuddihy committed Jun 23, 2022
1 parent 3dcafae commit 3dd10eb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ public JSONObject fromCsvUsingClassTemplate(@RequestBody IngestionFromStringsAnd

@Operation(
summary= "Get a class' default ingestion template and sample CSV file.",
description= "synchronous. Returns simpleResult containing \'sgjson\' JSON and \'csv\' String fields."
description= "synchronous. Returns simpleResult containing 'sgjson' JSON, 'csv' string, and 'csvTypes' string fields."
)
@CrossOrigin
@RequestMapping(value="/getClassTemplateAndCsv", method= RequestMethod.POST)
Expand All @@ -453,6 +453,7 @@ public JSONObject getClassTemplateAndCsv(@RequestBody IngestionFromStringsAndCla
SimpleResultSet result = new SimpleResultSet(true);
result.addResult("sgjson", builder.getSgjson().toJson());
result.addResult("csv", builder.getCsvTemplate());
result.addResult("csvTypes", builder.getCsvTypes());
return result.toJson();

} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ge.research.semtk.load.utility;
import java.util.ArrayList;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
** Copyright 2021 General Electric Company
Expand All @@ -25,6 +27,7 @@
import com.ge.research.semtk.ontologyTools.OntologyInfo;
import com.ge.research.semtk.ontologyTools.OntologyName;
import com.ge.research.semtk.sparqlX.SparqlConnection;
import com.ge.research.semtk.sparqlX.XSDSupportedType;

/**
* Builds an ingestion template (RACK "CDR") for a particular class based on oInfo.
Expand Down Expand Up @@ -53,6 +56,7 @@ public class IngestionNodegroupBuilder {
private OntologyInfo oInfo;
private SparqlGraphJson sgjson;
private StringBuilder csvTemplate;
private StringBuilder csvTypes;
private String idRegex = null;

/**
Expand Down Expand Up @@ -84,11 +88,28 @@ public SparqlGraphJson getSgjson() {
return this.sgjson;
}

/**
* Get a string of "colname1, colname2, ..."
* @return
*/
public String getCsvTemplate() {
return this.csvTemplate.toString();
}

/**
* Get a string of types that go along with the csv template column names
* Also comma separated
* If a property can have multiple types they will be space-separated
* Short types are used (XSDSupportedTypes simple lower camelcase names like "integer" or "dateTime")
* @return
*/
public String getCsvTypes() {
return this.csvTypes.toString();
}

public void build() throws Exception {
this.csvTemplate = new StringBuilder();
this.csvTypes = new StringBuilder();
ImportSpec ispecBuilder = new ImportSpec();

// create nodegroup with single node of stated type
Expand Down Expand Up @@ -123,7 +144,8 @@ public void build() throws Exception {
ispecBuilder.addMapping(node.getSparqlID(), pItem.getUriRelationship(), ispecBuilder.buildMappingWithCol(colName, new String [] {transformId}));

// add to csvTemplate
csvTemplate.append(colName + ",");
csvTemplate.append(colName + ",");
csvTypes.append(pItem.getValueTypesString(" ") + ",");
}

// connect a node for each object property
Expand Down Expand Up @@ -182,8 +204,9 @@ public void build() throws Exception {
ispecBuilder.addColumn(colName);
ispecBuilder.addMapping(objNode.getSparqlID(), pItem.getUriRelationship(), ispecBuilder.buildMappingWithCol(colName, new String [] {transformId}));

// add to csvTemplate
// add to csvTemplate and csvTypes
csvTemplate.append(colName + ",");
csvTypes.append(pItem.getValueTypesString(" ") + ",");
break;
}
}
Expand All @@ -197,6 +220,8 @@ public void build() throws Exception {
// replace last comma in csvTemplate with a line return
csvTemplate.setLength(Math.max(0,csvTemplate.length()-1));
csvTemplate.append("\n");
csvTypes.setLength(Math.max(0,csvTypes.length()-1));
csvTypes.append("\n");

}

Expand Down

0 comments on commit 3dd10eb

Please sign in to comment.