Search in sources :

Example 1 with IRepresentation

use of org.eclipse.sirius.components.representations.IRepresentation in project sirius-components by eclipse-sirius.

the class RepresentationStdDeserializer method deserialize.

@Override
public IRepresentation deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException {
    IRepresentation representation = null;
    ObjectCodec objectCodec = jsonParser.getCodec();
    if (objectCodec instanceof ObjectMapper) {
        ObjectMapper mapper = (ObjectMapper) objectCodec;
        ObjectNode root = mapper.readTree(jsonParser);
        // @formatter:off
        representation = this.representationDeserializers.stream().filter(representationDeserializer -> representationDeserializer.canHandle(root)).findFirst().flatMap(representationDeserializer -> representationDeserializer.handle(mapper, root)).orElse(null);
    // @formatter:on
    }
    return representation;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) IRepresentation(org.eclipse.sirius.components.representations.IRepresentation) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with IRepresentation

use of org.eclipse.sirius.components.representations.IRepresentation in project sirius-components by eclipse-sirius.

the class RenameDiagramEventHandlerTests method testRenameRepresentation.

@Test
public void testRenameRepresentation() {
    String projectId = UUID.randomUUID().toString();
    String representationId = UUID.randomUUID().toString();
    UUID targetObjectId = UUID.randomUUID();
    DiagramDescription diagramDescription = new TestDiagramDescriptionBuilder().getDiagramDescription(UUID.randomUUID(), List.of(), List.of(), List.of());
    // @formatter:off
    Diagram diagram = Diagram.newDiagram(representationId).label(OLD_LABEL).descriptionId(diagramDescription.getId()).targetObjectId(targetObjectId.toString()).size(Size.of(10, 10)).position(Position.at(0, 0)).nodes(Collections.emptyList()).edges(Collections.emptyList()).build();
    // @formatter:on
    IRepresentationSearchService representationSearchService = new IRepresentationSearchService() {

        @Override
        public <T extends IRepresentation> Optional<T> findById(IEditingContext editingContext, String representationId, Class<T> representationClass) {
            return Optional.of(diagram).map(representationClass::cast);
        }
    };
    RenameDiagramEventHandler handler = new RenameDiagramEventHandler(representationSearchService, new IRepresentationPersistenceService.NoOp(), new ICollaborativeDiagramMessageService.NoOp(), new SimpleMeterRegistry());
    var input = new RenameDiagramInput(UUID.randomUUID(), projectId, representationId, NEW_LABEL);
    assertThat(handler.canHandle(input)).isTrue();
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    One<IPayload> payloadSink = Sinks.one();
    handler.handle(payloadSink, changeDescriptionSink, new IEditingContext.NoOp(), new IDiagramContext.NoOp(), input);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.REPRESENTATION_RENAMING);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(RenameRepresentationSuccessPayload.class);
    assertThat(((RenameRepresentationSuccessPayload) payload).getRepresentation().getLabel()).isEqualTo(NEW_LABEL);
}
Also used : TestDiagramDescriptionBuilder(org.eclipse.sirius.components.diagrams.tests.TestDiagramDescriptionBuilder) IPayload(org.eclipse.sirius.components.core.api.IPayload) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) ICollaborativeDiagramMessageService(org.eclipse.sirius.components.collaborative.diagrams.messages.ICollaborativeDiagramMessageService) UUID(java.util.UUID) IRepresentationPersistenceService(org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceService) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IRepresentationSearchService(org.eclipse.sirius.components.collaborative.api.IRepresentationSearchService) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) IRepresentation(org.eclipse.sirius.components.representations.IRepresentation) Diagram(org.eclipse.sirius.components.diagrams.Diagram) RenameDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.dto.RenameDiagramInput) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) Test(org.junit.jupiter.api.Test)

Example 3 with IRepresentation

use of org.eclipse.sirius.components.representations.IRepresentation in project sirius-web by eclipse-sirius.

