use of org.obiba.mica.project.domain.ProjectState in project mica2 by obiba.
the class ProjectService method save.
@Override
public void save(@NotNull @Valid Project project, String comments) {
Project saved = project;
if (project.isNew()) {
generateId(saved);
} else {
saved = projectRepository.findOne(project.getId());
if (saved != null) {
BeanUtils.copyProperties(project, saved, "id", "version", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate", "dataAccessRequestId");
} else {
saved = project;
}
}
ProjectState projectState = findEntityState(project, () -> {
ProjectState defaultState = new ProjectState();
defaultState.setTitle(project.getTitle());
return defaultState;
});
if (!project.isNew())
ensureGitRepository(projectState);
projectState.incrementRevisionsAhead();
projectStateRepository.save(projectState);
saved.setLastModifiedDate(DateTime.now());
projectRepository.save(saved);
eventBus.post(new ProjectUpdatedEvent(saved));
gitService.save(saved);
}
use of org.obiba.mica.project.domain.ProjectState in project mica2 by obiba.
the class ProjectService method index.
/**
* Index a specific {@link Project} without updating it.
*
* @param id
* @throws NoSuchProjectException
*/
public void index(@NotNull String id) throws NoSuchProjectException {
ProjectState projectState = getEntityState(id);
Project project = findById(id);
eventBus.post(new ProjectUpdatedEvent(project));
if (projectState.isPublished())
eventBus.post(new ProjectPublishedEvent(project, getCurrentUsername()));
else
eventBus.post(new ProjectUpdatedEvent(project));
}
use of org.obiba.mica.project.domain.ProjectState in project mica2 by obiba.
the class ProjectDtos method asDto.
@NotNull
public Mica.ProjectDto asDto(@NotNull Project project, boolean asDraft) {
Mica.ProjectDto.Builder builder = Mica.ProjectDto.newBuilder().addAllTitle(//
localizedStringDtos.asDto(project.getTitle())).addAllSummary(localizedStringDtos.asDto(project.getSummary()));
if (project.hasModel())
builder.setContent(JSONUtils.toJSON(project.getModel()));
if (project.hasDataAccessRequestId()) {
try {
DataAccessRequest request = dataAccessRequestService.findById(project.getDataAccessRequestId());
Mica.DataAccessRequestSummaryDto.Builder darBuilder = Mica.DataAccessRequestSummaryDto.newBuilder();
darBuilder.setId(project.getDataAccessRequestId());
darBuilder.setStatus(request.getStatus().name());
darBuilder.setApplicant(request.getApplicant());
darBuilder.setViewable(subjectAclService.isPermitted("/data-access-request", "VIEW", request.getId()));
builder.setRequest(darBuilder);
} catch (NoSuchElementException e) {
// ignore
}
}
if (!project.isNew())
builder.setId(project.getId());
Mica.PermissionsDto permissionsDto = permissionsDtos.asDto(project);
if (asDraft) {
ProjectState projectState = projectService.getEntityState(project.getId());
//
builder.setTimestamps(TimestampsDtos.asDto(project)).setPublished(//
projectState.isPublished()).setExtension(Mica.EntityStateDto.projectState, entityStateDtos.asDto(projectState).setPermissions(permissionsDto).build());
}
builder.setPermissions(permissionsDto);
builder.setTimestamps(TimestampsDtos.asDto(project));
return builder.build();
}
Aggregations