Skip to content

Commit

Permalink
passed marklogic junits by having rest clients setUserAndPasswordIfEm…
Browse files Browse the repository at this point in the history
…pty()
  • Loading branch information
Paul Cuddihy committed Sep 11, 2023
1 parent 7b04811 commit 193dc3d
Show file tree
Hide file tree
Showing 20 changed files with 224 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ public class MarkLogicSparqlEndpointInterface extends SparqlEndpointInterface {
* @throws Exception
*/
public MarkLogicSparqlEndpointInterface(String server, String graph) throws Exception {
super(server, graph, "test", "password");
super(server, graph, "", "");

}

public MarkLogicSparqlEndpointInterface(String server, String graph, String user, String pass) throws Exception {
super(server, graph, user!=null?user:"test", pass!=null?pass:"password");
super(server, graph, user, pass);

}
// For MarkLogic, we're storing the database in "endpoint"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,17 @@ public void overrideSparqlServer(String serverAndPort) throws Exception {
* @throws Exception
*/
public static SparqlConnection deepCopy(SparqlConnection other) throws Exception {
return new SparqlConnection(other.toJson().toString());
SparqlConnection ret = new SparqlConnection(other.toJson().toString());
// copy passwords too
for (int i=0; i < other.getModelInterfaceCount(); i++) {
SparqlEndpointInterface osei = other.getModelInterface(i);
ret.modelInterfaces.get(i).setUserAndPassword(osei.getUserName(), osei.getPassword());
}
for (int i=0; i < other.getDataInterfaceCount(); i++) {
SparqlEndpointInterface osei = other.getDataInterface(i);
ret.dataInterfaces.get(i).setUserAndPassword(osei.getUserName(), osei.getPassword());
}
return ret;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
import com.ge.research.semtk.springutillib.properties.StatusServiceProperties;
import com.ge.research.semtk.springutillib.properties.NodegroupStoreServiceProperties;
import com.ge.research.semtk.springutillib.properties.OntologyInfoServiceProperties;
import com.ge.research.semtk.springutillib.properties.QueryServiceProperties;
import com.ge.research.semtk.springutillib.properties.ResultsServiceProperties;
import com.ge.research.semtk.springutillib.properties.ServicesGraphProperties;
import com.ge.research.semtk.utility.LocalLogger;
Expand Down Expand Up @@ -155,6 +156,8 @@ public class NodeGroupExecutionRestController {
private NodegroupStoreServiceProperties ngstore_prop;
@Autowired
private DispatchServiceProperties dispatch_prop;
@Autowired
private QueryServiceProperties query_prop;
@Autowired
private ResultsServiceProperties results_prop;
@Autowired
Expand All @@ -172,6 +175,7 @@ public void init() {
AuthorizationManager.authorizeWithExit(auth_prop);
ngstore_prop.validateWithExit();
dispatch_prop.validateWithExit();
query_prop.validateWithExit();
results_prop.validateWithExit();
status_prop.validateWithExit();
ingest_prop.validateWithExit();
Expand Down Expand Up @@ -531,7 +535,9 @@ public JSONObject dispatchAnyJobById(@RequestBody DispatchByIdRequestBody reques

NodeGroupExecutor ngExecutor = this.getExecutor(null );

SparqlConnection connection = requestBody.buildSparqlConnection();
SparqlConnection connection = requestBody.buildSparqlConnection();
query_prop.setUserAndPasswordIfMissing(connection);

// create a json object from the external data constraints.

// check if this is actually for a filter query
Expand Down Expand Up @@ -588,7 +594,7 @@ private JSONObject dispatchAnyJobFromNodegroup(@RequestBody DispatchFromNodegrou
if (connection == null || NodeGroupExecutor.isUseNodegroupConn(connection)) {
connection = sgJson.getSparqlConn();
}

query_prop.setUserAndPasswordIfMissing(connection);
String targetId = null;
if(requestBody instanceof FilterDispatchFromNodeGroupRequestBody){
// set the target ID
Expand Down Expand Up @@ -934,6 +940,7 @@ public JSONObject dispatchSelectInstanceDataPredicates(@RequestBody InstanceData

try {
SparqlConnection conn = new SparqlConnection(requestBody.getConn());
query_prop.setUserAndPasswordIfMissing(conn);
OntologyInfo oInfo = retrieveOInfo(conn);
ArrayList<String[]> pairsList = requestBody.buildPredicateListPairs();
if (pairsList.size() == 0) {
Expand Down Expand Up @@ -990,6 +997,7 @@ public JSONObject dispatchSelectInstanceDataSubjects(@RequestBody InstanceDataCl

try {
SparqlConnection conn = new SparqlConnection(requestBody.getConn());
query_prop.setUserAndPasswordIfMissing(conn);
OntologyInfo oInfo = retrieveOInfo(conn);
ArrayList<String> classList = requestBody.getClassValues();
if (classList.size() == 0) {
Expand Down Expand Up @@ -1041,6 +1049,7 @@ public JSONObject constructConnectedData(@RequestBody ConstructConnectedDataRequ
try {

SparqlConnection conn = requestBody.buildSparqlConnection();
query_prop.setUserAndPasswordIfMissing(conn);
ResultsClient resClient = results_prop.getClient();

ConnectedDataConstructor constructor = new ConnectedDataConstructor(
Expand Down Expand Up @@ -1076,7 +1085,8 @@ public JSONObject constructInstanceWithPredicates(@RequestBody ConstructInstance

try {
SparqlConnection conn = requestBody.buildSparqlConnection();

query_prop.setUserAndPasswordIfMissing(conn);

// create a nodegroup: instance connecting to given predicates
NodeGroup ng = new NodeGroup();
Node node = ng.addNode(requestBody.getInstanceClassUri(), this.retrieveOInfo(conn)); // add node for given class URI
Expand Down Expand Up @@ -1173,7 +1183,8 @@ public JSONObject dispatchRawSparql(@RequestBody DispatchRawSparqlRequestBody re

// try to create a sparql connection
SparqlConnection connection = requestBody.buildSparqlConnection();

query_prop.setUserAndPasswordIfMissing(connection);

// dispatch the job.
ngExecutor.dispatchRawSparql(connection, requestBody.getSparql(), requestBody.getResultType());
String id = ngExecutor.getJobID();
Expand Down Expand Up @@ -1217,7 +1228,8 @@ public JSONObject dispatchRawSparqlUpdate(@RequestBody DispatchRawSparqlRequestB
NodeGroupExecutor ngExecutor = this.getExecutor(null );
// try to create a sparql connection
SparqlConnection connection = requestBody.buildSparqlConnection();

query_prop.setUserAndPasswordIfMissing(connection);

// dispatch the job.
ngExecutor.dispatchRawSparqlUpdate(connection, requestBody.getSparql());
String id = ngExecutor.getJobID();
Expand Down Expand Up @@ -1262,9 +1274,7 @@ public JSONObject dispatchClearGraph(@RequestBody SparqlEndpointRequestBody requ
SparqlEndpointInterface sei = requestBody.buildSei();
SparqlEndpointInterface jobSei = servicesgraph_props.buildSei();

// PEC TODO security
// borrowing auth username password from the services graph
sei.setUserAndPassword(jobSei.getUserName(), jobSei.getPassword());
query_prop.setUserAndPasswordIfMissing(sei);

ResultsClient resClient = results_prop.getClient();

Expand Down Expand Up @@ -1322,6 +1332,8 @@ public JSONObject ingestFromCsvStrings(@RequestBody IngestByNodegroupCsvStrReque
NodeGroupExecutor nodeGroupExecutor = this.getExecutor(null);

SparqlGraphJson sparqlGraphJson = requestBody.buildSparqlGraphJson();
query_prop.setUserAndPasswordIfMissing(sparqlGraphJson);

retval = nodeGroupExecutor.ingestFromNodegroupAndCsvString(requestBody.buildSparqlConnection(), sparqlGraphJson, requestBody.getCsvContent(), requestBody.getTrackFlag(), requestBody.getOverrideBaseURI());
}catch(Exception e){
LoggerRestClient.easyLog(logger, SERVICE_NAME, ENDPOINT_NAME + " exception", "message", e.toString());
Expand Down Expand Up @@ -1358,6 +1370,7 @@ public JSONObject ingestFromCsvStringsAsync(@RequestBody IngestByNodegroupCsvStr
NodeGroupExecutor nodeGroupExecutor = this.getExecutor(null);

SparqlGraphJson sparqlGraphJson = requestBody.buildSparqlGraphJson();
query_prop.setUserAndPasswordIfMissing(sparqlGraphJson);
String jobId = nodeGroupExecutor.ingestFromNodegroupAndCsvStringAsync(
requestBody.buildSparqlConnection(),
sparqlGraphJson,
Expand Down Expand Up @@ -1403,8 +1416,9 @@ public JSONObject ingestFromCsvStringsById(@RequestBody IngestByIdCsvStrRequestB
RecordProcessResults retval = null;
try{
NodeGroupExecutor nodeGroupExecutor = this.getExecutor(null);

retval = nodeGroupExecutor.ingestFromNodegroupIdAndCsvString(requestBody.buildSparqlConnection(), requestBody.getNodegroupId(), requestBody.getCsvContent(), requestBody.getTrackFlag(), requestBody.getOverrideBaseURI());
SparqlConnection conn = requestBody.buildSparqlConnection();
query_prop.setUserAndPasswordIfMissing(conn);
retval = nodeGroupExecutor.ingestFromNodegroupIdAndCsvString(conn, requestBody.getNodegroupId(), requestBody.getCsvContent(), requestBody.getTrackFlag(), requestBody.getOverrideBaseURI());
}catch(Exception e){
LoggerRestClient.easyLog(logger, SERVICE_NAME, ENDPOINT_NAME + " exception", "message", e.toString());
retval = new RecordProcessResults(false);
Expand Down Expand Up @@ -1437,9 +1451,10 @@ public JSONObject ingestFromCsvStringsByIdAsync(@RequestBody IngestByIdCsvStrAsy
SimpleResultSet retval = null;
try{
NodeGroupExecutor nodeGroupExecutor = this.getExecutor(null);

SparqlConnection conn = requestBody.buildSparqlConnection();
query_prop.setUserAndPasswordIfMissing(conn);
String jobId = nodeGroupExecutor.ingestFromNodegroupIdAndCsvStringAsync(
requestBody.buildSparqlConnection(),
conn,
requestBody.getNodegroupId(),
requestBody.getCsvContent(),
requestBody.getSkipPrecheck(),
Expand Down Expand Up @@ -1479,6 +1494,7 @@ public JSONObject ingestFromCsvStringsByClassTemplateAsync(@RequestBody Ingestio
try {
// pass-through
IngestorRestClient iclient = ingest_prop.getClient();

String jobId = iclient.execFromCsvUsingClassTemplate(requestBody.getClassURI(), requestBody.getIdRegex(), requestBody.getData(), requestBody.getConnection(), requestBody.getTrackFlag(), requestBody.getOverrideBaseURI());

// success: add jobId
Expand Down Expand Up @@ -1701,6 +1717,7 @@ public JSONObject copyGraph(@RequestBody SparqlEndpointsRequestBody requestBody,
tracker.setJobPercentComplete(jobId, 10);
HeadersManager.setHeaders(headers);
SparqlEndpointInterface fromSei = requestBody.buildFromSei();
query_prop.setUserAndPasswordIfMissing(fromSei);

// fromGraph to temp file
String filename = UUID.randomUUID().toString();
Expand All @@ -1714,6 +1731,8 @@ public JSONObject copyGraph(@RequestBody SparqlEndpointsRequestBody requestBody,

// temp file to toGraph
SparqlEndpointInterface toSei = requestBody.buildToSei();
query_prop.setUserAndPasswordIfMissing(toSei);

InputStream fis = new FileInputStream(tempFile);
try {
this.uploadFile(toSei, fis, "temp.owl");
Expand Down Expand Up @@ -1770,7 +1789,9 @@ public JSONObject dispatchConstructToGraphById(@RequestBody DispatchConstructToG
try {
// dispatch
JSONObject simpleResJson = dispatchAnyJobById(requestBody, AutoGeneratedQueryTypes.CONSTRUCT, SparqlResultTypes.RDF);
waitThenStoreRdfToSei(jobId, (new SimpleResultSet(simpleResJson)).getJobId(), requestBody.buildResultsSei());
SparqlEndpointInterface sei = requestBody.buildResultsSei();
query_prop.setUserAndPasswordIfMissing(sei);
waitThenStoreRdfToSei(jobId, (new SimpleResultSet(simpleResJson)).getJobId(), sei);

} catch (Exception e) {
try {
Expand Down Expand Up @@ -1817,7 +1838,9 @@ public JSONObject dispatchConstructToGraphFromNodegroup(@RequestBody DispatchCon
try {
// dispatch
JSONObject simpleResJson = dispatchAnyJobFromNodegroup(requestBody, AutoGeneratedQueryTypes.CONSTRUCT, SparqlResultTypes.RDF);
waitThenStoreRdfToSei(jobId, (new SimpleResultSet(simpleResJson)).getJobId(), requestBody.buildResultsSei());
SparqlEndpointInterface sei = requestBody.buildResultsSei();
query_prop.setUserAndPasswordIfMissing(sei);
waitThenStoreRdfToSei(jobId, (new SimpleResultSet(simpleResJson)).getJobId(), sei);

} catch (Exception e) {
try {
Expand Down Expand Up @@ -1964,6 +1987,7 @@ public JSONObject dispatchCombineEntitiesTable(@RequestBody CombineEntitiesTable
String jobId = JobTracker.generateJobId();

SparqlConnection conn = requestBody.buildSparqlConnection();
query_prop.setUserAndPasswordIfMissing(conn);

new CombineEntitiesTableThread(
tracker, results_prop.getClient(), jobId, this.retrieveOInfo(conn), conn,
Expand Down Expand Up @@ -2001,8 +2025,7 @@ public JSONObject dispatchCombineEntitiesInConn(@RequestBody CombineEntitiesInCo
String jobId = JobTracker.generateJobId();

SparqlConnection conn = requestBody.buildSparqlConnection();


query_prop.setUserAndPasswordIfMissing(conn);
new CombineEntitiesInConnThread(
tracker, results_prop.getClient(), jobId, this.retrieveOInfo(conn), conn,
requestBody.getSameAsClassURI(), requestBody.getTargetPropURI(), requestBody.getDuplicatePropURI(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ ngstore.service.port=${PORT_NODEGROUPSTORE_SERVICE}
dispatch.service.protocol=${DISPATCH_SERVICE_PROTOCOL}
dispatch.service.server=${DISPATCH_SERVICE_HOST}
dispatch.service.port=${PORT_DISPATCH_SERVICE}

query.service.protocol=${SPARQLQUERY_SERVICE_PROTOCOL}
query.service.server=${SPARQLQUERY_SERVICE_HOST}
query.service.port=${PORT_SPARQL_QUERY_SERVICE}
query.service.user=${SPARQLQUERY_SERVICE_USER}
query.service.password=${SPARQLQUERY_SERVICE_PWD}

results.service.protocol=${RESULTS_SERVICE_PROTOCOL}
results.service.server=${RESULTS_SERVICE_HOST}
results.service.port=${PORT_SPARQLGRAPH_RESULTS_SERVICE}
Expand Down
Loading

0 comments on commit 193dc3d

Please sign in to comment.