Search in sources :

Example 1 with CombinedErrorModelSubclause

use of org.osate.ge.errormodel.combined.CombinedErrorModelSubclause 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();
    });
}
Also used : Operation(org.osate.ge.operations.Operation) ErrorPath(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath) CombinedErrorModelSubclause(org.osate.ge.errormodel.combined.CombinedErrorModelSubclause) GetCreateConnectionOperationContext(org.osate.ge.palette.GetCreateConnectionOperationContext) ErrorModelNamingUtil(org.osate.ge.errormodel.util.ErrorModelNamingUtil) ErrorModelFactory(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelFactory) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) CanStartConnectionContext(org.osate.ge.palette.CanStartConnectionContext) CreateConnectionPaletteCommand(org.osate.ge.palette.CreateConnectionPaletteCommand) ErrorModelGeUtil(org.osate.ge.errormodel.util.ErrorModelGeUtil) Optional(java.util.Optional) DirectionType(org.osate.aadl2.DirectionType) ErrorPath(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath) CombinedErrorModelSubclause(org.osate.ge.errormodel.combined.CombinedErrorModelSubclause) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 2 with CombinedErrorModelSubclause

use of org.osate.ge.errormodel.combined.CombinedErrorModelSubclause 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();
}
Also used : URI(org.eclipse.emf.common.util.URI) Feature(org.osate.aadl2.Feature) PropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPoint) KeywordPropagationPointType(org.osate.ge.errormodel.model.KeywordPropagationPointType) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ArrayList(java.util.ArrayList) PropagationTreeUtil(org.osate.ge.errormodel.combined.PropagationTreeUtil) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) BusinessObjectContext(org.osate.ge.BusinessObjectContext) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) ErrorModelUiUtil(org.osate.ge.errormodel.ui.ErrorModelUiUtil) BiConsumer(java.util.function.BiConsumer) DirectionType(org.osate.aadl2.DirectionType) Objects(com.google.common.base.Objects) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) AadlGraphicalEditorException(org.osate.ge.aadl2.AadlGraphicalEditorException) GetTargetedOperationContext(org.osate.ge.palette.GetTargetedOperationContext) Operation(org.osate.ge.operations.Operation) CombinedErrorModelSubclause(org.osate.ge.errormodel.combined.CombinedErrorModelSubclause) EObject(org.eclipse.emf.ecore.EObject) AadlPackage(org.osate.aadl2.AadlPackage) KeywordPropagationPoint(org.osate.ge.errormodel.model.KeywordPropagationPoint) Display(org.eclipse.swt.widgets.Display) FeatureorPPReference(org.osate.xtext.aadl2.errormodel.errorModel.FeatureorPPReference) ErrorModelFactory(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelFactory) List(java.util.List) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) PropagationNode(org.osate.ge.errormodel.combined.PropagationNode) StringUtil(org.osate.ge.StringUtil) ErrorModelSubclause(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelSubclause) ErrorModelGeUtil(org.osate.ge.errormodel.util.ErrorModelGeUtil) Optional(java.util.Optional) NamedElement(org.osate.aadl2.NamedElement) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand) PropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPoint) KeywordPropagationPoint(org.osate.ge.errormodel.model.KeywordPropagationPoint) AadlGraphicalEditorException(org.osate.ge.aadl2.AadlGraphicalEditorException) KeywordPropagationPoint(org.osate.ge.errormodel.model.KeywordPropagationPoint) EObject(org.eclipse.emf.ecore.EObject) CombinedErrorModelSubclause(org.osate.ge.errormodel.combined.CombinedErrorModelSubclause) Feature(org.osate.aadl2.Feature) URI(org.eclipse.emf.common.util.URI) FeatureorPPReference(org.osate.xtext.aadl2.errormodel.errorModel.FeatureorPPReference)

Example 3 with CombinedErrorModelSubclause

use of org.osate.ge.errormodel.combined.CombinedErrorModelSubclause in project osate2 by osate.

the class ErrorModelBusinessObjectProvider method getChildBusinessObjects.

