Search in sources :

Example 1 with OperationBuilder

use of org.osate.ge.operations.OperationBuilder in project osate2 by osate.

the class CreateVariablePaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
    return ctx.getTarget().getBusinessObject(BehaviorAnnex.class).map(behaviorAnnex -> {
        final PublicPackageSection section = getPackage(behaviorAnnex).map(AadlPackage::getPublicSection).orElse(null);
        if (section == null) {
            return null;
        }
        return Operation.createWithBuilder(builder -> {
            final OperationBuilder<DataClassifier> prompt = builder.supply(() -> BehaviorAnnexUtil.promptForDataClassifier(behaviorAnnex.eResource()).filter(c -> BehaviorAnnexUtil.getPackage(c).isPresent()).map(StepResult::forValue).orElseGet(StepResult::abort));
            final OperationBuilder<DataClassifier> addImportIfNeeded = prompt.modifyModel(null, (tag, prevResult) -> section, (tag, sectionToModify, dataClassifier) -> {
                BehaviorAnnexUtil.getPackage(dataClassifier).ifPresent(classifierPkg -> AadlImportsUtil.addImportIfNeeded(sectionToModify, classifierPkg));
                return StepResult.forValue(dataClassifier);
            });
            addImportIfNeeded.modifyModel(null, (tag, dataClassifier) -> behaviorAnnex, (tag, behaviorAnnexToModify, prevResult) -> {
                final BehaviorVariable newVariable = (BehaviorVariable) EcoreUtil.create(AadlBaPackage.eINSTANCE.getBehaviorVariable());
                final String newName = BehaviorAnnexNamingUtil.buildUniqueIdentifier(behaviorAnnexToModify, "new_behavior_variable");
                newVariable.setName(newName);
                newVariable.setDataClassifier(prevResult);
                behaviorAnnexToModify.getVariables().add(newVariable);
                return StepResultBuilder.create().showNewBusinessObject(ctx.getTarget(), newVariable).build();
            });
        });
    });
}
Also used : GetTargetedOperationContext(org.osate.ge.palette.GetTargetedOperationContext) BehaviorAnnexNamingUtil(org.osate.ge.ba.util.BehaviorAnnexNamingUtil) StepResult(org.osate.ge.operations.StepResult) Operation(org.osate.ge.operations.Operation) BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) AadlPackage(org.osate.aadl2.AadlPackage) AadlImportsUtil(org.osate.ge.aadl2.AadlImportsUtil) BehaviorAnnex(org.osate.ba.aadlba.BehaviorAnnex) BehaviorAnnexUtil.getPackage(org.osate.ge.ba.util.BehaviorAnnexUtil.getPackage) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) PublicPackageSection(org.osate.aadl2.PublicPackageSection) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) DataClassifier(org.osate.aadl2.DataClassifier) BehaviorAnnexUtil(org.osate.ge.ba.util.BehaviorAnnexUtil) Optional(java.util.Optional) OperationBuilder(org.osate.ge.operations.OperationBuilder) AadlBaPackage(org.osate.ba.aadlba.AadlBaPackage) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand) PublicPackageSection(org.osate.aadl2.PublicPackageSection) BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) BehaviorAnnex(org.osate.ba.aadlba.BehaviorAnnex) DataClassifier(org.osate.aadl2.DataClassifier) StepResult(org.osate.ge.operations.StepResult)

Example 2 with OperationBuilder

use of org.osate.ge.operations.OperationBuilder in project osate2 by osate.

the class OperationTest method testSplit.

