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);
}
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());
});
}
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;
}
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);
}
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);
}
Aggregations