コード例 #1
0
  @POST
  @Consumes({MediaType.MULTIPART_FORM_DATA})
  @Produces({MediaType.APPLICATION_JSON})
  public String createDocument(
      @PathParam("entityType") final String entityType,
      @PathParam("entityId") final Long entityId,
      @HeaderParam("Content-Length") final Long fileSize,
      @FormDataParam("file") final InputStream inputStream,
      @FormDataParam("file") final FormDataContentDisposition fileDetails,
      @FormDataParam("file") final FormDataBodyPart bodyPart,
      @FormDataParam("name") final String name,
      @FormDataParam("description") final String description) {

    FileUtils.validateFileSizeWithinPermissibleRange(
        fileSize, name, ApiConstants.MAX_FILE_UPLOAD_SIZE_IN_MB);

    /**
     * TODO: also need to have a backup and stop reading from stream after max size is reached to
     * protect against malicious clients
     */

    /** TODO: need to extract the actual file type and determine if they are permissable */
    final DocumentCommand documentCommand =
        new DocumentCommand(
            null,
            null,
            entityType,
            entityId,
            name,
            fileDetails.getFileName(),
            fileSize,
            bodyPart.getMediaType().toString(),
            description,
            null);

    final Long documentId =
        this.documentWritePlatformService.createDocument(documentCommand, inputStream);

    return this.toApiJsonSerializer.serialize(
        CommandProcessingResult.resourceResult(documentId, null));
  }
コード例 #2
0
  @POST
  @Path("{ticketId}/attachment")
  @Consumes({MediaType.MULTIPART_FORM_DATA})
  @Produces({MediaType.APPLICATION_JSON})
  public String addTicketDetails(
      @PathParam("ticketId") Long ticketId,
      @PathParam("entityType") String entityType,
      @PathParam("entityId") Long entityId,
      @HeaderParam("Content-Length") Long fileSize,
      @FormDataParam("file") InputStream inputStream,
      @FormDataParam("file") FormDataContentDisposition fileDetails,
      @FormDataParam("file") FormDataBodyPart bodyPart,
      @FormDataParam("comments") String comments,
      @FormDataParam("status") String status,
      @FormDataParam("assignedTo") Long assignedTo,
      @FormDataParam("ticketURL") String ticketURL,
      @FormDataParam("problemCode") Integer problemCode,
      @FormDataParam("priority") String priority,
      @FormDataParam("resolutionDescription") String resolutionDescription,
      @FormDataParam("username") String username) {

    FileUtils.validateFileSizeWithinPermissibleRange(
        fileSize, null, ApiConstants.MAX_FILE_UPLOAD_SIZE_IN_MB);

    /**
     * TODO: also need to have a backup and stop reading from stream after max size is reached to
     * protect against malicious clients
     */

    /** TODO: need to extract the actual file type and determine if they are permissable */
    Long createdbyId = context.authenticatedUser().getId();
    TicketMasterCommand ticketMasterCommand =
        new TicketMasterCommand(
            ticketId,
            comments,
            status,
            assignedTo,
            createdbyId,
            null,
            problemCode,
            priority,
            resolutionDescription,
            username);
    DocumentCommand documentCommand = null;
    if (fileDetails != null && bodyPart != null) {
      documentCommand =
          new DocumentCommand(
              null,
              null,
              entityType,
              entityId,
              null,
              fileDetails.getFileName(),
              fileSize,
              bodyPart.getMediaType().toString(),
              null,
              null);
    } else {
      documentCommand =
          new DocumentCommand(
              null, null, entityType, entityId, null, null, fileSize, null, null, null);
    }

    Long detailId =
        this.ticketMasterWritePlatformService.upDateTicketDetails(
            ticketMasterCommand, documentCommand, ticketId, inputStream, ticketURL);

    return this.toApiJsonSerializer.serialize(
        CommandProcessingResult.resourceResult(detailId, null));
  }
コード例 #3
0
  @PUT
  @Path("{documentId}")
  @Consumes({MediaType.MULTIPART_FORM_DATA})
  @Produces({MediaType.APPLICATION_JSON})
  public String updateDocument(
      @PathParam("entityType") final String entityType,
      @PathParam("entityId") final Long entityId,
      @PathParam("documentId") final Long documentId,
      @HeaderParam("Content-Length") final Long fileSize,
      @FormDataParam("file") final InputStream inputStream,
      @FormDataParam("file") final FormDataContentDisposition fileDetails,
      @FormDataParam("file") final FormDataBodyPart bodyPart,
      @FormDataParam("name") final String name,
      @FormDataParam("description") final String description) {

    FileUtils.validateFileSizeWithinPermissibleRange(
        fileSize, name, ApiConstants.MAX_FILE_UPLOAD_SIZE_IN_MB);

    final Set<String> modifiedParams = new HashSet<String>();
    modifiedParams.add("name");
    modifiedParams.add("description");

    /**
     * * Populate Document command based on whether a file has also been passed in as a part of the
     * update *
     */
    DocumentCommand documentCommand = null;
    if (inputStream != null && fileDetails.getFileName() != null) {
      modifiedParams.add("fileName");
      modifiedParams.add("size");
      modifiedParams.add("type");
      modifiedParams.add("location");
      documentCommand =
          new DocumentCommand(
              modifiedParams,
              documentId,
              entityType,
              entityId,
              name,
              fileDetails.getFileName(),
              fileSize,
              bodyPart.getMediaType().toString(),
              description,
              null);
    } else {
      documentCommand =
          new DocumentCommand(
              modifiedParams,
              documentId,
              entityType,
              entityId,
              name,
              null,
              null,
              null,
              description,
              null);
    }
    /** * TODO: does not return list of changes, should be done for consistency with rest of API */
    final CommandProcessingResult identifier =
        this.documentWritePlatformService.updateDocument(documentCommand, inputStream);

    return this.toApiJsonSerializer.serialize(identifier);
  }