Skip to content

Commit

Permalink
Interim commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Nov 28, 2016
1 parent 4a97202 commit 55d6617
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 73 deletions.
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.model.api.context;

import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

import java.util.List;

/**
* @author semancik
* @author mederly
*/
public interface AssignmentPath extends DebugDumpable {
List<? extends AssignmentPathSegment> getSegments();

AssignmentPathSegment getFirstAssignmentSegment();

boolean isEmpty();

int size();

EvaluationOrder getEvaluationOrder();

AssignmentPathSegment last();

boolean containsTarget(ObjectType target);
}
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.model.api.context;

import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

/**
* @author semancik
* @author mederly
*/
public interface AssignmentPathSegment extends DebugDumpable {
AssignmentType getAssignment();

ObjectType getTarget();

ObjectType getSource();

EvaluationOrder getEvaluationOrder();

ObjectType getOrderOneObject();
}
Expand Up @@ -36,7 +36,9 @@ public interface EvaluatedPolicyRule extends DebugDumpable, Serializable {
String getName();

PolicyRuleType getPolicyRule();


AssignmentPath getAssignmentPath();

PolicyConstraintsType getPolicyConstraints();

String getPolicySituation();
Expand Down
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.model.api.context;

import com.evolveum.midpoint.util.DebugDumpable;

import javax.xml.namespace.QName;

/**
* @author semancik
* @author mederly
*/
public interface EvaluationOrder extends DebugDumpable {

int getSummaryOrder();

EvaluationOrder advance();

EvaluationOrder advance(QName relation);

int getMatchingRelationOrder(QName relation);

String shortDump();
}
Expand Up @@ -23,7 +23,10 @@

import com.evolveum.midpoint.common.ActivationComputer;
import com.evolveum.midpoint.model.api.PolicyViolationException;
import com.evolveum.midpoint.model.api.context.AssignmentPath;
import com.evolveum.midpoint.model.api.context.AssignmentPathSegment;
import com.evolveum.midpoint.model.api.context.EvaluatedAssignment;
import com.evolveum.midpoint.model.api.context.EvaluationOrder;
import com.evolveum.midpoint.model.api.util.DeputyUtils;
import com.evolveum.midpoint.model.common.SystemObjectCache;
import com.evolveum.midpoint.model.common.expression.ExpressionUtil;
Expand Down Expand Up @@ -209,8 +212,8 @@ public EvaluatedAssignmentImpl<F> evaluate(ItemDeltaItem<PrismContainerValue<Ass
assertSource(source, assignmentIdi);
EvaluatedAssignmentImpl<F> evalAssignment = new EvaluatedAssignmentImpl<>();
evalAssignment.setAssignmentIdi(assignmentIdi);
AssignmentPath assignmentPath = new AssignmentPath();
AssignmentPathSegment assignmentPathSegment = new AssignmentPathSegment(assignmentIdi, null);
AssignmentPathImpl assignmentPath = new AssignmentPathImpl();
AssignmentPathSegmentImpl assignmentPathSegment = new AssignmentPathSegmentImpl(assignmentIdi, null);
assignmentPathSegment.setSource(source);
assignmentPathSegment.setEvaluationOrder(getInitialEvaluationOrder(assignmentIdi, evaluateOld));
assignmentPathSegment.setValidityOverride(true);
Expand All @@ -232,12 +235,12 @@ private EvaluationOrder getInitialEvaluationOrder(
if (assignmentType.getTargetRef() != null) {
relation = assignmentType.getTargetRef().getRelation();
}
return EvaluationOrder.ZERO.advance(relation);
return EvaluationOrderImpl.ZERO.advance(relation);
}

private <O extends ObjectType> void evaluateAssignment(EvaluatedAssignmentImpl<F> evalAssignment, AssignmentPathSegment assignmentPathSegment,
private <O extends ObjectType> void evaluateAssignment(EvaluatedAssignmentImpl<F> evalAssignment, AssignmentPathSegmentImpl assignmentPathSegment,
boolean evaluateOld, PlusMinusZero mode, boolean isParentValid, ObjectType source, String sourceDescription,
AssignmentPath assignmentPath, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, PolicyViolationException {
AssignmentPathImpl assignmentPath, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, PolicyViolationException {
assertSource(source, evalAssignment);

LOGGER.trace("Evaluate assignment {} (eval constr: {}, mode: {})", assignmentPath, assignmentPathSegment.isMatchingOrder(),
Expand Down Expand Up @@ -281,9 +284,9 @@ private <O extends ObjectType> void evaluateAssignment(EvaluatedAssignmentImpl<F
* Continues with assignment evaluation: Either there is a non-null (resolved) target, passed in "target" parameter,
* or traditional options stored in assignmentType (construction or focus mappings). TargetRef from assignmentType is ignored.
*/
private <O extends ObjectType> void evaluateAssignmentWithResolvedTarget(EvaluatedAssignmentImpl<F> evalAssignment, AssignmentPathSegment assignmentPathSegment,
private <O extends ObjectType> void evaluateAssignmentWithResolvedTarget(EvaluatedAssignmentImpl<F> evalAssignment, AssignmentPathSegmentImpl assignmentPathSegment,
boolean evaluateOld, PlusMinusZero mode, boolean isParentValid, ObjectType source, String sourceDescription,
AssignmentPath assignmentPath, AssignmentType assignmentType, PrismObject<O> target, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, PolicyViolationException {
AssignmentPathImpl assignmentPath, AssignmentType assignmentType, PrismObject<O> target, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, PolicyViolationException {
if (target != null && evalAssignment.getTarget() == null) {
evalAssignment.setTarget(target);
}
Expand Down Expand Up @@ -366,9 +369,9 @@ private <O extends ObjectType> void evaluateAssignmentWithResolvedTarget(Evaluat
assignmentPath.remove(assignmentPathSegment);
}

private void prepareConstructionEvaluation(EvaluatedAssignmentImpl<F> evaluatedAssignment, AssignmentPathSegment assignmentPathSegment,
private void prepareConstructionEvaluation(EvaluatedAssignmentImpl<F> evaluatedAssignment, AssignmentPathSegmentImpl assignmentPathSegment,
boolean evaluateOld, PlusMinusZero mode, boolean isValid, ObjectType source, String sourceDescription,
AssignmentPath assignmentPath, ObjectType orderOneObject, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
AssignmentPathImpl assignmentPath, ObjectType orderOneObject, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
assertSource(source, evaluatedAssignment);

AssignmentType assignmentTypeNew = LensUtil.getAssignmentType(assignmentPathSegment.getAssignmentIdi(), evaluateOld);
Expand Down Expand Up @@ -404,9 +407,9 @@ private void prepareConstructionEvaluation(EvaluatedAssignmentImpl<F> evaluatedA
}
}

private void evaluateFocusMappings(EvaluatedAssignmentImpl<F> evaluatedAssignment, AssignmentPathSegment assignmentPathSegment,
private void evaluateFocusMappings(EvaluatedAssignmentImpl<F> evaluatedAssignment, AssignmentPathSegmentImpl assignmentPathSegment,
boolean evaluateOld, ObjectType source, String sourceDescription,
AssignmentPath assignmentPath, ObjectType orderOneObject, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
AssignmentPathImpl assignmentPath, ObjectType orderOneObject, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
assertSource(source, evaluatedAssignment);

AssignmentType assignmentTypeNew = LensUtil.getAssignmentType(assignmentPathSegment.getAssignmentIdi(), evaluateOld);
Expand All @@ -428,22 +431,22 @@ private void evaluateFocusMappings(EvaluatedAssignmentImpl<F> evaluatedAssignmen
}
}

private void evaluatePolicyRule(EvaluatedAssignmentImpl<F> evaluatedAssignment, AssignmentPathSegment assignmentPathSegment,
private void evaluatePolicyRule(EvaluatedAssignmentImpl<F> evaluatedAssignment, AssignmentPathSegmentImpl assignmentPathSegment,
boolean evaluateOld, PlusMinusZero mode, boolean isValid, ObjectType source, String sourceDescription,
AssignmentPath assignmentPath, ObjectType orderOneObject, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
AssignmentPathImpl assignmentPath, ObjectType orderOneObject, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
assertSource(source, evaluatedAssignment);

AssignmentType assignmentTypeNew = LensUtil.getAssignmentType(assignmentPathSegment.getAssignmentIdi(), evaluateOld);
PolicyRuleType policyRuleType = assignmentTypeNew.getPolicyRule();

LOGGER.trace("Evaluating policy rule '{}' in {}", policyRuleType.getName(), source);

EvaluatedPolicyRuleImpl policyRule = new EvaluatedPolicyRuleImpl(policyRuleType);
EvaluatedPolicyRuleImpl policyRule = new EvaluatedPolicyRuleImpl(policyRuleType, assignmentPath.clone());

evaluatedAssignment.addPolicyRule(policyRule);
}

private <O extends ObjectType> List<PrismObject<O>> resolveTargets(AssignmentType assignmentType, AssignmentPathSegment assignmentPathSegment, ObjectType source, String sourceDescription, AssignmentPath assignmentPath, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
private <O extends ObjectType> List<PrismObject<O>> resolveTargets(AssignmentType assignmentType, AssignmentPathSegment assignmentPathSegment, ObjectType source, String sourceDescription, AssignmentPathImpl assignmentPath, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
ObjectReferenceType targetRef = assignmentType.getTargetRef();
String oid = targetRef.getOid();

Expand Down Expand Up @@ -488,7 +491,7 @@ private <O extends ObjectType> List<PrismObject<O>> resolveTargets(AssignmentTyp

}

private <O extends ObjectType> List<PrismObject<O>> resolveTargetsFromFilter(Class<O> clazz, AssignmentPathSegment assignmentPathSegment, ObjectType source, SearchFilterType filter, String sourceDescription, AssignmentPath assignmentPath, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException{
private <O extends ObjectType> List<PrismObject<O>> resolveTargetsFromFilter(Class<O> clazz, AssignmentPathSegment assignmentPathSegment, ObjectType source, SearchFilterType filter, String sourceDescription, AssignmentPathImpl assignmentPath, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException{
// SearchFilterType filter = targetRef.getFilter();
ModelExpressionThreadLocalHolder.pushLensContext(lensContext);
ModelExpressionThreadLocalHolder.pushCurrentResult(result);
Expand Down Expand Up @@ -524,9 +527,9 @@ private <O extends ObjectType> List<PrismObject<O>> resolveTargetsFromFilter(Cla

}

private boolean evaluateAssignmentTarget(EvaluatedAssignmentImpl<F> assignment, AssignmentPathSegment assignmentPathSegment,
private boolean evaluateAssignmentTarget(EvaluatedAssignmentImpl<F> assignment, AssignmentPathSegmentImpl assignmentPathSegment,
boolean evaluateOld, PlusMinusZero mode, boolean isValid, FocusType targetType, ObjectType source, QName relation, String sourceDescription,
AssignmentPath assignmentPath, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, PolicyViolationException {
AssignmentPathImpl assignmentPath, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, PolicyViolationException {
assertSource(source, assignment);

assignmentPathSegment.setTarget(targetType);
Expand Down Expand Up @@ -636,7 +639,7 @@ private boolean evaluateAssignmentTarget(EvaluatedAssignmentImpl<F> assignment,
ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> roleInducementIdi = new ItemDeltaItem<>();
roleInducementIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(roleInducement));
roleInducementIdi.recompute();
AssignmentPathSegment subAssignmentPathSegment = new AssignmentPathSegment(roleInducementIdi, null);
AssignmentPathSegmentImpl subAssignmentPathSegment = new AssignmentPathSegmentImpl(roleInducementIdi, null);
subAssignmentPathSegment.setSource(targetType);
subAssignmentPathSegment.setEvaluationOrder(evaluationOrder);
subAssignmentPathSegment.setOrderOneObject(orderOneObject);
Expand Down Expand Up @@ -679,7 +682,7 @@ private boolean evaluateAssignmentTarget(EvaluatedAssignmentImpl<F> assignment,
ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> roleAssignmentIdi = new ItemDeltaItem<>();
roleAssignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(roleAssignment));
roleAssignmentIdi.recompute();
AssignmentPathSegment subAssignmentPathSegment = new AssignmentPathSegment(roleAssignmentIdi, null);
AssignmentPathSegmentImpl subAssignmentPathSegment = new AssignmentPathSegmentImpl(roleAssignmentIdi, null);
subAssignmentPathSegment.setSource(targetType);
String subSourceDescription = targetType+" in "+sourceDescription;
QName subrelation = null;
Expand Down
Expand Up @@ -18,41 +18,43 @@
import java.util.ArrayList;
import java.util.List;

import com.evolveum.midpoint.model.api.context.AssignmentPath;
import com.evolveum.midpoint.model.api.context.AssignmentPathSegment;
import com.evolveum.midpoint.model.api.context.EvaluationOrder;
import com.evolveum.midpoint.model.common.expression.ItemDeltaItem;
import com.evolveum.midpoint.prism.PrismContainerDefinition;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;

/**
* @author semancik
*
*/
public class AssignmentPath implements DebugDumpable {
public class AssignmentPathImpl implements AssignmentPath {

private List<AssignmentPathSegment> segments;
private List<AssignmentPathSegmentImpl> segments;

public AssignmentPath() {
public AssignmentPathImpl() {
segments = createNewSegments();
}

AssignmentPath(ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> assignmentIdi) {
AssignmentPathImpl(ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> assignmentIdi) {
this.segments = createNewSegments();
segments.add(new AssignmentPathSegment(assignmentIdi, null));
segments.add(new AssignmentPathSegmentImpl(assignmentIdi, null));
}

private List<AssignmentPathSegment> createNewSegments() {
return new ArrayList<AssignmentPathSegment>();
private List<AssignmentPathSegmentImpl> createNewSegments() {
return new ArrayList<>();
}

public List<AssignmentPathSegment> getSegments() {
@Override
public List<AssignmentPathSegmentImpl> getSegments() {
return segments;
}

public void add(AssignmentPathSegment segment) {
public void add(AssignmentPathSegmentImpl segment) {
segments.add(segment);
}

Expand All @@ -61,24 +63,29 @@ public void remove(AssignmentPathSegment segment) {
}


public AssignmentPathSegment getFirstAssignmentSegment() {
@Override
public AssignmentPathSegmentImpl getFirstAssignmentSegment() {
return segments.get(0);
}

@Override
public boolean isEmpty() {
return segments.isEmpty();
}

@Override
public int size() { return segments.size(); }

@Override
public EvaluationOrder getEvaluationOrder() {
if (isEmpty()) {
return EvaluationOrder.ZERO;
return EvaluationOrderImpl.ZERO;
} else {
return segments.get(segments.size()-1).getEvaluationOrder();
}
}

@Override
public AssignmentPathSegment last() {
if (isEmpty()) {
return null;
Expand All @@ -87,6 +94,7 @@ public AssignmentPathSegment last() {
}
}

@Override
public boolean containsTarget(ObjectType target) {
if (target == null) {
return false;
Expand All @@ -111,8 +119,8 @@ public boolean containsTarget(ObjectType target) {
/**
* Shallow clone.
*/
public AssignmentPath clone() {
AssignmentPath clone = new AssignmentPath();
public AssignmentPathImpl clone() {
AssignmentPathImpl clone = new AssignmentPathImpl();
clone.segments.addAll(this.segments);
return clone;
}
Expand Down

0 comments on commit 55d6617

Please sign in to comment.