@GET
  @Path("{documentId}/attachment")
  @Consumes({MediaType.APPLICATION_JSON})
  @Produces({MediaType.APPLICATION_OCTET_STREAM})
  public Response downloadFile(
      @PathParam("entityType") final String entityType,
      @PathParam("entityId") final Long entityId,
      @PathParam("documentId") final Long documentId) {

    this.context.authenticatedUser().validateHasReadPermission(this.SystemEntityType);

    final DocumentData documentData =
        this.documentReadPlatformService.retrieveDocument(entityType, entityId, documentId);
    final File file = new File(documentData.fileLocation());
    final ResponseBuilder response = Response.ok(file);
    response.header(
        "Content-Disposition", "attachment; filename=\"" + documentData.fileName() + "\"");
    response.header("Content-Type", documentData.contentType());

    return response.build();
  }
  @GET
  @Path("{documentId}")
  @Consumes({MediaType.APPLICATION_JSON})
  @Produces({MediaType.APPLICATION_JSON})
  public String getDocument(
      @PathParam("entityType") final String entityType,
      @PathParam("entityId") final Long entityId,
      @PathParam("documentId") final Long documentId,
      @Context final UriInfo uriInfo) {

    this.context.authenticatedUser().validateHasReadPermission(this.SystemEntityType);

    final DocumentData documentData =
        this.documentReadPlatformService.retrieveDocument(entityType, entityId, documentId);

    // we do not want to send document location as a part of the response
    documentData.setLocation(null);

    final ApiRequestJsonSerializationSettings settings =
        this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
    return this.toApiJsonSerializer.serialize(
        settings, documentData, this.RESPONSE_DATA_PARAMETERS);
  }