use of javax.xml.datatype.Duration in project midpoint by Evolveum.
the class WfContextUtil method createTrigger.
@NotNull
private static TriggerType createTrigger(XMLGregorianCalendar triggerTime, WorkItemActionsType actions, Pair<Duration, AbstractWorkItemActionType> notifyInfo, PrismContext prismContext, @Nullable String workItemId, @NotNull String handlerUri) throws SchemaException {
TriggerType trigger = new TriggerType(prismContext);
trigger.setTimestamp(triggerTime);
trigger.setHandlerUri(handlerUri);
ExtensionType extension = new ExtensionType(prismContext);
trigger.setExtension(extension);
SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
if (workItemId != null) {
// work item id
@SuppressWarnings("unchecked") @NotNull PrismPropertyDefinition<String> workItemIdDef = prismContext.getSchemaRegistry().findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_WORK_ITEM_ID);
PrismProperty<String> workItemIdProp = workItemIdDef.instantiate();
workItemIdProp.addRealValue(workItemId);
trigger.getExtension().asPrismContainerValue().add(workItemIdProp);
}
// actions
if (actions != null) {
@NotNull PrismContainerDefinition<WorkItemActionsType> workItemActionsDef = schemaRegistry.findContainerDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_WORK_ITEM_ACTIONS);
PrismContainer<WorkItemActionsType> workItemActionsCont = workItemActionsDef.instantiate();
workItemActionsCont.add(actions.asPrismContainerValue().clone());
extension.asPrismContainerValue().add(workItemActionsCont);
}
// time before + action
if (notifyInfo != null) {
@NotNull PrismContainerDefinition<AbstractWorkItemActionType> workItemActionDef = schemaRegistry.findContainerDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_WORK_ITEM_ACTION);
PrismContainer<AbstractWorkItemActionType> workItemActionCont = workItemActionDef.instantiate();
workItemActionCont.add(notifyInfo.getValue().asPrismContainerValue().clone());
extension.asPrismContainerValue().add(workItemActionCont);
@SuppressWarnings("unchecked") @NotNull PrismPropertyDefinition<Duration> timeBeforeActionDef = schemaRegistry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_TIME_BEFORE_ACTION);
PrismProperty<Duration> timeBeforeActionProp = timeBeforeActionDef.instantiate();
timeBeforeActionProp.addRealValue(notifyInfo.getKey());
extension.asPrismContainerValue().add(timeBeforeActionProp);
}
return trigger;
}
use of javax.xml.datatype.Duration in project midpoint by Evolveum.
the class SystemConfigurationDto method getNewObject.
public SystemConfigurationType getNewObject() throws DatatypeConfigurationException {
SystemConfigurationType newObject = oldObject.clone();
if (StringUtils.isNotBlank(getPassPolicyDto().getOid())) {
ObjectReferenceType globalPassPolicyRef = ObjectTypeUtil.createObjectRef(getPassPolicyDto().getOid(), ObjectTypes.PASSWORD_POLICY);
newObject.setGlobalPasswordPolicyRef(globalPassPolicyRef);
} else {
newObject.setGlobalPasswordPolicyRef(null);
}
if (StringUtils.isNotBlank(getSecurityPolicyDto().getOid())) {
ObjectReferenceType globalSecurityPolicyRef = ObjectTypeUtil.createObjectRef(getSecurityPolicyDto().getOid(), WebComponentUtil.createPolyFromOrigString(getSecurityPolicyDto().getName()), ObjectTypes.SECURITY_POLICY);
newObject.setGlobalSecurityPolicyRef(globalSecurityPolicyRef);
} else {
newObject.setGlobalSecurityPolicyRef(null);
}
AssignmentPolicyEnforcementType globalAEP = AEPlevel.toAEPValueType(getAepLevel());
if (globalAEP != null) {
ProjectionPolicyType projectionPolicy = new ProjectionPolicyType();
projectionPolicy.setAssignmentPolicyEnforcement(globalAEP);
newObject.setGlobalAccountSynchronizationSettings(projectionPolicy);
}
Duration auditCleanupDuration = DatatypeFactory.newInstance().newDuration(getAuditCleanupValue());
Duration cleanupTaskDuration = DatatypeFactory.newInstance().newDuration(getTaskCleanupValue());
CleanupPolicyType auditCleanup = new CleanupPolicyType();
CleanupPolicyType taskCleanup = new CleanupPolicyType();
auditCleanup.setMaxAge(auditCleanupDuration);
taskCleanup.setMaxAge(cleanupTaskDuration);
CleanupPoliciesType cleanupPolicies = new CleanupPoliciesType();
cleanupPolicies.setAuditRecords(auditCleanup);
cleanupPolicies.setClosedTasks(taskCleanup);
newObject.setCleanupPolicy(cleanupPolicies);
SystemConfigurationTypeUtil.setEnableExperimentalCode(newObject, getEnableExperimentalCode());
newObject.setLogging(loggingConfig.getNewObject());
newObject.setNotificationConfiguration(notificationConfig.getNewObject(newObject));
newObject.setProfilingConfiguration(profilingDto.getNewObject());
ClassLoggerConfigurationType profilingClassLogger = profilingDto.getProfilingClassLogerConfig();
if (newObject.getLogging() != null) {
newObject.getLogging().getClassLogger().add(profilingClassLogger);
} else {
LoggingConfigurationType profLogging = new LoggingConfigurationType();
profLogging.getClassLogger().add(profilingClassLogger);
newObject.setLogging(profLogging);
}
return newObject;
}
use of javax.xml.datatype.Duration in project midpoint by Evolveum.
the class ShadowCache method expirePendingOperations.
private boolean expirePendingOperations(ProvisioningContext ctx, PrismObject<ShadowType> repoShadow, ObjectDelta<ShadowType> shadowDelta, XMLGregorianCalendar now, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
ShadowType shadowType = repoShadow.asObjectable();
Duration gracePeriod = null;
ResourceConsistencyType consistency = ctx.getResource().getConsistency();
if (consistency != null) {
gracePeriod = consistency.getPendingOperationGracePeriod();
}
boolean atLeastOneOperationRemains = false;
for (PendingOperationType pendingOperation : shadowType.getPendingOperation()) {
ItemPath containerPath = pendingOperation.asPrismContainerValue().getPath();
OperationResultStatusType statusType = pendingOperation.getResultStatus();
XMLGregorianCalendar completionTimestamp = pendingOperation.getCompletionTimestamp();
if (isCompleted(statusType) && isOverGrace(now, gracePeriod, completionTimestamp)) {
LOGGER.trace("Deleting pending operation because it is completed '{}' (and over grace): {}", statusType.value(), pendingOperation);
shadowDelta.addModificationDeleteContainer(new ItemPath(ShadowType.F_PENDING_OPERATION), pendingOperation.clone());
} else {
atLeastOneOperationRemains = true;
}
}
return atLeastOneOperationRemains;
}
use of javax.xml.datatype.Duration in project midpoint by Evolveum.
the class WfTaskController method onTaskEvent.
//endregion
//region Processing work item (task) events
// workItem contains taskRef, assignee, candidates resolved (if possible)
// workItem can be freely modified (e.g. by overriding result, etc.)
@SuppressWarnings("unchecked")
public void onTaskEvent(WorkItemType workItem, TaskEvent taskEvent, OperationResult result) throws WorkflowException, SchemaException {
final TaskType shadowTaskType = WfContextUtil.getTask(workItem);
if (shadowTaskType == null) {
LOGGER.warn("No task in workItem " + workItem + ", audit and notifications couldn't be performed.");
return;
}
final Task shadowTask = taskManager.createTaskInstance(shadowTaskType.asPrismObject(), result);
final WfTask wfTask = recreateWfTask(shadowTask);
// auditing & notifications & event
if (taskEvent instanceof TaskCreatedEvent) {
AuditEventRecord auditEventRecord = getChangeProcessor(taskEvent).prepareWorkItemCreatedAuditRecord(workItem, taskEvent, wfTask, result);
auditService.audit(auditEventRecord, wfTask.getTask());
try {
notifyWorkItemCreated(workItem.getOriginalAssigneeRef(), workItem, wfTask, result);
if (workItem.getAssigneeRef() != null) {
WorkItemAllocationChangeOperationInfo operationInfo = new WorkItemAllocationChangeOperationInfo(null, Collections.emptyList(), workItem.getAssigneeRef());
notifyWorkItemAllocationChangeNewActors(workItem, operationInfo, null, wfTask.getTask(), result);
}
} catch (SchemaException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't send notification about work item create event", e);
}
} else if (taskEvent instanceof TaskDeletedEvent) {
// this might be cancellation because of:
// (1) user completion of this task
// (2) timed completion of this task
// (3) user completion of another task
// (4) timed completion of another task
// (5) process stop/deletion
//
// Actually, when the source is (4) timed completion of another task, it is quite probable that this task
// would be closed for the same reason. For a user it would be misleading if we would simply view this task
// as 'cancelled', while, in fact, it is e.g. approved/rejected because of a timed action.
WorkItemOperationKindType operationKind = BooleanUtils.isTrue(ActivitiUtil.getVariable(taskEvent.getVariables(), CommonProcessVariableNames.VARIABLE_WORK_ITEM_WAS_COMPLETED, Boolean.class, prismContext)) ? WorkItemOperationKindType.COMPLETE : WorkItemOperationKindType.CANCEL;
WorkItemEventCauseInformationType cause = ActivitiUtil.getVariable(taskEvent.getVariables(), CommonProcessVariableNames.VARIABLE_CAUSE, WorkItemEventCauseInformationType.class, prismContext);
boolean genuinelyCompleted = operationKind == WorkItemOperationKindType.COMPLETE;
MidPointPrincipal user;
try {
user = SecurityUtil.getPrincipal();
} catch (SecurityViolationException e) {
throw new SystemException("Couldn't determine current user: " + e.getMessage(), e);
}
// partial fallback
ObjectReferenceType userRef = user != null ? user.toObjectReference() : workItem.getPerformerRef();
if (!genuinelyCompleted) {
TaskType task = wfTask.getTask().getTaskPrismObject().asObjectable();
int foundTimedActions = 0;
for (TriggerType trigger : task.getTrigger()) {
if (!WfTimedActionTriggerHandler.HANDLER_URI.equals(trigger.getHandlerUri())) {
continue;
}
String workItemId = ObjectTypeUtil.getExtensionItemRealValue(trigger.getExtension(), SchemaConstants.MODEL_EXTENSION_WORK_ITEM_ID);
if (!taskEvent.getTaskId().equals(workItemId)) {
continue;
}
Duration timeBeforeAction = ObjectTypeUtil.getExtensionItemRealValue(trigger.getExtension(), SchemaConstants.MODEL_EXTENSION_TIME_BEFORE_ACTION);
if (timeBeforeAction != null) {
continue;
}
WorkItemActionsType actions = ObjectTypeUtil.getExtensionItemRealValue(trigger.getExtension(), SchemaConstants.MODEL_EXTENSION_WORK_ITEM_ACTIONS);
if (actions == null || actions.getComplete() == null) {
continue;
}
long diff = XmlTypeConverter.toMillis(trigger.getTimestamp()) - clock.currentTimeMillis();
if (diff >= COMPLETION_TRIGGER_EQUALITY_THRESHOLD) {
continue;
}
CompleteWorkItemActionType completeAction = actions.getComplete();
operationKind = WorkItemOperationKindType.COMPLETE;
cause = new WorkItemEventCauseInformationType();
cause.setType(WorkItemEventCauseTypeType.TIMED_ACTION);
cause.setName(completeAction.getName());
cause.setDisplayName(completeAction.getDisplayName());
foundTimedActions++;
WorkItemResultType workItemOutput = new WorkItemResultType();
workItemOutput.setOutcome(completeAction.getOutcome() != null ? completeAction.getOutcome() : SchemaConstants.MODEL_APPROVAL_OUTCOME_REJECT);
workItem.setOutput(workItemOutput);
}
if (foundTimedActions > 1) {
LOGGER.warn("Multiple 'work item complete' timed actions ({}) for {}: {}", foundTimedActions, ObjectTypeUtil.toShortString(task), task.getTrigger());
}
}
// We don't pass userRef (initiator) to the audit method. It does need the whole object (not only the reference),
// so it fetches it directly from the security enforcer (logged-in user). This could change in the future.
AuditEventRecord auditEventRecord = getChangeProcessor(taskEvent).prepareWorkItemDeletedAuditRecord(workItem, cause, taskEvent, wfTask, result);
auditService.audit(auditEventRecord, wfTask.getTask());
try {
WorkItemAllocationChangeOperationInfo operationInfo = new WorkItemAllocationChangeOperationInfo(operationKind, workItem.getAssigneeRef(), null);
WorkItemOperationSourceInfo sourceInfo = new WorkItemOperationSourceInfo(userRef, cause, null);
if (workItem.getAssigneeRef().isEmpty()) {
notifyWorkItemDeleted(null, workItem, operationInfo, sourceInfo, wfTask, result);
} else {
for (ObjectReferenceType assignee : workItem.getAssigneeRef()) {
notifyWorkItemDeleted(assignee, workItem, operationInfo, sourceInfo, wfTask, result);
}
}
notifyWorkItemAllocationChangeCurrentActors(workItem, operationInfo, sourceInfo, null, wfTask.getTask(), result);
} catch (SchemaException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't audit work item complete event", e);
}
AbstractWorkItemOutputType output = workItem.getOutput();
if (genuinelyCompleted || output != null) {
WorkItemCompletionEventType event = new WorkItemCompletionEventType();
ActivitiUtil.fillInWorkItemEvent(event, user, taskEvent.getTaskId(), taskEvent.getVariables(), prismContext);
event.setCause(cause);
event.setOutput(output);
ObjectDeltaType additionalDelta = output instanceof WorkItemResultType && ((WorkItemResultType) output).getAdditionalDeltas() != null ? ((WorkItemResultType) output).getAdditionalDeltas().getFocusPrimaryDelta() : null;
MidpointUtil.recordEventInTask(event, additionalDelta, wfTask.getTask().getOid(), result);
}
MidpointUtil.removeTriggersForWorkItem(wfTask.getTask(), taskEvent.getTaskId(), result);
}
}
use of javax.xml.datatype.Duration in project midpoint by Evolveum.
the class CleanupTest method createPolicy.
private CleanupPolicyType createPolicy(Calendar when, long now) throws Exception {
CleanupPolicyType policy = new CleanupPolicyType();
Duration duration = createDuration(when, now);
policy.setMaxAge(duration);
return policy;
}
Aggregations