Class CalculatedFieldSet

Object
DomainObject
PersistedObject
PartitionedObject
AbstractCalculable
CalculableObject
CalculatedFieldSet
All Implemented Interfaces:
Calculable, HasCalculableObjectItems, JobNameProvider, JobSettingsProvider, UserGroupRestrictedObject

@Entity public class CalculatedFieldSet extends CalculableObject implements UserGroupRestrictedObject, JobSettingsProvider
A Calculated Field Set (CFS, type code 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_THRESHOLD

    Fields inherited from class PartitionedObject

    FIELD_PARTITION, FIELD_PARTITIONID, PARTITION_FILTER_NAME, PARTITION_FILTER_PARAM

    Fields inherited from class PersistedObject

    FIELD_CREATEDATE, FIELD_CREATEDBY, FIELD_DELETEDATE, FIELD_DELETEDBY, FIELD_ID, FIELD_ISDELETED, FIELD_LASTUPDATEBY, FIELD_LASTUPDATEDATE, FIELD_VERSION

    Fields inherited from interface UserGroupRestrictedObject

    FIELD_USERGROUPEDIT, FIELD_USERGROUPVIEWDETAILS
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    CalculatedFieldSetConfiguration
    The configuration of this Calculated Field Set, deserialized from getConfiguration(): 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.TrackerType
    The 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.
    int
    getShotgunThreshold(PersistedObjectService objService, JobStatusTracker jst)
    The minimum job size (see jobSize(PersistedObjectService, JobStatusTracker, int)) above which the calculation framework switches to shotgun (distributed) mode instead of a single sequential run, when isShotgunEnabled(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.
    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.
    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.
    void
    onDelete(PersistedObjectService objService, boolean hardDelete)
    Called by the persistence layer when this Calculated Field Set is deleted.
    void
    setCalculatedFieldSetConfiguration(CalculatedFieldSetConfiguration config)
    Sets the configuration of this Calculated Field Set; it is stored as JSON (see getConfiguration()).
    void
    setConfiguration(String configuration)
    Sets the configuration of this Calculated Field Set as a JSON string (see getConfiguration()).
    void
    setNumberOfFailedItems(Integer numberOfFailedItems)
    Sets the number of failed rows.
    void
    setRelativeTargetDateDays(Integer relativeTargetDateDays)
    Sets the offset in days used when this Calculated Field Set has no explicit target date (see getRelativeTargetDateDays()).
    void
    Sets the User Group(s) whose members may edit this Calculated Field Set (see getUserGroupEdit()).
    void
    Sets the User Group(s) whose members may view the details of this Calculated Field Set (see getUserGroupViewDetails()).
    boolean
    validate(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, setWriteOnlyChangedItems

    Methods inherited from class AbstractCalculable

    calculationDate, calculationStartDate, getCalculationDate, getCalculationMessages, getCalculationMessagesAsList, getCalculationStartDate, getJobName, getLabel, getLocale, getStatus, getTargetDate, isAnonymousCalculable, setCalculationDate, setCalculationMessages, setCalculationMessages, setCalculationStartDate, setLabel, setLocale, setStatus, setTargetDate

    Methods inherited from class PartitionedObject

    addUniqueConstraint, getLoginNameByUserId, getPartition, setPartition, toString

    Methods 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, userGroupEditBulkloadFilter

    Methods 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, truncatedToString

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface JobSettingsProvider

    getAgentOption1
  • Constructor Details

    • CalculatedFieldSet

      public CalculatedFieldSet()
  • Method Details

    • getConfiguration

      public String 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 of getCalculatedFieldSetConfiguration(). Not meant to be used directly in Groovy.
      Returns:
      The configuration as JSON, or null if the set has not been configured yet.
    • setConfiguration

      public void setConfiguration(String configuration)
      Sets the configuration of this Calculated Field Set as a JSON string (see getConfiguration()). Not meant to be used directly in Groovy.
      Parameters:
      configuration - The configuration as JSON, or null to clear it.
    • getRelativeTargetDateDays

      public Integer 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 (see validate(ValidationVisitor, PersistedObjectService)).
      Returns:
      The offset in days, or null if not configured or if an explicit target date is set.
    • setRelativeTargetDateDays

      public void setRelativeTargetDateDays(Integer relativeTargetDateDays)
      Sets the offset in days used when this Calculated Field Set has no explicit target date (see getRelativeTargetDateDays()).
      Parameters:
      relativeTargetDateDays - The offset in days from the current date, or null to clear it.
    • getNumberOfFailedItems

      public Integer 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

      public void setNumberOfFailedItems(Integer numberOfFailedItems)
      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 from getConfiguration(): 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 (see getConfiguration()). Not meant to be used directly in Groovy.
      Parameters:
      config - The configuration to store.
    • getUserGroupEdit

      public String getUserGroupEdit()
      The User Group(s) whose members may edit this Calculated Field Set. Users with the USERGROUP_OVERRIDE permission bypass the restriction.
      Specified by:
      getUserGroupEdit in interface UserGroupRestrictedObject
      Returns:
      A User Group unique name or a comma-separated list of them, or null if editing is not restricted by User Group.
    • setUserGroupEdit

      public void setUserGroupEdit(String userGroup)
      Sets the User Group(s) whose members may edit this Calculated Field Set (see getUserGroupEdit()).
      Specified by:
      setUserGroupEdit in interface UserGroupRestrictedObject
      Parameters:
      userGroup - A User Group unique name or a comma-separated list of them, or null to remove the restriction.
    • getUserGroupViewDetails

      public String getUserGroupViewDetails()
      The User Group(s) whose members may view the details of this Calculated Field Set. Users with the USERGROUP_OVERRIDE permission bypass the restriction.
      Specified by:
      getUserGroupViewDetails in interface UserGroupRestrictedObject
      Returns:
      A User Group unique name or a comma-separated list of them, or null if viewing is not restricted by User Group.
    • setUserGroupViewDetails

      public void setUserGroupViewDetails(String userGroup)
      Sets the User Group(s) whose members may view the details of this Calculated Field Set (see getUserGroupViewDetails()).
      Specified by:
      setUserGroupViewDetails in interface UserGroupRestrictedObject
      Parameters:
      userGroup - A User Group unique name or a comma-separated list of them, or null to remove the restriction.
    • validate

      public boolean validate(ValidationVisitor validationVisitor, PersistedObjectService objService)
      Validates this Calculated Field Set before it is saved. Clears getRelativeTargetDateDays() 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:
      validate in class AbstractCalculable
      Parameters:
      validationVisitor - Receives a validation error when this Calculated Field Set is invalid.
      objService - Used to delegate to the superclass validation.
      Returns:
      true if this Calculated Field Set is valid, false otherwise.
    • 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:
      onDelete in class PersistedObject
      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

      public Class<? extends PriceCalculableObjectItem> 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:
      getItemClass in interface HasCalculableObjectItems
      Returns:
      Always null.
    • getItemListFilterField

      public String 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:
      getItemListFilterField in interface HasCalculableObjectItems
      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:
      getDefaultTrackerType in class AbstractCalculable
      Returns:
      TrackerType.CFS.
    • getCalculationConcurrencyKey

      public String 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:
      getCalculationConcurrencyKey in class AbstractCalculable
      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

      public Class<? extends ElementAttributeMeta> 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:
      getItemAttributeMetaClass in interface HasCalculableObjectItems
      Returns:
      Always null.
    • getJobType

      public String getJobType()
      The job-type discriminator used for background calculation job naming and routing. Not meant to be used directly in Groovy.
      Specified by:
      getJobType in interface JobSettingsProvider
      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 (see getGlobalOXName(PersistedObjectService)). Not meant to be used directly in Groovy.
      Specified by:
      isShotgunEnabled in interface JobSettingsProvider
      Parameters:
      txn - Used to resolve the source type of the configuration.
      Returns:
      true if shotgun mode is enabled in the configuration and the source is not a global object extension, false otherwise.
    • getGlobalOXName

      public Optional<String> getGlobalOXName(PersistedObjectService txn)
      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 empty Optional if the source is not a global object extension.
    • getShotgunThreshold

      public int getShotgunThreshold(PersistedObjectService objService, JobStatusTracker jst)
      The minimum job size (see jobSize(PersistedObjectService, JobStatusTracker, int)) above which the calculation framework switches to shotgun (distributed) mode instead of a single sequential run, when isShotgunEnabled(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:
      getShotgunThreshold in interface JobSettingsProvider
      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:
      jobSize in interface JobSettingsProvider
      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 0 if it cannot be determined.