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