Search in sources :

Example 1 with ProjectState

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);
}
Also used : Project(org.obiba.mica.project.domain.Project) ProjectState(org.obiba.mica.project.domain.ProjectState) ProjectUpdatedEvent(org.obiba.mica.project.event.ProjectUpdatedEvent)

Example 2 with ProjectState

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));
}
Also used : Project(org.obiba.mica.project.domain.Project) ProjectPublishedEvent(org.obiba.mica.project.event.ProjectPublishedEvent) ProjectState(org.obiba.mica.project.domain.ProjectState) ProjectUpdatedEvent(org.obiba.mica.project.event.ProjectUpdatedEvent)

Example 3 with ProjectState

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();
}
Also used : DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) ProjectState(org.obiba.mica.project.domain.ProjectState) NoSuchElementException(java.util.NoSuchElementException) NotNull(javax.validation.constraints.NotNull)

Aggregations

ProjectState (org.obiba.mica.project.domain.ProjectState)3 Project (org.obiba.mica.project.domain.Project)2 ProjectUpdatedEvent (org.obiba.mica.project.event.ProjectUpdatedEvent)2 NoSuchElementException (java.util.NoSuchElementException)1 NotNull (javax.validation.constraints.NotNull)1 DataAccessRequest (org.obiba.mica.access.domain.DataAccessRequest)1 ProjectPublishedEvent (org.obiba.mica.project.event.ProjectPublishedEvent)1