Search in sources :

Example 1 with IEditingContextEPackageService

use of org.eclipse.sirius.components.emf.services.IEditingContextEPackageService in project sirius-components by eclipse-sirius.

the class EMFQueryServiceTests method testEMFQueryServiceContents.

@Test
public void testEMFQueryServiceContents() {
    IEditingContext editingContext = this.createEditingContext();
    IEditingContextEPackageService editingContextEPackageService = new IEditingContextEPackageService() {

        @Override
        public List<EPackage> getEPackages(String editingContextId) {
            return List.of(EcorePackage.eINSTANCE);
        }
    };
    IQueryService queryService = new EMFQueryService(editingContextEPackageService, List.of());
    // $NON-NLS-1$
    QueryBasedIntInput input = new QueryBasedIntInput(UUID.randomUUID(), "aql:editingContext.contents()->size()", Map.of());
    IPayload payload = queryService.execute(editingContext, input);
    assertTrue(payload instanceof QueryBasedIntSuccessPayload);
    assertEquals(2, ((QueryBasedIntSuccessPayload) payload).getResult());
}
Also used : QueryBasedIntInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedIntInput) QueryBasedIntSuccessPayload(org.eclipse.sirius.components.collaborative.dto.QueryBasedIntSuccessPayload) IQueryService(org.eclipse.sirius.components.collaborative.api.IQueryService) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) EPackage(org.eclipse.emf.ecore.EPackage) IPayload(org.eclipse.sirius.components.core.api.IPayload) Test(org.junit.jupiter.api.Test)

Example 2 with IEditingContextEPackageService

use of org.eclipse.sirius.components.emf.services.IEditingContextEPackageService in project sirius-web by eclipse-sirius.

the class EditingContextSearchServiceTests method testEditingContextWithNoDocuments.

// @formatter:on
@Test
public void testEditingContextWithNoDocuments() {
    IProjectRepository projectRepository = new NoOpProjectRepository();
    IDocumentRepository documentRepository = new NoOpDocumentRepository();
    ComposedAdapterFactory composedAdapterFactory = new ComposedAdapterFactory();
    EPackage.Registry ePackageRegistry = new EPackageRegistryImpl();
    ePackageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
    String projectId = UUID.randomUUID().toString();
    IEditingContextEPackageService editingContextEPackageService = editingContextId -> List.of();
    IEditingContextSearchService editingContextSearchService = new EditingContextSearchService(projectRepository, documentRepository, editingContextEPackageService, composedAdapterFactory, ePackageRegistry, new SimpleMeterRegistry());
    IEditingContext editingContext = editingContextSearchService.findById(projectId).get();
    assertThat(editingContext).isInstanceOf(EditingContext.class);
    EditingDomain editingDomain = ((EditingContext) editingContext).getDomain();
    assertThat(editingDomain.getResourceSet().getResources()).hasSize(0);
}
Also used : IProjectRepository(org.eclipse.sirius.web.persistence.repositories.IProjectRepository) DocumentEntity(org.eclipse.sirius.web.persistence.entities.DocumentEntity) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) DocumentMetadataAdapter(org.eclipse.sirius.web.services.documents.DocumentMetadataAdapter) URI(org.eclipse.emf.common.util.URI) ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) EcorePackage(org.eclipse.emf.ecore.EcorePackage) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UUID(java.util.UUID) IProjectRepository(org.eclipse.sirius.web.persistence.repositories.IProjectRepository) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) EPackage(org.eclipse.emf.ecore.EPackage) EPackageRegistryImpl(org.eclipse.emf.ecore.impl.EPackageRegistryImpl) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) Test(org.junit.jupiter.api.Test) List(java.util.List) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) IDocumentRepository(org.eclipse.sirius.web.persistence.repositories.IDocumentRepository) ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) Resource(org.eclipse.emf.ecore.resource.Resource) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) EPackage(org.eclipse.emf.ecore.EPackage) IDocumentRepository(org.eclipse.sirius.web.persistence.repositories.IDocumentRepository) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) EPackageRegistryImpl(org.eclipse.emf.ecore.impl.EPackageRegistryImpl) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) Test(org.junit.jupiter.api.Test)

Example 3 with IEditingContextEPackageService

use of org.eclipse.sirius.components.emf.services.IEditingContextEPackageService in project sirius-web by eclipse-sirius.

the class EditingContextSearchServiceTests method testEditingContextWithDocuments.

