Interface ModelAttachment

All Known Implementing Classes:
Attachment

public interface ModelAttachment
Represents a document which can be attached to a Model. To write an attachment, instantiate the ModelAttachment using AttachmentService, set meta-data properties like description and filename, stream the attachment payload, then add it the ModelAttachment owning Model and write it using ModelDataService:
 ModelAttachment attch = Services.get(AttachmentService.class).newAttachment();
 attch.setDescription("New York Times review");
 attch.setFileName("NewYorkTimesReview.doc");
 InputStream in = new FileInputStream("NewYorkTimesReview.doc");
 attch.writePayload(in);
 
 // Assume "Book" is an SDK model with a field "Review" of type Attachment
 Book book = new Book();
 book.setTitle("To Kill a Mockingbird");
 book.getReviews().add(attch);
 ModelList<Book> modelList = new ModelList<Book>("ZBKS.Create", book);
 modelDataService.write(modelList, userContext);
 
ModelAttachments are typically read from the database by reading the parent:
 Book book = modelDataService.readById(Book.class, bookId, userContext);
 InputStream in = book.getReviews().get(0).readPayload();
 // input stream can be read to fetch attachment payload content
 
  • Method Summary

    Modifier and Type Method Description
    java.lang.String getFileName()
    Returns the user-displayed filename for the attachment
    java.lang.String getFilePath()
    Returns the internal location of the Attachment in the document store
    void markForDelete​(boolean mark)
    Marks this Attachment for deletion for the next call to Model.write().
    void parseFromJson​(org.json.JSONObject json)
    Converts a Json to an Attachment representation and updates the object itself.(This does not include the payload.)
    java.io.InputStream readPayload()
    Returns the InputStream of attachment document
    void setDescription​(java.lang.String value)
    Set the description on the attachment
    void setEnterpriseName​(java.lang.String value)
    Set the owning enterprise of the attachment
    void setFileName​(java.lang.String value)
    Sets the user-displayed filename for the attachment
    void setValueChainId​(long value)
    Set the value chain id of the attachment
    org.json.JSONObject toJSON()
    Returns a JSON representation of this Attachment.
    default org.json.JSONObject toJSON​(PlatformUserProfile profile)
    Returns a JSON representation of this Attachment.
    java.lang.String writePayload​(java.io.InputStream content)
    Writes the contents of the attachment and returns the attachment path in document storage.
  • Method Details

    • setValueChainId

      void setValueChainId​(long value)
      Set the value chain id of the attachment
      Parameters:
      value - value chain id of the attachment
    • setEnterpriseName

      void setEnterpriseName​(java.lang.String value)
      Set the owning enterprise of the attachment
      Parameters:
      value - owning enterprise of the attachment
    • setDescription

      void setDescription​(java.lang.String value)
      Set the description on the attachment
      Parameters:
      value - description on the attachment
    • toJSON

      org.json.JSONObject toJSON()
      Returns a JSON representation of this Attachment. (This does not include the payload.)
    • toJSON

      default org.json.JSONObject toJSON​(PlatformUserProfile profile)
      Returns a JSON representation of this Attachment. Will consult the given user profile for Date and other localized formats.
      Parameters:
      profile - user profile, from which localized date format and other information is taken
    • parseFromJson

      void parseFromJson​(org.json.JSONObject json)
      Converts a Json to an Attachment representation and updates the object itself.(This does not include the payload.)
      Parameters:
      json - json object
    • markForDelete

      void markForDelete​(boolean mark)
      Marks this Attachment for deletion for the next call to Model.write().
      Parameters:
      mark - whether to delete
    • getFileName

      java.lang.String getFileName()
      Returns the user-displayed filename for the attachment
    • setFileName

      void setFileName​(java.lang.String value)
      Sets the user-displayed filename for the attachment
      Parameters:
      value - user-displayed filename for the attachment
    • getFilePath

      java.lang.String getFilePath()
      Returns the internal location of the Attachment in the document store
    • writePayload

      java.lang.String writePayload​(java.io.InputStream content)
      Writes the contents of the attachment and returns the attachment path in document storage.
    • readPayload

      java.io.InputStream readPayload()
      Returns the InputStream of attachment document