Search in sources :

Example 1 with HarmonizationStudy

use of org.obiba.mica.study.domain.HarmonizationStudy in project mica2 by obiba.

the class DraftHarmonizationStudiesResource method create.

@POST
@Path("/harmonization-studies")
@Timed
@RequiresPermissions({ "/draft/harmonization-study:ADD" })
public Response create(@SuppressWarnings("TypeMayBeWeakened") Mica.StudyDto studyDto, @Context UriInfo uriInfo, @Nullable @QueryParam("comment") String comment) {
    HarmonizationStudy study = (HarmonizationStudy) dtos.fromDto(studyDto);
    harmonizationStudyService.save(study, comment);
    return Response.created(uriInfo.getBaseUriBuilder().path(DraftHarmonizationStudiesResource.class, "study").build(study.getId())).build();
}
Also used : HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 2 with HarmonizationStudy

use of org.obiba.mica.study.domain.HarmonizationStudy in project mica2 by obiba.

the class DraftHarmonizationStudyResource method file.

@Path("/file/{fileId}")
public FileResource file(@PathParam("fileId") String fileId, @QueryParam("key") String key) {
    checkPermission("/draft/harmonization-study", "VIEW", key);
    FileResource fileResource = applicationContext.getBean(FileResource.class);
    HarmonizationStudy study = studyService.findDraft(id);
    if (study.hasLogo() && study.getLogo().getId().equals(fileId)) {
        fileResource.setAttachment(study.getLogo());
    } else {
        List<Attachment> attachments = fileSystemService.findAttachments(String.format("^/harmonization-study/%s", study.getId()), false).stream().filter(a -> a.getId().equals(fileId)).collect(Collectors.toList());
        if (attachments.isEmpty())
            throw NoSuchEntityException.withId(Attachment.class, fileId);
        fileResource.setAttachment(attachments.get(0));
    }
    return fileResource;
}
Also used : RevisionStatus(org.obiba.mica.core.domain.RevisionStatus) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ConstraintException(org.obiba.mica.study.ConstraintException) Path(javax.ws.rs.Path) HashMap(java.util.HashMap) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) AbstractGitPersistableResource(org.obiba.mica.AbstractGitPersistableResource) QueryParam(javax.ws.rs.QueryParam) Lists(com.google.common.collect.Lists) PublishCascadingScope(org.obiba.mica.core.domain.PublishCascadingScope) SubjectAclResource(org.obiba.mica.security.rest.SubjectAclResource) Map(java.util.Map) Mica(org.obiba.mica.web.model.Mica) DefaultValue(javax.ws.rs.DefaultValue) HarmonizationStudyState(org.obiba.mica.study.domain.HarmonizationStudyState) Dtos(org.obiba.mica.web.model.Dtos) Nullable(javax.annotation.Nullable) DELETE(javax.ws.rs.DELETE) FileResource(org.obiba.mica.file.rest.FileResource) Attachment(org.obiba.mica.file.Attachment) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) HarmonizationStudyService(org.obiba.mica.study.service.HarmonizationStudyService) FileSystemService(org.obiba.mica.file.service.FileSystemService) IOException(java.io.IOException) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) Maps(com.google.common.collect.Maps) NoSuchEntityException(org.obiba.mica.NoSuchEntityException) HarmonizedDatasetService(org.obiba.mica.dataset.service.HarmonizedDatasetService) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Component(org.springframework.stereotype.Component) Response(javax.ws.rs.core.Response) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) PUT(javax.ws.rs.PUT) AbstractGitPersistableService(org.obiba.mica.core.service.AbstractGitPersistableService) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) FileResource(org.obiba.mica.file.rest.FileResource) Attachment(org.obiba.mica.file.Attachment) Path(javax.ws.rs.Path)

Example 3 with HarmonizationStudy

use of org.obiba.mica.study.domain.HarmonizationStudy in project mica2 by obiba.

the class DraftHarmonizationStudyResource method update.

@PUT
@Timed
public Response update(@SuppressWarnings("TypeMayBeWeakened") Mica.StudyDto studyDto, @Nullable @QueryParam("comment") String comment) {
    checkPermission("/draft/harmonization-study", "EDIT");
    // ensure study exists
    studyService.findDraft(id);
    HarmonizationStudy study = (HarmonizationStudy) dtos.fromDto(studyDto);
    HashMap<Object, Object> response = Maps.newHashMap();
    response.put("study", study);
    response.put("potentialConflicts", studyService.getPotentialConflicts(study, false));
    studyService.save(study, comment);
    return Response.ok(response, MediaType.APPLICATION_JSON_TYPE).build();
}
Also used : HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 4 with HarmonizationStudy

use of org.obiba.mica.study.domain.HarmonizationStudy in project mica2 by obiba.

the class HarmonizationStudyService method getPotentialConflicts.

/**
 * @param study
 * @param publishing
 * @return
 */
