use of com.evolveum.midpoint.wf.impl.processes.itemApproval.ApprovalRequest in project midpoint by Evolveum.
the class ModifyAssignmentAspect method getApprovalRequests.
private List<ApprovalRequest<AssignmentModification>> getApprovalRequests(ModelContext<?> modelContext, WfConfigurationType wfConfigurationType, ObjectDelta<? extends ObjectType> change, Task taskFromModel, OperationResult result) throws SchemaException {
if (change.getChangeType() != ChangeType.MODIFY) {
return null;
}
PrismObject<F> focusOld = (PrismObject<F>) modelContext.getFocusContext().getObjectOld();
F focusTypeOld = focusOld.asObjectable();
PcpAspectConfigurationType config = primaryChangeAspectHelper.getPcpAspectConfigurationType(wfConfigurationType, this);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Relevant assignments in focus modify delta: ");
}
List<ApprovalRequest<AssignmentModification>> approvalRequestList = new ArrayList<>();
final ItemPath ASSIGNMENT_PATH = new ItemPath(UserType.F_ASSIGNMENT);
PrismContainer<AssignmentType> assignmentsOld = focusOld.findContainer(ASSIGNMENT_PATH);
// deltas sorted by assignment to which they are related
Map<Long, List<ItemDeltaType>> deltasById = new HashMap<>();
Iterator<? extends ItemDelta> deltaIterator = change.getModifications().iterator();
while (deltaIterator.hasNext()) {
ItemDelta delta = deltaIterator.next();
if (!ASSIGNMENT_PATH.isSubPath(delta.getPath())) {
continue;
}
// id may be null
Long id = getAssignmentIdFromDeltaPath(assignmentsOld, delta.getPath());
AssignmentType assignmentType = getAssignmentToBeModified(assignmentsOld, id);
if (isAssignmentRelevant(assignmentType)) {
T target = getAssignmentApprovalTarget(assignmentType, result);
boolean approvalRequired = shouldAssignmentBeApproved(config, target);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(" - target: {} (approval required = {})", target, approvalRequired);
}
if (approvalRequired) {
addToDeltas(deltasById, assignmentType.getId(), delta);
deltaIterator.remove();
}
}
}
if (!deltasById.isEmpty()) {
for (Map.Entry<Long, List<ItemDeltaType>> entry : deltasById.entrySet()) {
Long id = entry.getKey();
AssignmentType assignmentType = getAssignmentToBeModified(assignmentsOld, id);
AssignmentType aCopy = cloneAndCanonicalizeAssignment(assignmentType);
T target = getAssignmentApprovalTarget(assignmentType, result);
ApprovalRequest approvalRequest = createApprovalRequestForModification(config, aCopy, target, entry.getValue(), createRelationResolver(target, result), createReferenceResolver(modelContext, taskFromModel, result));
approvalRequestList.add(approvalRequest);
}
}
return approvalRequestList;
}
use of com.evolveum.midpoint.wf.impl.processes.itemApproval.ApprovalRequest in project midpoint by Evolveum.
the class ChangePasswordAspect method prepareTasks.
@NotNull
@Override
public List<PcpChildWfTaskCreationInstruction> prepareTasks(@NotNull ObjectTreeDeltas objectTreeDeltas, ModelInvocationContext ctx, @NotNull OperationResult result) throws SchemaException {
List<ApprovalRequest<String>> approvalRequestList = new ArrayList<>();
List<PcpChildWfTaskCreationInstruction> instructions = new ArrayList<>();
ObjectDelta changeRequested = objectTreeDeltas.getFocusChange();
if (changeRequested == null || changeRequested.getChangeType() != ChangeType.MODIFY) {
return Collections.emptyList();
}
Iterator<? extends ItemDelta> deltaIterator = changeRequested.getModifications().iterator();
ItemPath passwordPath = new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE);
while (deltaIterator.hasNext()) {
ItemDelta delta = deltaIterator.next();
// also, what if we replace whole 'credentials' container?
if (passwordPath.equivalent(delta.getPath())) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Found password-changing delta, moving it into approval request. Delta = " + delta.debugDump());
}
ApprovalRequest<String> approvalRequest = createApprovalRequest(delta, ctx.modelContext, ctx.taskFromModel, result);
approvalRequestList.add(approvalRequest);
instructions.add(createStartProcessInstruction(ctx.modelContext, delta, approvalRequest, ctx.taskFromModel, result));
deltaIterator.remove();
}
}
return instructions;
}
use of com.evolveum.midpoint.wf.impl.processes.itemApproval.ApprovalRequest in project midpoint by Evolveum.
the class AddAssociationAspect method getApprovalRequestsFromShadowModify.
private List<ApprovalRequest<AssociationAdditionType>> getApprovalRequestsFromShadowModify(PcpAspectConfigurationType config, PrismObject<ShadowType> shadowOld, ObjectDelta<ShadowType> change, ResourceShadowDiscriminator rsd, ModelContext<?> modelContext, Task taskFromModel, OperationResult result) {
LOGGER.trace("Relevant associations in shadow modify delta:");
List<ApprovalRequest<AssociationAdditionType>> approvalRequestList = new ArrayList<>();
Iterator<? extends ItemDelta> deltaIterator = change.getModifications().iterator();
final ItemPath ASSOCIATION_PATH = new ItemPath(ShadowType.F_ASSOCIATION);
while (deltaIterator.hasNext()) {
ItemDelta delta = deltaIterator.next();
if (!ASSOCIATION_PATH.equivalent(delta.getPath())) {
continue;
}
if (delta.getValuesToAdd() != null && !delta.getValuesToAdd().isEmpty()) {
Iterator<PrismContainerValue<ShadowAssociationType>> valueIterator = delta.getValuesToAdd().iterator();
while (valueIterator.hasNext()) {
PrismContainerValue<ShadowAssociationType> association = valueIterator.next();
ApprovalRequest<AssociationAdditionType> req = processAssociationToAdd(config, association, rsd, modelContext, taskFromModel, result);
if (req != null) {
approvalRequestList.add(req);
valueIterator.remove();
}
}
}
if (delta.getValuesToReplace() != null && !delta.getValuesToReplace().isEmpty()) {
Iterator<PrismContainerValue<ShadowAssociationType>> valueIterator = delta.getValuesToReplace().iterator();
while (valueIterator.hasNext()) {
PrismContainerValue<ShadowAssociationType> association = valueIterator.next();
if (existsEquivalentValue(shadowOld, association)) {
continue;
}
ApprovalRequest<AssociationAdditionType> req = processAssociationToAdd(config, association, rsd, modelContext, taskFromModel, result);
if (req != null) {
approvalRequestList.add(req);
valueIterator.remove();
}
}
}
// let's sanitize the delta
if (delta.getValuesToAdd() != null && delta.getValuesToAdd().isEmpty()) {
// empty set of values to add is an illegal state
delta.resetValuesToAdd();
}
if (delta.getValuesToAdd() == null && delta.getValuesToReplace() == null && delta.getValuesToDelete() == null) {
deltaIterator.remove();
}
}
return approvalRequestList;
}
use of com.evolveum.midpoint.wf.impl.processes.itemApproval.ApprovalRequest in project midpoint by Evolveum.
the class AddAssignmentAspect method getApprovalRequestsFromFocusModify.
private List<ApprovalRequest<AssignmentType>> getApprovalRequestsFromFocusModify(PcpAspectConfigurationType config, PrismObject<?> focusOld, ObjectDelta<? extends ObjectType> change, ModelContext<?> modelContext, Task taskFromModel, OperationResult result) {
LOGGER.trace("Relevant assignments in focus modify delta:");
List<ApprovalRequest<AssignmentType>> approvalRequestList = new ArrayList<>();
Iterator<? extends ItemDelta> deltaIterator = change.getModifications().iterator();
final ItemPath ASSIGNMENT_PATH = new ItemPath(FocusType.F_ASSIGNMENT);
while (deltaIterator.hasNext()) {
ItemDelta delta = deltaIterator.next();
if (!ASSIGNMENT_PATH.equivalent(delta.getPath())) {
continue;
}
if (delta.getValuesToAdd() != null && !delta.getValuesToAdd().isEmpty()) {
Iterator<PrismContainerValue<AssignmentType>> valueIterator = delta.getValuesToAdd().iterator();
while (valueIterator.hasNext()) {
PrismContainerValue<AssignmentType> assignmentValue = valueIterator.next();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Assignment to add = {}", assignmentValue.debugDump());
}
ApprovalRequest<AssignmentType> req = processAssignmentToAdd(config, assignmentValue, modelContext, taskFromModel, result);
if (req != null) {
approvalRequestList.add(req);
valueIterator.remove();
}
}
}
if (delta.getValuesToReplace() != null && !delta.getValuesToReplace().isEmpty()) {
Iterator<PrismContainerValue<AssignmentType>> valueIterator = delta.getValuesToReplace().iterator();
while (valueIterator.hasNext()) {
PrismContainerValue<AssignmentType> assignmentValue = valueIterator.next();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Assignment to replace = {}", assignmentValue.debugDump());
}
if (existsEquivalentValue(focusOld, assignmentValue)) {
continue;
}
ApprovalRequest<AssignmentType> req = processAssignmentToAdd(config, assignmentValue, modelContext, taskFromModel, result);
if (req != null) {
approvalRequestList.add(req);
valueIterator.remove();
}
}
}
// let's sanitize the delta
if (delta.getValuesToAdd() != null && delta.getValuesToAdd().isEmpty()) {
// empty set of values to add is an illegal state
delta.resetValuesToAdd();
}
if (delta.getValuesToAdd() == null && delta.getValuesToReplace() == null && delta.getValuesToDelete() == null) {
deltaIterator.remove();
}
}
return approvalRequestList;
}
Aggregations