Search in sources :

Example 1 with RepresentationEntity

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

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

the class RepresentationRepositoryIntegrationTests method testInsertAndRetrieveARepresentation.

@Test
@Transactional
public void testInsertAndRetrieveARepresentation() {
    ProjectEntity savedProject = this.createAndSaveProjectEntity();
    RepresentationEntity representationEntity = this.createRepresentationEntity(savedProject, FIRST_DIAGRAM_LABEL, FIRST_TARGET_OBJECT_ID);
    RepresentationEntity savedRepresentation = this.representationRepository.save(representationEntity);
    assertThat(savedRepresentation.getId()).isNotNull();
    var optionalRepresentationFound = this.representationRepository.findById(savedRepresentation.getId());
    assertThat(optionalRepresentationFound.isPresent()).isTrue();
    optionalRepresentationFound.ifPresent(representationFound -> {
        assertThat(representationFound.getLabel()).isEqualTo(representationEntity.getLabel());
        assertThat(representationFound.getTargetObjectId()).isEqualTo(representationEntity.getTargetObjectId());
        assertThat(representationFound.getContent()).isEqualTo(representationEntity.getContent());
        assertThat(representationFound.getKind()).isEqualTo(representationEntity.getKind());
    });
}
Also used : RepresentationEntity(org.eclipse.sirius.web.persistence.entities.RepresentationEntity) ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with RepresentationEntity

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

the class RepresentationRepositoryIntegrationTests method createRepresentationEntity.

private RepresentationEntity createRepresentationEntity(ProjectEntity projectEntity, String label, String targetObjectId) {
    RepresentationEntity representationEntity = new RepresentationEntity();
    representationEntity.setId(UUID.randomUUID());
    representationEntity.setLabel(label);
    representationEntity.setProject(projectEntity);
    representationEntity.setTargetObjectId(targetObjectId);
    // $NON-NLS-1$
    representationEntity.setKind("siriusComponents://representation?type=Diagram");
    representationEntity.setDescriptionId(UUID.randomUUID().toString());
    // $NON-NLS-1$
    representationEntity.setContent("{ \"nodes\": [], \"edges\": []}");
    return representationEntity;
}
Also used : RepresentationEntity(org.eclipse.sirius.web.persistence.entities.RepresentationEntity)

Example 4 with RepresentationEntity

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

the class RepresentationRepositoryIntegrationTests method testFindAllByProjectId.

@Test
@Transactional
public void testFindAllByProjectId() {
    ProjectEntity savedProject = this.createAndSaveProjectEntity();
    RepresentationEntity firstRepresentationEntity = this.createRepresentationEntity(savedProject, FIRST_DIAGRAM_LABEL, FIRST_TARGET_OBJECT_ID);
    RepresentationEntity secondRepresentationEntity = this.createRepresentationEntity(savedProject, SECOND_DIAGRAM_LABEL, FIRST_TARGET_OBJECT_ID);
    this.representationRepository.save(firstRepresentationEntity);
    this.representationRepository.save(secondRepresentationEntity);
    List<RepresentationEntity> representationEntities = this.representationRepository.findAllByProjectId(savedProject.getId());
    assertThat(representationEntities).hasSize(2);
}
Also used : RepresentationEntity(org.eclipse.sirius.web.persistence.entities.RepresentationEntity) ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with RepresentationEntity

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

the class RepresentationRepositoryIntegrationTests method testDeleteRepresentations.

@Test
@Transactional
public void testDeleteRepresentations() {
    ProjectEntity savedProject = this.createAndSaveProjectEntity();
    RepresentationEntity firstRepresentationEntity = this.createRepresentationEntity(savedProject, FIRST_DIAGRAM_LABEL, FIRST_TARGET_OBJECT_ID);
    RepresentationEntity secondRepresentationEntity = this.createRepresentationEntity(savedProject, SECOND_DIAGRAM_LABEL, FIRST_TARGET_OBJECT_ID);
    RepresentationEntity thirdRepresentationEntity = this.createRepresentationEntity(savedProject, THIRD_DIAGRAM_LABEL, FIRST_TARGET_OBJECT_ID);
    firstRepresentationEntity = this.representationRepository.save(firstRepresentationEntity);
    this.representationRepository.save(secondRepresentationEntity);
    this.representationRepository.save(thirdRepresentationEntity);
    assertThat(this.representationRepository.count()).isEqualTo(3);
    this.representationRepository.deleteById(firstRepresentationEntity.getId());
    assertThat(this.representationRepository.count()).isEqualTo(2);
    this.representationRepository.deleteAll();
    assertThat(this.representationRepository.count()).isEqualTo(0);
}
Also used : RepresentationEntity(org.eclipse.sirius.web.persistence.entities.RepresentationEntity) ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RepresentationEntity (org.eclipse.sirius.web.persistence.entities.RepresentationEntity)11 ProjectEntity (org.eclipse.sirius.web.persistence.entities.ProjectEntity)9 Test (org.junit.jupiter.api.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 Transactional (org.springframework.transaction.annotation.Transactional)8 UUID (java.util.UUID)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 AccountEntity (org.eclipse.sirius.web.persistence.entities.AccountEntity)1 DocumentEntity (org.eclipse.sirius.web.persistence.entities.DocumentEntity)1 IDParser (org.eclipse.sirius.web.services.api.id.IDParser)1