public Map<String, List<String>> getPotentialConflicts(HarmonizationStudy study, boolean publishing) {
    if (study.getId() != null) {
        HarmonizationStudy oldStudy = publishing ? study : harmonizationStudyRepository.findOne(study.getId());
        if (oldStudy != null) {
            List<String> populationUIDs = publishing ? toListOfPopulationUids(study) : populationsAffected(study, oldStudy);
            if (populationUIDs != null) {
                List<String> networkIds = networkRepository.findByStudyIds(study.getId()).stream().map(AbstractGitPersistable::getId).collect(toList());
                List<String> harmoDatasetIds = findHarmonizedDatasetDependencies(study.getId(), populationUIDs);
                if (!harmoDatasetIds.isEmpty() || !networkIds.isEmpty()) {
                    return new HashMap<String, List<String>>() {

                        {
                            put("harmonizationDataset", harmoDatasetIds);
                            put("network", networkIds);
                        }
                    };
                }
            }
        }
    }
    return null;
}
Also used : HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) HashMap(java.util.HashMap)

Example 5 with HarmonizationStudy

use of org.obiba.mica.study.domain.HarmonizationStudy in project mica2 by obiba.

the class StudyDtos method fromDto.

@NotNull
BaseStudy fromDto(@NotNull Mica.StudyDtoOrBuilder dto) {
    Assert.isTrue(dto.hasExtension(Mica.CollectionStudyDto.type) || dto.hasExtension(Mica.HarmonizationStudyDto.type), "StudyDto must of a type extension.");
    BaseStudy study = dto.hasExtension(Mica.CollectionStudyDto.type) ? new Study() : new HarmonizationStudy();
    if (dto.hasId())
        study.setId(dto.getId());
    if (dto.getNameCount() > 0)
        study.setName(localizedStringDtos.fromDto(dto.getNameList()));
    if (dto.getAcronymCount() > 0)
        study.setAcronym(localizedStringDtos.fromDto(dto.getAcronymList()));
    if (dto.hasLogo())
        study.setLogo(attachmentDtos.fromDto(dto.getLogo()));
    if (dto.hasTimestamps())
        TimestampsDtos.fromDto(dto.getTimestamps(), study);
    if (dto.getObjectivesCount() > 0)
        study.setObjectives(localizedStringDtos.fromDto(dto.getObjectivesList()));
    if (dto.hasOpal())
        study.setOpal(dto.getOpal());
    if (dto.getMembershipsCount() > 0) {
        Map<String, List<Membership>> memberships = Maps.newHashMap();
        dto.getMembershipsList().forEach(e -> memberships.put(e.getRole(), e.getMembersList().stream().map(p -> new Membership(personDtos.fromDto(p), e.getRole())).collect(toList())));
        study.setMemberships(memberships);
    }
    if (dto.getPopulationsCount() > 0) {
        study.setPopulations(dto.getPopulationsList().stream().map(populationDtos::fromDto).collect(Collectors.toCollection(TreeSet<org.obiba.mica.study.domain.Population>::new)));
    }
    if (dto.hasContent() && !Strings.isNullOrEmpty(dto.getContent()))
        study.setModel(JSONUtils.toMap(dto.getContent()));
    else
        study.setModel(new HashMap<>());
    return study;
}
Also used : HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) HarmonizationStudyService(org.obiba.mica.study.service.HarmonizationStudyService) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Membership(org.obiba.mica.core.domain.Membership) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) HashMap(java.util.HashMap) NotNull(javax.validation.constraints.NotNull) Assert(io.jsonwebtoken.lang.Assert) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) TreeSet(java.util.TreeSet) Inject(javax.inject.Inject) IndividualStudyService(org.obiba.mica.study.service.IndividualStudyService) Strings(com.google.common.base.Strings) List(java.util.List) Component(org.springframework.stereotype.Component) Collectors.toList(java.util.stream.Collectors.toList) Study(org.obiba.mica.study.domain.Study) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) Map(java.util.Map) JSONUtils(org.obiba.mica.JSONUtils) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) HarmonizedDatasetHelper(org.obiba.mica.dataset.support.HarmonizedDatasetHelper) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Study(org.obiba.mica.study.domain.Study) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) Membership(org.obiba.mica.core.domain.Membership) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) BaseStudy(org.obiba.mica.study.domain.BaseStudy) NotNull(javax.validation.constraints.NotNull)

Aggregations

HarmonizationStudy (org.obiba.mica.study.domain.HarmonizationStudy)7 Timed (com.codahale.metrics.annotation.Timed)4 HashMap (java.util.HashMap)3 HarmonizationDataset (org.obiba.mica.dataset.domain.HarmonizationDataset)3 Maps (com.google.common.collect.Maps)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 NotNull (javax.validation.constraints.NotNull)2 GET (javax.ws.rs.GET)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 BaseStudy (org.obiba.mica.study.domain.BaseStudy)2 Study (org.obiba.mica.study.domain.Study)2 HarmonizationStudyService (org.obiba.mica.study.service.HarmonizationStudyService)2 Strings (com.google.common.base.Strings)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Lists (com.google.common.collect.Lists)1 Assert (io.jsonwebtoken.lang.Assert)1