Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Oct 12, 2017
2 parents ff1e28c + ece28ce commit 44e2135
Show file tree
Hide file tree
Showing 34 changed files with 757 additions and 170 deletions.
Expand Up @@ -16,6 +16,7 @@
package com.evolveum.midpoint.gui.api.util;

import static com.evolveum.midpoint.gui.api.page.PageBase.createStringResourceStatic;
import static com.evolveum.midpoint.schema.util.ObjectTypeUtil.normalizeRelation;

import java.io.PrintWriter;
import java.io.StringWriter;
Expand Down Expand Up @@ -913,7 +914,7 @@ public static <C extends Containerable> String getDisplayName(PrismContainerValu
C containerable = prismContainerValue.asContainerable();
if (containerable instanceof AssignmentType && ((AssignmentType) containerable).getTargetRef() != null) {
ObjectReferenceType assignemntTargetRef = ((AssignmentType) containerable).getTargetRef();
return getName(assignemntTargetRef) + " - " + assignemntTargetRef.getRelation().getLocalPart();
return getName(assignemntTargetRef) + " - " + normalizeRelation(assignemntTargetRef.getRelation()).getLocalPart();
}

if (containerable instanceof ExclusionPolicyConstraintType){
Expand Down
Expand Up @@ -19,6 +19,7 @@
import java.util.Arrays;
import java.util.List;

import com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import org.apache.wicket.model.IModel;
import org.apache.wicket.request.resource.PackageResourceReference;
Expand Down Expand Up @@ -89,7 +90,7 @@ private void initLayout() {
}

private List<ItemPath> getVisibleContainers() {
return Arrays.asList(ItemPath.EMPTY_PATH, SchemaConstants.PATH_ACTIVATION, SchemaConstants.PATH_PASSWORD);
return Arrays.asList(ItemPath.EMPTY_PATH, new ItemPath(AbstractRoleType.F_DATA_PROTECTION), SchemaConstants.PATH_ACTIVATION, SchemaConstants.PATH_PASSWORD);
}


Expand Down
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2010-2017 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.prism;

import com.evolveum.midpoint.prism.xjc.PrismForJAXBUtil;
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;
import com.evolveum.prism.xml.ns._public.types_3.EvaluationTimeType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import javax.xml.namespace.QName;
import java.io.Serializable;

/**
* Used when PrismReferenceValue.getRealValue is called, and no referencable is present in the PRV.
* It is analogous to ObjectReferenceType; however, the ORT is part of common-3, whereas this one is located in prism layer.
*
* @author mederly
*/
public class DefaultReferencableImpl implements Referencable, Cloneable, Serializable {

private static final long serialVersionUID = 1L;

private PrismReferenceValue referenceValue;

public DefaultReferencableImpl(PrismReferenceValue value) {
this.referenceValue = value;
}

@Override
public PrismReferenceValue asReferenceValue() {
return referenceValue;
}

@Override
public void setupReferenceValue(PrismReferenceValue value) {
referenceValue = value;
}

@Override
public String getOid() {
return referenceValue.getOid();
}

@Override
public QName getType() {
return referenceValue.getTargetType();
}

@Override
public PolyStringType getTargetName() {
return PrismForJAXBUtil.getReferenceTargetName(referenceValue);
}

@Override
public QName getRelation() {
return referenceValue.getRelation();
}

@Override
public String getDescription() {
return referenceValue.getDescription();
}

@Override
public EvaluationTimeType getResolutionTime() {
return referenceValue.getResolutionTime();
}

@Override
public SearchFilterType getFilter() {
SearchFilterType filter = new SearchFilterType();
filter.setFilterClauseXNode(PrismForJAXBUtil.getReferenceFilterClauseXNode(referenceValue));
return filter;
}

public DefaultReferencableImpl clone() {
DefaultReferencableImpl clone;
try {
clone = (DefaultReferencableImpl) super.clone();
} catch (CloneNotSupportedException e) {
throw new IllegalStateException(e);
}
if (referenceValue != null) {
clone.referenceValue = referenceValue.clone();
}
return clone;
}

@Override
public String toString() {
return "DefaultReferencableImpl(" + referenceValue + ')';
}
}
Expand Up @@ -170,6 +170,15 @@ public PrismContainer<?> getExtension() {
return (PrismContainer<?>) getValue().findItem(getExtensionContainerElementName(), PrismContainer.class);
}

public PrismContainerValue<?> getExtensionContainerValue() {
PrismContainer<?> extension = getExtension();
if (extension == null || extension.getValues().isEmpty()) {
return null;
} else {
return extension.getValue();
}
}

public <I extends Item> I findExtensionItem(QName elementName) {
PrismContainer<?> extension = getExtension();
if (extension == null) {
Expand Down
Expand Up @@ -562,47 +562,7 @@ public Referencable asReferencable() {
}

// A hack, just to avoid crashes. TODO think about this!
return new Referencable() {
PrismReferenceValue referenceValue = PrismReferenceValue.this;
@Override
public PrismReferenceValue asReferenceValue() {
return referenceValue;
}
@Override
public void setupReferenceValue(PrismReferenceValue value) {
referenceValue = value;
}
@Override
public String getOid() {
return referenceValue.getOid();
}
@Override
public QName getType() {
return referenceValue.getTargetType();
}
@Override
public PolyStringType getTargetName() {
return PrismForJAXBUtil.getReferenceTargetName(referenceValue);
}
@Override
public QName getRelation() {
return referenceValue.getRelation();
}
@Override
public String getDescription() {
return referenceValue.getDescription();
}
@Override
public EvaluationTimeType getResolutionTime() {
return referenceValue.getResolutionTime();
}
@Override
public SearchFilterType getFilter() {
SearchFilterType filter = new SearchFilterType();
filter.setFilterClauseXNode(PrismForJAXBUtil.getReferenceFilterClauseXNode(referenceValue));
return filter;
}
};
return new DefaultReferencableImpl(this);
}

@NotNull
Expand Down
Expand Up @@ -94,4 +94,5 @@ public class ExpressionConstants {
public static final QName VAR_WORKFLOW_CONTEXT = new QName(SchemaConstants.NS_C, "workflowContext");
public static final QName VAR_TASK = new QName(SchemaConstants.NS_C, "task");
public static final QName VAR_RULE_EVALUATION_CONTEXT = new QName(SchemaConstants.NS_C, "ruleEvaluationContext");
public static final QName VAR_STAGE_DEFINITION = new QName(SchemaConstants.NS_C, "stageDefinition");
}
Expand Up @@ -221,14 +221,22 @@ public static String getObjectTypeUri(String objectType) {
return getObjectType(objectType).getObjectTypeUri();
}

public static Class<? extends ObjectType> getObjectTypeClass(String objectType) {
public static Class<? extends ObjectType> getObjectTypeClass(String typeNameLocal) {
for (ObjectTypes type : values()) {
if (type.getValue().equals(objectType)) {
if (type.getValue().equals(typeNameLocal)) {
return type.getClassDefinition();
}
}
throw new IllegalArgumentException("Unsupported object type " + typeNameLocal);
}

throw new IllegalArgumentException("Unsupported object type " + objectType);
public static Class<? extends ObjectType> getObjectTypeClass(QName typeName) {
for (ObjectTypes type : values()) {
if (QNameUtil.match(type.getTypeQName(), typeName)) {
return type.getClassDefinition();
}
}
throw new IllegalArgumentException("Unsupported object type " + typeName);
}

@SuppressWarnings("unchecked")
Expand Down
Expand Up @@ -735,4 +735,14 @@ public static boolean matchOnOid(ObjectReferenceType ref1, ObjectReferenceType r
return ref1 != null && ref2 != null && ref1.getOid() != null && ref2.getOid() != null
&& ref1.getOid().equals(ref2.getOid());
}

public static void mergeExtension(PrismContainerValue<?> dstExtensionContainerValue, PrismContainerValue<?> srcExtensionContainerValue) throws SchemaException {
for (Item<?,?> srcExtensionItem: srcExtensionContainerValue.getItems()) {
Item<?,?> magicItem = dstExtensionContainerValue.findItem(srcExtensionItem.getElementName());
if (magicItem == null) {
//noinspection unchecked
dstExtensionContainerValue.add(srcExtensionItem.clone());
}
}
}
}
Expand Up @@ -37,6 +37,7 @@
import java.util.stream.Collectors;

import static com.evolveum.midpoint.prism.polystring.PolyString.getOrig;
import static java.util.Collections.emptyList;

/**
* TODO clean up these formatting methods
Expand Down Expand Up @@ -200,7 +201,7 @@ public static ItemApprovalWorkItemPartType getItemApprovalWorkItemInfo(WorkItemT
public static List<SchemaAttachedPolicyRuleType> getAttachedPolicyRules(WfContextType workflowContext, int order) {
ItemApprovalProcessStateType info = getItemApprovalProcessInfo(workflowContext);
if (info == null || info.getPolicyRules() == null) {
return Collections.emptyList();
return emptyList();
}
return info.getPolicyRules().getEntry().stream()
.filter(e -> e.getStageMax() != null && e.getStageMax() != null
Expand Down Expand Up @@ -766,16 +767,36 @@ public static List<List<EvaluatedPolicyRuleType>> getRulesPerStage(WfContextType
}
List<SchemaAttachedPolicyRuleType> entries = info.getPolicyRules().getEntry();
for (int i = 0; i < info.getApprovalSchema().getStage().size(); i++) {
int stageNumber = i+1;
List<EvaluatedPolicyRuleType> rulesForStage = new ArrayList<>();
for (SchemaAttachedPolicyRuleType entry : entries) {
if (entry.getStageMin() != null && stageNumber >= entry.getStageMin()
&& entry.getStageMax() != null && stageNumber <= entry.getStageMax()) {
rulesForStage.add(entry.getRule());
}
}
rv.add(rulesForStage);
rv.add(getRulesForStage(entries, i+1));
}
return rv;
}

@NotNull
private static List<EvaluatedPolicyRuleType> getRulesForStage(List<SchemaAttachedPolicyRuleType> entries, int stageNumber) {
List<EvaluatedPolicyRuleType> rulesForStage = new ArrayList<>();
for (SchemaAttachedPolicyRuleType entry : entries) {
if (entry.getStageMin() != null && stageNumber >= entry.getStageMin()
&& entry.getStageMax() != null && stageNumber <= entry.getStageMax()) {
rulesForStage.add(entry.getRule());
}
}
return rulesForStage;
}

// Do not use in approval expressions, because they are evaluated also on process start/preview.
// Use explicit stage number instead.
@NotNull
public static List<EvaluatedPolicyRuleType> getRulesForCurrentStage(WfContextType wfc) {
return getRulesForStage(wfc, wfc.getStageNumber());
}

@NotNull
public static List<EvaluatedPolicyRuleType> getRulesForStage(WfContextType wfc, Integer stageNumber) {
ItemApprovalProcessStateType info = getItemApprovalProcessInfo(wfc);
if (info == null || info.getPolicyRules() == null || stageNumber == null) {
return emptyList();
}
return getRulesForStage(info.getPolicyRules().getEntry(), stageNumber);
}
}
12 changes: 11 additions & 1 deletion infra/schema/src/main/resources/localization/schema.properties
Expand Up @@ -435,5 +435,15 @@ DefaultPolicyConstraint.not=Included constraints have not triggered
DefaultPolicyConstraint.transition=Transition policy constraint matched
DefaultPolicyConstraint.situation=Situation policy constraint matched
PolicyViolationException.message.aggregate={0} policy violations occurred
AbstractRoleType.dataProtection=Data protection
DataProtectionType.controllerName=Controller name
DataProtectionType.controllerContact=Controller contact
DataProtectionType.dpoContact=DPO contact
DataProtectionType.processingPurposesDescription=Processing purposes
DataProtectionType.legitimateInterestDescription=Legitimate interest
DataProtectionType.dataRecipientDescription=Data recipient
DataProtectionType.periodOfStorageDescription=Period of storage
DataProtectionType.automatedDecisionMakingDescription=Automated decision making
DataProtectionType.securityMeasuresDescription=Security measures
PolicyRuleEvaluationTargetType.OBJECT=Object
PolicyRuleEvaluationTargetType.ASSIGNMENT=Assignment
PolicyRuleEvaluationTargetType.ASSIGNMENT=Assignment

0 comments on commit 44e2135

Please sign in to comment.