use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.
the class PersonDtos method asStudyMembershipDto.
private Mica.PersonDto.MembershipDto asStudyMembershipDto(Person.Membership membership, boolean asDraft) {
Mica.PersonDto.MembershipDto.Builder builder = Mica.PersonDto.MembershipDto.newBuilder();
builder.setRole(membership.getRole());
builder.setParentId(membership.getParentId());
if (membership.getParentId() != null) {
BaseStudy study = asDraft ? studyService.findStudy(membership.getParentId()) : publishedStudyService.findById(membership.getParentId());
if (study != null) {
builder.addAllParentAcronym(localizedStringDtos.asDto(study.getAcronym()));
builder.addAllParentName(localizedStringDtos.asDto(study.getName()));
builder.setExtension(Mica.PersonDto.StudyMembershipDto.meta, Mica.PersonDto.StudyMembershipDto.newBuilder().setType(study.getResourcePath()).build());
}
}
return builder.build();
}
use of org.obiba.mica.study.domain.BaseStudy 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;
}
use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.
the class StudyEntitiesCountService method newQueries.
/**
* Parse the RQL query and translate each node as a Opal query wrapped in a {@link StudyEntitiesCountQuery}.
*
* @param query
* @param entityType
* @return
*/
public List<StudyEntitiesCountQuery> newQueries(String query, String entityType) {
RQLCriteriaOpalConverter converter = applicationContext.getBean(RQLCriteriaOpalConverter.class);
converter.parse(query);
Map<BaseStudy, List<RQLCriterionOpalConverter>> studyConverters = converter.getCriterionConverters().stream().filter(// TODO include Dataschema variables
c -> !c.hasMultipleStudyTables()).collect(Collectors.groupingBy(c -> c.getVariableReferences().getStudy()));
return studyConverters.keySet().stream().map(study -> newQuery(entityType, study, studyConverters.get(study))).collect(Collectors.toList());
}
use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.
the class AbstractPublishedStudyResource method getStudyFileResource.
protected FileResource getStudyFileResource(String id, String fileId) {
checkAccess(id);
FileResource fileResource = applicationContext.getBean(FileResource.class);
BaseStudy study = getStudy(id);
if (study.hasLogo() && study.getLogo().getId().equals(fileId)) {
fileResource.setAttachment(study.getLogo());
} else {
List<Attachment> attachments = fileSystemService.findAttachments(String.format("^/%s/%s", getStudyPath(id), id), true).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.BaseStudy in project mica2 by obiba.
the class PublishedStudyResource method getStudyDto.
@GET
@Timed
public Mica.StudyDto getStudyDto(@PathParam("id") String id, @QueryParam("locale") String locale) {
checkAccess(id);
BaseStudy study = getStudy(id, locale);
return study instanceof Study ? dtos.asDto((Study) study) : dtos.asDto((HarmonizationStudy) study);
}
Aggregations