use of org.osate.ge.query.QueryResult in project osate2 by osate.
the class ConnectionHandler method getGraphicalConfiguration.
@Override
public Optional<GraphicalConfiguration> getGraphicalConfiguration(final GetGraphicalConfigurationContext ctx) {
final BusinessObjectContext boc = ctx.getBusinessObjectContext();
final QueryService queryService = ctx.getQueryService();
final Connection c = boc.getBusinessObject(Connection.class).orElseThrow();
final QueryResult src = queryService.getFirstResult(SRC_QUERY, boc, c).orElse(null);
final QueryResult dst = queryService.getFirstResult(DST_QUERY, boc, c).orElse(null);
final boolean partial = (src != null && src.isPartial()) || (dst != null && dst.isPartial());
final StyleBuilder sb = StyleBuilder.create(AadlInheritanceUtil.isInherited(boc) ? Styles.INHERITED_ELEMENT : Style.EMPTY);
if (partial) {
sb.dotted();
}
return Optional.of(GraphicalConfigurationBuilder.create().graphic(GRAPHIC).style(sb.build()).source(src == null ? null : src.getBusinessObjectContext()).destination(dst == null ? null : dst.getBusinessObjectContext()).build());
}
use of org.osate.ge.query.QueryResult in project osate2 by osate.
the class FlowSpecificationInstanceHandler method getGraphicalConfiguration.
@Override
public Optional<GraphicalConfiguration> getGraphicalConfiguration(final GetGraphicalConfigurationContext ctx) {
final BusinessObjectContext boc = ctx.getBusinessObjectContext();
final FlowSpecificationInstance fsi = boc.getBusinessObject(FlowSpecificationInstance.class).get();
final QueryService queryService = ctx.getQueryService();
final QueryResult srcResult = queryService.getFirstResult(SRC_QUERY, boc, fsi).orElse(null);
final BusinessObjectContext src = srcResult == null ? null : srcResult.getBusinessObjectContext();
boolean partial = (srcResult != null && srcResult.isPartial());
BusinessObjectContext dst = null;
if (fsi.getFlowSpecification().getKind() == FlowKind.PATH) {
final QueryResult dstResult = queryService.getFirstResult(DST_QUERY, boc, fsi).orElse(null);
dst = dstResult == null ? null : dstResult.getBusinessObjectContext();
partial |= (dstResult != null && dstResult.isPartial());
}
final StyleBuilder sb = StyleBuilder.create(AadlInheritanceUtil.isInherited(boc) ? Styles.INHERITED_ELEMENT : Style.EMPTY);
if (fsi.getFlowSpecification().getKind() == FlowKind.PATH) {
sb.lineWidth(4.0);
}
if (partial) {
sb.dotted();
}
return Optional.of(GraphicalConfigurationBuilder.create().graphic(AadlGraphics.getFlowSpecificationGraphic(fsi.getFlowSpecification())).style(sb.build()).source(src).destination(dst).build());
}
use of org.osate.ge.query.QueryResult in project osate2 by osate.
the class ReferenceValueWithContext method resolve.
// Rename q. It is the lowest element to which the element applies.
public AadlPropertyResolutionResults resolve(final BusinessObjectContext q, final QueryService queryService) {
// Get the queryable
boolean referenceOwnerInTree = true;
BusinessObjectContext tmp = q;
for (int i = 0; i < propertyAssociationOwnerAncestorLevel; i++) {
tmp = tmp.getParent();
if (tmp == null) {
referenceOwnerInTree = false;
break;
}
}
// Decide whether to show it as connection or not.
final boolean hasPartialDestination;
final boolean hasFinalDestination;
final BusinessObjectContext dst;
if (referenceOwnerInTree) {
final QueryResult dstResult = queryService.getFirstResult(CNE_QUERY, tmp, referenceValue).orElse(null);
dst = dstResult == null ? null : dstResult.getBusinessObjectContext();
hasPartialDestination = dstResult != null;
hasFinalDestination = dstResult != null && !dstResult.isPartial() && !containsArrayElementReference(referenceValue);
} else {
dst = null;
hasPartialDestination = false;
hasFinalDestination = false;
}
return new AadlPropertyResolutionResults(dst, hasPartialDestination && !hasFinalDestination);
}
use of org.osate.ge.query.QueryResult in project osate2 by osate.
the class IfElseQuery method run.
@Override
void run(final Deque<DefaultQuery<T>> remainingQueries, final BusinessObjectContext ctx, final QueryExecutionState<T> state, final QueryResults result) {
try {
this.innerRootValue = ctx;
// Set Condition Arguments
@SuppressWarnings("unchecked") final ExpressionArguments<T> conditionArgs = (ExpressionArguments<T>) state.cache.computeIfAbsent(this, t -> new ExpressionArguments<>());
conditionArgs.update(state, ctx);
// Evaluate the condition
final Boolean condResult = cond.apply(conditionArgs);
final DefaultQuery<T> innerQuery = condResult.booleanValue() ? trueQuery : falseQuery;
// Process the results of the inner query.
// NOTE: Ideally this would be lazily evaluated instead of retrieving all the results. However, in the current use cases, only one result will be
// returned by the inner query.
final List<QueryResult> containers = state.queryRunner.getResults(innerQuery, state.arg);
for (final QueryResult container : containers) {
processResultValue(remainingQueries, container.getBusinessObjectContext(), state, result);
if (result.isDone()) {
return;
}
}
} finally {
innerRootValue = null;
}
}
use of org.osate.ge.query.QueryResult in project osate2 by osate.
the class CommonAncestorsQuery method run.
@Override
void run(final Deque<DefaultQuery<T>> remainingQueries, final BusinessObjectContext ctx, final QueryExecutionState<T> state, final QueryResults result) {
final List<QueryResult> q1Result = state.queryRunner.getResults(q1, state.arg);
final List<QueryResult> q2Result = state.queryRunner.getResults(q2, state.arg);
// Check sizes
if (q1Result.size() == 0 || q2Result.size() == 0) {
return;
}
if (q1Result.size() > 1) {
throw new RuntimeException("q1 returns more than one element");
}
if (q2Result.size() > 1) {
throw new RuntimeException("q2 returns more than one element");
}
final Optional<BusinessObjectContext> commonAncestor = BusinessObjectContext.getFirstCommonAncestor(q1Result.get(0).getBusinessObjectContext().getParent(), q2Result.get(0).getBusinessObjectContext().getParent());
if (commonAncestor.isPresent()) {
// Process common ancestors
for (BusinessObjectContext tmp = commonAncestor.get(); tmp != null && !result.isDone(); tmp = tmp.getParent()) {
processResultValue(remainingQueries, tmp, state, result);
}
}
}
Aggregations