Search in sources :

Example 26 with DocumentSet

use of org.obiba.mica.core.domain.DocumentSet in project mica2 by obiba.

the class DataAccessEntityResource method createOrUpdateVariablesSet.

// 
// Private methods
// 
/**
 * Create or update a variables set from user's cart.
 *
 * @param entity
 * @return
 */
protected DocumentSet createOrUpdateVariablesSet(DataAccessEntity entity) {
    DocumentSet set;
    DocumentSet cart = variableSetService.getCartCurrentUser();
    String setId = String.format("dar:%s", entity.getId());
    Optional<DocumentSet> setOpt = variableSetService.getAllCurrentUser().stream().filter(docset -> setId.equals(docset.getName())).findFirst();
    if (setOpt.isPresent()) {
        // reuse and append an existing set with same name
        set = variableSetService.addIdentifiers(setId, Lists.newArrayList(cart.getIdentifiers()));
    } else {
        // create a new one
        set = variableSetService.create(setId, Lists.newArrayList(cart.getIdentifiers()));
    }
    // case an administrator is by-passing the flow
    if (!DataAccessEntityStatus.OPENED.equals(entity.getStatus())) {
        variableSetService.setLock(set, true);
    }
    return set;
}
Also used : SubjectAclService(org.obiba.mica.security.service.SubjectAclService) ForbiddenException(javax.ws.rs.ForbiddenException) VariableSetService(org.obiba.mica.dataset.service.VariableSetService) DataAccessConfigUpdatedEvent(org.obiba.mica.micaConfig.event.DataAccessConfigUpdatedEvent) Roles(org.obiba.mica.security.Roles) DataAccessEntity(org.obiba.mica.access.domain.DataAccessEntity) Collectors(java.util.stream.Collectors) DataAccessEntityService(org.obiba.mica.access.service.DataAccessEntityService) FileStoreService(org.obiba.mica.file.FileStoreService) DocumentSet(org.obiba.mica.core.domain.DocumentSet) List(java.util.List) Lists(com.google.common.collect.Lists) Stream(java.util.stream.Stream) DataAccessEntityStatus(org.obiba.mica.access.domain.DataAccessEntityStatus) Response(javax.ws.rs.core.Response) DataAccessConfigService(org.obiba.mica.micaConfig.service.DataAccessConfigService) Optional(java.util.Optional) Subscribe(com.google.common.eventbus.Subscribe) BadRequestException(javax.ws.rs.BadRequestException) SecurityUtils(org.apache.shiro.SecurityUtils) DocumentSet(org.obiba.mica.core.domain.DocumentSet)

Example 27 with DocumentSet

use of org.obiba.mica.core.domain.DocumentSet in project mica2 by obiba.

the class PublishedStudiesSetResource method reportStudies.

@GET
@Path("/documents/_report")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response reportStudies(@PathParam("id") String id, @QueryParam("locale") @DefaultValue("en") String locale) {
    DocumentSet documentSet = getSecuredDocumentSet(id);
    ReportGenerator reporter = new StudyCsvReportGenerator(studySetService.getPublishedStudies(documentSet, true), locale, personService);
    StreamingOutput stream = reporter::write;
    return Response.ok(stream).header("Content-Disposition", "attachment; filename=\"Studies.zip\"").build();
}
Also used : StudyCsvReportGenerator(org.obiba.mica.search.reports.generators.StudyCsvReportGenerator) ReportGenerator(org.obiba.mica.search.reports.ReportGenerator) StreamingOutput(javax.ws.rs.core.StreamingOutput) DocumentSet(org.obiba.mica.core.domain.DocumentSet) StudyCsvReportGenerator(org.obiba.mica.search.reports.generators.StudyCsvReportGenerator)

Example 28 with DocumentSet

use of org.obiba.mica.core.domain.DocumentSet in project mica2 by obiba.

the class PublishedStudiesSetResource 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.STUDY, query);
    if (result.hasStudyResultDto() && result.getStudyResultDto().getTotalHits() > 0) {
        List<String> ids = result.getStudyResultDto().getExtension(MicaSearch.StudyResultDto.result).getSummariesList().stream().map(Mica.StudySummaryDto::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 29 with DocumentSet

use of org.obiba.mica.core.domain.DocumentSet in project mica2 by obiba.

the class PublishedDatasetVariablesSetResource method reportVariables.

@GET
@Path("/documents/_report")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response reportVariables(@PathParam("id") String id, @QueryParam("locale") @DefaultValue("en") String locale) {
    DocumentSet documentSet = getSecuredDocumentSet(id);
    ReportGenerator reporter = new DatasetVariableCsvReportGenerator(variableSetService.getVariables(documentSet, false), locale);
    StreamingOutput stream = reporter::write;
    return Response.ok(stream).header("Content-Disposition", "attachment; filename=\"Variables.zip\"").build();
}
Also used : DatasetVariableCsvReportGenerator(org.obiba.mica.search.reports.generators.DatasetVariableCsvReportGenerator) DatasetVariableCsvReportGenerator(org.obiba.mica.search.reports.generators.DatasetVariableCsvReportGenerator) ReportGenerator(org.obiba.mica.search.reports.ReportGenerator) StreamingOutput(javax.ws.rs.core.StreamingOutput) DocumentSet(org.obiba.mica.core.domain.DocumentSet)

Example 30 with DocumentSet

use of org.obiba.mica.core.domain.DocumentSet in project mica2 by obiba.

the class PublishedDatasetVariablesSetResource method createOpalViewsGet.

@GET
@Path("/documents/_opal")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response createOpalViewsGet(@PathParam("id") String id, @QueryParam("ids") String identifiers) {
    DocumentSet set = getSecuredDocumentSet(id);
    if (!subjectAclService.isAdministrator() && !subjectAclService.isDataAccessOfficer())
        throw new AuthorizationException();
    StreamingOutput streamingOutput;
    if (!Strings.isNullOrEmpty(identifiers)) {
        streamingOutput = stream -> variableSetService.createOpalViewsZip(variableSetService.getVariables(Sets.newHashSet(identifiers.split(","))), micaConfigService.getConfig().getOpalViewsGrouping(), new BufferedOutputStream(stream));
    } else {
        streamingOutput = stream -> variableSetService.createOpalViewsZip(variableSetService.getVariables(set), micaConfigService.getConfig().getOpalViewsGrouping(), new BufferedOutputStream(stream));
    }
    return Response.ok(streamingOutput, MediaType.APPLICATION_OCTET_STREAM).header("Content-Disposition", "attachment; filename=\"opal-views-" + id + ".zip\"").build();
}
Also used : AuthorizationException(org.apache.shiro.authz.AuthorizationException) StreamingOutput(javax.ws.rs.core.StreamingOutput) DocumentSet(org.obiba.mica.core.domain.DocumentSet) BufferedOutputStream(java.io.BufferedOutputStream)

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