Class CalculatedFieldSet
- All Implemented Interfaces:
Calculable,HasCalculableObjectItems,JobNameProvider,JobSettingsProvider,UserGroupRestrictedObject
CFS) is a data enrichment task: it runs a calculation logic over the rows of one source table and writes the results back to mapped fields of the same rows. The source can be, for example, Products, Customers, Product Extensions, Customer Extensions, Seller Extensions, global object extensions, Company Parameters, Price Records, Rebate Records or Manual Price Lists. A CFS usually runs after a data upload, to prepare the values that price calculations then read.
To read a Calculated Field Set from a logic, use api.findCalculatedFieldSets(targetDate, label). It matches the CFS label and returns the sets whose target date is empty or not later than the given date. The source, the filter, the calculation logic and the field mapping are stored in the CFS configuration. A calculation uses the explicit target date of the CFS or, when none is set, the current date plus getRelativeTargetDateDays() days. When a calculation of the CFS on its own source finishes successfully, the header is updated with the number of processed rows and the number of failed rows (getNumberOfFailedItems()). A failed or cancelled run, or a run for a linked Manual Price List, leaves the previous values.
CFS jobs that work on the same source run one at a time, unless their configurations set different concurrency key suffixes (see getCalculationConcurrencyKey()). A Manual Price List can link to a CFS; deleting the CFS clears the link on every Manual Price List that links to it. Access to the detail view and the edit actions of a CFS can be restricted to specific User Groups via getUserGroupViewDetails() and getUserGroupEdit().
Example, looking up a Calculated Field Set by label and checking its last calculation for failed rows:
def cfs = api.findCalculatedFieldSets(api.targetDate(), "Enrich Product Costs")?.find()
if (cfs?.numberOfFailedItems > 0) {
// ...
}
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class PersistedObject
PersistedObject.BatchDelete, PersistedObject.BulkloadFilterCheckCallback, PersistedObject.ComputedFieldMapping, PersistedObject.ComputedFields, PersistedObject.HardDelete, PersistedObject.ImportManagerEnabled, PersistedObject.PersistedObjectMeta, PersistedObject.VirtualField, PersistedObject.VirtualFieldMapping, PersistedObject.VirtualFields, PersistedObject.VirtualSearchFields, PersistedObject.VirtualSortFields -
Field Summary
Fields inherited from class AbstractCalculable
FIELD_CALCDATE, FIELD_CALCMESSAGES, FIELD_CALCSTARTDATE, FIELD_STATUS, MAX_CALCULATION_MESSAGE_LENGTH, MAX_CALCULATION_MESSAGE_THRESHOLDFields inherited from class PartitionedObject
FIELD_PARTITION, FIELD_PARTITIONID, PARTITION_FILTER_NAME, PARTITION_FILTER_PARAMFields inherited from class PersistedObject
FIELD_CREATEDATE, FIELD_CREATEDBY, FIELD_DELETEDATE, FIELD_DELETEDBY, FIELD_ID, FIELD_ISDELETED, FIELD_LASTUPDATEBY, FIELD_LASTUPDATEDATE, FIELD_VERSIONFields inherited from interface UserGroupRestrictedObject
FIELD_USERGROUPEDIT, FIELD_USERGROUPVIEWDETAILS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCalculatedFieldSetConfigurationThe configuration of this Calculated Field Set, deserialized fromgetConfiguration(): the source type and filter, the calculation logic, the field mapping, the concurrency key suffix and the calculation options.The concurrency key of the calculation jobs started for this Calculated Field Set.The configuration of this Calculated Field Set as a JSON string: the source type and filter, the calculation logic, the field mapping and the calculation options.JobStatusTracker.TrackerTypeThe kind of background job tracker used by default when this Calculated Field Set is calculated.getGlobalOXName(PersistedObjectService txn) The name of the global object extension this Calculated Field Set calculates, if its source is one.Class<? extends ElementAttributeMeta> Part of the calculable-object contract.Class<? extends PriceCalculableObjectItem> Part of the calculable-object contract.Part of the calculable-object contract.The job-type discriminator used for background calculation job naming and routing.The number of source rows that failed in the last successful calculation of this Calculated Field Set.An offset, in days from the current date, that a calculation uses as its target date when this Calculated Field Set has no explicit target date.intgetShotgunThreshold(PersistedObjectService objService, JobStatusTracker jst) The minimum job size (seejobSize(PersistedObjectService, JobStatusTracker, int)) above which the calculation framework switches to shotgun (distributed) mode instead of a single sequential run, whenisShotgunEnabled(PersistedObjectService)allows it.The User Group(s) whose members may edit this Calculated Field Set.The User Group(s) whose members may view the details of this Calculated Field Set.booleanisShotgunEnabled(PersistedObjectService txn) Whether "shotgun mode" (a distributed calculation spread across multiple worker agents instead of one sequential run) is allowed for this Calculated Field Set.intjobSize(PersistedObjectService objectService, JobStatusTracker jst, int runNumber) The number of source rows the current calculation run is expected to process: the count of rows in the source table that match the source filter of the configuration.voidonDelete(PersistedObjectService objService, boolean hardDelete) Called by the persistence layer when this Calculated Field Set is deleted.voidsetCalculatedFieldSetConfiguration(CalculatedFieldSetConfiguration config) Sets the configuration of this Calculated Field Set; it is stored as JSON (seegetConfiguration()).voidsetConfiguration(String configuration) Sets the configuration of this Calculated Field Set as a JSON string (seegetConfiguration()).voidsetNumberOfFailedItems(Integer numberOfFailedItems) Sets the number of failed rows.voidsetRelativeTargetDateDays(Integer relativeTargetDateDays) Sets the offset in days used when this Calculated Field Set has no explicit target date (seegetRelativeTargetDateDays()).voidsetUserGroupEdit(String userGroup) Sets the User Group(s) whose members may edit this Calculated Field Set (seegetUserGroupEdit()).voidsetUserGroupViewDetails(String userGroup) Sets the User Group(s) whose members may view the details of this Calculated Field Set (seegetUserGroupViewDetails()).booleanvalidate(ValidationVisitor validationVisitor, PersistedObjectService objService) Validates this Calculated Field Set before it is saved.Methods inherited from class CalculableObject
getEffectiveTargetDate, getKeepManualOverrides, getNumberOfItems, getWriteOnlyChangedItems, itemsStateChanged, setKeepManualOverrides, setNumberOfItems, setWriteOnlyChangedItemsMethods inherited from class AbstractCalculable
calculationDate, calculationStartDate, getCalculationDate, getCalculationMessages, getCalculationMessagesAsList, getCalculationStartDate, getJobName, getLabel, getLocale, getStatus, getTargetDate, isAnonymousCalculable, setCalculationDate, setCalculationMessages, setCalculationMessages, setCalculationStartDate, setLabel, setLocale, setStatus, setTargetDateMethods inherited from class PartitionedObject
addUniqueConstraint, getLoginNameByUserId, getPartition, setPartition, toStringMethods inherited from class PersistedObject
auditOperation, bumpVersion, canAdd, canDelete, canEdit, canEdit, canRead, canReadElements, createDate, entityIsHardDeleted, entityIsMassDeletable, entityIsSafeInserted, entityIsSafeInserted, getBulkloadMap, getBusinessKey, getCreateDate, getCreatedBy, getDbColumnNameForField, getDeleteDate, getDeletedBy, getId, getLastUpdateBy, getLastUpdateDate, getSensitiveFields, getSignificantFields, getTypeCode, getTypedId, getVersion, getVirtualSearchFieldMappings, getVirtualSortFieldMappings, isAudited, isDeleted, isHardDeleted, isVirtualSearchField, lastUpdateDate, notifyOnBusinessKeyChange, onBusinessKeyChange, onRefreshed, onSavedOrUpdated, onSaveOrUpdate, setCreateDate, setCreateDateShouldBeIgnored, setCreateDateTime, setCreatedBy, setDeleted, setDeleteDate, setDeletedBy, setId, setLastUpdateBy, setLastUpdateDate, setLastUpdateDateTime, setTypedId, setVersion, userGroupEditBulkloadFilter, userGroupEditBulkloadFilterMethods inherited from class DomainObject
deepCopy, getNewMidnightDate, getNewMidnightDateTime, isMidnight, isMidnight, jsonDeserialize, jsonDeserialize, jsonDeserialize, jsonDeserialize, jsonDeserialize, jsonDeserialize, jsonDeserialize, jsonDeserialize, jsonDeserialize, jsonDeserialize, jsonDeserialize, jsonDeserialize, jsonSerialize, jsonSerialize, jsonSerialize, jsonSerialize, jsonSerialize, jsonSerialize, jsonSerializedSizeOK, jsonSerializeToBytes, jsonSerializeToBytes, setToDayEnd, setToDayEnd, setToMidnight, setToMidnight, setToMidnightAsLocalDateTime, toPropertyMap, truncatedToStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface JobSettingsProvider
getAgentOption1
-
Constructor Details
-
CalculatedFieldSet
public CalculatedFieldSet()
-
-
Method Details
-
getConfiguration
The configuration of this Calculated Field Set as a JSON string: the source type and filter, the calculation logic, the field mapping and the calculation options. This is the persisted form ofgetCalculatedFieldSetConfiguration(). Not meant to be used directly in Groovy.- Returns:
- The configuration as JSON, or
nullif the set has not been configured yet.
-
setConfiguration
Sets the configuration of this Calculated Field Set as a JSON string (seegetConfiguration()). Not meant to be used directly in Groovy.- Parameters:
configuration- The configuration as JSON, ornullto clear it.
-
getRelativeTargetDateDays
An offset, in days from the current date, that a calculation uses as its target date when this Calculated Field Set has no explicit target date. The current date is adjusted to the time zone of the partition. Cleared automatically once an explicit target date is set (seevalidate(ValidationVisitor, PersistedObjectService)).- Returns:
- The offset in days, or
nullif not configured or if an explicit target date is set.
-
setRelativeTargetDateDays
Sets the offset in days used when this Calculated Field Set has no explicit target date (seegetRelativeTargetDateDays()).- Parameters:
relativeTargetDateDays- The offset in days from the current date, ornullto clear it.
-
getNumberOfFailedItems
The number of source rows that failed in the last successful calculation of this Calculated Field Set. Set when a calculation of the CFS on its own source finishes successfully; a failed or cancelled run, or a run for a linked Manual Price List, leaves the previous value.- Returns:
- The count of failed rows in the last successful calculation.
-
setNumberOfFailedItems
Sets the number of failed rows. A successful calculation of the CFS on its own source overwrites it. Not meant to be used directly in Groovy.- Parameters:
numberOfFailedItems- The count of failed rows.
-
getCalculatedFieldSetConfiguration
public CalculatedFieldSetConfiguration getCalculatedFieldSetConfiguration()The configuration of this Calculated Field Set, deserialized fromgetConfiguration(): the source type and filter, the calculation logic, the field mapping, the concurrency key suffix and the calculation options. Not meant to be used directly in Groovy.- Returns:
- The deserialized configuration; an empty configuration object if the set has not been configured yet.
-
setCalculatedFieldSetConfiguration
public void setCalculatedFieldSetConfiguration(CalculatedFieldSetConfiguration config) Sets the configuration of this Calculated Field Set; it is stored as JSON (seegetConfiguration()). Not meant to be used directly in Groovy.- Parameters:
config- The configuration to store.
-
getUserGroupEdit
The User Group(s) whose members may edit this Calculated Field Set. Users with theUSERGROUP_OVERRIDEpermission bypass the restriction.- Specified by:
getUserGroupEditin interfaceUserGroupRestrictedObject- Returns:
- A User Group unique name or a comma-separated list of them, or
nullif editing is not restricted by User Group.
-
setUserGroupEdit
Sets the User Group(s) whose members may edit this Calculated Field Set (seegetUserGroupEdit()).- Specified by:
setUserGroupEditin interfaceUserGroupRestrictedObject- Parameters:
userGroup- A User Group unique name or a comma-separated list of them, ornullto remove the restriction.
-
getUserGroupViewDetails
The User Group(s) whose members may view the details of this Calculated Field Set. Users with theUSERGROUP_OVERRIDEpermission bypass the restriction.- Specified by:
getUserGroupViewDetailsin interfaceUserGroupRestrictedObject- Returns:
- A User Group unique name or a comma-separated list of them, or
nullif viewing is not restricted by User Group.
-
setUserGroupViewDetails
Sets the User Group(s) whose members may view the details of this Calculated Field Set (seegetUserGroupViewDetails()).- Specified by:
setUserGroupViewDetailsin interfaceUserGroupRestrictedObject- Parameters:
userGroup- A User Group unique name or a comma-separated list of them, ornullto remove the restriction.
-
validate
public boolean validate(ValidationVisitor validationVisitor, PersistedObjectService objService) Validates this Calculated Field Set before it is saved. ClearsgetRelativeTargetDateDays()once an explicit target date is present, then delegates to the base validation of the superclass. Not meant to be used directly in Groovy.- Overrides:
validatein classAbstractCalculable- Parameters:
validationVisitor- Receives a validation error when this Calculated Field Set is invalid.objService- Used to delegate to the superclass validation.- Returns:
trueif this Calculated Field Set is valid,falseotherwise.
-
onDelete
public void onDelete(PersistedObjectService objService, boolean hardDelete) Called by the persistence layer when this Calculated Field Set is deleted. Clears the CFS link (linkedCFStypedId) on every Manual Price List that references this set. Not meant to be used directly in Groovy.- Overrides:
onDeletein classPersistedObject- Parameters:
objService- Used to update the linked Manual Price Lists.hardDelete- A Calculated Field Set is always deleted permanently (true); the link is cleared either way.
-
getItemClass
Part of the calculable-object contract. A Calculated Field Set has no line items of its own; it writes into the rows of its source table. Not meant to be used directly in Groovy.- Specified by:
getItemClassin interfaceHasCalculableObjectItems- Returns:
- Always
null.
-
getItemListFilterField
Part of the calculable-object contract. A Calculated Field Set has no line items of its own, so there is no field that links items to it. Not meant to be used directly in Groovy.- Specified by:
getItemListFilterFieldin interfaceHasCalculableObjectItems- Returns:
- Always
null.
-
getDefaultTrackerType
public JobStatusTracker.TrackerType getDefaultTrackerType()The kind of background job tracker used by default when this Calculated Field Set is calculated. Not meant to be used directly in Groovy.- Specified by:
getDefaultTrackerTypein classAbstractCalculable- Returns:
TrackerType.CFS.
-
getCalculationConcurrencyKey
The concurrency key of the calculation jobs started for this Calculated Field Set. It is built from the source type code and, when set, the concurrency key suffix of the configuration, so jobs that work on the same source run one at a time unless they have different suffixes. Not meant to be used directly in Groovy.- Overrides:
getCalculationConcurrencyKeyin classAbstractCalculable- Returns:
- The source type code, followed by
"-"and the suffix when one is set (for example"P-1"), or the string"null"(no source type) if the set has not been configured yet.
-
getItemAttributeMetaClass
Part of the calculable-object contract. A Calculated Field Set has no line items, so it has no line item attribute metadata. Not meant to be used directly in Groovy.- Specified by:
getItemAttributeMetaClassin interfaceHasCalculableObjectItems- Returns:
- Always
null.
-
getJobType
The job-type discriminator used for background calculation job naming and routing. Not meant to be used directly in Groovy.- Specified by:
getJobTypein interfaceJobSettingsProvider- Returns:
- This Calculated Field Set's type code,
"CFS".
-
isShotgunEnabled
public boolean isShotgunEnabled(PersistedObjectService txn) Whether "shotgun mode" (a distributed calculation spread across multiple worker agents instead of one sequential run) is allowed for this Calculated Field Set. It requires the shotgun mode setting of the configuration and a source that is not a global object extension (seegetGlobalOXName(PersistedObjectService)). Not meant to be used directly in Groovy.- Specified by:
isShotgunEnabledin interfaceJobSettingsProvider- Parameters:
txn- Used to resolve the source type of the configuration.- Returns:
trueif shotgun mode is enabled in the configuration and the source is not a global object extension,falseotherwise.
-
getGlobalOXName
The name of the global object extension this Calculated Field Set calculates, if its source is one. A global extension is configured with the"GLOBAL."prefix in front of its name. Not meant to be used directly in Groovy.- Parameters:
txn- Used to resolve the source type of the configuration.- Returns:
- The extension name without the
"GLOBAL."prefix, or an emptyOptionalif the source is not a global object extension.
-
getShotgunThreshold
public int getShotgunThreshold(PersistedObjectService objService, JobStatusTracker jst) The minimum job size (seejobSize(PersistedObjectService, JobStatusTracker, int)) above which the calculation framework switches to shotgun (distributed) mode instead of a single sequential run, whenisShotgunEnabled(PersistedObjectService)allows it. The threshold is set for the whole instance (default 5000) and can be overridden per partition by an application property. Not meant to be used directly in Groovy.- Specified by:
getShotgunThresholdin interfaceJobSettingsProvider- Parameters:
objService- Used to resolve the configured threshold.jst- The job status tracker for the current calculation run.- Returns:
- The shotgun mode threshold for this run.
-
jobSize
public int jobSize(PersistedObjectService objectService, JobStatusTracker jst, int runNumber) The number of source rows the current calculation run is expected to process: the count of rows in the source table that match the source filter of the configuration. Not meant to be used directly in Groovy.- Specified by:
jobSizein interfaceJobSettingsProvider- Parameters:
objectService- Used to count the matching source rows.jst- The job status tracker for the current calculation run.runNumber- The current pass number of a multi-pass calculation; not used by this implementation.- Returns:
- The number of matching source rows, or
0if it cannot be determined.
-