com.memority.citadel.shared.api.context.CitadelContext Maven / Gradle / Ivy
Show all versions of citadel-api Show documentation
/*
* Copyright (c) 2016-2023 Memority. All Rights Reserved.
*
* This file is part of Memority Citadel API , a Memority project.
*
* This file is released under the Memority Public Artifacts End-User License Agreement,
* see
* Unauthorized copying of this file, via any medium is strictly prohibited.
*/
package com.memority.citadel.shared.api.context;
import com.memority.toolkit.rule.api.context.ActorsContext;
import com.memority.toolkit.rule.api.context.Context;
import com.memority.toolkit.rule.api.context.StandardContext;
import com.memority.toolkit.rule.api.context.VariablesContext;
import com.memority.citadel.shared.api.im.ApiObject;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* The parent context made available to all Citadel rules.
*
* Root Contexts are made available directly to groovy scripts through their corresponding key (see public constants
* beginning with KEY_
.
*/
@SuppressWarnings("JavaDoc")
public class CitadelContext extends StandardContext implements Context {
public static final CitadelContext EMPTY = new CitadelContext(
null, null, null, null, null,
null, null, null, null, null,
null, null, null, null, null,
null, null, null, null, null,false);
private OperationContext operationContext;
private OperationContext primaryOperationContext;
private FeatureContext featureContext;
private ReportingContext reportingContext;
private TriggerContext triggerContext;
private AttributeContext attributeContext;
private WorkflowContext workflowContext;
private ExternalContext externalContext;
private String accessCodeId;
private VariablesContext notificationPayload = new VariablesContext();
private DimensionContext dimensionContext;
private RoleRequestContext roleRequestContext;
private RoleAssignmentOperationContext roleAssignmentOperationContext;
private ListWidgetContext listWidgetContext;
private ObjectRecertificationContext objectRecertificationContext;
/**
* Keeps track of the chained "actions", ie everything that may initiate one or several object operations, namely:
*
* - Object Policies
* - Business Policies
* - Feature Executions
*
* This chain is not allowed to grow indefinitely, it is the responsibility of the executors to enforce a max length
*/
private List actionStack = Collections.emptyList();
/**
* The IM operation key, exposed as {@value #KEY_OPERATION}
*/
public static final String KEY_OPERATION = "OPERATION";
/**
* The IM primary operation key, exposed as {@value #KEY_PRIMARY_OPERATION}
*/
public static final String KEY_PRIMARY_OPERATION = "PRIMARY_OPERATION";
/**
* The IM object key, exposed as {@value #KEY_OBJECT}
*/
public static final String KEY_OBJECT = "OBJECT";
/**
* The IM original object key, exposed as {@value #KEY_ORIGINAL_OBJECT}
*/
public static final String KEY_ORIGINAL_OBJECT = "ORIGINAL_OBJECT";
/**
* The attribute context key, exposed as {@value #KEY_ATTRIBUTE}
*/
@SuppressWarnings("WeakerAccess")
public static final String KEY_ATTRIBUTE = "ATTRIBUTE";
/**
* The feature context key, exposed as {@value #KEY_FEATURE}
*/
@SuppressWarnings("WeakerAccess")
public static final String KEY_FEATURE = "FEATURE";
/**
* The reporting context key, exposed as {@value #KEY_REPORTING}.
* This context will hold information regarding a reporting request
* such as the criteria sent by the user.
* Not to be confused with {@link CitadelContext#KEY_API_REPORTING}
* which deals with management of reporting collections.
*/
@SuppressWarnings("WeakerAccess")
public static final String KEY_REPORTING = "REPORTING";
/**
* The current reporting document when available, exposed as {@value KEY_REPORTING_DOCUMENT}
*/
public static final String KEY_REPORTING_DOCUMENT = "REPORTING_DOCUMENT";
/**
* The trigger context key, exposed as {@value #KEY_TRIGGER}
*/
@SuppressWarnings("WeakerAccess")
public static final String KEY_TRIGGER = "TRIGGER";
/**
* The external context key, exposed as {@value #KEY_EXTERNAL}
*/
@SuppressWarnings("WeakerAccess")
public static final String KEY_EXTERNAL = "EXTERNAL";
/**
* The workflow context key, exposed as {@value #KEY_WORKFLOW}
*/
@SuppressWarnings("WeakerAccess")
public static final String KEY_WORKFLOW = "WORKFLOW";
/**
* The binding context key, exposed as {@value #KEY_DIMENSION}
*/
@SuppressWarnings("WeakerAccess")
public static final String KEY_DIMENSION = "DIMENSION";
/**
* The binding context key, exposed as {@value #KEY_ROLE_REQUEST}
*/
@SuppressWarnings("WeakerAccess")
public static final String KEY_ROLE_REQUEST = "ROLE_REQUEST";
/**
* The binding context key, exposed as {@value #KEY_ROLE_ASSIGNMENT}
*/
@SuppressWarnings("WeakerAccess")
public static final String KEY_ROLE_ASSIGNMENT = "ROLE_ASSIGNMENT";
/**
* The list widget context key, exposed as {@value #KEY_LIST_WIDGET}
*/
public static final String KEY_LIST_WIDGET = "LIST_WIDGET";
/**
* The reference tables provider API key, exposed as {@value #KEY_API_REFTABLE}.
*
* @see com.memority.citadel.shared.api.services.reftable.ReferenceTableDataFinderProvider
*/
public static final String KEY_API_REFTABLE = "REF";
/**
* The sequence provider API key, exposed as {@value #KEY_API_SEQPROV}
*
* @see com.memority.citadel.shared.api.services.seq.SequenceProvider
*/
public static final String KEY_API_SEQPROV = "SEQ";
/**
* The ObjectFinder API key, expose as {@value #KEY_API_SEQPROV}
*
* @see com.memority.citadel.shared.api.services.finder.ObjectFinderProvider
*/
public static final String KEY_API_FINDPROV = "FIND";
public static final String KEY_API_NOTIFY = "NOTIFY";
public static final String KEY_API_MANAGE = "MANAGE";
public static final String KEY_ACCESS_CODE = "ACCESS_CODE";
public static final String KEY_FIELDS = "FIELDS";
public static final String KEY_API_INWEBO = "API_INWEBO"; // TODO CTD-9249 remove
public static final String KEY_API_MYMFA = "API_MYMFA";
public static final String KEY_API_FEATURE = "API_FEATURE";
public static final String KEY_API_WORKFLOW = "API_WORKFLOW";
public static final String KEY_API_REPORTING = "API_REPORTING";
public static final String KEY_API_OTP = "API_OTP";
public static final String KEY_API_ROLE_ASSIGNMENT = "API_ROLE_ASSIGNMENT";
public static final String KEY_RECERTIFICATION_API = "API_RECERTIFICATION";
public static final String KEY_RECERTIFICATION_CAMPAIGN_API = "API_RECERTIFICATION_CAMPAIGN";
public static final String KEY_OBJECT_RECERTIFICATION_API = "API_OBJECT_RECERTIFICATION";
public static final String KEY_OBJECT_RECERTIFICATION_CAMPAIGN_API = "API_OBJECT_RECERTIFICATION_CAMPAIGN";
public static final String KEY_API_VAULT = "VAULT";
public static final String KEY_API_HTTP = "HTTP";
public static final String KEY_API_SETTINGS = "SETTINGS";
public static final String KEY_API_CHANGES = "CHANGES";
public static final String KEY_OBJECT_RECERTIFICATION = "OBJECT_RECERTIFICATION";
@SuppressWarnings("unused") //for serialization
private CitadelContext() {
super();
}
public CitadelContext(ActorsContext actorsContext,
VariablesContext variablesContext,
OperationContext operationContext,
OperationContext primaryOperationContext,
FeatureContext featureContext,
ReportingContext reportingContext,
TriggerContext triggerContext,
AttributeContext attributeContext,
WorkflowContext workflowContext,
ExternalContext externalContext,
DimensionContext dimensionContext,
String accessCodeId,
List actionStack,
String notificationEventType,
Long randomSeed,
VariablesContext notificationPayload,
RoleRequestContext roleRequestContext,
RoleAssignmentOperationContext roleAssignmentOperationContext,
ListWidgetContext listWidgetContext,
ObjectRecertificationContext objectRecertificationContext,
boolean simulation) {
super(randomSeed);
this.simulation = simulation;
this.workflowContext = workflowContext;
this.actorsContext = actorsContext;
this.variablesContext = variablesContext;
this.operationContext = operationContext;
this.primaryOperationContext = primaryOperationContext;
this.featureContext = featureContext;
this.reportingContext = reportingContext;
this.triggerContext = triggerContext;
this.attributeContext = attributeContext;
this.externalContext = externalContext;
this.dimensionContext = dimensionContext;
this.accessCodeId = accessCodeId;
this.actionStack = actionStack != null ? actionStack : Collections.emptyList();
this.notificationEventType = notificationEventType;
this.notificationPayload = notificationPayload;
this.roleRequestContext = roleRequestContext;
this.roleAssignmentOperationContext = roleAssignmentOperationContext;
this.listWidgetContext = listWidgetContext;
this.objectRecertificationContext = objectRecertificationContext;
}
public AttributeContext getAttributeContext() {
return this.attributeContext;
}
public OperationContext getOperationContext() {
return this.operationContext;
}
public OperationContext getPrimaryOperationContext() {
return primaryOperationContext;
}
public FeatureContext getFeatureContext() {
return this.featureContext;
}
public ReportingContext getReportingContext() {
return this.reportingContext;
}
public TriggerContext getTriggerContext() {
return triggerContext;
}
public ExternalContext getExternalContext() {
return externalContext;
}
@SuppressWarnings("WeakerAccess") //API
public WorkflowContext getWorkflowContext() {
return workflowContext;
}
public String getAccessCodeId() {
return accessCodeId;
}
public VariablesContext getNotificationPayload() {
return notificationPayload;
}
/**
* Set a variable value in the notificationPayload {@link VariablesContext}.
*
* @param varName the variable name
* @param varValue the variable value
* @return this context
*/
public CitadelContext putNotificationPayload(String varName, Object varValue) {
this.getNotificationPayload().put(varName, varValue);
return self();
}
/**
* Returns the variable with the given name valueOf the notificationPayload {@link VariablesContext}.
*
* @param varName the variable name
* @return the variable value, maybe null
*/
public Object getNotificationPayload(String varName) {
return this.getNotificationPayload().get(varName);
}
public DimensionContext getBindingContext() {
return dimensionContext;
}
public RoleRequestContext getRoleRequestContext() {
return roleRequestContext;
}
public RoleAssignmentOperationContext getRoleAssignmentOperationContext() {
return roleAssignmentOperationContext;
}
public ListWidgetContext getListWidgetContext() {
return listWidgetContext;
}
public ObjectRecertificationContext getObjectRecertificationContext() {
return objectRecertificationContext;
}
@Override
public Map getRootContexts() {
Map rootContexts = super.getRootContexts();
rootContexts.put(KEY_OPERATION, getOperationContext());
rootContexts.put(KEY_PRIMARY_OPERATION, getPrimaryOperationContext());
rootContexts.put(KEY_OBJECT, getOperationContext() == null ? null : getOperationContext().getObject());
rootContexts.put(KEY_ATTRIBUTE, getAttributeContext());
rootContexts.put(KEY_FEATURE, getFeatureContext());
rootContexts.put(KEY_REPORTING, getReportingContext());
rootContexts.put(KEY_REPORTING_DOCUMENT, getReportingContext() == null ? null : getReportingContext().getDocument());
rootContexts.put(KEY_FIELDS, getFeatureContext() == null ? null : getFeatureContext().getFields());
rootContexts.put(KEY_TRIGGER, getTriggerContext());
rootContexts.put(KEY_EXTERNAL, getExternalContext());
rootContexts.put(KEY_WORKFLOW, getWorkflowContext());
rootContexts.put(KEY_DIMENSION, getBindingContext());
rootContexts.put(KEY_ROLE_REQUEST, getRoleRequestContext());
rootContexts.put(KEY_ROLE_ASSIGNMENT, getRoleAssignmentOperationContext());
rootContexts.put(KEY_LIST_WIDGET, getListWidgetContext());
rootContexts.put(KEY_OBJECT_RECERTIFICATION, getObjectRecertificationContext());
return rootContexts;
}
public List getActionStack() {
return Collections.unmodifiableList(actionStack);
}
}