Search in sources :

Example 11 with DocumentSet

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);
        }
    }
}
Also used : Arrays(java.util.Arrays) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Logger(org.slf4j.Logger) VariableSetService(org.obiba.mica.dataset.service.VariableSetService) Roles(org.obiba.mica.security.Roles) LoggerFactory(org.slf4j.LoggerFactory) HttpServletResponse(javax.servlet.http.HttpServletResponse) UserProfileService(org.obiba.mica.user.UserProfileService) Collectors(java.util.stream.Collectors) HandlerInterceptorAdapter(org.springframework.web.servlet.handler.HandlerInterceptorAdapter) NetworkSetService(org.obiba.mica.network.service.NetworkSetService) SubjectAcl(org.obiba.mica.security.domain.SubjectAcl) Inject(javax.inject.Inject) ModelAndView(org.springframework.web.servlet.ModelAndView) DocumentSet(org.obiba.mica.core.domain.DocumentSet) Component(org.springframework.stereotype.Component) HttpServletRequest(javax.servlet.http.HttpServletRequest) List(java.util.List) Lists(com.google.common.collect.Lists) Subject(org.apache.shiro.subject.Subject) Map(java.util.Map) Cart(org.obiba.mica.web.controller.domain.Cart) SecurityUtils(org.apache.shiro.SecurityUtils) StudySetService(org.obiba.mica.study.service.StudySetService) DocumentSet(org.obiba.mica.core.domain.DocumentSet) Subject(org.apache.shiro.subject.Subject) Cart(org.obiba.mica.web.controller.domain.Cart)

Example 12 with DocumentSet

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);
}
Also used : Async(org.springframework.scheduling.annotation.Async) DocumentSetUpdatedEvent(org.obiba.mica.core.event.DocumentSetUpdatedEvent) DatasetDeletedEvent(org.obiba.mica.dataset.event.DatasetDeletedEvent) Logger(org.slf4j.Logger) DatasetPublishedEvent(org.obiba.mica.dataset.event.DatasetPublishedEvent) DocumentSetDeletedEvent(org.obiba.mica.core.event.DocumentSetDeletedEvent) VariableSetService(org.obiba.mica.dataset.service.VariableSetService) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) LoggerFactory(org.slf4j.LoggerFactory) CollectedDatasetService(org.obiba.mica.dataset.service.CollectedDatasetService) Dataset(org.obiba.mica.dataset.domain.Dataset) Indexer(org.obiba.mica.spi.search.Indexer) DatasetUnpublishedEvent(org.obiba.mica.dataset.event.DatasetUnpublishedEvent) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Inject(javax.inject.Inject) DocumentSet(org.obiba.mica.core.domain.DocumentSet) Component(org.springframework.stereotype.Component) List(java.util.List) Lists(com.google.common.collect.Lists) Map(java.util.Map) Subscribe(com.google.common.eventbus.Subscribe) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) List(java.util.List) DocumentSet(org.obiba.mica.core.domain.DocumentSet) Async(org.springframework.scheduling.annotation.Async) Subscribe(com.google.common.eventbus.Subscribe)

Example 13 with DocumentSet

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);
}
Also used : Async(org.springframework.scheduling.annotation.Async) DocumentSetUpdatedEvent(org.obiba.mica.core.event.DocumentSetUpdatedEvent) PersonService(org.obiba.mica.core.service.PersonService) Logger(org.slf4j.Logger) DocumentSetDeletedEvent(org.obiba.mica.core.event.DocumentSetDeletedEvent) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Indexable(org.obiba.mica.spi.search.Indexable) LoggerFactory(org.slf4j.LoggerFactory) Membership(org.obiba.mica.core.domain.Membership) StudyService(org.obiba.mica.study.service.StudyService) Indexer(org.obiba.mica.spi.search.Indexer) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) DocumentSet(org.obiba.mica.core.domain.DocumentSet) Component(org.springframework.stereotype.Component) List(java.util.List) Lists(com.google.common.collect.Lists) Map(java.util.Map) Subscribe(com.google.common.eventbus.Subscribe) org.obiba.mica.study.event(org.obiba.mica.study.event) StudySetService(org.obiba.mica.study.service.StudySetService) List(java.util.List) DocumentSet(org.obiba.mica.core.domain.DocumentSet) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Async(org.springframework.scheduling.annotation.Async) Subscribe(com.google.common.eventbus.Subscribe)

Example 14 with DocumentSet

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);
}
Also used : MicaSearch(org.obiba.mica.web.model.MicaSearch) DocumentSet(org.obiba.mica.core.domain.DocumentSet) Mica(org.obiba.mica.web.model.Mica)

Example 15 with DocumentSet

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();
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) DocumentSet(org.obiba.mica.core.domain.DocumentSet)

Aggregations

DocumentSet (org.obiba.mica.core.domain.DocumentSet)35 Lists (com.google.common.collect.Lists)7 List (java.util.List)7 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 Inject (javax.inject.Inject)6 StreamingOutput (javax.ws.rs.core.StreamingOutput)5 VariableSetService (org.obiba.mica.dataset.service.VariableSetService)5 Mica (org.obiba.mica.web.model.Mica)5 MicaSearch (org.obiba.mica.web.model.MicaSearch)5 Component (org.springframework.stereotype.Component)5 Subscribe (com.google.common.eventbus.Subscribe)4 ForbiddenException (javax.ws.rs.ForbiddenException)4 Strings (com.google.common.base.Strings)3 SecurityUtils (org.apache.shiro.SecurityUtils)3 AuthorizationException (org.apache.shiro.authz.AuthorizationException)3 Subject (org.apache.shiro.subject.Subject)3 DocumentSetUpdatedEvent (org.obiba.mica.core.event.DocumentSetUpdatedEvent)3 ReportGenerator (org.obiba.mica.search.reports.ReportGenerator)3 Logger (org.slf4j.Logger)3