Search in sources :

Example 1 with Duration

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;
}
Also used : Duration(javax.xml.datatype.Duration) NotNull(org.jetbrains.annotations.NotNull) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Duration

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;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) LoggingConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.LoggingConfigurationType) AssignmentPolicyEnforcementType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentPolicyEnforcementType) CleanupPoliciesType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPoliciesType) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) Duration(javax.xml.datatype.Duration) ClassLoggerConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ClassLoggerConfigurationType) ProjectionPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProjectionPolicyType)

Example 3 with Duration

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;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Duration(javax.xml.datatype.Duration) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 4 with Duration

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);
    }
}
Also used : PcpWfTask(com.evolveum.midpoint.wf.impl.processors.primary.PcpWfTask) Task(com.evolveum.midpoint.task.api.Task) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) Duration(javax.xml.datatype.Duration) PcpWfTask(com.evolveum.midpoint.wf.impl.processors.primary.PcpWfTask) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord)

Example 5 with Duration

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;
}
Also used : CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) Duration(javax.xml.datatype.Duration)

Aggregations

Duration (javax.xml.datatype.Duration)110 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)50 Test (org.junit.Test)17 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 ArrayList (java.util.ArrayList)11 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)8 GregorianCalendar (java.util.GregorianCalendar)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 Date (java.util.Date)7 CleanupPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType)6 Calendar (java.util.Calendar)6 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 XSDayTimeDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration)5 Collection (java.util.Collection)4 NodeValue (org.apache.jena.sparql.expr.NodeValue)4 NotNull (org.jetbrains.annotations.NotNull)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)3 Task (com.evolveum.midpoint.task.api.Task)3