Search in sources :

Example 1 with Project

use of org.obiba.mica.project.domain.Project in project mica2 by obiba.

the class DraftProjectResource method update.

@PUT
public Response update(@SuppressWarnings("TypeMayBeWeakened") Mica.ProjectDto projectDto, @Nullable @QueryParam("comment") String comment) {
    checkPermission("/draft/project", "EDIT");
    // ensure network exists
    projectService.findById(id);
    Project project = dtos.fromDto(projectDto);
    projectService.save(project, comment);
    return Response.noContent().build();
}
Also used : Project(org.obiba.mica.project.domain.Project)

Example 2 with Project

use of org.obiba.mica.project.domain.Project in project mica2 by obiba.

the class ProjectService method dataAccessRequestUpdated.

// 
// Event handling
// 
@Async
@Subscribe
public void dataAccessRequestUpdated(DataAccessRequestUpdatedEvent event) {
    DataAccessRequest request = event.getPersistable();
    if (!projectRepository.exists(request.getId()) && request.getStatus() == DataAccessRequest.Status.APPROVED) {
        Project project = new Project();
        project.setId(event.getPersistable().getId());
        project.setDataAccessRequestId(event.getPersistable().getId());
        String title = dataAccessRequestUtilService.getRequestTitle(request);
        if (!Strings.isNullOrEmpty(title)) {
            project.setTitle(LocalizedString.from(micaConfigService.getConfig().getLocales(), title));
        }
        String summary = dataAccessRequestUtilService.getRequestSummary(request);
        if (!Strings.isNullOrEmpty(summary)) {
            project.setSummary(LocalizedString.from(micaConfigService.getConfig().getLocales(), summary));
        }
        save(project, "Created from Data Access Request");
    }
}
Also used : Project(org.obiba.mica.project.domain.Project) DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) LocalizedString(org.obiba.mica.core.domain.LocalizedString) Async(org.springframework.scheduling.annotation.Async) Subscribe(com.google.common.eventbus.Subscribe)

Example 3 with Project

use of org.obiba.mica.project.domain.Project in project mica2 by obiba.

the class ProjectService method publish.

/**
 * Set the publication flag on a {@link Project}.
 *
 * @param id
 * @throws NoSuchProjectException
 */
@Caching(evict = { @CacheEvict(value = "aggregations-metadata", key = "'project'") })
public void publish(@NotNull String id, boolean publish, PublishCascadingScope cascadingScope) throws NoSuchEntityException {
    Project project = projectRepository.findOne(id);
    if (project == null)
        return;
    if (publish) {
        publishState(id);
        eventBus.post(new ProjectPublishedEvent(project, getCurrentUsername(), cascadingScope));
    } else {
        unPublishState(id);
        eventBus.post(new ProjectUnpublishedEvent(project));
    }
}
Also used : Project(org.obiba.mica.project.domain.Project) ProjectPublishedEvent(org.obiba.mica.project.event.ProjectPublishedEvent) ProjectUnpublishedEvent(org.obiba.mica.project.event.ProjectUnpublishedEvent) Caching(org.springframework.cache.annotation.Caching)

Example 4 with Project

use of org.obiba.mica.project.domain.Project in project mica2 by obiba.

the class ProjectDtos method fromDto.

@NotNull
public Project fromDto(@NotNull Mica.ProjectDto dto) {
    Project.Builder builder = Project.newBuilder();
    builder.content(dto.hasContent() ? dto.getContent() : null);
    builder.title(localizedStringDtos.fromDto(dto.getTitleList()));
    builder.summary(localizedStringDtos.fromDto(dto.getSummaryList()));
    Project project = builder.build();
    if (dto.hasId())
        project.setId(dto.getId());
    TimestampsDtos.fromDto(dto.getTimestamps(), project);
    return project;
}
Also used : Project(org.obiba.mica.project.domain.Project) NotNull(javax.validation.constraints.NotNull)

Example 5 with Project

use of org.obiba.mica.project.domain.Project 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)

Aggregations

Project (org.obiba.mica.project.domain.Project)9 NotNull (javax.validation.constraints.NotNull)2 ProjectState (org.obiba.mica.project.domain.ProjectState)2 ProjectPublishedEvent (org.obiba.mica.project.event.ProjectPublishedEvent)2 ProjectUpdatedEvent (org.obiba.mica.project.event.ProjectUpdatedEvent)2 Timed (com.codahale.metrics.annotation.Timed)1 Subscribe (com.google.common.eventbus.Subscribe)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1 DataAccessRequest (org.obiba.mica.access.domain.DataAccessRequest)1 LocalizedString (org.obiba.mica.core.domain.LocalizedString)1 ProjectDeletedEvent (org.obiba.mica.project.event.ProjectDeletedEvent)1 ProjectUnpublishedEvent (org.obiba.mica.project.event.ProjectUnpublishedEvent)1 NoSuchProjectException (org.obiba.mica.project.service.NoSuchProjectException)1 ObibaRealm (org.obiba.shiro.realm.ObibaRealm)1 Caching (org.springframework.cache.annotation.Caching)1 Async (org.springframework.scheduling.annotation.Async)1