use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.
the class SpecificStudyReportGenerator method writeEachLine.
@Override
protected void writeEachLine(CSVWriter writer) {
for (String studyId : studyIds) {
BaseStudy publishedStudy = publishedStudyService.findById(studyId);
if (publishedStudy != null) {
List<String> publishedStudyDetails = generatePublishedStudyDetails(publishedStudy);
Iterator<Population> populationIterator = publishedStudy.getPopulations().iterator();
if (!populationIterator.hasNext()) {
writer.writeNext(publishedStudyDetails.toArray(new String[publishedStudyDetails.size()]));
}
while (populationIterator.hasNext()) {
List<String> buildingCompleteLine = new ArrayList<>(publishedStudyDetails);
Population next = populationIterator.next();
buildingCompleteLine.addAll(generatePopulationDetails(next));
writer.writeNext(buildingCompleteLine.toArray(new String[buildingCompleteLine.size()]));
}
} else {
BaseStudy draftStudy = studyService.findStudy(studyId);
if (draftStudy != null) {
List<String> lineOfDratStudy = generateDraftStudyDetails(draftStudy);
writer.writeNext(lineOfDratStudy.toArray(new String[lineOfDratStudy.size()]));
}
}
}
}
use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.
the class RQLCriteriaOpalConverter method parseField.
private RQLFieldReferences parseField(String path) {
DatasetVariable.IdResolver resolver = DatasetVariable.IdResolver.from(path);
if (resolver.getType() == null || DatasetVariable.Type.Collected.equals(resolver.getType())) {
StudyDataset ds = collectedDatasetService.findById(resolver.getDatasetId());
BaseStudyTable studyTable = ds.getStudyTable();
BaseStudy study = studyService.findStudy(studyTable.getStudyId());
return new RQLFieldReferences(path, ds, studyTable, study, getDatasetVariableInternal(Indexer.VARIABLE_TYPE, path));
} else if (DatasetVariable.Type.Dataschema.equals(resolver.getType())) {
HarmonizationDataset ds = harmonizedDatasetService.findById(resolver.getDatasetId());
BaseStudy study = studyService.findStudy(ds.getHarmonizationTable().getStudyId());
return new RQLFieldReferences(path, ds, ds.getBaseStudyTables(), study, getDatasetVariableInternal(Indexer.VARIABLE_TYPE, path));
} else if (DatasetVariable.Type.Harmonized.equals(resolver.getType())) {
HarmonizationDataset ds = harmonizedDatasetService.findById(resolver.getDatasetId());
Optional<BaseStudyTable> studyTable = ds.getBaseStudyTables().stream().filter(st -> st.getStudyId().equals(resolver.getStudyId()) && st.getProject().equals(resolver.getProject()) && st.getTable().equals(resolver.getTable())).findFirst();
if (!studyTable.isPresent())
throw new IllegalArgumentException("Not a valid variable: " + path);
BaseStudy study = studyService.findStudy(studyTable.get().getStudyId());
return new RQLFieldReferences(path, ds, studyTable.get(), study, getDatasetVariableInternal(Indexer.HARMONIZED_VARIABLE_TYPE, path));
}
throw new IllegalArgumentException("Not a valid variable: " + path);
}
use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.
the class AbstractPublishedStudyResource method getStudy.
protected BaseStudy getStudy(String id, String locale) {
BaseStudy study = publishedStudyService.findById(id);
if (study == null)
throw NoSuchStudyException.withId(id);
translateModels(locale, study);
log.debug("Study acronym {}", study.getAcronym());
return study;
}
use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.
the class SubjectAclService method studyDeleted.
@Async
@Subscribe
public void studyDeleted(StudyDeletedEvent event) {
BaseStudy persistable = event.getPersistable();
removeInstance(persistable instanceof Study ? "/individual-study" : "/harmonization-study", persistable.getId());
}
use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.
the class NetworkDtos method asDtoBuilder.
@NotNull
Mica.NetworkDto.Builder asDtoBuilder(@NotNull Network network, boolean asDraft) {
Mica.NetworkDto.Builder builder = Mica.NetworkDto.newBuilder();
if (network.hasModel())
builder.setContent(JSONUtils.toJSON(network.getModel()));
//
builder.setId(network.getId()).addAllName(//
localizedStringDtos.asDto(network.getName())).addAllDescription(//
localizedStringDtos.asDto(network.getDescription())).addAllAcronym(localizedStringDtos.asDto(network.getAcronym()));
Mica.PermissionsDto permissionsDto = permissionsDtos.asDto(network);
NetworkState networkState = networkService.getEntityState(network.getId());
builder.setPublished(networkState.isPublished());
if (asDraft) {
//
builder.setTimestamps(TimestampsDtos.asDto(network)).setPublished(//
networkState.isPublished()).setExtension(Mica.EntityStateDto.state, entityStateDtos.asDto(networkState).setPermissions(permissionsDto).build());
}
builder.setPermissions(permissionsDto);
List<String> roles = micaConfigService.getConfig().getRoles();
if (network.getMemberships() != null) {
List<Mica.MembershipsDto> memberships = network.getMemberships().entrySet().stream().filter(e -> roles.contains(e.getKey())).map(e -> Mica.MembershipsDto.newBuilder().setRole(e.getKey()).addAllMembers(e.getValue().stream().map(m -> personDtos.asDto(m.getPerson(), asDraft)).collect(toList())).build()).collect(toList());
builder.addAllMemberships(memberships);
}
List<BaseStudy> publishedStudies = publishedStudyService.findByIds(network.getStudyIds());
Set<String> publishedStudyIds = publishedStudies.stream().map(AbstractGitPersistable::getId).collect(Collectors.toSet());
Sets.SetView<String> unpublishedStudyIds = Sets.difference(ImmutableSet.copyOf(network.getStudyIds().stream().filter(sId -> asDraft && subjectAclService.isPermitted("/draft/individual-study", "VIEW", sId) || subjectAclService.isAccessible("/individual-study", sId)).collect(toList())), publishedStudyIds);
if (!publishedStudies.isEmpty()) {
Map<String, Long> datasetVariableCounts = asDraft ? null : datasetVariableService.getCountByStudyIds(Lists.newArrayList(publishedStudyIds));
publishedStudies.forEach(study -> {
builder.addStudyIds(study.getId());
builder.addStudySummaries(studySummaryDtos.asDtoBuilder(study, true, datasetVariableCounts == null ? 0 : datasetVariableCounts.get(study.getId())));
});
}
unpublishedStudyIds.forEach(studyId -> {
try {
builder.addStudySummaries(studySummaryDtos.asDto(studyId));
builder.addStudyIds(studyId);
} catch (NoSuchEntityException e) {
log.warn("Study not found in network {}: {}", network.getId(), studyId);
// ignore
}
});
if (network.getLogo() != null) {
builder.setLogo(attachmentDtos.asDto(network.getLogo()));
}
network.getNetworkIds().stream().filter(nId -> asDraft && subjectAclService.isPermitted("/draft/network", "VIEW", nId) || subjectAclService.isAccessible("/network", nId)).forEach(nId -> {
try {
builder.addNetworkSummaries(networkSummaryDtos.asDtoBuilder(nId, asDraft));
builder.addNetworkIds(nId);
} catch (NoSuchEntityException e) {
log.warn("Network not found in network {}: {}", network.getId(), nId);
// ignore
}
});
return builder;
}
Aggregations