Class CalculableLineItemCollectionBuilder<T extends CalculableLineItemCollectionBuilder>

  • Direct Known Subclasses:
    BasicRebateAgreementBuilder, ContractBuilder, QuoteBuilder

    public abstract class CalculableLineItemCollectionBuilder<T extends CalculableLineItemCollectionBuilder>
    extends AbstractBuilder
    This is the shared builder class for Quotes, RebateAgreements and Contracts.
    Some important notes on the sequence that changes to the document structure a re processed:

    Any modifying action (adding lines, inputs etc or a structure object etc) IS NOT executed as per sequence of the groovy logic! The groovy logic should be more considered as a routine that collects all necessary changes. These changes are not executed immediately. They are rather collected (per execution phase) and then executed in this order:
    • Add line items
    • Delete line items (PRE phase only!)
    • Move line items (PRE phase only!)
    • Rename folders
    • Add inputs
    • Add outputs
    • Update header fields
    • Constructor Detail

      • CalculableLineItemCollectionBuilder

        public CalculableLineItemCollectionBuilder​(String instanceId,
                                                   String classId,
                                                   IdGenerator idGenerator,
                                                   Invocations<MethodInvocation> invocations,
                                                   HeaderPhase phase)
    • Method Detail

      • isPrePhase

        public boolean isPrePhase()
        Determines current calculation phase of logic execution
        Returns:
        true if the current context is "pre"/before line item calculation
      • isPostPhase

        public boolean isPostPhase()
        Determines current calculation phase of logic execution
        Returns:
        true if the current context is "post"/after line item calculation
      • addOrUpdateOutput

        public T addOrUpdateOutput​(Map<String,​Object> calculationResult)
        This method adds or updates a result value (an output value) on the root level
        Parameters:
        calculationResult - A map describing a calculation result
        Returns:
        itself (for flow pattern)
      • addOrUpdateOutput

        public T addOrUpdateOutput​(String lineId,
                                   Map<String,​Object> calculationResult)
        This method adds or updates a result value (an output value) on a line item

        Example how to set a background color for the header output results:

         quoteprocessor.addOrUpdateOutput(folderId, ["resultName": "RedMinimumMargin",
                              "resultLabel": "Red (Minimum) Margin",
                              "suffix": "", 
                              "cssProperties": "background-color: red;", 
                              "result": totalMinimumRed])
         
        Parameters:
        lineId - The id of the line
        calculationResult - A map describing a calculation result
        Returns:
        itself (for flow pattern)
      • addOrUpdateInput

        public T addOrUpdateInput​(Map<String,​Object> contextParameter)
        This method adds or updates an input value on the root level
        Parameters:
        contextParameter - A map describing the context parameter
        Returns:
        itself (for flow pattern)
      • addOrUpdateInput

        public T addOrUpdateInput​(String lineId,
                                  Map<String,​Object> contextParameter)
        This method adds or updates an input value on a line item
        Parameters:
        lineId - The id of the line
        contextParameter - A map describing the context parameter
        Returns:
        itself (for flow pattern)
      • updateField

        public T updateField​(String lineId,
                             String fieldName,
                             Object value)
        Updates a field on the line. Note: Not supported for all objects e.g. quotes
        Parameters:
        lineId - The id of the line
        fieldName - The field name
        value - The new value
        Returns:
        itself (for flow pattern)
      • updateField

        public T updateField​(String fieldName,
                             Object value)
        Updates a header field value For quotes supported fields are: additionalInfo1 additionalInfo2 additionalInfo3 additionalInfo4 externalRef expiryDate editabilityStatus targetDate label userGroupEdit userGroupViewDetails
        Parameters:
        fieldName - The field name
        value - The new value
        Returns:
        itself (for flow pattern)
      • setRenderInfo

        public T setRenderInfo​(String fieldName,
                               String key,
                               Object value)
        Sets (adds or updates) rendering information for particular header fields (or buttons). The available key/value pairs depend on the particular field. If a key is used that is unknown to the client it will be simply ignored. For fields these 3 keys are currently supported: hide,required,disabled. All three with a value attribute of boolean type. As field names currently supported are all fields shown in the header input portlet. The field names correspond to the names in the json data structure There are four buttons currently supported: saveButton, submitButton, creationWorkflowSubmitAndNext and creationWorkflowBack. Buttons only support a key of hide. Once you hide a button, you will have to explicitely set hide to false or use clearRenderInfo(String) in order to let the button reappear.
        Parameters:
        fieldName - The field or button this setting should be applied on
        key - The setting name
        value - The setting value
        Returns:
        itself (for flow pattern)
      • clearRenderInfo

        public T clearRenderInfo​(String fieldName)
        Clears existing render info for a field or for all fields
        Parameters:
        fieldName - The field name to clear all info for, or null for all info for all fields
        Returns:
      • addLineItem

        public T addLineItem​(String key)
        This method adds a new line item in the root folder
        Parameters:
        key - The key (usually the sku)
        Returns:
        itself (for flow pattern)
      • addLineItem

        public T addLineItem​(String parentLineId,
                             String key)
        This method adds a new line item in the specified parent (folder id)
        Parameters:
        parentLineId - id of parent item
        key - The key (usually the sku)
        Returns:
        itself (for flow pattern)
      • addLineItem

        public T addLineItem​(String parentLineId,
                             String key,
                             List<Map<String,​Object>> contextParameter)
        This method adds a new line item in the specified parent (folder id) and sets some context parameters.

        Sometimes it is required to pass values from a header logic to line items that this logic creates. You can use the HIDDEN input type and reference it in the calculation logic. The following code sample creates a new quote line with parameters fetched from the header logic:

         def params = [[name:"MyHiddenParam", type: InputType.HIDDEN, value:"ABC"]]
         quoteProcessor.addLineItem("ROOT","MB-0003",params)
         
        In the line calculation logic, this value then can be retrieved by:
         def val = api.input("MyHiddenParam")
         
        Notes:
        • This way you can also set default values of "real" input parameters as determined by the line calculation logic. Set the value in the header logic and make sure that the names of the parameter match in both logics.
        • If you use this method only to transport values between header & line, set the parameter type to HIDDEN. The value can also be a map to transport more structured data.
        • Any parameter that is non-HIDDEN and not determined by the line logic will be removed.
        • Be aware that this hidden data is also exposed to the user (it is part of the quote response). It is not visible in the UI, but it is neither a secure storage! Also, try to keep the data volume reasonably low.
        You can also set default values for items created using the quoteStructure class:
         def params = [[name:"MyHiddenParam", type: InputType.HIDDEN, value:"ABC"]]
         def qs = new QuoteStructure()
         qs.addPart("MySKU",params) //use add.Folder for a folder
         
        Parameters:
        parentLineId - id of parent item
        key - The key (usually the sku)
        contextParameter - A list of maps describing the context parameters
        Returns:
        itself (for flow pattern)
      • moveItem

        public T moveItem​(String lineId,
                          String newParentId)
        Moves an item or folder underneath a new parent. Only works in PRE phase!
        Parameters:
        lineId - The line ID of the item to move
        newParentId - The line ID of the target folder. null if you want to move it to root folder
        Returns:
        itself (for flow pattern)
      • renameFolder

        public T renameFolder​(String lineId,
                              String newFolderLabel)
        Renames a folder (not items!)
        Parameters:
        lineId - The line ID of the folder to rename
        newFolderLabel - New label
        Returns:
        itself (for flow pattern)
      • deleteItem

        public T deleteItem​(String lineId)
        Deletes an item or folder. Only works in PRE phase!
        Parameters:
        lineId - The line ID of the item to remove
        Returns:
        itself (for flow pattern)