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 in which changes to the document structure are 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 is more like a routine to collect all necessary changes. These changes are not executed immediately. They are 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 the current calculation phase of the header logic execution.
        Returns:
        true if the current context is "pre"/before line items calculation
      • isPostPhase

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

        public T addOrUpdateOutput​(Map<String,​Object> calculationResult)
        Adds or updates a result value (an output value) on the ROOT level.

        For map example/details, see addOrUpdateOutput(String, Map)

        Parameters:
        calculationResult - A map describing a calculation result
        Returns:
        itself (for flow pattern)
      • addOrUpdateOutput

        public T addOrUpdateOutput​(String lineId,
                                   Map<String,​Object> calculationResult)
        Adds or updates a result value (an output value) on a folder (or line item) with given lineId

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

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

        public T addOrUpdateInput​(Map<String,​Object> contextParameter)
        Adds or updates an input parameter on the ROOT level.

        For map example/details, see addOrUpdateInput(String, Map)

        Parameters:
        contextParameter - A map describing the context parameter
        Returns:
        itself (for flow pattern)
      • addOrUpdateInput

        public T addOrUpdateInput​(String lineId,
                                  Map<String,​Object> contextParameter)
        Adds or updates an input parameter on a folder (or line) with given lineId.

        Example:

         if(quoteProcessor.isPrePhase()) {
           quoteProcessor.addOrUpdateInput(
               [
                 "name"     : "DeliveryType",
                 "label"    : "Delivery Type",
                 "type"     : InputType.OPTION,
                 "required" : true,
                 "parameterConfig" : [
                   "labels" : [
                     "Express" : "Express Delivery",
                     "Standard" : "Standard Delivery"
                   ]
                 ],
                 "valueOptions" : [
                   "Express",
                   "Standard"
                 ]
               ]
            )
         }
         

        Example:

         if (quoteProcessor.isPrePhase()) {
             quoteProcessor.addOrUpdateInput(lineItem.lineId, [
                "name": "CompetitorPrice",
                "label": "Competitor Price",
                "type" : InputType.USERENTRY,
                "value": primaryCompetitor,
                "parameterGroup": "Competition Information",
               ])
         }
         

        Example:

         if(quoteProcessor.isPrePhase()) {
             quoteProcessor.addOrUpdateInput( lineId,
                   [
                      "name"    : "SpecialBundlePromotion",
                      "label"   : "SpecialBundlePromotion",
                      "type"    : InputType.HIDDEN,
                      "required": false,
                      "readOnly": true,
                      "value"   : value
                   ]
             )
         }
         
        Parameters:
        lineId - The id of the line
        contextParameter - A map describing the context parameter
        Returns:
        itself (for flow pattern)
        See Also:
        InputType
      • 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 the 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 and buttons. The available key/value pairs depend on a particular field. If a key is used that is unknown to the client, it will be simply ignored.

        The following keys are currently supported for fields: hide, required, disabled (all boolean type). The field names correspond to the names in the JSON data structure. The following fieldNames are supported:

        • Common for Q/CT/RA: uniqueName, workflowState, creationWorkflowStatus, creationWorkflowLabel, supersededBy, prevRev, label, startDate, endDate, attachments, signatureStatus, userGroupEdit, userGroupViewDetails, directLink.
        • Additionally only for Quotes: externalRef, quoteStatus.
        • Additionally only for Contracts: targetDate, contractExternalRef, contractStatus.
        • Additionally only for Rebate Agreements: targetDate, payoutDate, rebateAgreementStatus.
        • Rebate Agreements Templates have their own list of supported fieldNames: label, startDate, endDate, payoutDate, targetDate, userGroupEdit, userGroupViewDetails.
        As for buttons, the following ones are supported by this method: saveButton, submitButton, creationWorkflowSubmitAndNext and creationWorkflowBack. Buttons only support the key hide. Once you hide a button, you have to explicitly 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 the 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)
        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)
        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)
        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 the header and 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 item 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 that does not make it 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 under a new parent. Only works in the 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 the PRE phase.
        Parameters:
        lineId - The line ID of the item to remove
        Returns:
        itself (for flow pattern)