Search in sources :

Example 1 with ProjectEntity

use of org.eclipse.sirius.web.persistence.entities.ProjectEntity in project sirius-web by eclipse-sirius.

the class ProjectService method createProject.

@Override
public IPayload createProject(CreateProjectInput input) {
    IPayload payload = null;
    String name = input.getName().trim();
    if (!this.isValidProjectName(name)) {
        payload = new ErrorPayload(input.getId(), this.messageService.invalidProjectName());
    } else {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        var optionalOwner = this.accountRepository.findByUsername(authentication.getName());
        if (!optionalOwner.isEmpty()) {
            ProjectEntity projectEntity = this.createProjectEntity(name, optionalOwner.get(), input.getVisibility());
            projectEntity = this.projectRepository.save(projectEntity);
            Project project = this.projectMapper.toDTO(projectEntity);
            payload = new CreateProjectSuccessPayload(input.getId(), project);
        }
    }
    return payload;
}
Also used : Project(org.eclipse.sirius.web.services.api.projects.Project) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) Authentication(org.springframework.security.core.Authentication) CreateProjectSuccessPayload(org.eclipse.sirius.web.services.api.projects.CreateProjectSuccessPayload) IPayload(org.eclipse.sirius.components.core.api.IPayload)

Example 2 with ProjectEntity

use of org.eclipse.sirius.web.persistence.entities.ProjectEntity in project sirius-web by eclipse-sirius.

the class ProjectService method renameProject.

@Override
public Optional<Project> renameProject(UUID projectId, String newName) {
    Optional<ProjectEntity> optionalProjectEntity = this.projectRepository.findByIdIfVisibleBy(projectId, this.getCurrentUserName());
    if (optionalProjectEntity.isPresent()) {
        ProjectEntity projectEntity = optionalProjectEntity.get();
        projectEntity.setName(newName);
        return Optional.of(this.projectRepository.save(projectEntity)).map(this.projectMapper::toDTO);
    }
    return Optional.empty();
}
Also used : ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity)

Example 3 with ProjectEntity

use of org.eclipse.sirius.web.persistence.entities.ProjectEntity in project sirius-web by eclipse-sirius.

the class RepresentationService method save.

@Override
public void save(IEditingContext editingContext, ISemanticRepresentation representation) {
    long start = System.currentTimeMillis();
    var editingContextId = new IDParser().parse(editingContext.getId());
    var representationId = new IDParser().parse(representation.getId());
    if (editingContextId.isPresent() && representationId.isPresent()) {
        UUID editingContextUUID = editingContextId.get();
        UUID representationUUID = representationId.get();
        var optionalProjectEntity = this.projectRepository.findById(editingContextUUID);
        if (optionalProjectEntity.isPresent()) {
            ProjectEntity projectEntity = optionalProjectEntity.get();
            RepresentationEntity representationEntity = this.toEntity(projectEntity, representationUUID, representation);
            this.representationRepository.save(representationEntity);
        }
    }
    long end = System.currentTimeMillis();
    this.timer.record(end - start, TimeUnit.MILLISECONDS);
}
Also used : RepresentationEntity(org.eclipse.sirius.web.persistence.entities.RepresentationEntity) ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) IDParser(org.eclipse.sirius.web.services.api.id.IDParser) UUID(java.util.UUID)

Example 4 with ProjectEntity

use of org.eclipse.sirius.web.persistence.entities.ProjectEntity 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 5 with ProjectEntity

use of org.eclipse.sirius.web.persistence.entities.ProjectEntity in project sirius-web by eclipse-sirius.

the class DocumentMapper method toDTO.

public Document toDTO(DocumentEntity documentEntity) {
    ProjectEntity projectEntity = documentEntity.getProject();
    var profile = new Profile(projectEntity.getOwner().getId(), projectEntity.getOwner().getUsername());
    var visibility = Visibility.valueOf(projectEntity.getVisibility().name());
    Project project = new Project(projectEntity.getId(), projectEntity.getName(), profile, visibility);
    return new Document(documentEntity.getId(), project, documentEntity.getName(), documentEntity.getContent());
}
Also used : Project(org.eclipse.sirius.web.services.api.projects.Project) ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) Document(org.eclipse.sirius.web.services.api.document.Document) Profile(org.eclipse.sirius.web.services.api.accounts.Profile)

Aggregations

ProjectEntity (org.eclipse.sirius.web.persistence.entities.ProjectEntity)28 Test (org.junit.jupiter.api.Test)21 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)19 Transactional (org.springframework.transaction.annotation.Transactional)19 RepresentationEntity (org.eclipse.sirius.web.persistence.entities.RepresentationEntity)9 AccountEntity (org.eclipse.sirius.web.persistence.entities.AccountEntity)8 DocumentEntity (org.eclipse.sirius.web.persistence.entities.DocumentEntity)8 UUID (java.util.UUID)4 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)2 EditingContext (org.eclipse.sirius.components.emf.services.EditingContext)2 IDocumentRepository (org.eclipse.sirius.web.persistence.repositories.IDocumentRepository)2 Project (org.eclipse.sirius.web.services.api.projects.Project)2 DocumentMetadataAdapter (org.eclipse.sirius.web.services.documents.DocumentMetadataAdapter)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 URI (org.eclipse.emf.common.util.URI)1 EClass (org.eclipse.emf.ecore.EClass)1 EPackage (org.eclipse.emf.ecore.EPackage)1