@Override
public Stream<?> getChildBusinessObjects(final BusinessObjectProviderContext ctx) {
    final Object bo = ctx.getBusinessObjectContext().getBusinessObject();
    if (bo instanceof AadlPackage) {
        return ErrorModelGeUtil.getErrorModelLibrary((AadlPackage) bo).map(lib -> Stream.concat(Stream.concat(lib.getTypes().stream(), lib.getTypesets().stream()), lib.getBehaviors().stream())).orElseGet(Stream::empty);
    } else if (bo instanceof ErrorBehaviorStateMachine) {
        final ErrorBehaviorStateMachine stateMachine = (ErrorBehaviorStateMachine) bo;
        return Stream.concat(Stream.concat(stateMachine.getEvents().stream(), stateMachine.getStates().stream()), stateMachine.getTransitions().stream());
    } else if (bo instanceof ErrorBehaviorTransition) {
        // See ErrorBehaviorTransitionHandler for details regarding how the business objects related to error behavior transitions are represented.
        final ErrorBehaviorTransition t = (ErrorBehaviorTransition) bo;
        return t.getDestinationBranches().isEmpty() ? Stream.empty() : Stream.concat(Stream.of(new BehaviorTransitionTrunk(t)), t.getDestinationBranches().stream());
    } else if (bo instanceof ErrorType) {
        final ErrorType errorType = (ErrorType) bo;
        if (errorType.getSuperType() != null) {
            return Stream.of(new ErrorTypeExtension(errorType.getSuperType(), errorType));
        }
    } else if (bo instanceof Classifier || bo instanceof Subcomponent) {
        // Anytime the children of a classifier or subcomponent is requested, process of error model subclauses
        // in the element or extended elements and cache the result.
        // Ideally, we would only do this if the classifier has changed but it would require a reliable means to
        // determine if a classifier or any classifiers it extends has changed. If extended classifiers are in another
        // package, the classifier be the same instance.
        // The object is cached so it is available when calling the business object provider on children.
        final Classifier classifier = ErrorModelGeUtil.getClassifier(ctx.getBusinessObjectContext()).orElse(null);
        if (classifier != null) {
            final CombinedErrorModelSubclause cacheEntry = CombinedErrorModelSubclause.create(classifier);
            classifierCache.put(classifier, cacheEntry);
            if (cacheEntry.subclauseExists()) {
                final Set<KeywordPropagationPointType> usedKeywordTypes = cacheEntry.getUsedKeywordPropagations();
                return Stream.of(cacheEntry.getPoints(), cacheEntry.getPaths(), cacheEntry.getFlows(), Arrays.stream(KeywordPropagationPointType.values()).map(t -> new KeywordPropagationPoint(classifier, t, usedKeywordTypes.contains(t)))).flatMap(Function.identity());
            }
        }
    } else if (bo instanceof Feature || bo instanceof PropagationPoint || bo instanceof KeywordPropagationPoint) {
        // Propagation(and containment) objects
        final CombinedErrorModelSubclause cacheEntry = getClassifierCacheEntry(ctx.getBusinessObjectContext());
        return PropagationTreeUtil.getPropagationsForBusinessObjectContext(cacheEntry.getPropagations(), ctx.getBusinessObjectContext());
    }
    return Stream.empty();
}
Also used : Arrays(java.util.Arrays) Feature(org.osate.aadl2.Feature) CombinedErrorModelSubclause(org.osate.ge.errormodel.combined.CombinedErrorModelSubclause) ErrorBehaviorTransition(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition) PropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPoint) KeywordPropagationPointType(org.osate.ge.errormodel.model.KeywordPropagationPointType) Set(java.util.Set) BusinessObjectProviderContext(org.osate.ge.BusinessObjectProviderContext) BehaviorTransitionTrunk(org.osate.ge.errormodel.model.BehaviorTransitionTrunk) AadlPackage(org.osate.aadl2.AadlPackage) KeywordPropagationPoint(org.osate.ge.errormodel.model.KeywordPropagationPoint) Function(java.util.function.Function) ErrorTypeExtension(org.osate.ge.errormodel.model.ErrorTypeExtension) ErrorBehaviorStateMachine(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorStateMachine) PropagationTreeUtil(org.osate.ge.errormodel.combined.PropagationTreeUtil) Stream(java.util.stream.Stream) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Classifier(org.osate.aadl2.Classifier) BusinessObjectProvider(org.osate.ge.BusinessObjectProvider) ErrorModelGeUtil(org.osate.ge.errormodel.util.ErrorModelGeUtil) Subcomponent(org.osate.aadl2.Subcomponent) WeakHashMap(java.util.WeakHashMap) ErrorType(org.osate.xtext.aadl2.errormodel.errorModel.ErrorType) AadlPackage(org.osate.aadl2.AadlPackage) ErrorTypeExtension(org.osate.ge.errormodel.model.ErrorTypeExtension) CombinedErrorModelSubclause(org.osate.ge.errormodel.combined.CombinedErrorModelSubclause) Classifier(org.osate.aadl2.Classifier) Feature(org.osate.aadl2.Feature) ErrorBehaviorTransition(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition) ErrorType(org.osate.xtext.aadl2.errormodel.errorModel.ErrorType) PropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPoint) KeywordPropagationPoint(org.osate.ge.errormodel.model.KeywordPropagationPoint) ErrorBehaviorStateMachine(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorStateMachine) Subcomponent(org.osate.aadl2.Subcomponent) KeywordPropagationPoint(org.osate.ge.errormodel.model.KeywordPropagationPoint) Stream(java.util.stream.Stream) BehaviorTransitionTrunk(org.osate.ge.errormodel.model.BehaviorTransitionTrunk) KeywordPropagationPointType(org.osate.ge.errormodel.model.KeywordPropagationPointType)