the class ProjectExportService method createRepresentationManifest.

/**
 * Creates a {@link RepresentationManifest} for the given {@link RepresentationDescriptor}.
 *
 * @param representationDescriptor
 *            The {@link RepresentationDescriptor}
 * @param resourceSet
 *            The {@link ResourceSet} containing all loaded documents
 * @return the {@link RepresentationManifest} for the given {@link RepresentationDescriptor}
 */
private RepresentationManifest createRepresentationManifest(RepresentationDescriptor representationDescriptor, ResourceSet resourceSet) {
    IRepresentation representation = representationDescriptor.getRepresentation();
    String descriptionId = representationDescriptor.getDescriptionId();
    /*
         * If the given descriptionId does not match with an existing IdMappingEntity, the current representation is
         * based on a custom description. We use the descriptionId as descriptionURI.
         */
    // @formatter:off
    String descriptionURI = this.idMappingRepository.findById(descriptionId).map(IdMappingEntity::getExternalId).orElse(descriptionId.toString());
    // @formatter:on
    // $NON-NLS-1$
    String uriFragment = "";
    String targetObjectId = representationDescriptor.getTargetObjectId();
    for (Resource resource : resourceSet.getResources()) {
        EObject eObject = resource.getEObject(targetObjectId);
        if (eObject != null) {
            uriFragment = EcoreUtil.getURI(eObject).toString();
            break;
        }
    }
    if (uriFragment.isEmpty()) {
        // $NON-NLS-1$
        this.logger.warn("The serialization of the representationManifest won't be complete.");
    }
    // @formatter:off
    return RepresentationManifest.newRepresentationManifest().type(representation.getKind()).descriptionURI(descriptionURI).targetObjectURI(uriFragment).build();
// @formatter:on
}
Also used : EObject(org.eclipse.emf.ecore.EObject) JsonResource(org.eclipse.sirius.emfjson.resource.JsonResource) Resource(org.eclipse.emf.ecore.resource.Resource) IRepresentation(org.eclipse.sirius.components.representations.IRepresentation)

Example 4 with IRepresentation

use of org.eclipse.sirius.components.representations.IRepresentation in project sirius-components by eclipse-sirius.

the class EditingContextEventProcessor method refreshOtherRepresentations.

/**
 * Refresh all the representations except the one with the given representationId.
 *
 * @param input
 *            The input which has triggered the refresh sequence
 * @param representationId
 *            The identifier of the representation which should not be refreshed
 * @param changeDescription
 *            The description of change to consider in order to determine if the representation should be refreshed
 */
