Search in sources :

Example 21 with DataAccessRequest

use of org.obiba.mica.access.domain.DataAccessRequest in project mica2 by obiba.

the class DataAccessRequestsResource method exportCsv.

@GET
@Timed
@Path("/csv")
@Produces("text/csv")
public Response exportCsv(@QueryParam("lang") String lang) {
    List<DataAccessRequest> dataAccessRequests = listByStatusFilteringPermitted(null);
    DataAccessForm dataAccessForm = dataAccessFormService.find().get();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    new CsvReportGenerator(dataAccessRequests, dataAccessForm.getCsvExportFormat(), lang).write(byteArrayOutputStream);
    String date = new DateTime().toString("YYYY-MM-dd");
    return Response.ok(byteArrayOutputStream.toByteArray()).header("Content-Disposition", String.format("attachment; filename=\"Access-Requests-Report_%s.csv\"", date)).build();
}
Also used : DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) DataAccessForm(org.obiba.mica.micaConfig.domain.DataAccessForm) DateTime(org.joda.time.DateTime) Timed(com.codahale.metrics.annotation.Timed)

Example 22 with DataAccessRequest

use of org.obiba.mica.access.domain.DataAccessRequest in project mica2 by obiba.

the class DataAccessRequestsResource method create.

@POST
@Timed
@RequiresPermissions("/data-access-request:ADD")
public Response create(Mica.DataAccessRequestDto dto, @Context UriInfo uriInfo) {
    DataAccessRequest request = dtos.fromDto(dto);
    // force applicant and make sure it is a new request
    String applicant = SecurityUtils.getSubject().getPrincipal().toString();
    request.setApplicant(applicant);
    request.setId(null);
    request.setStatus(DataAccessRequest.Status.OPENED);
    dataAccessRequestService.save(request);
    subjectAclService.addPermission("/data-access-request", "VIEW,EDIT,DELETE", request.getId());
    subjectAclService.addPermission("/data-access-request/" + request.getId(), "EDIT", "_status");
    subjectAclService.addPermission("/data-access-request/" + request.getId() + "/_attachments", "EDIT");
    subjectAclService.addGroupPermission(Roles.MICA_DAO, "/data-access-request/" + request.getId() + "/_attachments", "EDIT", null);
    return Response.created(uriInfo.getBaseUriBuilder().segment("data-access-request", request.getId()).build()).build();
}
Also used : DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Timed(com.codahale.metrics.annotation.Timed)

Example 23 with DataAccessRequest

use of org.obiba.mica.access.domain.DataAccessRequest in project mica2 by obiba.

the class CsvReportGeneratorTest method can_generate_report.

@Test
public void can_generate_report() throws IOException {
    String csvSchema = givenValidCsvSchema();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    List<DataAccessRequest> dataAccessRequest = new ArrayList<>();
    dataAccessRequest.add(openedDataAccessRequest());
    dataAccessRequest.add(submittedDataAccessRequest());
    dataAccessRequest.add(approvedDataAccessRequest());
    new CsvReportGenerator(dataAccessRequest, csvSchema, "fr").write(byteArrayOutputStream);
    assertThat(byteArrayOutputStream.toString(), is(expectedResult()));
}
Also used : ArrayList(java.util.ArrayList) DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 24 with DataAccessRequest

use of org.obiba.mica.access.domain.DataAccessRequest in project mica2 by obiba.

the class CsvReportGeneratorTest method submittedDataAccessRequest.

private DataAccessRequest submittedDataAccessRequest() {
    DataAccessRequest dataAccessRequest = DataAccessRequest.newBuilder().status(Status.SUBMITTED.toString()).content("{'title':'Opened request title', 'isWaiting':true}").build();
    dataAccessRequest.setId("refused id");
    dataAccessRequest.setCreatedDate(new DateTime(2016, 8, 20, 14, 36));
    dataAccessRequest.setLastModifiedDate(new DateTime(2016, 8, 25, 14, 36));
    dataAccessRequest.setStatusChangeHistory(Collections.singletonList(StatusChange.newBuilder().changedOn(new DateTime(2016, 6, 1, 1, 1)).current(Status.SUBMITTED).build()));
    return dataAccessRequest;
}
Also used : DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) DateTime(org.joda.time.DateTime)

Example 25 with DataAccessRequest

use of org.obiba.mica.access.domain.DataAccessRequest in project mica2 by obiba.

the class CsvReportGeneratorTest method openedDataAccessRequest.

private DataAccessRequest openedDataAccessRequest() {
    DataAccessRequest dataAccessRequest = DataAccessRequest.newBuilder().status(Status.OPENED.toString()).content("{'title':'Opened request title'}").build();
    dataAccessRequest.setId("refused id");
    dataAccessRequest.setCreatedDate(new DateTime(2016, 8, 20, 14, 36));
    dataAccessRequest.setLastModifiedDate(new DateTime(2016, 8, 25, 14, 36));
    dataAccessRequest.setStatusChangeHistory(Collections.singletonList(StatusChange.newBuilder().changedOn(new DateTime(2016, 6, 1, 1, 1)).current(Status.SUBMITTED).build()));
    return dataAccessRequest;
}
Also used : DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) DateTime(org.joda.time.DateTime)

Aggregations

DataAccessRequest (org.obiba.mica.access.domain.DataAccessRequest)25 Timed (com.codahale.metrics.annotation.Timed)6 DateTime (org.joda.time.DateTime)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 Map (java.util.Map)3 NotNull (javax.validation.constraints.NotNull)3 BadRequestException (javax.ws.rs.BadRequestException)3 Attachment (org.obiba.mica.file.Attachment)3 DataAccessForm (org.obiba.mica.micaConfig.domain.DataAccessForm)3 Strings (com.google.common.base.Strings)2 EventBus (com.google.common.eventbus.EventBus)2 DocumentException (com.itextpdf.text.DocumentException)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 ForbiddenException (javax.ws.rs.ForbiddenException)2 PUT (javax.ws.rs.PUT)2 SecurityUtils (org.apache.shiro.SecurityUtils)2 NoSuchDataAccessRequestException (org.obiba.mica.access.NoSuchDataAccessRequestException)2