Example 4 with CombinedErrorModelSubclause

use of org.osate.ge.errormodel.combined.CombinedErrorModelSubclause in project osate2 by osate.

the class ErrorPropagationHandler method canDelete.

@Override
public boolean canDelete(final CanDeleteContext ctx) {
    final ErrorPropagation bo = ctx.getBusinessObject(ErrorPropagation.class).get();
    // Don't allow deleting if there exists an error flow that references the error propagation
    final CombinedErrorModelSubclause combined = CombinedErrorModelSubclause.create(bo.getContainingClassifier());
    return !combined.getFlows().anyMatch(f -> {
        if (f instanceof ErrorSource) {
            final ErrorSource src = (ErrorSource) f;
            return src.getSourceModelElement() == bo;
        } else if (f instanceof ErrorSink) {
            final ErrorSink snk = (ErrorSink) f;
            return snk.getIncoming() == bo;
        } else if (f instanceof ErrorPath) {
            final ErrorPath path = (ErrorPath) f;
            return path.getIncoming() == bo || path.getOutgoing() == bo;
        }
        return false;
    });
}
Also used : GetNameForDiagramContext(org.osate.ge.businessobjecthandling.GetNameForDiagramContext) BusinessObjectHandler(org.osate.ge.businessobjecthandling.BusinessObjectHandler) ErrorPath(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath) CanDeleteContext(org.osate.ge.businessobjecthandling.CanDeleteContext) GraphicalConfiguration(org.osate.ge.GraphicalConfiguration) Style(org.osate.ge.graphics.Style) ErrorSink(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSink) Strings(com.google.common.base.Strings) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) Graphic(org.osate.ge.graphics.Graphic) GetGraphicalConfigurationContext(org.osate.ge.businessobjecthandling.GetGraphicalConfigurationContext) ErrorSource(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource) GetNameContext(org.osate.ge.businessobjecthandling.GetNameContext) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) CanCopyContext(org.osate.ge.businessobjecthandling.CanCopyContext) LabelBuilder(org.osate.ge.graphics.LabelBuilder) GraphicalConfigurationBuilder(org.osate.ge.GraphicalConfigurationBuilder) CombinedErrorModelSubclause(org.osate.ge.errormodel.combined.CombinedErrorModelSubclause) GraphicalExtensionUtil(org.osate.ge.aadl2.GraphicalExtensionUtil) FeatureorPPReference(org.osate.xtext.aadl2.errormodel.errorModel.FeatureorPPReference) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) StyleBuilder(org.osate.ge.graphics.StyleBuilder) IsApplicableContext(org.osate.ge.businessobjecthandling.IsApplicableContext) ReferenceContext(org.osate.ge.businessobjecthandling.ReferenceContext) Optional(java.util.Optional) ErrorSource(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource) ErrorPath(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) CombinedErrorModelSubclause(org.osate.ge.errormodel.combined.CombinedErrorModelSubclause) ErrorSink(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSink)

Aggregations

CombinedErrorModelSubclause (org.osate.ge.errormodel.combined.CombinedErrorModelSubclause)4 Optional (java.util.Optional)3 BusinessObjectContext (org.osate.ge.BusinessObjectContext)3 ErrorModelGeUtil (org.osate.ge.errormodel.util.ErrorModelGeUtil)3 AadlPackage (org.osate.aadl2.AadlPackage)2 DirectionType (org.osate.aadl2.DirectionType)2 Feature (org.osate.aadl2.Feature)2 PropagationTreeUtil (org.osate.ge.errormodel.combined.PropagationTreeUtil)2 KeywordPropagationPoint (org.osate.ge.errormodel.model.KeywordPropagationPoint)2 KeywordPropagationPointType (org.osate.ge.errormodel.model.KeywordPropagationPointType)2 Operation (org.osate.ge.operations.Operation)2 StepResultBuilder (org.osate.ge.operations.StepResultBuilder)2 BasePaletteCommand (org.osate.ge.palette.BasePaletteCommand)2 ErrorModelFactory (org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelFactory)2 Objects (com.google.common.base.Objects)1 Strings (com.google.common.base.Strings)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Set (java.util.Set)1