private void refreshOtherRepresentations(ChangeDescription changeDescription) {
    // @formatter:off
    this.representationEventProcessors.entrySet().stream().filter(entry -> !Objects.equals(entry.getKey(), changeDescription.getSourceId())).map(Entry::getValue).map(RepresentationEventProcessorEntry::getRepresentationEventProcessor).forEach(representationEventProcessor -> {
        representationEventProcessor.refresh(changeDescription);
        IRepresentation representation = representationEventProcessor.getRepresentation();
        this.applicationEventPublisher.publishEvent(new RepresentationRefreshedEvent(this.editingContext.getId(), representation));
    });
// @formatter:on
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) Sinks(reactor.core.publisher.Sinks) IEditingContextEventProcessor(org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessor) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) Disposable(reactor.core.Disposable) IRepresentationConfiguration(org.eclipse.sirius.components.collaborative.api.IRepresentationConfiguration) LoggerFactory(org.slf4j.LoggerFactory) One(reactor.core.publisher.Sinks.One) IDanglingRepresentationDeletionService(org.eclipse.sirius.components.collaborative.api.IDanglingRepresentationDeletionService) IInput(org.eclipse.sirius.components.core.api.IInput) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) IEditingContextPersistenceService(org.eclipse.sirius.components.core.api.IEditingContextPersistenceService) IRepresentationEventProcessorComposedFactory(org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessorComposedFactory) Duration(java.time.Duration) Map(java.util.Map) IRepresentation(org.eclipse.sirius.components.representations.IRepresentation) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) ICollaborativeMessageService(org.eclipse.sirius.components.collaborative.messages.ICollaborativeMessageService) EmitResult(reactor.core.publisher.Sinks.EmitResult) Schedulers(reactor.core.scheduler.Schedulers) IRepresentationEventProcessor(org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor) RepresentationRefreshedEvent(org.eclipse.sirius.components.collaborative.dto.RepresentationRefreshedEvent) ExecutorService(java.util.concurrent.ExecutorService) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) Logger(org.slf4j.Logger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) RenameRepresentationInput(org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput) RepresentationRenamedEventPayload(org.eclipse.sirius.components.collaborative.dto.RepresentationRenamedEventPayload) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) IRepresentationInput(org.eclipse.sirius.components.core.api.IRepresentationInput) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) Flux(reactor.core.publisher.Flux) List(java.util.List) IPayload(org.eclipse.sirius.components.core.api.IPayload) DelegatingRequestContextExecutorService(org.eclipse.sirius.components.collaborative.requestcontext.DelegatingRequestContextExecutorService) Entry(java.util.Map.Entry) Many(reactor.core.publisher.Sinks.Many) Optional(java.util.Optional) IEditingContextEventHandler(org.eclipse.sirius.components.collaborative.api.IEditingContextEventHandler) DeleteRepresentationInput(org.eclipse.sirius.components.collaborative.dto.DeleteRepresentationInput) Entry(java.util.Map.Entry) RepresentationRefreshedEvent(org.eclipse.sirius.components.collaborative.dto.RepresentationRefreshedEvent) IRepresentation(org.eclipse.sirius.components.representations.IRepresentation)

Example 5 with IRepresentation

use of org.eclipse.sirius.components.representations.IRepresentation in project sirius-components by eclipse-sirius.

the class EditingContextEventProcessor method setupChangeDescriptionSinkConsumer.

