Class PrintTemplateUtil

java.lang.Object
com.ssgllc.fish.service.util.published.PrintTemplateUtil

@Component public final class PrintTemplateUtil extends Object
  • Constructor Details

    • PrintTemplateUtil

      public PrintTemplateUtil()
  • Method Details

    • generateDocument

      public static com.ssgllc.fish.document.GeneratedDoc generateDocument(String printTemplateName, String entityId, Map<String,Object> formData, String taskInstanceId, String type, Instant asOfDate) throws Exception
      Generates a document based on the specified print template, entity data, and other parameters. Note that the entity and field permissions are not checked for the current user and the document is generated with super user permissions


      Example:
      def formData = [field1: "value1", field2: "value2"]
      def doc = printTemplateUtil.generateDocument("PersonTemplate", "c0a83801-655d-13e2-8191-9067f826208c", [:], null, "docx", dateUtil.startOfToday())
      return bpmUtil.createProcessDocFromGeneratedDoc(doc, execution.processInstanceId)

      Returns:
      A generated DOCX document based on the "PersonTemplate" for the entity with the specified id.
      Parameters:
      printTemplateName - The name of the print template to be used.
      entityId - The ID of the entity for which the document is generated.
      formData - A map of form data used as input for the print template.
      taskInstanceId - The ID of the task instance associated with the document generation.
      type - The type of document to generate ("pdf", "docx", or "report").
      asOfDate - The date for fetching entity data as of a particular moment in time, if applicable.
      Returns:
      A GeneratedDoc object containing the generated document, or null if the document could not be generated.
      Throws:
      NoSuchMethodException - If a required method for document generation is not found.
      IOException - If an I/O error occurs during document generation.
      Exception
    • generateDocumentWithDataSource

      public static com.ssgllc.fish.document.GeneratedDoc generateDocumentWithDataSource(String printTemplateName, String entityId, Map<String,Object> formData, String taskInstanceId, Instant asOfDate, List<?> dataSource) throws Exception
      Generate a document from a Jasper template while passing it a specific "data source". Since only Jasper templates support dataSource, type is assumed to be "report". For general documentation, see generateDocument(java.lang.String, java.lang.String, java.util.Map<java.lang.String, java.lang.Object>, java.lang.String, java.lang.String, java.time.Instant).

      dataSource can be in one of 3 formats:
      • A list of maps, as in [[firstName: "John", lastName: "Doe"], [firstName: "Jane", lastName: "Doe"]]. Each map is a "row" of data and their keys are "columns". Because of this, all maps must have the same keys.
      • A list of entities. Each entity must be the same type. Remember to define fields in the Jasper template corresponding to the entities' fields.
      • A list of arrays. The list items must be arrays, not lists. The first array consists of strings that name the "columns" used by all the other arrays. The other arrays are the "rows", and can contain any type. All arrays must be the same length.
      Parameters:
      printTemplateName - The name of the print template to be used.
      entityId - The ID of the entity for which the document is generated.
      formData - A map of form data used as input for the print template.
      taskInstanceId - The ID of the task instance associated with the document generation.
      asOfDate - The date for fetching entity data as of a particular moment in time, if applicable.
      dataSource - The primary data source given to Jasper when generating the document.
      Returns:
      Throws:
      Exception