You are here:
TimePolicyInterface
The TimePolicyInterface calculates the start and end dates for certain records based on the context and given input.
Type
Loosely typed
Triggered When
Adding a promotion to the cart, creating price adjustments, creating assets, and creating an order from assets trigger the TimePolicyInterface.
Called In
The following classes call the TimePolicyInterface:
-
CpqAddCartPromotionItemActionV2.cls
-
CpqPriceAdjustmentCartItemActionV2.cls
-
CreateAsset.cls
-
CreateOrder.cls
-
ObjectsClonerController.cls
-
PricingElementServiceImplementation.cls
Signature
Access |
Signature |
|---|---|
global |
|
Default Implementation
DefaultTimePolicyImplementationDefaultTimePolicyImplementation
Other Implementations
None
Input Parameters
methodName
Required
Type: String
The name of the method to execute, for example, setStartEndTimes sets the start and end times for the given objects.
inputMap
Required
Type: Map<String, Object>
The input map contains the following:
-
calcType
Type: String
Required
Options:
-
AddToOrder: Called when adding an item to the order cart, does respective time plan calculation -
AddToQuote: Called when adding an item to the quote cart, does respective time plan calculation -
AddToOpportunity: Called when adding an item to an opportunity cart, does respective time plan calculation
-
-
OpportunityId
Type: Id
Optional
ID of opportunity
-
PromotionId
Type: Id
Optional
ID of promotion that was added to the cart
-
AppliedPromotion
Type: OpportunityAppliedPromotion__c, QuoteAppliedPromotion__c, or OrderAppliedPromotion__c
Optional
AppliedPromotion object associated with the promotion that was added
-
OpportunityPriceAdjustmentList
Type: List<OpportunityPriceAdjustment__c>
Optional
List of price adjustment objects associated with the opportunity
-
OrderPriceAdjustmentList
Type: List<OrderPriceAdjustment__c>
Optional
List of price adjustment objects associated with the order
-
QuotePriceAdjustmentList
Type: List<QuotePriceAdjustment__c>
Optional
List of price adjustment objects associated with the quote
-
OrderId
Type: Id
Optional
ID of order
-
QuoteId
Type: Id
Optional
ID of quote
Output Parameters
None
Sample Implementation
global with sharing class DefaultTimePolicyImplementation implements VlocityOpenInterface {
public enum CalculationMode {STARTMODE, ENDMODE}
global Boolean invokeMethod(String methodName, Map<String,Object> inputMap, Map<String,Object> outMap, Map<String,Object> options) {
Boolean success = true;
try {
if (methodName == 'setStartEndTimes') {
if (outMap == null) {
outMap = new Map<String, Object>();
}
setStartEndTimes(inputMap, outMap);
}
} catch (Exception e) {
System.debug(LoggingLevel.ERROR,'exception::::' + e);
System.debug(LoggingLevel.ERROR,'Exception stack trace:::::' + e.getStackTraceString());
Map<String, Object> errors = new Map<String, Object>();
errors.put('Exception message',e.getMessage());
errors.put('Exception stack trace', e.getStackTraceString());
outMap.put('Error', errors);
success = false;
}
return success;
}
/* Given some inputs, calculate and set the start and end times for the given Object
* Input includes:
*
*/
public static void setStartEndTimes(Map<String, Object> inputMap, Map<String, Object> outMap) {
String calcType = (String) inputMap.get('Type');
if (calcType == 'AddToOrder') {
// came from adding item to Order cart, do respective time plan calculation
calcStartEndOrder(inputMap);
}
else if (calcType == 'AddToQuote') {
// came from adding item to Quote cart, do respective time plan calculation
calcStartEndQuote(inputMap);
} else if(calcType == 'AddToOpportunity') {
// came from adding item to Opportunity cart, do respective time plan calculation
calcStartEndOpportunity(inputMap);
}
else if (calcType == 'CreateAsset') {
// came from creating Assets, do respective time plan calculation
calcStartEndAsset(inputMap);
}
else if (calcType == 'QuoteToOrder') {
// came from creating Order from Quote, do respective time plan calculation
//TODO: implement function
}
else if (calcType == 'ActivateAssets') {
// came from Activating Assets, do respective time plan calculation
//TODO: implement function
} else {
System.debug(LoggingLevel.ERROR,'Exception::::: Time Policy calculation Type undefined');
}
}
/*
* Start/End time calculation after adding item to Opportunity
*/
public static void calcStartEndOpportunity(Map<String, Object> inputMap) {
Id opportunityId = (Id) inputMap.get('OpportunityId');
Id promoId = (Id) inputMap.get('PromotionId');
OpportunityAppliedPromotion__c appliedPromo = (OpportunityAppliedPromotion__c) inputMap.get('AppliedPromotion');
List<OpportunityPriceAdjustment__c> opportunityPriceAdjList = (List<OpportunityPriceAdjustment__c>) inputMap.get('OpportunityPriceAdjustmentList');
Set<Id> timePolicyIds = new Set<Id>();
Set<Id> timePlanIds = new Set<Id>();
Promotion__c promo;
>if (promoId != null)
{
//Get time plans and policies from Promotion object
promo = [SELECT Id,BenefitTimePlanId__c,BenefitTimePolicyId__c,DurationTimePlanId__c,DurationTimePolicyId__c FROM Promotion__c WHERE Id =: promoId];
timePolicyIds.add(promo.DurationTimePolicyId__c);
timePolicyIds.add(promo.BenefitTimePolicyId__c);
timePlanIds.add(promo.DurationTimePlanId__c);
timePlanIds.add(promo.BenefitTimePlanId__c);
}
Map<Id, Id> pleIdToTimePlanId = new Map<Id, Id>();
Map<Id, Id> pleIdToTimePolicyId = new Map<Id, Id>();
if (opportunityPriceAdjList != null && !opportunityPriceAdjList.isEmpty())
{
Set<Id> pleIds = new Set<Id>();
for (OpportunityPriceAdjustment__c opa : opportunityPriceAdjList)
{
if (opa.PriceListEntryId__c != null)
{
pleIds.add(opa.PriceListEntryId__c);
}
}
if (!pleIds.isEmpty())
{
List<PriceListEntry__c> pleList = [SELECT Id, TimePlanId__c, TimePolicyId__c FROM PriceListEntry__c WHERE Id IN :pleIds];
for (PriceListEntry__c ple : pleList)
{
if (ple.TimePlanId__c != null)
{
timePlanIds.add(ple.TimePlanId__c);
pleIdToTimePlanId.put(ple.Id, ple.TimePlanId__c);
}
if (ple.TimePolicyId__c != null)
{
timePolicyIds.add(ple.TimePolicyId__c);
pleIdToTimePolicyId.put(ple.Id, ple.TimePolicyId__c);
}
}
}
}
This example has been truncated. To see more, go to the Apex classes in your org and click DefaultTimePolicyImplementation.
