Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Business description

To secure the cost process, our company decide decided to block possibility to see issues by unauthorized employees. An access unauthorized employees' possibility of seeing issues. Access to them will be related to the department and cost center or cost group and cost category.

Solution Brief

Using decision tables, we will calculate , which group is authorized and set them to the custom field. Final validation will be done based on that data.

To solve that, we We prepare two decision tables to solve that - each one will return a list of group groups based on related parameters.

...

Info
titleNote

In this script, we use some superclasses, which help us in code management. For more information, see the Usage of base groovy classes and utilities page.

...

Code Block
languagegroovy
themeRDark
def departmentField = issueFieldOperator.forField(FieldUtils.getCustomField(CustomFieldCode.DEPARTMENT_CF))
def costCentreField = issueFieldOperator.forField(FieldUtils.getCustomField(CustomFieldCode.COST_CENTRE))

def costGroupField = issueFieldOperator.forField(FieldUtils.getCustomField(CustomFieldCode.COST_GROUP))
def costCategoryField = issueFieldOperator.forField(FieldUtils.getCustomField(CustomFieldCode.COST_CATEGORY))

def groupAssigneeField = issueFieldOperator.forField(FieldUtils.getCustomField(CustomFieldCode.GROUP_ASSIGNEE))
def accessibleForGroupsField = issueFieldOperator.forField(FieldUtils.getCustomField(CustomFieldCode.ACCESSIBLE_FOR_GROUPS))

Next The next step is to get references to the necessary fields.

Code Block
languagegroovy
themeRDark
accessibleForGroupsField.config.exceptionHandlingStrategy.globalCheckStrategy
				.setSourceHandlingMode(ExceptionHandlingMode.REGISTER)
				.setRegistryHandlingMode(ExceptionHandlingMode.LOG_WARNING)

This time we want to register possible errors - for example, non-existing group. In that situation, terminate the operation is unnecessary, but we would like to log them, just in case.

...

 We are going to combine results from two decision tables and the current group assignee if it exists. We will do this using transient variables, thanks . Thanks to them, all changes is are made on variables and that does do not interfere with change history.

Code Block
languagegroovy
themeRDark
accessibleForGroupsField.setObjectValue(null)
accessibleForGroupsField.appendValue(groupAssigneeField.getValue().multi())

Operations is are started with clear field value values and set there current the currently assigned group.

Code Block
languagegroovy
themeRDark
def dtCostCentreResult = decisionTableManager.getDMNDecisionTableOperations(
	"costAccess",
	"costCentreAccess"
).executeQuery([
	"department": departmentField.getBusinessKey().first(),
	"costCentre": costCentreField.getBusinessKey().first()
])
issueFieldOperator.getConfig().setCurrentExecutionInfo(dtCostCentreResult.executionContextInfo)

We get possibilities from the first decision table.

Code Block
languagegroovy
themeRDark
def groupNames = dtCostCentreResult.multiNonNull().collect({elem -> elem.get("accessibleForGroups")})
accessibleForGroupsField.appendValue(accessibleForGroupsField.getValueByBusinessKey(groupNames))

...