Class CalculableLineItemCollectionBuilder<T extends CalculableLineItemCollectionBuilder>
- Object
-
- ObjectIdentity
-
- AbstractBuilder
-
- CalculableLineItemCollectionBuilder<T>
-
- 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
-
-
Field Summary
Fields Modifier and Type Field Description static String
METHOD_ADD_LINE_ITEM
static String
METHOD_ADD_OR_UPDATE_INPUT
static String
METHOD_ADD_OR_UPDATE_OUTPUT
static String
METHOD_UPDATE_FIELD
protected HeaderPhase
phase
static String
ROOT_LINE_ID
-
Constructor Summary
Constructors Constructor Description CalculableLineItemCollectionBuilder(String instanceId, String classId, IdGenerator idGenerator, Invocations<MethodInvocation> invocations, HeaderPhase phase)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
addLineItem(String key)
Adds a new line item in the root folder.T
addLineItem(String parentLineId, String key)
Adds a new line item in the specified parent (folder ID).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.T
addOrUpdateInput(String lineId, Map<String,Object> contextParameter)
Adds or updates an input parameter on a folder (or line) with givenlineId
.T
addOrUpdateInput(Map<String,Object> contextParameter)
Adds or updates an input parameter on the ROOT level.T
addOrUpdateOutput(String lineId, Map<String,Object> calculationResult)
Adds or updates a result value (an output value) on a folder (or line item) with givenlineId
T
addOrUpdateOutput(Map<String,Object> calculationResult)
Adds or updates a result value (an output value) on the ROOT level.T
clearRenderInfo(String fieldName)
Clears the existing render info for a field or for all fieldsT
deleteItem(String lineId)
Deletes an item or folder.boolean
isPostPhase()
Determines the current calculation phase of the header logic execution.boolean
isPrePhase()
Determines the current calculation phase of the header logic execution.T
moveItem(String lineId, String newParentId)
Moves an item or folder under a new parent.T
renameFolder(String lineId, String newFolderLabel)
Renames a folder (not items).T
setRenderInfo(String fieldName, String key, Object value)
Sets (adds or updates) rendering information for particular header fields and buttons.T
updateField(String fieldName, Object value)
Updates a header field value.T
updateField(String lineId, String fieldName, Object value)
Updates a field on the line.
Note: Not supported for all objects, e.g.
-
-
-
Field Detail
-
phase
protected final HeaderPhase phase
-
METHOD_ADD_OR_UPDATE_OUTPUT
public static final String METHOD_ADD_OR_UPDATE_OUTPUT
- See Also:
- Constant Field Values
-
METHOD_ADD_OR_UPDATE_INPUT
public static final String METHOD_ADD_OR_UPDATE_INPUT
- See Also:
- Constant Field Values
-
METHOD_UPDATE_FIELD
public static final String METHOD_UPDATE_FIELD
- See Also:
- Constant Field Values
-
METHOD_ADD_LINE_ITEM
public static final String METHOD_ADD_LINE_ITEM
- See Also:
- Constant Field Values
-
ROOT_LINE_ID
public static final String ROOT_LINE_ID
- See Also:
- Constant Field Values
-
-
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 givenlineId
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/linecalculationResult
- 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 givenlineId
.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 linecontextParameter
- 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 linefieldName
- The field namevalue
- 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 namevalue
- 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
.
saveButton
,submitButton
,creationWorkflowSubmitAndNext
andcreationWorkflowBack
. Buttons only support the keyhide
. Once you hide a button, you have to explicitly set hide to false or useclearRenderInfo(String)
in order to let the button reappear.- Parameters:
fieldName
- The field or button this setting should be applied onkey
- The setting namevalue
- The setting value- Returns:
- itself (for flow pattern)
- Common for Q/CT/RA:
-
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 itemkey
- 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)
def val = api.input("MyHiddenParam")
- 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.
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 itemkey
- 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 movenewParentId
- 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 renamenewFolderLabel
- New label- Returns:
- itself (for flow pattern)
-
-