Search in sources :

Example 1 with RenameProjectInput

use of org.eclipse.sirius.web.services.api.projects.RenameProjectInput in project sirius-web by eclipse-sirius.

the class RenameProjectEventHandler method handle.

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IInput input) {
    String message = this.messageService.invalidInput(input.getClass().getSimpleName(), RenameProjectInput.class.getSimpleName());
    IPayload payload = new ErrorPayload(input.getId(), message);
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input);
    if (input instanceof RenameProjectInput) {
        RenameProjectInput renameProjectInput = (RenameProjectInput) input;
        Optional<Project> optionalProject = this.projectService.renameProject(renameProjectInput.getProjectId(), renameProjectInput.getNewName());
        if (optionalProject.isPresent()) {
            payload = new RenameProjectSuccessPayload(input.getId(), optionalProject.get());
            changeDescription = new ChangeDescription(ChangeKind.PROJECT_RENAMING, editingContext.getId(), input);
        }
    }
    payloadSink.tryEmitValue(payload);
    changeDescriptionSink.tryEmitNext(changeDescription);
}
Also used : Project(org.eclipse.sirius.web.services.api.projects.Project) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) RenameProjectSuccessPayload(org.eclipse.sirius.web.services.api.projects.RenameProjectSuccessPayload) RenameProjectInput(org.eclipse.sirius.web.services.api.projects.RenameProjectInput) IPayload(org.eclipse.sirius.components.core.api.IPayload)

Example 2 with RenameProjectInput

use of org.eclipse.sirius.web.services.api.projects.RenameProjectInput in project sirius-web by eclipse-sirius.

the class RenameProjectEventHandlerTests method testRenameProject.

@Test
public void testRenameProject() {
    // $NON-NLS-1$ //$NON-NLS-2$
    Project project = new Project(UUID.randomUUID(), "newName", new Profile(UUID.randomUUID(), "system"), Visibility.PUBLIC);
    AtomicBoolean hasBeenCalled = new AtomicBoolean();
    IProjectService projectService = new IProjectService.NoOp() {

        @Override
        public Optional<Project> renameProject(UUID projectId, String newName) {
            hasBeenCalled.set(true);
            return Optional.of(project);
        }
    };
    RenameProjectEventHandler handler = new RenameProjectEventHandler(new NoOpServicesMessageService(), projectService);
    // $NON-NLS-1$
    var input = new RenameProjectInput(UUID.randomUUID(), UUID.randomUUID(), "newName");
    IEditingContext editingContext = () -> UUID.randomUUID().toString();
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    One<IPayload> payloadSink = Sinks.one();
    assertThat(handler.canHandle(editingContext, input)).isTrue();
    handler.handle(payloadSink, changeDescriptionSink, editingContext, input);
    assertThat(hasBeenCalled.get()).isTrue();
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.PROJECT_RENAMING);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(RenameProjectSuccessPayload.class);
}
Also used : IProjectService(org.eclipse.sirius.web.services.api.projects.IProjectService) RenameProjectInput(org.eclipse.sirius.web.services.api.projects.RenameProjectInput) Profile(org.eclipse.sirius.web.services.api.accounts.Profile) IPayload(org.eclipse.sirius.components.core.api.IPayload) Project(org.eclipse.sirius.web.services.api.projects.Project) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)2 IPayload (org.eclipse.sirius.components.core.api.IPayload)2 Project (org.eclipse.sirius.web.services.api.projects.Project)2 RenameProjectInput (org.eclipse.sirius.web.services.api.projects.RenameProjectInput)2 UUID (java.util.UUID)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)1 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)1 Profile (org.eclipse.sirius.web.services.api.accounts.Profile)1 IProjectService (org.eclipse.sirius.web.services.api.projects.IProjectService)1 RenameProjectSuccessPayload (org.eclipse.sirius.web.services.api.projects.RenameProjectSuccessPayload)1 Test (org.junit.jupiter.api.Test)1