use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class SEEQSource method getEnd.
/**
* Gets the end.
*
* @param customQueryOptions the custom query options
* @return the end
*/
private String getEnd(CustomQueryOptions customQueryOptions) {
if (customQueryOptions != null && customQueryOptions.containsKey(END)) {
Resource endDateTime = customQueryOptions.get(END);
return endDateTime.getValue().stringValue();
} else {
if (customQueryOptions != null && customQueryOptions.containsKey(START)) {
Resource startDateTime = customQueryOptions.get(START);
String start = startDateTime.getValue().stringValue();
return start;
} else {
// LocalDateTime.now().format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now().truncatedTo(ChronoUnit.HOURS));
}
}
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class SEEQSource method getSEEQSignal.
/**
* Gets the SEEQ signal.
*
* @param thing the thing
* @param signal the signal
* @param customQueryOptions the custom query options
* @return the SEEQ signal
* @throws ScriptFailedException the script failed exception
*/
public static Resource getSEEQSignal(Thing thing, String signal, CustomQueryOptions customQueryOptions) throws ScriptFailedException {
signal = Utilities.trimIRIString(signal);
String[] elements = signal.split("/");
Object result;
SEEQSource seeqSource = null;
try {
if (elements.length < 6) {
thing.getEvaluationContext().getTracer().decrementLevel();
String error = String.format("Unsupported signal source: %s", signal);
logger.error(error);
thing.getEvaluationContext().getTracer().traceSignalError(error);
throw new ScriptFailedException(error);
} else {
thing.getEvaluationContext().getTracer().traceSEEQ(elements[5], customQueryOptions);
seeqSource = thing.getSource().seeqSourceFactory(elements[2]);
result = seeqSource.getSignal(elements[5], customQueryOptions);
thing.getEvaluationContext().getTracer().decrementLevel();
return Resource.create(thing.getSource(), literal((Double) result), thing.getEvaluationContext());
}
} catch (ScriptException e) {
throw new ScriptFailedException(e);
} catch (HandledException e) {
throw new ScriptFailedException(e);
}
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentStatementPaths method hasNext.
/**
* Checks for next.
*
* @return true, if successful
* @throws QueryEvaluationException the query evaluation exception
*/
@Override
public boolean hasNext() throws QueryEvaluationException {
if (resultsIterator != null && resultsIterator.hasNext()) {
return true;
} else {
while (pathIteration < this.sortedIterations.size()) {
CustomQueryOptions customQueryOptions = CustomQueryOption.getCustomQueryOptions(contexts, source.getRepositoryContext().getPrefixes());
pathTupleExpr = pathElement.pathPatternQuery(pathIteration, customQueryOptions);
if (this.thing == null && pathTupleExpr.getBoundVariable() == null) {
throw new QueryEvaluationException("Paths query unbound");
} else {
this.boundVariableName = pathTupleExpr.getBoundVariable().getName();
}
pathIteration++;
this.resultsIterator = intelligentGraphConnection.getResultsIterator(source, thing, pathElement, pathTupleExpr, contexts);
boolean hasNext = resultsIterator.hasNext();
if (hasNext)
return true;
}
return false;
}
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphRepository method getFacts.
public ResourceResults getFacts(String boundPredicatePattern, CustomQueryOptions customQueryOptions) {
logger.debug("getFacts{}\n", boundPredicatePattern);
// this.getEvaluationContext().getTracer().traceFacts(this, queryPattern);
SimpleDataset dataset = getDataset(customQueryOptions);
// dataset.addDefaultGraph(this.graphName);
org.eclipse.rdf4j.model.Resource[] contextArray = dataset.getDefaultGraphs().toArray(new org.eclipse.rdf4j.model.Resource[0]);
ResourceStatementResults results = null;
IRI predicate = preparePredicate(PATHQL.getFacts, boundPredicatePattern);
if (this.getRepository() == null) {
CloseableIteration<? extends Statement, QueryEvaluationException> localStatementIterator = this.getTripleSource().getStatements(null, predicate, null);
results = new ResourceStatementResults(localStatementIterator, this, null, customQueryOptions);
} else {
CloseableIteration<Statement, RepositoryException> statementIterator = this.getRepository().getConnection().getStatements(null, predicate, null, contextArray);
results = new ResourceStatementResults(statementIterator, this, null, customQueryOptions);
}
return results;
}
use of com.inova8.intelligentgraph.context.CustomQueryOptions in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphRepository method getCustomQueryOptions.
/**
* Gets the custom query options.
*
* @param customQueryOptionsArray the custom query options array
* @return the custom query options
*/
public CustomQueryOptions getCustomQueryOptions(Value[] customQueryOptionsArray) {
CustomQueryOptions customQueryOptions = CustomQueryOptions.create(this, customQueryOptionsArray);
if (customQueryOptions != null) {
if (customQueryOptions.contains("service")) {
com.inova8.intelligentgraph.model.Resource service = customQueryOptions.get("service");
String serviceURL = service.toString();
String serviceIRI = null;
if (serviceURL.indexOf('?') > 0) {
serviceIRI = serviceURL.substring(0, serviceURL.indexOf('?'));
}
if (serviceIRI != null)
setCacheService(serviceIRI);
}
}
return customQueryOptions;
}
Aggregations