Search in sources :

Example 1 with OperationResults

use of org.osate.ge.internal.operations.OperationResults 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 2 with OperationResults

use of org.osate.ge.internal.operations.OperationResults 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 3 with OperationResults

use of org.osate.ge.internal.operations.OperationResults 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 4 with OperationResults

use of org.osate.ge.internal.operations.OperationResults in project osate2 by osate.

the class OperationResultsProcessor method processResults.

/**
 * @param editor the editor which is displaying the diagram for which the operation was executed
 * @param targetNode is the node to which the targetPosition is relative.
 * @param targetPosition the position at which the operation was executed. Relative to the target node. This is used to position
 * a newly created diagram element.
 * @param results the results to process
 */
public static void processResults(final InternalDiagramEditor editor, final DiagramNode targetNode, final Point targetPosition, final OperationResults results) {
    Objects.requireNonNull(editor, "diagram must not be null");
    boolean update = false;
    // Notify the diagram updater to add the element on the next update
    for (final Entry<BusinessObjectContext, OperationResults.BusinessObjectToShowDetails> containerToBoEntry : results.getContainerToBoToShowDetailsMap().entries()) {
        if (containerToBoEntry.getKey() instanceof DiagramNode) {
            final DiagramNode containerNode = (DiagramNode) containerToBoEntry.getKey();
            final OperationResults.BusinessObjectToShowDetails newValue = containerToBoEntry.getValue();
            // Don't set the position if multiple items are being added.
            // Don't set the position if the incremental layout mode is set to diagram.
            // This will ensure the shape is laid out even if it is a docked shape.
            final Point position;
            if (results.getContainerToBoToShowDetailsMap().size() == 1 && LayoutPreferences.getCurrentIncrementalLayoutMode() != IncrementalLayoutMode.LAYOUT_DIAGRAM && containerNode == targetNode) {
                position = targetPosition;
            } else {
                position = null;
            }
            // If the BO being added is an embedded business object, it must be provided to the diagram updater.
            final EmbeddedBusinessObject embeddedBo = (newValue.bo instanceof EmbeddedBusinessObject) ? (EmbeddedBusinessObject) newValue.bo : null;
            editor.getDiagramUpdater().addToNextUpdate(containerNode, newValue.ref, new FutureElementInfo(position, embeddedBo));
            if (embeddedBo != null) {
                update = true;
            }
        }
    }
    // If an embedded business object was added, then update the diagram to ensure it was updated.
    if (update) {
        editor.updateDiagram();
    }
}
Also used : DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) FutureElementInfo(org.osate.ge.internal.diagram.runtime.updating.FutureElementInfo) OperationResults(org.osate.ge.internal.operations.OperationResults) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) Point(org.osate.ge.graphics.Point) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 5 with OperationResults

use of org.osate.ge.internal.operations.OperationResults in project osate2 by osate.

the class OperationTest method testMapAfterModify.

@Test
public void testMapAfterModify() {
    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();
    }).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)

Aggregations

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