@Test
public void testEditingContextWithDocuments() {
    UUID projectId = UUID.randomUUID();
    ProjectEntity projectEntity = new ProjectEntity();
    projectEntity.setId(projectId);
    // $NON-NLS-1$
    projectEntity.setName("");
    DocumentEntity firstDocumentEntity = new DocumentEntity();
    firstDocumentEntity.setId(UUID.randomUUID());
    // $NON-NLS-1$
    firstDocumentEntity.setName("First Document");
    firstDocumentEntity.setProject(projectEntity);
    firstDocumentEntity.setContent(CONTENT);
    DocumentEntity secondDocumentEntity = new DocumentEntity();
    secondDocumentEntity.setId(UUID.randomUUID());
    // $NON-NLS-1$
    secondDocumentEntity.setName("Second Document");
    secondDocumentEntity.setProject(projectEntity);
    secondDocumentEntity.setContent(CONTENT);
    IProjectRepository projectRepository = new NoOpProjectRepository();
    IDocumentRepository documentRepository = new NoOpDocumentRepository() {

        @Override
        public List<DocumentEntity> findAllByProjectId(UUID projectId) {
            return List.of(firstDocumentEntity, secondDocumentEntity);
        }
    };
    ComposedAdapterFactory composedAdapterFactory = new ComposedAdapterFactory();
    EPackage.Registry ePackageRegistry = new EPackageRegistryImpl();
    ePackageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
    IEditingContextEPackageService editingContextEPackageService = editingContextId -> List.of();
    IEditingContextSearchService editingContextSearchService = new EditingContextSearchService(projectRepository, documentRepository, editingContextEPackageService, composedAdapterFactory, ePackageRegistry, new SimpleMeterRegistry());
    IEditingContext editingContext = editingContextSearchService.findById(projectId.toString()).get();
    assertThat(editingContext).isInstanceOf(EditingContext.class);
    EditingDomain editingDomain = ((EditingContext) editingContext).getDomain();
    assertThat(editingDomain.getResourceSet().getResources()).hasSize(2);
    Resource firstResource = editingDomain.getResourceSet().getResource(URI.createURI(firstDocumentEntity.getId().toString()), true);
    this.assertProperResourceLoading(firstResource, firstDocumentEntity);
    Resource secondResource = editingDomain.getResourceSet().getResource(URI.createURI(secondDocumentEntity.getId().toString()), true);
    this.assertProperResourceLoading(secondResource, secondDocumentEntity);
}
Also used : IProjectRepository(org.eclipse.sirius.web.persistence.repositories.IProjectRepository) DocumentEntity(org.eclipse.sirius.web.persistence.entities.DocumentEntity) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) DocumentMetadataAdapter(org.eclipse.sirius.web.services.documents.DocumentMetadataAdapter) URI(org.eclipse.emf.common.util.URI) ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) EcorePackage(org.eclipse.emf.ecore.EcorePackage) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UUID(java.util.UUID) IProjectRepository(org.eclipse.sirius.web.persistence.repositories.IProjectRepository) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) EPackage(org.eclipse.emf.ecore.EPackage) EPackageRegistryImpl(org.eclipse.emf.ecore.impl.EPackageRegistryImpl) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) Test(org.junit.jupiter.api.Test) List(java.util.List) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) IDocumentRepository(org.eclipse.sirius.web.persistence.repositories.IDocumentRepository) ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) Resource(org.eclipse.emf.ecore.resource.Resource) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Resource(org.eclipse.emf.ecore.resource.Resource) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) EPackage(org.eclipse.emf.ecore.EPackage) IDocumentRepository(org.eclipse.sirius.web.persistence.repositories.IDocumentRepository) DocumentEntity(org.eclipse.sirius.web.persistence.entities.DocumentEntity) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) EPackageRegistryImpl(org.eclipse.emf.ecore.impl.EPackageRegistryImpl) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 4 with IEditingContextEPackageService

use of org.eclipse.sirius.components.emf.services.IEditingContextEPackageService in project sirius-components by eclipse-sirius.

the class EMFQueryServiceTests method testEMFQueryServiceAllContents.

