Search in sources :

Example 1 with StereotypeDescription

use of org.eclipse.sirius.components.core.configuration.StereotypeDescription in project sirius-web by eclipse-sirius.

the class CreateDocumentEventHandlerTests method testCreateTwoDocumentWithSameName.

@Test
public void testCreateTwoDocumentWithSameName() {
    IDocumentService documentService = new IDocumentService.NoOp() {

        @Override
        public Optional<Document> createDocument(String projectId, String name, String content) {
            // $NON-NLS-1$ //$NON-NLS-2$
            return Optional.of(new Document(UUID.randomUUID(), new Project(UUID.fromString(projectId), "", new Profile(UUID.randomUUID(), "username"), Visibility.PUBLIC), name, content));
        }
    };
    IStereotypeDescriptionService stereotypeDescriptionService = new IStereotypeDescriptionService.NoOp() {

        @Override
        public Optional<StereotypeDescription> getStereotypeDescriptionById(String editingContextId, UUID stereotypeId) {
            // $NON-NLS-1$
            StereotypeDescription stereotypeDescription = new StereotypeDescription(stereotypeId, "label", () -> CONTENT);
            return Optional.of(stereotypeDescription);
        }
    };
    IServicesMessageService messageService = new NoOpServicesMessageService();
    AdapterFactoryEditingDomain editingDomain = new EditingDomainFactory().create();
    EditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain);
    CreateDocumentEventHandler handler = new CreateDocumentEventHandler(documentService, stereotypeDescriptionService, messageService, new SimpleMeterRegistry());
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    changeDescriptionSink.asFlux().subscribe(changeDescription -> {
        assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
    });
    var firstCreateInput = new CreateDocumentInput(UUID.randomUUID(), editingContext.getId(), DOCUMENT_NAME, STEREOTYPE_DESCRIPTION_ID);
    assertThat(handler.canHandle(editingContext, firstCreateInput)).isTrue();
    One<IPayload> firstPayloadSink = Sinks.one();
    handler.handle(firstPayloadSink, changeDescriptionSink, editingContext, firstCreateInput);
    IPayload firstPayload = firstPayloadSink.asMono().block();
    assertThat(firstPayload).isInstanceOf(CreateDocumentSuccessPayload.class);
    var secondCreatedInput = new CreateDocumentInput(UUID.randomUUID(), editingContext.getId(), DOCUMENT_NAME, STEREOTYPE_DESCRIPTION_ID);
    assertThat(handler.canHandle(editingContext, secondCreatedInput)).isTrue();
    One<IPayload> secondPayloadSink = Sinks.one();
    handler.handle(secondPayloadSink, changeDescriptionSink, editingContext, secondCreatedInput);
    IPayload secondPayload = firstPayloadSink.asMono().block();
    assertThat(secondPayload).isInstanceOf(CreateDocumentSuccessPayload.class);
}
Also used : AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) StereotypeDescription(org.eclipse.sirius.components.core.configuration.StereotypeDescription) IServicesMessageService(org.eclipse.sirius.web.services.messages.IServicesMessageService) NoOpServicesMessageService(org.eclipse.sirius.web.services.projects.NoOpServicesMessageService) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IStereotypeDescriptionService(org.eclipse.sirius.web.services.api.stereotypes.IStereotypeDescriptionService) Document(org.eclipse.sirius.web.services.api.document.Document) 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) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) IDocumentService(org.eclipse.sirius.web.services.api.document.IDocumentService) UUID(java.util.UUID) CreateDocumentInput(org.eclipse.sirius.components.collaborative.dto.CreateDocumentInput) Test(org.junit.jupiter.api.Test)

Example 2 with StereotypeDescription

use of org.eclipse.sirius.components.core.configuration.StereotypeDescription in project sirius-web by eclipse-sirius.

the class CreateDocumentEventHandlerTests method testCreateDocument.

