use of org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService in project sirius-components by eclipse-sirius.
the class EdgeMappingConverterTests method testEdgeFromNodeToContainer.
/**
* Non-regression test for the create edges issue. This test will ensure that a container description can be used as
* a valid target for an edge.
*/
@Test
public void testEdgeFromNodeToContainer() {
EdgeMapping edgeMapping = DescriptionFactory.eINSTANCE.createEdgeMapping();
NodeMapping nodeMapping = DescriptionFactory.eINSTANCE.createNodeMapping();
// $NON-NLS-1$
nodeMapping.setName("nodeMapping");
ContainerMapping containerMapping = DescriptionFactory.eINSTANCE.createContainerMapping();
// $NON-NLS-1$
containerMapping.setName("containerMapping");
edgeMapping.getSourceMapping().add(nodeMapping);
edgeMapping.getTargetMapping().add(containerMapping);
// @formatter:off
UUID nodeMappingUUID = UUID.nameUUIDFromBytes(nodeMapping.getName().getBytes());
UUID containerMappingUUID = UUID.nameUUIDFromBytes(containerMapping.getName().getBytes());
Map<UUID, NodeDescription> id2NodeDescriptions = Map.of(nodeMappingUUID, this.createNodeDescription(nodeMappingUUID), containerMappingUUID, this.createNodeDescription(containerMappingUUID));
// @formatter:on
IObjectService objectService = new IObjectService.NoOp();
IRepresentationMetadataSearchService representationMetadataSearchService = new IRepresentationMetadataSearchService.NoOp();
IIdentifierProvider identifierProvider = new IIdentifierProvider.NoOp() {
@Override
public String getIdentifier(Object element) {
return containerMappingUUID.toString();
}
};
ISemanticCandidatesProviderFactory semanticCandidatesProviderFactory = SemanticCandidatesProvider::new;
IModelOperationHandlerSwitchProvider modelOperationHandlerSwitchProvider = interpeter -> new ModelOperationHandlerSwitch(objectService, representationMetadataSearchService, identifierProvider, List.of(), interpeter);
EdgeMappingConverter edgeMappingConverter = new EdgeMappingConverter(new IObjectService.NoOp(), new IEditService.NoOp(), identifierProvider, semanticCandidatesProviderFactory, modelOperationHandlerSwitchProvider);
EdgeDescription edgeDescription = edgeMappingConverter.convert(edgeMapping, new AQLInterpreter(List.of(), List.of()), id2NodeDescriptions);
assertThat(edgeDescription.getTargetNodeDescriptions()).contains(id2NodeDescriptions.get(containerMappingUUID));
}
use of org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService in project sirius-components by eclipse-sirius.
the class EdgeMappingConverterTests method testEdgeFromContainerToContainer.
/**
* Non-regression test for the create edges issue. This test will ensure that a container description can be used as
* both a valid source and a valid target for an edge.
*/
@Test
public void testEdgeFromContainerToContainer() {
EdgeMapping edgeMapping = DescriptionFactory.eINSTANCE.createEdgeMapping();
ContainerMapping sourceContainerMapping = DescriptionFactory.eINSTANCE.createContainerMapping();
// $NON-NLS-1$
sourceContainerMapping.setName("sourceContainerMapping");
ContainerMapping targetContainerMapping = DescriptionFactory.eINSTANCE.createContainerMapping();
// $NON-NLS-1$
targetContainerMapping.setName("targetContainerMapping");
edgeMapping.getSourceMapping().add(sourceContainerMapping);
edgeMapping.getTargetMapping().add(targetContainerMapping);
// @formatter:off
UUID sourceContainerMappingUUID = UUID.nameUUIDFromBytes(sourceContainerMapping.getName().getBytes());
UUID targetContainerMappingUUID = UUID.nameUUIDFromBytes(targetContainerMapping.getName().getBytes());
Map<UUID, NodeDescription> id2NodeDescriptions = Map.of(sourceContainerMappingUUID, this.createNodeDescription(sourceContainerMappingUUID), targetContainerMappingUUID, this.createNodeDescription(targetContainerMappingUUID));
// @formatter:on
IObjectService objectService = new IObjectService.NoOp();
IRepresentationMetadataSearchService representationMetadataSearchService = new IRepresentationMetadataSearchService.NoOp();
IIdentifierProvider identifierProvider = new IIdentifierProvider() {
@Override
public String getIdentifier(Object element) {
return targetContainerMappingUUID.toString();
}
@Override
public Optional<String> findVsmElementId(UUID id) {
return Optional.empty();
}
};
ISemanticCandidatesProviderFactory semanticCandidatesProviderFactory = SemanticCandidatesProvider::new;
IModelOperationHandlerSwitchProvider modelOperationHandlerSwitchProvider = interpeter -> new ModelOperationHandlerSwitch(objectService, representationMetadataSearchService, identifierProvider, List.of(), interpeter);
EdgeMappingConverter edgeMappingConverter = new EdgeMappingConverter(objectService, new IEditService.NoOp(), identifierProvider, semanticCandidatesProviderFactory, modelOperationHandlerSwitchProvider);
EdgeDescription edgeDescription = edgeMappingConverter.convert(edgeMapping, new AQLInterpreter(List.of(), List.of()), id2NodeDescriptions);
edgeDescription.getSourceNodeDescriptions().contains(id2NodeDescriptions.get(sourceContainerMappingUUID));
assertThat(edgeDescription.getTargetNodeDescriptions()).contains(id2NodeDescriptions.get(targetContainerMappingUUID));
}
use of org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService in project sirius-components by eclipse-sirius.
the class EdgeMappingConverterTests method testEdgeFromContainerToNode.
/**
* Non-regression test for the create edges issue. This test will ensure that a container description can be used as
* a valid source for an edge.
*/
@Test
public void testEdgeFromContainerToNode() {
EdgeMapping edgeMapping = DescriptionFactory.eINSTANCE.createEdgeMapping();
NodeMapping nodeMapping = DescriptionFactory.eINSTANCE.createNodeMapping();
// $NON-NLS-1$
nodeMapping.setName("nodeMapping");
ContainerMapping containerMapping = DescriptionFactory.eINSTANCE.createContainerMapping();
// $NON-NLS-1$
containerMapping.setName("containerMapping");
edgeMapping.getSourceMapping().add(containerMapping);
edgeMapping.getTargetMapping().add(nodeMapping);
// @formatter:off
UUID nodeMappingUUID = UUID.nameUUIDFromBytes(nodeMapping.getName().getBytes());
UUID containerMappingUUID = UUID.nameUUIDFromBytes(containerMapping.getName().getBytes());
Map<UUID, NodeDescription> id2NodeDescriptions = Map.of(nodeMappingUUID, this.createNodeDescription(nodeMappingUUID), containerMappingUUID, this.createNodeDescription(containerMappingUUID));
// @formatter:on
IObjectService objectService = new IObjectService.NoOp();
IRepresentationMetadataSearchService representationMetadataSearchService = new IRepresentationMetadataSearchService.NoOp();
IIdentifierProvider identifierProvider = new IIdentifierProvider() {
@Override
public String getIdentifier(Object element) {
return containerMappingUUID.toString();
}
@Override
public Optional<String> findVsmElementId(UUID id) {
return Optional.empty();
}
};
ISemanticCandidatesProviderFactory semanticCandidatesProviderFactory = SemanticCandidatesProvider::new;
IModelOperationHandlerSwitchProvider modelOperationHandlerSwitchProvider = interpeter -> new ModelOperationHandlerSwitch(objectService, representationMetadataSearchService, identifierProvider, List.of(), interpeter);
EdgeMappingConverter edgeMappingConverter = new EdgeMappingConverter(objectService, new IEditService.NoOp(), identifierProvider, semanticCandidatesProviderFactory, modelOperationHandlerSwitchProvider);
EdgeDescription edgeDescription = edgeMappingConverter.convert(edgeMapping, new AQLInterpreter(List.of(), List.of()), id2NodeDescriptions);
assertThat(edgeDescription.getSourceNodeDescriptions()).contains(id2NodeDescriptions.get(containerMappingUUID));
}
use of org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService in project sirius-components by eclipse-sirius.
the class ChildModelOperationHandler method handle.
public IStatus handle(IObjectService objectService, IRepresentationMetadataSearchService representationMetadataSearchService, IIdentifierProvider identifierProvider, AQLInterpreter interpreter, Map<String, Object> variables, List<ModelOperation> modelOperations) {
Success success = new Success();
boolean hasBeenSuccessfullyExecuted = true;
ModelOperationHandlerSwitch modelOperationHandlerSwitch = new ModelOperationHandlerSwitch(objectService, representationMetadataSearchService, identifierProvider, this.externalJavaActionProviders, interpreter);
for (ModelOperation modelOperation : modelOperations) {
Optional<IModelOperationHandler> optionalModelOperationHandler = modelOperationHandlerSwitch.apply(modelOperation);
IStatus status = optionalModelOperationHandler.map(handler -> {
return handler.handle(variables);
}).orElse(// $NON-NLS-1$
new Failure(""));
hasBeenSuccessfullyExecuted = hasBeenSuccessfullyExecuted && status instanceof Success;
if (hasBeenSuccessfullyExecuted) {
// @formatter:off
var optionalChildModelOperationNewSelection = Optional.of(status).filter(Success.class::isInstance).map(Success.class::cast).map(result -> result.getParameters().get(Success.NEW_SELECTION)).filter(WorkbenchSelection.class::isInstance).map(WorkbenchSelection.class::cast);
if (optionalChildModelOperationNewSelection.isPresent()) {
WorkbenchSelection childWorkbenchSelection = optionalChildModelOperationNewSelection.get();
Object newSelection = success.getParameters().get(Success.NEW_SELECTION);
if (newSelection instanceof WorkbenchSelection) {
((WorkbenchSelection) newSelection).getEntries().addAll(childWorkbenchSelection.getEntries());
} else if (newSelection == null) {
success.getParameters().put(Success.NEW_SELECTION, new WorkbenchSelection(childWorkbenchSelection.getEntries()));
}
}
}
}
if (hasBeenSuccessfullyExecuted) {
return success;
}
// $NON-NLS-1$
return new Failure("");
}
use of org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService in project sirius-components by eclipse-sirius.
the class FormRendererTests method testEcoreModel.
@Test
public void testEcoreModel() {
ViewExtensionDescription viewExtensionDescription = this.createSiriusProperties();
AQLInterpreterFactory interpreterFactory = new AQLInterpreterFactory() {
@Override
public AQLInterpreter create(ViewExtensionDescription viewExtensionDescription) {
return new AQLInterpreter(List.of(), List.of(EcorePackage.eINSTANCE));
}
};
IObjectService objectService = new IObjectService.NoOp();
IRepresentationMetadataSearchService representationMetadataSearchService = new IRepresentationMetadataSearchService.NoOp();
IIdentifierProvider identifierProvider = new IIdentifierProvider.NoOp() {
@Override
public String getIdentifier(Object element) {
return UUID.randomUUID().toString();
}
};
IdentifiedElementLabelProvider identifiedElementLabelProvider = new IdentifiedElementLabelProvider();
ISemanticCandidatesProviderFactory semanticCandidatesProviderFactory = SemanticCandidatesProvider::new;
IModelOperationHandlerSwitchProvider modelOperationHandlerSwitchProvider = interpeter -> new ModelOperationHandlerSwitch(objectService, representationMetadataSearchService, identifierProvider, List.of(), interpeter);
ViewExtensionDescriptionConverter converter = new ViewExtensionDescriptionConverter(objectService, interpreterFactory, identifierProvider, semanticCandidatesProviderFactory, modelOperationHandlerSwitchProvider, identifiedElementLabelProvider);
FormDescription description = converter.convert(viewExtensionDescription);
this.checkResult(description);
}
Aggregations