use of org.obiba.mica.core.domain.DocumentSet in project mica2 by obiba.
the class SessionInterceptor method populateUserEntries.
public static void populateUserEntries(ModelAndView modelAndView, UserProfileService userProfileService, VariableSetService variableSetService, StudySetService studySetService, NetworkSetService networkSetService, SubjectAclService subjectAclService) {
Subject subject = SecurityUtils.getSubject();
if (subject.isAuthenticated()) {
String username = subject.getPrincipal().toString();
try {
Map<String, Object> params = userProfileService.getProfileMap(username, true);
List<String> roles = Lists.newArrayList(Roles.MICA_ADMIN, Roles.MICA_REVIEWER, Roles.MICA_EDITOR, Roles.MICA_DAO, Roles.MICA_USER);
boolean[] result = subject.hasRoles(roles);
for (int i = result.length - 1; i >= 0; i--) {
if (!result[i])
roles.remove(i);
}
params.put("roles", roles);
params.put("hasPermissionOnAnyDraftDocument", subjectAclService.findBySubject(subject.getPrincipal().toString(), SubjectAcl.Type.USER).stream().anyMatch(acl -> Arrays.stream(ALL_DRAFT_RESOURCES).anyMatch(res -> res.equals(acl.getResource()))));
params.put("variablesCart", new Cart(variableSetService.getCartCurrentUser()));
params.put("variablesLists", variableSetService.getAllCurrentUser().stream().filter(DocumentSet::hasName).collect(Collectors.toList()));
params.put("studiesCart", new Cart(studySetService.getCartCurrentUser()));
params.put("networksCart", new Cart(networkSetService.getCartCurrentUser()));
modelAndView.getModel().put("user", params);
} catch (Exception e) {
log.warn("Cannot retrieve profile of user {}", username, e);
}
}
}
use of org.obiba.mica.core.domain.DocumentSet in project mica2 by obiba.
the class VariableIndexer method documentSetDeleted.
@Async
@Subscribe
public synchronized void documentSetDeleted(DocumentSetDeletedEvent event) {
if (!variableSetService.isForType(event.getPersistable()))
return;
DocumentSet documentSet = event.getPersistable();
List<DatasetVariable> toIndex = Lists.newArrayList();
{
List<DatasetVariable> toRemove = variableSetService.getVariables(event.getPersistable(), false);
toRemove.forEach(var -> var.removeSet(documentSet.getId()));
toIndex.addAll(toRemove);
}
indexer.indexAllIndexables(Indexer.PUBLISHED_VARIABLE_INDEX, toIndex);
}
use of org.obiba.mica.core.domain.DocumentSet in project mica2 by obiba.
the class StudyIndexer method documentSetDeleted.
@Async
@Subscribe
public synchronized void documentSetDeleted(DocumentSetDeletedEvent event) {
if (!studySetService.isForType(event.getPersistable()))
return;
DocumentSet documentSet = event.getPersistable();
List<BaseStudy> toIndex = Lists.newArrayList();
{
List<BaseStudy> toRemove = studySetService.getPublishedStudies(event.getPersistable(), false);
toRemove.forEach(std -> std.removeSet(documentSet.getId()));
toIndex.addAll(toRemove);
}
indexer.indexAllIndexables(Indexer.PUBLISHED_STUDY_INDEX, toIndex);
}
use of org.obiba.mica.core.domain.DocumentSet in project mica2 by obiba.
the class PublishedDatasetVariablesSetResource method importQueryDocuments.
private Mica.DocumentSetDto importQueryDocuments(String id, String query) {
DocumentSet set = getSecuredDocumentSet(id);
if (Strings.isNullOrEmpty(query))
return dtos.asDto(set);
MicaSearch.JoinQueryResultDto result = makeQuery(QueryType.VARIABLE, query);
if (result.hasVariableResultDto() && result.getVariableResultDto().getTotalHits() > 0) {
List<String> ids = result.getVariableResultDto().getExtension(MicaSearch.DatasetVariableResultDto.result).getSummariesList().stream().map(Mica.DatasetVariableResolverDto::getId).collect(Collectors.toList());
getDocumentSetService().addIdentifiers(id, ids);
set = getSecuredDocumentSet(id);
}
return dtos.asDto(set);
}
use of org.obiba.mica.core.domain.DocumentSet in project mica2 by obiba.
the class DataAccessEntityResource method submit.
protected Response submit(String id) {
T request = getService().findById(id);
boolean fromOpened = request.getStatus() == DataAccessEntityStatus.OPENED;
boolean fromConditionallyApproved = request.getStatus() == DataAccessEntityStatus.CONDITIONALLY_APPROVED;
if (fromOpened && !subjectAclService.isCurrentUser(request.getApplicant()) && !SecurityUtils.getSubject().hasRole(Roles.MICA_ADMIN)) {
// only applicant can submit an opened request
throw new ForbiddenException();
}
getService().updateStatus(id, DataAccessEntityStatus.SUBMITTED);
if (fromOpened || fromConditionallyApproved) {
restoreDaoActions(id);
}
if (request.hasVariablesSet()) {
DocumentSet set = request.getVariablesSet();
variableSetService.setLock(set, true);
}
// link to latest form revision
request = getService().findById(id);
request.setFormRevision(getFormLatestRevision());
getService().save(request);
return Response.noContent().build();
}
Aggregations