@Test
public void testCreateDocument() {
    IDocumentService documentService = new IDocumentService.NoOp() {

        @Override
        public Optional<Document> createDocument(String projectId, String name, String content) {
            // $NON-NLS-1$ //$NON-NLS-2$
            return Optional.of(new Document(UUID.randomUUID(), new Project(UUID.fromString(projectId), "", new Profile(UUID.randomUUID(), "username"), Visibility.PUBLIC), name, content));
        }
    };
    IStereotypeDescriptionService stereotypeDescriptionService = new IStereotypeDescriptionService.NoOp() {

        @Override
        public Optional<StereotypeDescription> getStereotypeDescriptionById(String editingContextId, UUID stereotypeId) {
            // $NON-NLS-1$
            StereotypeDescription stereotypeDescription = new StereotypeDescription(stereotypeId, "label", () -> CONTENT);
            return Optional.of(stereotypeDescription);
        }
    };
    IServicesMessageService messageService = new NoOpServicesMessageService();
    CreateDocumentEventHandler handler = new CreateDocumentEventHandler(documentService, stereotypeDescriptionService, messageService, new SimpleMeterRegistry());
    var input = new CreateDocumentInput(UUID.randomUUID(), UUID.randomUUID().toString(), DOCUMENT_NAME, STEREOTYPE_DESCRIPTION_ID);
    AdapterFactoryEditingDomain editingDomain = new EditingDomainFactory().create();
    EditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain);
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    One<IPayload> payloadSink = Sinks.one();
    assertThat(handler.canHandle(editingContext, input)).isTrue();
    handler.handle(payloadSink, changeDescriptionSink, editingContext, input);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(CreateDocumentSuccessPayload.class);
    assertThat(editingDomain.getResourceSet().getResources().size()).isEqualTo(1);
    // $NON-NLS-1$
    Condition<Object> condition = new Condition<>(adapter -> adapter instanceof DocumentMetadataAdapter, "has an DocumentMetadataAdapter");
    assertThat(editingDomain.getResourceSet().getResources().get(0).eAdapters()).areAtLeastOne(condition);
}
Also used : AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) NoOpServicesMessageService(org.eclipse.sirius.web.services.projects.NoOpServicesMessageService) IStereotypeDescriptionService(org.eclipse.sirius.web.services.api.stereotypes.IStereotypeDescriptionService) Document(org.eclipse.sirius.web.services.api.document.Document) Profile(org.eclipse.sirius.web.services.api.accounts.Profile) IPayload(org.eclipse.sirius.components.core.api.IPayload) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) UUID(java.util.UUID) CreateDocumentInput(org.eclipse.sirius.components.collaborative.dto.CreateDocumentInput) Condition(org.assertj.core.api.Condition) StereotypeDescription(org.eclipse.sirius.components.core.configuration.StereotypeDescription) IServicesMessageService(org.eclipse.sirius.web.services.messages.IServicesMessageService) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Project(org.eclipse.sirius.web.services.api.projects.Project) IDocumentService(org.eclipse.sirius.web.services.api.document.IDocumentService) Test(org.junit.jupiter.api.Test)

Example 3 with StereotypeDescription

use of org.eclipse.sirius.components.core.configuration.StereotypeDescription in project sirius-web by eclipse-sirius.

the class EditingContextStereotypeDescriptionsDataFetcher method get.

@Override
public Connection<StereotypeDescription> get(DataFetchingEnvironment environment) throws Exception {
    String editingContextId = environment.getSource();
    var stereotypeDescriptions = this.stereotypeDescriptionService.getStereotypeDescriptions(editingContextId);
    // @formatter:off
    List<Edge<StereotypeDescription>> stereotypeDescriptionEdges = stereotypeDescriptions.stream().map(stereotypeDescription -> {
        String value = Base64.getEncoder().encodeToString(stereotypeDescription.getId().toString().getBytes());
        ConnectionCursor cursor = new DefaultConnectionCursor(value);
        return new DefaultEdge<>(stereotypeDescription, cursor);
    }).collect(Collectors.toList());
    // @formatter:on
    ConnectionCursor startCursor = stereotypeDescriptionEdges.stream().findFirst().map(Edge::getCursor).orElse(null);
    ConnectionCursor endCursor = null;
    if (!stereotypeDescriptionEdges.isEmpty()) {
        endCursor = stereotypeDescriptionEdges.get(stereotypeDescriptionEdges.size() - 1).getCursor();
    }
    PageInfo pageInfo = new DefaultPageInfo(startCursor, endCursor, false, false);
    return new DefaultConnection<>(stereotypeDescriptionEdges, pageInfo);
}
Also used : PageInfo(graphql.relay.PageInfo) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) QueryDataFetcher(org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher) DefaultEdge(graphql.relay.DefaultEdge) IDataFetcherWithFieldCoordinates(org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates) Collectors(java.util.stream.Collectors) DefaultConnectionCursor(graphql.relay.DefaultConnectionCursor) Objects(java.util.Objects) Base64(java.util.Base64) List(java.util.List) IStereotypeDescriptionService(org.eclipse.sirius.web.services.api.stereotypes.IStereotypeDescriptionService) DefaultPageInfo(graphql.relay.DefaultPageInfo) Connection(graphql.relay.Connection) DefaultConnection(graphql.relay.DefaultConnection) Edge(graphql.relay.Edge) ConnectionCursor(graphql.relay.ConnectionCursor) StereotypeDescription(org.eclipse.sirius.components.core.configuration.StereotypeDescription) EditingContextTypeProvider(org.eclipse.sirius.web.graphql.schema.EditingContextTypeProvider) DefaultConnectionCursor(graphql.relay.DefaultConnectionCursor) ConnectionCursor(graphql.relay.ConnectionCursor) PageInfo(graphql.relay.PageInfo) DefaultPageInfo(graphql.relay.DefaultPageInfo) DefaultConnection(graphql.relay.DefaultConnection) DefaultEdge(graphql.relay.DefaultEdge) Edge(graphql.relay.Edge) DefaultPageInfo(graphql.relay.DefaultPageInfo) DefaultConnectionCursor(graphql.relay.DefaultConnectionCursor)

