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();
}
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();
}
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()));
}
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;
}
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;
}
Aggregations