@Test
public void testSplit() {
    DefaultOperationBuilder rootOpBuilder = new DefaultOperationBuilder();
    final OperationBuilder<Integer> b = rootOpBuilder.map(arg -> StepResultBuilder.create(1).build());
    b.map(pr -> StepResultBuilder.create(pr + 2).build()).modifyModel(null, (tag, prevResult) -> testBo, (tag, boToModify, prevResult) -> {
        return StepResultBuilder.create(prevResult + 1).build();
    }).modifyModel(null, (tag, prevResult) -> testBo, (tag, boToModify, prevResult) -> {
        return StepResultBuilder.create().showNewBusinessObject(stubBoc, prevResult + 2).build();
    });
    b.map(pr -> StepResultBuilder.create(pr + 6).build()).modifyModel(null, (tag, prevResult) -> testBo, (tag, boToModify, prevResult) -> {
        return StepResultBuilder.create().showNewBusinessObject(stubBoc, prevResult + 3).build();
    });
    final Step firstStep = rootOpBuilder.build();
    final OperationExecutor executor = new OperationExecutor(modificationService, referenceBuilder);
    final OperationResults results = executor.execute(firstStep);
    // Verify that results were created from both paths
    final ImmutableSet<Integer> expectedBosToShow = ImmutableSet.of(6, 10);
    final Set<?> bosToShow = results.getContainerToBoToShowDetailsMap().values().stream().map(v -> v.bo).collect(Collectors.toSet());
    assertEquals(expectedBosToShow, bosToShow);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) Step(org.osate.ge.internal.operations.Step) Collection(java.util.Collection) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OperationExecutor(org.osate.ge.internal.operations.OperationExecutor) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test) Collectors(java.util.stream.Collectors) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) List(java.util.List) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Point(org.osate.ge.diagram.Point) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) DefaultOperationBuilder(org.osate.ge.internal.operations.DefaultOperationBuilder) Assert(org.junit.Assert) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) OperationBuilder(org.osate.ge.operations.OperationBuilder) Collections(java.util.Collections) OperationResults(org.osate.ge.internal.operations.OperationResults) OperationResults(org.osate.ge.internal.operations.OperationResults) OperationExecutor(org.osate.ge.internal.operations.OperationExecutor) Step(org.osate.ge.internal.operations.Step) DefaultOperationBuilder(org.osate.ge.internal.operations.DefaultOperationBuilder) Test(org.junit.Test)

Example 3 with OperationBuilder

use of org.osate.ge.operations.OperationBuilder in project osate2 by osate.

the class OperationTest method testSequential.

/**
 * Tests a simple sequential modification
 */
@Test
public void testSequential() {
    DefaultOperationBuilder rootOpBuilder = new DefaultOperationBuilder();
    final OperationBuilder<Integer> b = rootOpBuilder.map(arg -> StepResultBuilder.create(1).build());
    b.map(pr -> StepResultBuilder.create(pr + 2).build()).modifyModel(null, (tag, prevResult) -> testBo, (tag, boToModify, prevResult) -> {
        return StepResultBuilder.create(prevResult + 1).build();
    }).modifyModel(null, (tag, prevResult) -> testBo, (tag, boToModify, prevResult) -> {
        return StepResultBuilder.create().showNewBusinessObject(stubBoc, prevResult + 2).build();
    });
    final Step firstStep = rootOpBuilder.build();
    final OperationExecutor executor = new OperationExecutor(modificationService, referenceBuilder);
    final OperationResults results = executor.execute(firstStep);
    // Verify that result was created.
    final ImmutableSet<Integer> expectedBosToShow = ImmutableSet.of(6);
    final Set<?> bosToShow = results.getContainerToBoToShowDetailsMap().values().stream().map(v -> v.bo).collect(Collectors.toSet());
    assertEquals(expectedBosToShow, bosToShow);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) Step(org.osate.ge.internal.operations.Step) Collection(java.util.Collection) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OperationExecutor(org.osate.ge.internal.operations.OperationExecutor) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test) Collectors(java.util.stream.Collectors) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) List(java.util.List) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Point(org.osate.ge.diagram.Point) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) DefaultOperationBuilder(org.osate.ge.internal.operations.DefaultOperationBuilder) Assert(org.junit.Assert) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) OperationBuilder(org.osate.ge.operations.OperationBuilder) Collections(java.util.Collections) OperationResults(org.osate.ge.internal.operations.OperationResults) OperationResults(org.osate.ge.internal.operations.OperationResults) OperationExecutor(org.osate.ge.internal.operations.OperationExecutor) Step(org.osate.ge.internal.operations.Step) DefaultOperationBuilder(org.osate.ge.internal.operations.DefaultOperationBuilder) Test(org.junit.Test)

Example 4 with OperationBuilder

use of org.osate.ge.operations.OperationBuilder in project osate2 by osate.

the class OperationTest method testMapWithoutodify.

