use of org.obiba.mica.study.domain.Study in project mica2 by obiba.
the class StudySeedService method importStudy.
/**
* Import a Study from a jackson file.
*
* @param json
*/
private void importStudy(File json) throws IOException {
log.info("Seeding study with file: {}", json.getAbsolutePath());
InputStream inputStream = new FileInputStream(json);
Study study = objectMapper.readValue(inputStream, Study.class);
individualStudyService.save(study);
individualStudyService.publish(study.getId(), true);
}
use of org.obiba.mica.study.domain.Study 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.Study in project mica2 by obiba.
the class IndividualStudyService method getPotentialConflicts.
public Map<String, List<String>> getPotentialConflicts(Study study, boolean publishing) {
if (study.getId() != null) {
Study oldStudy = publishing ? study : studyRepository.findOne(study.getId());
if (oldStudy != null) {
List<String> dceUIDs = publishing ? toListOfDceUids(study, true) : populationsOrDceAffected(study, oldStudy, true);
if (dceUIDs != null) {
List<String> studyDatasetIds = findStudyDatasetDependencies(dceUIDs);
List<String> harmoDatasetIds = findHarmonizedDatasetDependencies(dceUIDs);
List<String> networkIds = networkRepository.findByStudyIds(study.getId()).stream().map(AbstractGitPersistable::getId).collect(toList());
if (!harmoDatasetIds.isEmpty() || !studyDatasetIds.isEmpty() || !networkIds.isEmpty()) {
return new HashMap<String, List<String>>() {
{
put("harmonizationDataset", harmoDatasetIds);
put("studyDataset", studyDatasetIds);
put("network", networkIds);
}
};
}
}
}
}
return null;
}
use of org.obiba.mica.study.domain.Study in project mica2 by obiba.
the class IndividualStudyService method getFromCommit.
@Override
public Study getFromCommit(@NotNull Study study, @NotNull String commitId) {
String studyBlob = gitService.getBlob(study, commitId, Study.class);
InputStream inputStream = new ByteArrayInputStream(studyBlob.getBytes(StandardCharsets.UTF_8));
Study restoredStudy;
try {
restoredStudy = objectMapper.readValue(inputStream, Study.class);
} catch (IOException e) {
throw Throwables.propagate(e);
}
return restoredStudy;
}
use of org.obiba.mica.study.domain.Study 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