use of org.eclipse.sirius.components.collaborative.dto.CreateRepresentationSuccessPayload in project sirius-web by eclipse-sirius.
the class ProjectImporter method createRepresentations.
/**
* Creates all representations in the project thanks to the {@link IEditingContextEventProcessor} and the create
* representation input. If at least one representation has not been created it will return <code>false</code>.
*
* @param inputId
* The identifier of the input which has triggered this import
*
* @return <code>true</code> whether all representations has been created, <code>false</code> otherwise
*/
private boolean createRepresentations(UUID inputId) {
boolean allRepresentationCreated = true;
for (RepresentationDescriptor representationDescriptor : this.representations) {
RepresentationManifest representationManifest = this.projectManifest.getRepresentations().get(representationDescriptor.getId().toString());
String targetObjectURI = representationManifest.getTargetObjectURI();
String oldDocumentId = URI.create(targetObjectURI).getPath();
Document newDocument = this.oldDocumentIdToNewDocument.get(oldDocumentId);
final String objectId;
if (newDocument != null) {
objectId = targetObjectURI.replace(oldDocumentId, newDocument.getId().toString());
} else {
objectId = targetObjectURI;
}
boolean representationCreated = false;
String descriptionURI = representationManifest.getDescriptionURI();
// @formatter:off
var inputHandle = this.idMappingRepository.findByExternalId(descriptionURI).map(IdMappingEntity::getId).or(() -> Optional.of(descriptionURI)).map(representationDescriptionId -> new CreateRepresentationInput(inputId, this.projectId.toString(), representationDescriptionId.toString(), objectId, representationDescriptor.getLabel())).map(this.editingContextEventProcessor::handle).orElseGet(Mono::empty);
representationCreated = inputHandle.filter(CreateRepresentationSuccessPayload.class::isInstance).map(CreateRepresentationSuccessPayload.class::cast).map(CreateRepresentationSuccessPayload::getRepresentation).blockOptional().isPresent();
if (!representationCreated) {
// $NON-NLS-1$
this.logger.warn("The representation {} has not been created", representationDescriptor.getLabel());
}
allRepresentationCreated = allRepresentationCreated && representationCreated;
}
return allRepresentationCreated;
}
use of org.eclipse.sirius.components.collaborative.dto.CreateRepresentationSuccessPayload in project sirius-components by eclipse-sirius.
the class CreateDiagramEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IInput input) {
this.counter.increment();
String message = this.messageService.invalidInput(input.getClass().getSimpleName(), CreateRepresentationInput.class.getSimpleName());
IPayload payload = new ErrorPayload(input.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input);
if (input instanceof CreateRepresentationInput) {
CreateRepresentationInput createRepresentationInput = (CreateRepresentationInput) input;
// @formatter:off
Optional<DiagramDescription> optionalDiagramDescription = this.representationDescriptionSearchService.findById(editingContext, createRepresentationInput.getRepresentationDescriptionId()).filter(DiagramDescription.class::isInstance).map(DiagramDescription.class::cast);
// @formatter:on
Optional<Object> optionalObject = this.objectService.getObject(editingContext, createRepresentationInput.getObjectId());
if (optionalDiagramDescription.isPresent() && optionalObject.isPresent()) {
DiagramDescription diagramDescription = optionalDiagramDescription.get();
Object object = optionalObject.get();
Diagram diagram = this.diagramCreationService.create(createRepresentationInput.getRepresentationName(), object, diagramDescription, editingContext);
this.representationPersistenceService.save(editingContext, diagram);
payload = new CreateRepresentationSuccessPayload(input.getId(), diagram);
changeDescription = new ChangeDescription(ChangeKind.REPRESENTATION_CREATION, editingContext.getId(), input);
}
}
payloadSink.tryEmitValue(payload);
changeDescriptionSink.tryEmitNext(changeDescription);
}
use of org.eclipse.sirius.components.collaborative.dto.CreateRepresentationSuccessPayload in project sirius-components by eclipse-sirius.
the class CreateFormEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IInput input) {
this.counter.increment();
String message = this.messageService.invalidInput(input.getClass().getSimpleName(), CreateRepresentationInput.class.getSimpleName());
IPayload payload = new ErrorPayload(input.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input);
if (input instanceof CreateRepresentationInput) {
CreateRepresentationInput createRepresentationInput = (CreateRepresentationInput) input;
Optional<IRepresentationDescription> optionalRepresentationDescription = this.representationDescriptionSearchService.findById(editingContext, createRepresentationInput.getRepresentationDescriptionId());
Optional<Object> optionalObject = this.objectService.getObject(editingContext, createRepresentationInput.getObjectId());
if (optionalRepresentationDescription.isPresent() && optionalObject.isPresent()) {
IRepresentationDescription representationDescription = optionalRepresentationDescription.get();
String targetObjectId = this.objectService.getId(optionalObject.get());
if (representationDescription instanceof FormDescription) {
// @formatter:off
Form form = Form.newForm(UUID.randomUUID().toString()).label(createRepresentationInput.getRepresentationName()).targetObjectId(targetObjectId).descriptionId(representationDescription.getId()).pages(// We don't store form pages, it will be re-render by the FormProcessor.
List.of()).build();
// @formatter:on
this.representationPersistenceService.save(editingContext, form);
payload = new CreateRepresentationSuccessPayload(input.getId(), form);
changeDescription = new ChangeDescription(ChangeKind.REPRESENTATION_CREATION, editingContext.getId(), input);
}
}
}
payloadSink.tryEmitValue(payload);
changeDescriptionSink.tryEmitNext(changeDescription);
}
Aggregations