@Test
public void testEMFQueryServiceAllContents() {
    IEditingContext editingContext = this.createEditingContext();
    IEditingContextEPackageService editingContextEPackageService = new IEditingContextEPackageService() {

        @Override
        public List<EPackage> getEPackages(String editingContextId) {
            return List.of(EcorePackage.eINSTANCE);
        }
    };
    IQueryService queryService = new EMFQueryService(editingContextEPackageService, List.of());
    // $NON-NLS-1$
    QueryBasedIntInput input = new QueryBasedIntInput(UUID.randomUUID(), "aql:editingContext.allContents()->size()", Map.of());
    IPayload payload = queryService.execute(editingContext, input);
    assertTrue(payload instanceof QueryBasedIntSuccessPayload);
    assertEquals(8, ((QueryBasedIntSuccessPayload) payload).getResult());
}
Also used : QueryBasedIntInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedIntInput) QueryBasedIntSuccessPayload(org.eclipse.sirius.components.collaborative.dto.QueryBasedIntSuccessPayload) IQueryService(org.eclipse.sirius.components.collaborative.api.IQueryService) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) EPackage(org.eclipse.emf.ecore.EPackage) IPayload(org.eclipse.sirius.components.core.api.IPayload) Test(org.junit.jupiter.api.Test)

Example 5 with IEditingContextEPackageService

use of org.eclipse.sirius.components.emf.services.IEditingContextEPackageService in project sirius-components by eclipse-sirius.

the class EMFQueryServiceTests method testEMFQueryServiceGetObjectById.

@Test
public void testEMFQueryServiceGetObjectById() {
    EditingContext editingContext = this.createEditingContext();
    IEditingContextEPackageService editingContextEPackageService = new IEditingContextEPackageService() {

        @Override
        public List<EPackage> getEPackages(String editingContextId) {
            return List.of(EcorePackage.eINSTANCE);
        }
    };
    IQueryService queryService = new EMFQueryService(editingContextEPackageService, List.of());
    // @formatter:off
    EObject eObjectToRetrieve = editingContext.getDomain().getResourceSet().getResources().get(0).getContents().get(0);
    Optional<IDAdapter> optionalIDAdapter = eObjectToRetrieve.eAdapters().stream().filter(IDAdapter.class::isInstance).map(IDAdapter.class::cast).findFirst();
    // $NON-NLS-1$
    String id = optionalIDAdapter.map(IDAdapter::getId).map(Object::toString).orElse("");
    // @formatter:on
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryBasedObjectInput input = new QueryBasedObjectInput(UUID.randomUUID(), "aql:editingContext.getObjectById('" + id + "')", Map.of());
    IPayload payload = queryService.execute(editingContext, input);
    assertTrue(payload instanceof QueryBasedObjectSuccessPayload);
    assertEquals(eObjectToRetrieve, ((QueryBasedObjectSuccessPayload) payload).getResult());
    // $NON-NLS-1$ //$NON-NLS-2$
    input = new QueryBasedObjectInput(UUID.randomUUID(), "aql:editingContext.getObjectById('" + id + "wrong')", Map.of());
    payload = queryService.execute(editingContext, input);
    assertTrue(payload instanceof ErrorPayload);
}
Also used : IQueryService(org.eclipse.sirius.components.collaborative.api.IQueryService) QueryBasedObjectSuccessPayload(org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectSuccessPayload) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) IDAdapter(org.eclipse.sirius.components.emf.services.IDAdapter) EPackage(org.eclipse.emf.ecore.EPackage) 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) EObject(org.eclipse.emf.ecore.EObject) QueryBasedObjectInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectInput) Test(org.junit.jupiter.api.Test)

Aggregations

EPackage (org.eclipse.emf.ecore.EPackage)5 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)5 IEditingContextEPackageService (org.eclipse.sirius.components.emf.services.IEditingContextEPackageService)5 Test (org.junit.jupiter.api.Test)5 IQueryService (org.eclipse.sirius.components.collaborative.api.IQueryService)3 IPayload (org.eclipse.sirius.components.core.api.IPayload)3 EditingContext (org.eclipse.sirius.components.emf.services.EditingContext)3 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 List (java.util.List)2 UUID (java.util.UUID)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 URI (org.eclipse.emf.common.util.URI)2 EcorePackage (org.eclipse.emf.ecore.EcorePackage)2 EPackageRegistryImpl (org.eclipse.emf.ecore.impl.EPackageRegistryImpl)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 ECrossReferenceAdapter (org.eclipse.emf.ecore.util.ECrossReferenceAdapter)2 EditingDomain (org.eclipse.emf.edit.domain.EditingDomain)2 ComposedAdapterFactory (org.eclipse.emf.edit.provider.ComposedAdapterFactory)2 QueryBasedIntInput (org.eclipse.sirius.components.collaborative.dto.QueryBasedIntInput)2 QueryBasedIntSuccessPayload (org.eclipse.sirius.components.collaborative.dto.QueryBasedIntSuccessPayload)2