Search in sources :

Example 1 with DataAccessRequest

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

the class DataAccessRequestService method updateContent.

/**
 * Update the content of the {@link DataAccessRequest} matching the identifier.
 *
 * @param id
 * @param content
 */
public void updateContent(@NotNull String id, String content) {
    DataAccessRequest request = findById(id);
    if (request.getStatus() != DataAccessRequest.Status.OPENED)
        throw new IllegalArgumentException("Data access request content can only be modified when status is draft");
    request.setContent(content);
    save(request);
}
Also used : DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest)

Example 2 with DataAccessRequest

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

the class DataAccessRequestService method delete.

/**
 * Delete the {@link DataAccessRequest} matching the identifier.
 *
 * @param id
 * @throws NoSuchDataAccessRequestException
 */
public void delete(@NotNull String id) throws NoSuchDataAccessRequestException {
    DataAccessRequest dataAccessRequest = findById(id);
    List<Attachment> attachments = dataAccessRequest.getAttachments();
    dataAccessRequestRepository.deleteWithReferences(dataAccessRequest);
    schemaFormContentFileService.deleteFiles(dataAccessRequest);
    attachments.forEach(a -> fileStoreService.delete(a.getId()));
    eventBus.post(new DataAccessRequestDeletedEvent(dataAccessRequest));
}
Also used : DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) Attachment(org.obiba.mica.file.Attachment) DataAccessRequestDeletedEvent(org.obiba.mica.access.event.DataAccessRequestDeletedEvent)

Example 3 with DataAccessRequest

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

the class DataAccessRequestService method getRequestPdf.

public byte[] getRequestPdf(String id, String lang) {
    DataAccessRequest dataAccessRequest = findById(id);
    ByteArrayOutputStream ba = new ByteArrayOutputStream();
    Object content = defaultConfiguration().jsonProvider().parse(dataAccessRequest.getContent());
    try {
        fillPdfTemplateFromRequest(getTemplate(Locale.forLanguageTag(lang)), ba, content);
    } catch (IOException | DocumentException e) {
        throw Throwables.propagate(e);
    }
    return ba.toByteArray();
}
Also used : DocumentException(com.itextpdf.text.DocumentException) DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 4 with DataAccessRequest

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

the class CsvReportGeneratorTest method approvedDataAccessRequest.

private DataAccessRequest approvedDataAccessRequest() {
    DataAccessRequest dataAccessRequest = DataAccessRequest.newBuilder().status(Status.APPROVED.toString()).content("{'title':'Approved request title', 'isWaiting':false}").build();
    dataAccessRequest.setId("approved id");
    dataAccessRequest.setCreatedDate(new DateTime(2016, 8, 20, 14, 36));
    dataAccessRequest.setLastModifiedDate(new DateTime(2015, 8, 25, 14, 36));
    dataAccessRequest.setStatusChangeHistory(asList(StatusChange.newBuilder().changedOn(new DateTime(2017, 1, 1, 1, 1)).current(Status.APPROVED).build(), 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 5 with DataAccessRequest

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

the class DataAccessRequestResource method updateAttachments.

@PUT
@Timed
@Path("/_attachments")
public Response updateAttachments(@PathParam("id") String id, Mica.DataAccessRequestDto dto) {
    subjectAclService.checkPermission("/data-access-request", "VIEW", id);
    if (!id.equals(dto.getId()))
        throw new BadRequestException();
    DataAccessRequest request = dtos.fromDto(dto);
    dataAccessRequestService.saveAttachments(request);
    return Response.noContent().build();
}
Also used : BadRequestException(javax.ws.rs.BadRequestException) DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

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