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;
}
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);
}
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
}
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
}
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);
}
Aggregations