Search in sources :

Example 1 with QueryResult

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());
}
Also used : QueryResult(org.osate.ge.query.QueryResult) QueryService(org.osate.ge.services.QueryService) Connection(org.osate.aadl2.Connection) StyleBuilder(org.osate.ge.graphics.StyleBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 2 with QueryResult

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());
}
Also used : QueryResult(org.osate.ge.query.QueryResult) QueryService(org.osate.ge.services.QueryService) StyleBuilder(org.osate.ge.graphics.StyleBuilder) FlowSpecificationInstance(org.osate.aadl2.instance.FlowSpecificationInstance) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 3 with QueryResult

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);
}
Also used : QueryResult(org.osate.ge.query.QueryResult) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 4 with QueryResult

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;
    }
}
Also used : Objects(java.util.Objects) Query(org.osate.ge.query.Query) List(java.util.List) BusinessObjectContext(org.osate.ge.BusinessObjectContext) QueryResult(org.osate.ge.query.QueryResult) Deque(java.util.Deque) Function(java.util.function.Function) QueryResult(org.osate.ge.query.QueryResult)

Example 5 with QueryResult

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);
        }
    }
}
Also used : QueryResult(org.osate.ge.query.QueryResult) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Aggregations

QueryResult (org.osate.ge.query.QueryResult)9 BusinessObjectContext (org.osate.ge.BusinessObjectContext)8 StyleBuilder (org.osate.ge.graphics.StyleBuilder)4 QueryService (org.osate.ge.services.QueryService)4 Deque (java.util.Deque)1 List (java.util.List)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Connection (org.osate.aadl2.Connection)1 FlowSpecification (org.osate.aadl2.FlowSpecification)1 ConnectionReference (org.osate.aadl2.instance.ConnectionReference)1 FlowSpecificationInstance (org.osate.aadl2.instance.FlowSpecificationInstance)1 Query (org.osate.ge.query.Query)1 PropagationPath (org.osate.xtext.aadl2.errormodel.errorModel.PropagationPath)1