Search in sources :

Example 1 with DeleteListItemSuccessPayload

use of org.eclipse.sirius.components.collaborative.forms.dto.DeleteListItemSuccessPayload in project sirius-components by eclipse-sirius.

the class DeleteListItemEventHandler method handle.

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, Form form, IFormInput formInput) {
    this.counter.increment();
    String message = this.messageService.invalidInput(formInput.getClass().getSimpleName(), DeleteListItemInput.class.getSimpleName());
    IPayload payload = new ErrorPayload(formInput.getId(), message);
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, formInput.getRepresentationId(), formInput);
    if (formInput instanceof DeleteListItemInput) {
        DeleteListItemInput input = (DeleteListItemInput) formInput;
        // @formatter:off
        var optionalListItem = this.formQueryService.findWidget(form, input.getListId()).filter(List.class::isInstance).map(List.class::cast).stream().map(List::getItems).flatMap(Collection::stream).filter(item -> item.getId().toString().equals(input.getListItemId())).findFirst();
        var status = optionalListItem.map(ListItem::getDeleteHandler).map(handler -> handler.get()).orElse(// $NON-NLS-1$
        new Failure(""));
        if (status instanceof Success) {
            Success success = (Success) status;
            changeDescription = new ChangeDescription(success.getChangeKind(), formInput.getRepresentationId(), formInput, success.getParameters());
            payload = new DeleteListItemSuccessPayload(formInput.getId());
        } else if (status instanceof Failure) {
            payload = new ErrorPayload(formInput.getId(), ((Failure) status).getMessage());
        }
    }
    changeDescriptionSink.tryEmitNext(changeDescription);
    payloadSink.tryEmitValue(payload);
}
Also used : DeleteListItemInput(org.eclipse.sirius.components.collaborative.forms.dto.DeleteListItemInput) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) Counter(io.micrometer.core.instrument.Counter) Form(org.eclipse.sirius.components.forms.Form) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) Failure(org.eclipse.sirius.components.representations.Failure) ListItem(org.eclipse.sirius.components.forms.ListItem) Collection(java.util.Collection) Success(org.eclipse.sirius.components.representations.Success) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) One(reactor.core.publisher.Sinks.One) List(org.eclipse.sirius.components.forms.List) Objects(java.util.Objects) IFormEventHandler(org.eclipse.sirius.components.collaborative.forms.api.IFormEventHandler) DeleteListItemSuccessPayload(org.eclipse.sirius.components.collaborative.forms.dto.DeleteListItemSuccessPayload) IFormQueryService(org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService) ICollaborativeFormMessageService(org.eclipse.sirius.components.collaborative.forms.messages.ICollaborativeFormMessageService) IPayload(org.eclipse.sirius.components.core.api.IPayload) Monitoring(org.eclipse.sirius.components.collaborative.api.Monitoring) Service(org.springframework.stereotype.Service) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Many(reactor.core.publisher.Sinks.Many) IFormInput(org.eclipse.sirius.components.collaborative.forms.api.IFormInput) Success(org.eclipse.sirius.components.representations.Success) DeleteListItemSuccessPayload(org.eclipse.sirius.components.collaborative.forms.dto.DeleteListItemSuccessPayload) IPayload(org.eclipse.sirius.components.core.api.IPayload) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) Collection(java.util.Collection) List(org.eclipse.sirius.components.forms.List) ListItem(org.eclipse.sirius.components.forms.ListItem) DeleteListItemInput(org.eclipse.sirius.components.collaborative.forms.dto.DeleteListItemInput) Failure(org.eclipse.sirius.components.representations.Failure)

Aggregations

Counter (io.micrometer.core.instrument.Counter)1 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 Collection (java.util.Collection)1 Objects (java.util.Objects)1 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)1 Monitoring (org.eclipse.sirius.components.collaborative.api.Monitoring)1 IFormEventHandler (org.eclipse.sirius.components.collaborative.forms.api.IFormEventHandler)1 IFormInput (org.eclipse.sirius.components.collaborative.forms.api.IFormInput)1 IFormQueryService (org.eclipse.sirius.components.collaborative.forms.api.IFormQueryService)1 DeleteListItemInput (org.eclipse.sirius.components.collaborative.forms.dto.DeleteListItemInput)1 DeleteListItemSuccessPayload (org.eclipse.sirius.components.collaborative.forms.dto.DeleteListItemSuccessPayload)1 ICollaborativeFormMessageService (org.eclipse.sirius.components.collaborative.forms.messages.ICollaborativeFormMessageService)1 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)1 IPayload (org.eclipse.sirius.components.core.api.IPayload)1 Form (org.eclipse.sirius.components.forms.Form)1 List (org.eclipse.sirius.components.forms.List)1 ListItem (org.eclipse.sirius.components.forms.ListItem)1 Failure (org.eclipse.sirius.components.representations.Failure)1 Success (org.eclipse.sirius.components.representations.Success)1