Class ReprintableDocumentManager


  • @ApplicationScoped
    public class ReprintableDocumentManager
    extends Object
    Centralizes the ReprintableDocument Management. Any action to manage reprintable documents in Openbravo should be done through this class.
    • Constructor Detail

      • ReprintableDocumentManager

        public ReprintableDocumentManager()
    • Method Detail

      • upload

        public ReprintableDocument upload​(org.codehaus.jettison.json.JSONObject document)
                                   throws org.codehaus.jettison.json.JSONException
        Creates a new ReprintableDocument and uploads its data as an attachment using the attachment method of the configuration for "Reprintable Documents" defined for the current session client. If such configuration does not exist for the current client then the one defined at system level is used. And if no attachment configuration is found at all, then the {#link AttachmentUtils#DEFAULT_METHOD} method is used by default. Important Note: this method flushes the current transaction when creating the ReprintableDocument record in order to trigger the unique constraint checks because in case the record cannot be saved, this method should not continue doing the attachment upload in order to avoid creating attachments not linked to any record.
        Parameters:
        document - A JSONObject containing the properties documentData (string containing the report), documentId (the ticket id), documentType (ORDER or INVOICE) and documentFormat (XML or PDF).
        Returns:
        the newly created ReprintableDocument
        Throws:
        org.codehaus.jettison.json.JSONException - if it is not possible to find a required property inside the document parameter
      • upload

        public ReprintableDocument upload​(InputStream documentData,
                                          ReprintableDocumentManager.Format format,
                                          ReprintableSourceDocument<?> sourceDocument)
        Creates a new ReprintableDocument and uploads its data as an attachment using the attachment method of the configuration for "Reprintable Documents" defined for the current session client. If such configuration does not exist for the current client then the one defined at system level is used. And if no attachment configuration is found at all, then the {#link AttachmentUtils#DEFAULT_METHOD} method is used by default. Important Note: this method flushes the current transaction when creating the ReprintableDocument record in order to trigger the unique constraint checks because in case the record cannot be saved, this method should not continue doing the attachment upload in order to avoid creating attachments not linked to any record.
        Parameters:
        documentData - An InputStream with the document data. This method is in charge of closing it when finish its execution.
        format - The format of document
        sourceDocument - The document used as source data for the ReprintableDocument
        Returns:
        the newly created ReprintableDocument
        Throws:
        OBSecurityException - if the write access to the source document is not granted in the current context because in such case is not allowed to create a ReprintableDocument linked to the source document.
        OBException - if it is not possible to find a handler for the selected attachment method
      • download

        public ReprintableDocument download​(ReprintableSourceDocument<?> sourceDocument,
                                            OutputStream outputStream)
                                     throws IOException,
                                            DocumentNotFoundException
        Retrieves the data of a ReprintableDocument linked to the provided document
        Parameters:
        sourceDocument - The document used as source data for the ReprintableDocument
        outputStream - outputStream where document data is provided. Code invoking this method is also responsible of closing it.
        Returns:
        the ReprintableDocument linked to the source document
        Throws:
        DocumentNotFoundException - if it is not possible to find the ReprintableDocument linked to the provided source document
        OBSecurityException - if the read access to the source document is not granted in the current context because in such case is not allowed to access to the ReprintableDocument linked to the source document.
        OBException - if it is not possible to find a handler for the attachment method defined in the ReprintableDocument attachment configuration
        IOException
      • isReprintDocumentsEnabled

        public boolean isReprintDocumentsEnabled​(String orgId)
        Checks whether documents reprinting is enabled for a given organization which is determined by the value returned with Organization.getReprintDocuments(). Note that in case that value is not defined (null) for the given organization, it is taken from the closest organization in the parent organization tree that has a value defined (not null).
        Parameters:
        orgId - The ID of the organization to check
        Returns:
        true if document reprinting is enabled for the given organization or false otherwise
      • isReprintableDocumentsWindow

        public boolean isReprintableDocumentsWindow​(String windowId)
        Checks if reprintable documents can be generated from a given window. For the moment it is only supported to generate reprintable documents from these windows: Sales Order, Sales Invoice, Purchase Order and Purchase Invoice.
        Parameters:
        windowId - The ID of the AD window
        Returns:
        true if reprintable documents can be generated from the given window or false in other case