@SuppressWarnings("checkstyle:IllegalCatch")
private Disposable setupChangeDescriptionSinkConsumer() {
    Consumer<ChangeDescription> consumer = changeDescription -> {
        if (ChangeKind.REPRESENTATION_TO_DELETE.equals(changeDescription.getKind())) {
            Object representationId = changeDescription.getParameters().get(REPRESENTATION_ID);
            if (representationId instanceof String) {
                DeleteRepresentationInput deleteRepresentationInput = new DeleteRepresentationInput(UUID.randomUUID(), (String) representationId);
                this.doHandle(Sinks.one(), deleteRepresentationInput);
            }
        } else if (ChangeKind.REPRESENTATION_TO_RENAME.equals(changeDescription.getKind())) {
            Object representationId = changeDescription.getParameters().get(REPRESENTATION_ID);
            Object representationLabel = changeDescription.getParameters().get(REPRESENTATION_LABEL);
            if (representationId instanceof String && representationLabel instanceof String) {
                RenameRepresentationInput renameRepresentationInput = new RenameRepresentationInput(UUID.randomUUID(), this.getEditingContextId(), (String) representationId, (String) representationLabel);
                this.doHandle(Sinks.one(), renameRepresentationInput);
            }
        }
        this.publishEvent(changeDescription);
        this.disposeRepresentationIfNeeded();
        RepresentationEventProcessorEntry representationEventProcessorEntry = this.representationEventProcessors.get(changeDescription.getSourceId());
        if (representationEventProcessorEntry != null) {
            try {
                IRepresentationEventProcessor representationEventProcessor = representationEventProcessorEntry.getRepresentationEventProcessor();
                representationEventProcessor.refresh(changeDescription);
                IRepresentation representation = representationEventProcessor.getRepresentation();
                this.applicationEventPublisher.publishEvent(new RepresentationRefreshedEvent(this.editingContext.getId(), representation));
            } catch (Exception exception) {
                this.logger.warn(exception.getMessage(), exception);
            }
        }
        this.refreshOtherRepresentations(changeDescription);
        if (this.shouldPersistTheEditingContext(changeDescription)) {
            this.editingContextPersistenceService.persist(this.editingContext);
        }
        this.danglingRepresentationDeletionService.deleteDanglingRepresentations(this.editingContext.getId());
    };
    Consumer<Throwable> errorConsumer = throwable -> this.logger.warn(throwable.getMessage(), throwable);
    return this.changeDescriptionSink.asFlux().subscribe(consumer, errorConsumer);
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) Sinks(reactor.core.publisher.Sinks) IEditingContextEventProcessor(org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessor) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) Disposable(reactor.core.Disposable) IRepresentationConfiguration(org.eclipse.sirius.components.collaborative.api.IRepresentationConfiguration) LoggerFactory(org.slf4j.LoggerFactory) One(reactor.core.publisher.Sinks.One) IDanglingRepresentationDeletionService(org.eclipse.sirius.components.collaborative.api.IDanglingRepresentationDeletionService) IInput(org.eclipse.sirius.components.core.api.IInput) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) IEditingContextPersistenceService(org.eclipse.sirius.components.core.api.IEditingContextPersistenceService) IRepresentationEventProcessorComposedFactory(org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessorComposedFactory) Duration(java.time.Duration) Map(java.util.Map) IRepresentation(org.eclipse.sirius.components.representations.IRepresentation) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) ICollaborativeMessageService(org.eclipse.sirius.components.collaborative.messages.ICollaborativeMessageService) EmitResult(reactor.core.publisher.Sinks.EmitResult) Schedulers(reactor.core.scheduler.Schedulers) IRepresentationEventProcessor(org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor) RepresentationRefreshedEvent(org.eclipse.sirius.components.collaborative.dto.RepresentationRefreshedEvent) ExecutorService(java.util.concurrent.ExecutorService) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) Logger(org.slf4j.Logger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) RenameRepresentationInput(org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput) RepresentationRenamedEventPayload(org.eclipse.sirius.components.collaborative.dto.RepresentationRenamedEventPayload) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) IRepresentationInput(org.eclipse.sirius.components.core.api.IRepresentationInput) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) Flux(reactor.core.publisher.Flux) List(java.util.List) IPayload(org.eclipse.sirius.components.core.api.IPayload) DelegatingRequestContextExecutorService(org.eclipse.sirius.components.collaborative.requestcontext.DelegatingRequestContextExecutorService) Entry(java.util.Map.Entry) Many(reactor.core.publisher.Sinks.Many) Optional(java.util.Optional) IEditingContextEventHandler(org.eclipse.sirius.components.collaborative.api.IEditingContextEventHandler) DeleteRepresentationInput(org.eclipse.sirius.components.collaborative.dto.DeleteRepresentationInput) RepresentationRefreshedEvent(org.eclipse.sirius.components.collaborative.dto.RepresentationRefreshedEvent) DeleteRepresentationInput(org.eclipse.sirius.components.collaborative.dto.DeleteRepresentationInput) IRepresentation(org.eclipse.sirius.components.representations.IRepresentation) ExecutionException(java.util.concurrent.ExecutionException) IRepresentationEventProcessor(org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) RenameRepresentationInput(org.eclipse.sirius.components.collaborative.dto.RenameRepresentationInput)

Aggregations

IRepresentation (org.eclipse.sirius.components.representations.IRepresentation)5 UUID (java.util.UUID)3 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)3 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)3 IPayload (org.eclipse.sirius.components.core.api.IPayload)3 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutorService (java.util.concurrent.ExecutorService)2 Future (java.util.concurrent.Future)2 Consumer (java.util.function.Consumer)2 Collectors (java.util.stream.Collectors)2 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)2 IDanglingRepresentationDeletionService (org.eclipse.sirius.components.collaborative.api.IDanglingRepresentationDeletionService)2