Search in sources :

Example 1 with DeleteDocumentSuccessPayload

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);
}
Also used : AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) URI(org.eclipse.emf.common.util.URI) One(reactor.core.publisher.Sinks.One) IInput(org.eclipse.sirius.components.core.api.IInput) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) Document(org.eclipse.sirius.web.services.api.document.Document) Monitoring(org.eclipse.sirius.components.collaborative.api.Monitoring) Service(org.springframework.stereotype.Service) DeleteDocumentInput(org.eclipse.sirius.components.collaborative.dto.DeleteDocumentInput) Counter(io.micrometer.core.instrument.Counter) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) IDocumentService(org.eclipse.sirius.web.services.api.document.IDocumentService) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) Collectors(java.util.stream.Collectors) DeleteDocumentSuccessPayload(org.eclipse.sirius.components.collaborative.dto.DeleteDocumentSuccessPayload) Objects(java.util.Objects) List(java.util.List) IPayload(org.eclipse.sirius.components.core.api.IPayload) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Resource(org.eclipse.emf.ecore.resource.Resource) IServicesMessageService(org.eclipse.sirius.web.services.messages.IServicesMessageService) Many(reactor.core.publisher.Sinks.Many) Optional(java.util.Optional) IEditingContextEventHandler(org.eclipse.sirius.components.collaborative.api.IEditingContextEventHandler) AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Document(org.eclipse.sirius.web.services.api.document.Document) URI(org.eclipse.emf.common.util.URI) IPayload(org.eclipse.sirius.components.core.api.IPayload) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) DeleteDocumentInput(org.eclipse.sirius.components.collaborative.dto.DeleteDocumentInput) DeleteDocumentSuccessPayload(org.eclipse.sirius.components.collaborative.dto.DeleteDocumentSuccessPayload)

Aggregations

Counter (io.micrometer.core.instrument.Counter)1 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 URI (org.eclipse.emf.common.util.URI)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 AdapterFactoryEditingDomain (org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain)1 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)1 IEditingContextEventHandler (org.eclipse.sirius.components.collaborative.api.IEditingContextEventHandler)1 Monitoring (org.eclipse.sirius.components.collaborative.api.Monitoring)1 DeleteDocumentInput (org.eclipse.sirius.components.collaborative.dto.DeleteDocumentInput)1 DeleteDocumentSuccessPayload (org.eclipse.sirius.components.collaborative.dto.DeleteDocumentSuccessPayload)1 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)1 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)1 IInput (org.eclipse.sirius.components.core.api.IInput)1 IPayload (org.eclipse.sirius.components.core.api.IPayload)1