Search in sources :

Example 6 with DocumentSet

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

the class PublishedNetworksSetResource method reportNetworks.

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

Example 7 with DocumentSet

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

the class AbstractPublishedDocumentsSetResource method getDocumentSet.

protected Mica.DocumentSetDto getDocumentSet(String id) {
    DocumentSet documentSet = getSecuredDocumentSet(id);
    getDocumentSetService().touch(documentSet);
    return dtos.asDto(documentSet);
}
Also used : DocumentSet(org.obiba.mica.core.domain.DocumentSet)

Example 8 with DocumentSet

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

the class AbstractPublishedDocumentsSetResource method getSecuredDocumentSet.

protected DocumentSet getSecuredDocumentSet(String id) {
    DocumentSet documentSet = getDocumentSetService().get(id);
    if (!subjectAclService.isCurrentUser(documentSet.getUsername()) && !subjectAclService.isAdministrator() && !subjectAclService.isDataAccessOfficer())
        throw new AuthorizationException();
    boolean enabled = isCartEnabled(micaConfigService.getConfig());
    // cart
    if (!enabled && !documentSet.hasName())
        throw new AuthorizationException();
    if (enabled && !subjectAclService.hasMicaRole() && !documentSet.hasName())
        // cart
        throw new AuthorizationException();
    if (documentSet.hasName() && !subjectAclService.hasMicaRole())
        throw new AuthorizationException();
    getDocumentSetService().touch(documentSet);
    return documentSet;
}
Also used : AuthorizationException(org.apache.shiro.authz.AuthorizationException) DocumentSet(org.obiba.mica.core.domain.DocumentSet)

Example 9 with DocumentSet

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

the class AbstractPublishedDocumentsSetResource method exportDocuments.

protected StreamingOutput exportDocuments(String id) {
    DocumentSet documentSet = getSecuredDocumentSet(id);
    getDocumentSetService().touch(documentSet);
    return toStream(documentSet.getIdentifiers());
}
Also used : DocumentSet(org.obiba.mica.core.domain.DocumentSet)

Example 10 with DocumentSet

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

the class AbstractPublishedDocumentsSetResource method importDocuments.

protected Mica.DocumentSetDto importDocuments(String id, String body) {
    DocumentSet set = getSecuredDocumentSet(id);
    if (Strings.isNullOrEmpty(body))
        return dtos.asDto(set);
    getDocumentSetService().addIdentifiers(id, getDocumentSetService().extractIdentifiers(body));
    return dtos.asDto(getDocumentSetService().get(id));
}
Also used : 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