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