@Test
public void testMapWithoutodify() {
    DefaultOperationBuilder rootOpBuilder = new DefaultOperationBuilder();
    final OperationBuilder<Integer> b = rootOpBuilder.map(arg -> StepResultBuilder.create(1).build());
    b.map(pr -> StepResultBuilder.create().showNewBusinessObject(stubBoc, Integer.valueOf(100)).build());
    final Step firstStep = rootOpBuilder.build();
    final OperationExecutor executor = new OperationExecutor(modificationService, referenceBuilder);
    final OperationResults results = executor.execute(firstStep);
    // Verify that result was created from the map after the modification
    final ImmutableSet<Integer> expectedBosToShow = ImmutableSet.of(100);
    final Set<?> bosToShow = results.getContainerToBoToShowDetailsMap().values().stream().map(v -> v.bo).collect(Collectors.toSet());
    assertEquals(expectedBosToShow, bosToShow);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) Step(org.osate.ge.internal.operations.Step) Collection(java.util.Collection) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OperationExecutor(org.osate.ge.internal.operations.OperationExecutor) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test) Collectors(java.util.stream.Collectors) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) List(java.util.List) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Point(org.osate.ge.diagram.Point) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) DefaultOperationBuilder(org.osate.ge.internal.operations.DefaultOperationBuilder) Assert(org.junit.Assert) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) OperationBuilder(org.osate.ge.operations.OperationBuilder) Collections(java.util.Collections) OperationResults(org.osate.ge.internal.operations.OperationResults) OperationResults(org.osate.ge.internal.operations.OperationResults) OperationExecutor(org.osate.ge.internal.operations.OperationExecutor) Step(org.osate.ge.internal.operations.Step) DefaultOperationBuilder(org.osate.ge.internal.operations.DefaultOperationBuilder) Test(org.junit.Test)

Example 5 with OperationBuilder

use of org.osate.ge.operations.OperationBuilder in project osate2 by osate.

the class OperationTest method testAbort.

@Test
public void testAbort() {
    final DefaultOperationBuilder rootOpBuilder = new DefaultOperationBuilder();
    final OperationBuilder<Integer> b = rootOpBuilder.map(arg -> StepResultBuilder.create(1).build());
    final AtomicBoolean executed = new AtomicBoolean(false);
    b.map(pr -> StepResultBuilder.create(pr + 2).build()).modifyModel(null, (tag, prevResult) -> testBo, (tag, boToModify, prevResult) -> {
        return StepResultBuilder.create(prevResult + 1).abort().build();
    }).modifyModel(null, (tag, prevResult) -> testBo, (tag, boToModify, prevResult) -> {
        executed.set(true);
        return StepResultBuilder.create().showNewBusinessObject(stubBoc, prevResult + 2).build();
    });
    final Step firstStep = rootOpBuilder.build();
    final OperationExecutor executor = new OperationExecutor(modificationService, referenceBuilder);
    executor.execute(firstStep);
    assertEquals(false, executed.get());
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) Step(org.osate.ge.internal.operations.Step) Collection(java.util.Collection) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OperationExecutor(org.osate.ge.internal.operations.OperationExecutor) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test) Collectors(java.util.stream.Collectors) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) List(java.util.List) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Point(org.osate.ge.diagram.Point) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) DefaultOperationBuilder(org.osate.ge.internal.operations.DefaultOperationBuilder) Assert(org.junit.Assert) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) OperationBuilder(org.osate.ge.operations.OperationBuilder) Collections(java.util.Collections) OperationResults(org.osate.ge.internal.operations.OperationResults) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OperationExecutor(org.osate.ge.internal.operations.OperationExecutor) Step(org.osate.ge.internal.operations.Step) DefaultOperationBuilder(org.osate.ge.internal.operations.DefaultOperationBuilder) Test(org.junit.Test)

Aggregations

OperationBuilder (org.osate.ge.operations.OperationBuilder)7 StepResultBuilder (org.osate.ge.operations.StepResultBuilder)7 ImmutableSet (com.google.common.collect.ImmutableSet)6 Collection (java.util.Collection)6 Collections (java.util.Collections)6 List (java.util.List)6 Set (java.util.Set)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Collectors (java.util.stream.Collectors)6 EObject (org.eclipse.emf.ecore.EObject)6 Assert (org.junit.Assert)6 Test (org.junit.Test)6 BusinessObjectContext (org.osate.ge.BusinessObjectContext)6 CanonicalBusinessObjectReference (org.osate.ge.CanonicalBusinessObjectReference)6 RelativeBusinessObjectReference (org.osate.ge.RelativeBusinessObjectReference)6 Point (org.osate.ge.diagram.Point)6 DefaultOperationBuilder (org.osate.ge.internal.operations.DefaultOperationBuilder)6 OperationExecutor (org.osate.ge.internal.operations.OperationExecutor)6 OperationResults (org.osate.ge.internal.operations.OperationResults)6 Step (org.osate.ge.internal.operations.Step)6