use of org.osate.aadl2.Operation in project oracle-db-examples by oracle.
the class MultiOperation method processChildRowOperation.
/**
* Process next resultset. Get the child operation from the queue (if any submitted) and pass
* the resultset to it for the processing. If no child operation in the queue then process resultset
* with the help of user supplied row handler or the default one. Wait for the child operation or
* the handler to process all rows of a resultset.
*
* @return the completion stage of the child operation.
* @throws SQLException
*/
private CompletionStage<T> processChildRowOperation() throws SQLException {
// Get the result set
ResultSet resultSet = jdbcStatement.getResultSet();
// Remove child operation, if any exist
Operation operationFromQueue = resultOperations.poll();
// Keep as effective final, because it uses in lambda expression
Operation operation;
boolean onRowsHandler = (operationFromQueue == null);
if (onRowsHandler) {
// Handle using onRows handler.
operation = new MultiRowOperation<T>(session, group, true);
} else
operation = operationFromQueue;
if (!(operation instanceof ChildRowOperation)) {
// Throw invalid state
throw new IllegalStateException("TODO");
}
// Trigger child operation to process the resultset
resultStage = ((ChildRowOperation) operation).setResultSet(resultSet, resultStage);
if (onRowsHandler)
resultStage = resultStage.thenRun(() -> rowsHandler.accept(resultNum, (RowOperation<T>) operation));
// Then again move to moreResult stage to process next resultset.
return resultStage.thenComposeAsync(((ChildRowOperation) operation)::resultProcessed, getExecutor()).thenComposeAsync(this::checkForMoreResults, getExecutor());
}
use of org.osate.aadl2.Operation in project osate2 by osate.
the class CreatePropagatonPathPaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetCreateConnectionOperationContext ctx) {
// Check the type of the destination business object
if (!isValidEndpoint(ctx.getDestination())) {
return Optional.empty();
}
// Find the common ancestor which is a source for the classifier to update
final BusinessObjectContext classifierSourceBoc = BusinessObjectContext.getFirstCommonAncestor(ctx.getSource().getParent(), ctx.getDestination().getParent()).flatMap(ancestor -> ErrorModelGeUtil.getClassifierSourceBoc(ancestor)).orElse(null);
if (classifierSourceBoc == null) {
return Optional.empty();
}
return ErrorModelGeUtil.createErrorModelSubclauseModifyOperation(classifierSourceBoc, subclause -> {
final PropagationPath newPath = ErrorModelFactory.eINSTANCE.createPropagationPath();
final String newName = ErrorModelNamingUtil.buildUniqueIdentifier(subclause.getContainingClassifier(), "new_propagation_path");
newPath.setName(newName);
newPath.setSource(createQualifiedPropagationPoint(subclause, ctx.getSource(), classifierSourceBoc));
newPath.setTarget(createQualifiedPropagationPoint(subclause, ctx.getDestination(), classifierSourceBoc));
subclause.getPaths().add(newPath);
return StepResultBuilder.create().showNewBusinessObject(classifierSourceBoc, newPath).build();
});
}
use of org.osate.aadl2.Operation in project osate2 by osate.
the class CreateErrorPathPaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetCreateConnectionOperationContext ctx) {
// Check if the destination is a potential end
if (!ErrorFlowPaletteCommandUtil.isPotentialEnd(ctx.getDestination())) {
return Optional.empty();
}
// Find the common ancestor which is a source for the classifier to update
final BusinessObjectContext classifierSourceBoc = BusinessObjectContext.getFirstCommonAncestor(ctx.getSource().getParent(), ctx.getDestination().getParent()).flatMap(ancestor -> ErrorModelGeUtil.getClassifierSourceBoc(ancestor)).orElse(null);
if (classifierSourceBoc == null) {
return Optional.empty();
}
return ErrorModelGeUtil.createErrorModelSubclausePromptAndModifyOperation(classifierSourceBoc, () -> {
final CombinedErrorModelSubclause combined = CombinedErrorModelSubclause.create(ErrorModelGeUtil.getClassifier(classifierSourceBoc).get());
// Validate both the source and the destination
return (ErrorFlowPaletteCommandUtil.validateAndShowError(combined, ctx.getSource(), DirectionType.IN) && ErrorFlowPaletteCommandUtil.validateAndShowError(combined, ctx.getDestination(), DirectionType.OUT)) ? Optional.of(true) : Optional.empty();
}, (subclause, unused) -> {
final ErrorPath newFlow = ErrorModelFactory.eINSTANCE.createErrorPath();
// Set name
final String newName = ErrorModelNamingUtil.buildUniqueIdentifier(subclause.getContainingClassifier(), "new_error_flow");
newFlow.setName(newName);
// Set the incoming and outgoing fields of the flow
final CombinedErrorModelSubclause combined = CombinedErrorModelSubclause.create(subclause.getContainingClassifier());
final boolean allSrc = ErrorFlowPaletteCommandUtil.isAll(ctx.getSource());
if (allSrc) {
newFlow.setAllIncoming(allSrc);
} else {
newFlow.setIncoming(ErrorFlowPaletteCommandUtil.findErrorPropagationOrThrow(combined, ctx.getSource(), DirectionType.IN));
}
final boolean allDst = ErrorFlowPaletteCommandUtil.isAll(ctx.getDestination());
if (allDst) {
newFlow.setAllOutgoing(allDst);
} else {
newFlow.setOutgoing(ErrorFlowPaletteCommandUtil.findErrorPropagationOrThrow(combined, ctx.getDestination(), DirectionType.OUT));
}
// Add the flow to the subclause
subclause.getFlows().add(newFlow);
return StepResultBuilder.create().showNewBusinessObject(classifierSourceBoc, newFlow).build();
});
}
use of org.osate.aadl2.Operation in project osate2 by osate.
the class CreateErrorPropagationPaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
final Object bo = ctx.getTarget().getBusinessObject();
if (bo instanceof Feature) {
return createPropgationCreationOperation(ctx.getTarget(), (newPropagation, subclause) -> {
// Find the feature in the context of the EMV subclause. This is needed for reliable serialization.
final List<URI> path = ErrorModelGeUtil.createQualifiedPropagationPointPath(ctx.getTarget(), ErrorModelGeUtil.getClassifierSourceBoc(ctx.getTarget()).get(), new ArrayList<>());
newPropagation.setFeatureorPPRef(buildFeatureReference(subclause.eResource().getResourceSet(), path));
});
} else if (bo instanceof KeywordPropagationPoint) {
final KeywordPropagationPoint kw = (KeywordPropagationPoint) bo;
if (kw.getType() != KeywordPropagationPointType.ALL) {
return createPropgationCreationOperation(ctx.getTarget(), (newPropagation, subclause) -> newPropagation.setKind(kw.getType().getKind()));
}
} else if (bo instanceof PropagationPoint) {
return createPropgationCreationOperation(ctx.getTarget(), (newPropagation, subclause) -> {
// Find the propagation in the context of the EMV subclause.
// Check inherited subclauses as well. This is needed for reliable serialization.
final CombinedErrorModelSubclause combined = CombinedErrorModelSubclause.create(subclause.getContainingClassifier());
final String boName = ((PropagationPoint) bo).getName();
final PropagationPoint pp = combined.getPoints().filter(p -> Objects.equal(p.getName(), boName)).findAny().orElseThrow(() -> new AadlGraphicalEditorException("Unable to find propagation point"));
final FeatureorPPReference ppRef = ErrorModelFactory.eINSTANCE.createFeatureorPPReference();
ppRef.setFeatureorPP(pp);
newPropagation.setFeatureorPPRef(ppRef);
});
}
return Optional.empty();
}
use of org.osate.aadl2.Operation in project osate2 by osate.
the class CreateErrorPropagationPaletteCommand method createPropgationCreationOperation.
/**
* Creates an operation for creating a propagation for the target.
* @param target is the target of the propagation. It should be the context which will be the parent of the propagation
* @param init function called to finish initializing the propagation. It must set the kind or the feature or PP reference.
* @return the operation or an empty optional if a classifier could not be determined.
*/
private Optional<Operation> createPropgationCreationOperation(final BusinessObjectContext target, final BiConsumer<ErrorPropagation, ErrorModelSubclause> init) {
return ErrorModelGeUtil.getClassifierSourceBoc(target).flatMap(container -> {
final AadlPackage pkg = container.getBusinessObject(NamedElement.class).map(ne -> ne.getElementRoot()).map(root -> root instanceof AadlPackage ? ((AadlPackage) root) : null).orElseThrow(() -> new AadlGraphicalEditorException("Unable to find model"));
return ErrorModelGeUtil.createErrorModelSubclausePromptAndModifyOperation(container, () -> {
if (propagationAlreadyExists(target)) {
final String propagationOrContainmentLabel = (containment ? "containment" : "propagation");
final String inputOrOutputLabel = direction == DirectionType.IN ? "intput" : "output";
MessageDialog.openError(Display.getDefault().getActiveShell(), "Unable to create " + propagationOrContainmentLabel, "Propagation already exists. A propagation point may only have one " + inputOrOutputLabel + " error " + propagationOrContainmentLabel + " defined.");
return Optional.empty();
}
return ErrorModelUiUtil.promptForTypeSet(pkg);
}, (subclause, typeSet) -> {
final ErrorPropagation newPropagation = ErrorModelFactory.eINSTANCE.createErrorPropagation();
newPropagation.setTypeSet(typeSet);
newPropagation.setNot(containment);
newPropagation.setDirection(direction);
init.accept(newPropagation, subclause);
subclause.getPropagations().add(newPropagation);
return StepResultBuilder.create().showNewBusinessObject(target, newPropagation).build();
});
});
}
Aggregations