Example 4 with StereotypeDescription

use of org.eclipse.sirius.components.core.configuration.StereotypeDescription in project sirius-web by eclipse-sirius.

the class CreateDocumentEventHandler method handle.

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IInput input) {
    this.counter.increment();
    IPayload payload = new ErrorPayload(input.getId(), this.messageService.unexpectedError());
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input);
    if (input instanceof CreateDocumentInput) {
        CreateDocumentInput createDocumentInput = (CreateDocumentInput) input;
        String name = createDocumentInput.getName().trim();
        String editingContextId = createDocumentInput.getEditingContextId();
        UUID stereotypeDescriptionId = createDocumentInput.getStereotypeDescriptionId();
        Optional<StereotypeDescription> optionalStereotypeDescription = this.stereotypeDescriptionService.getStereotypeDescriptionById(editingContextId, stereotypeDescriptionId);
        if (name.isBlank()) {
            payload = new ErrorPayload(input.getId(), this.messageService.invalidDocumentName(name));
            payloadSink.tryEmitValue(payload);
            changeDescriptionSink.tryEmitNext(changeDescription);
        } else if (optionalStereotypeDescription.isEmpty()) {
            payload = new ErrorPayload(input.getId(), this.messageService.stereotypeDescriptionNotFound(stereotypeDescriptionId));
            payloadSink.tryEmitValue(payload);
            changeDescriptionSink.tryEmitNext(changeDescription);
        } else {
            StereotypeDescription stereotypeDescription = optionalStereotypeDescription.get();
            this.createDocument(payloadSink, changeDescriptionSink, createDocumentInput, editingContext, editingContextId, name, stereotypeDescription);
        }
    }
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) StereotypeDescription(org.eclipse.sirius.components.core.configuration.StereotypeDescription) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) UUID(java.util.UUID) IPayload(org.eclipse.sirius.components.core.api.IPayload) CreateDocumentInput(org.eclipse.sirius.components.collaborative.dto.CreateDocumentInput)

Example 5 with StereotypeDescription

use of org.eclipse.sirius.components.core.configuration.StereotypeDescription in project sirius-web by eclipse-sirius.

the class StereotypeDescriptionRegistryConfigurer method addStereotypeDescriptions.

@Override
public void addStereotypeDescriptions(IStereotypeDescriptionRegistry registry) {
    registry.add(new StereotypeDescription(EMPTY_FLOW_ID, EMPTY_FLOW_LABEL, this::getEmptyFlowContent));
    if (this.studiosEnabled) {
        registry.add(new StereotypeDescription(EMPTY_DOMAIN_ID, EMPTY_DOMAIN_LABEL, this::getEmptyDomainContent));
        registry.add(new StereotypeDescription(EMPTY_VIEW_ID, EMPTY_VIEW_LABEL, this::getEmptyViewContent));
    }
    registry.add(new StereotypeDescription(ROBOT_FLOW_ID, ROBOT_FLOW_LABEL, this::getRobotFlowContent));
    registry.add(new StereotypeDescription(BIG_GUY_FLOW_ID, BIG_GUY_FLOW_LABEL, this::getBigGuyFlowContent));
    // $NON-NLS-1$
    registry.add(new StereotypeDescription(EMPTY_ID, EMPTY_LABEL, "New", this::getEmptyContent));
}
Also used : StereotypeDescription(org.eclipse.sirius.components.core.configuration.StereotypeDescription)

Aggregations

StereotypeDescription (org.eclipse.sirius.components.core.configuration.StereotypeDescription)5 UUID (java.util.UUID)3 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)3 CreateDocumentInput (org.eclipse.sirius.components.collaborative.dto.CreateDocumentInput)3 IPayload (org.eclipse.sirius.components.core.api.IPayload)3 IStereotypeDescriptionService (org.eclipse.sirius.web.services.api.stereotypes.IStereotypeDescriptionService)3 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 AdapterFactoryEditingDomain (org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain)2 EditingContext (org.eclipse.sirius.components.emf.services.EditingContext)2 Profile (org.eclipse.sirius.web.services.api.accounts.Profile)2 Document (org.eclipse.sirius.web.services.api.document.Document)2 IDocumentService (org.eclipse.sirius.web.services.api.document.IDocumentService)2 Project (org.eclipse.sirius.web.services.api.projects.Project)2 IServicesMessageService (org.eclipse.sirius.web.services.messages.IServicesMessageService)2 NoOpServicesMessageService (org.eclipse.sirius.web.services.projects.NoOpServicesMessageService)2 Test (org.junit.jupiter.api.Test)2 Connection (graphql.relay.Connection)1 ConnectionCursor (graphql.relay.ConnectionCursor)1 DefaultConnection (graphql.relay.DefaultConnection)1 DefaultConnectionCursor (graphql.relay.DefaultConnectionCursor)1