use of org.eclipse.sirius.components.collaborative.dto.DeleteDocumentSuccessPayload in project sirius-web by eclipse-sirius.
the class DeleteDocumentEventHandler 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(), DeleteDocumentInput.class.getSimpleName());
IPayload payload = new ErrorPayload(input.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input);
// @formatter:off
var optionalEditingDomain = Optional.of(editingContext).filter(EditingContext.class::isInstance).map(EditingContext.class::cast).map(EditingContext::getDomain);
if (input instanceof DeleteDocumentInput) {
DeleteDocumentInput deleteDocumentInput = (DeleteDocumentInput) input;
var optionalDocument = this.documentService.getDocument(deleteDocumentInput.getDocumentId());
if (optionalEditingDomain.isPresent() && optionalDocument.isPresent()) {
AdapterFactoryEditingDomain editingDomain = optionalEditingDomain.get();
Document document = optionalDocument.get();
ResourceSet resourceSet = editingDomain.getResourceSet();
URI uri = URI.createURI(document.getId().toString());
// @formatter:off
List<Resource> resourcesToDelete = resourceSet.getResources().stream().filter(resource -> resource.getURI().equals(uri)).collect(Collectors.toUnmodifiableList());
resourcesToDelete.stream().forEach(resourceSet.getResources()::remove);
// @formatter:on
this.documentService.delete(document.getId());
payload = new DeleteDocumentSuccessPayload(input.getId());
changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, editingContext.getId(), input);
}
}
payloadSink.tryEmitValue(payload);
changeDescriptionSink.tryEmitNext(changeDescription);
}
Aggregations