Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Oct 16, 2017
2 parents e9e6f31 + 9b3c32d commit 9e5df26
Show file tree
Hide file tree
Showing 55 changed files with 932 additions and 377 deletions.
Expand Up @@ -138,7 +138,7 @@ public SceneDto getObject() {
? modelContext.getHookPreviewResult(PolicyRuleEnforcerHookPreviewOutputType.class)
: null;
List<EvaluatedTriggerGroupDto> triggerGroups = enforcements != null
? Collections.singletonList(EvaluatedTriggerGroupDto.createFrom(enforcements.getRule(), false, null))
? Collections.singletonList(EvaluatedTriggerGroupDto.initializeFromRules(enforcements.getRule(), false, null))
: Collections.emptyList();
policyViolationsModel = Model.ofList(triggerGroups);

Expand Down

This file was deleted.

Expand Up @@ -76,7 +76,7 @@ public static ApprovalProcessExecutionInformationDto createFrom(ApprovalSchemaEx
String targetName = WfContextUtil.getTargetName(info);
WfContextType wfc = WfContextUtil.getWorkflowContext(info);
boolean running = wfc != null && wfc.getEndTimestamp() == null;
EvaluatedTriggerGroupDto triggers = EvaluatedTriggerGroupDto.createFrom(WfContextUtil.getAllRules(info.getPolicyRules()), false, new ArrayList<>());
EvaluatedTriggerGroupDto triggers = EvaluatedTriggerGroupDto.initializeFromRules(WfContextUtil.getAllRules(info.getPolicyRules()), false, new EvaluatedTriggerGroupDto.UniquenessFilter());
ApprovalProcessExecutionInformationDto rv =
new ApprovalProcessExecutionInformationDto(wholeProcess, currentStageNumber, numberOfStages, processName,
targetName, triggers, running);
Expand Down
Expand Up @@ -16,13 +16,12 @@

package com.evolveum.midpoint.web.page.admin.workflow.dto;

import com.evolveum.midpoint.model.api.util.EvaluatedPolicyRuleUtil;
import com.evolveum.midpoint.util.TreeNode;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.jetbrains.annotations.NotNull;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* @author mederly
Expand All @@ -36,10 +35,10 @@ public class EvaluatedTriggerDto implements Serializable {
@NotNull private final EvaluatedTriggerGroupDto children;
private boolean highlighted;

private EvaluatedTriggerDto(@NotNull EvaluatedPolicyRuleTriggerType trigger, boolean highlighted) {
this.trigger = trigger;
this.children = new EvaluatedTriggerGroupDto(null);
this.highlighted = highlighted;
public EvaluatedTriggerDto(TreeNode<EvaluatedPolicyRuleUtil.AugmentedTrigger<EvaluatedTriggerGroupDto.HighlightingInformation>> node) {
this.trigger = node.getUserObject().trigger;
this.children = new EvaluatedTriggerGroupDto(null, node.getChildren());
this.highlighted = node.getUserObject().additionalData.value;
}

@NotNull
Expand All @@ -56,54 +55,6 @@ public EvaluatedTriggerGroupDto getChildren() {
return children;
}

// copies logic from EvaluatedPolicyRuleImpl.createMessageTreeNode
public static void create(List<EvaluatedTriggerDto> resultList, EvaluatedPolicyRuleTriggerType trigger, boolean highlighted,
List<AlreadyShownTriggerRecord> triggersAlreadyShown) {
boolean hidden = Boolean.TRUE.equals(trigger.isHidden());
boolean isFinal = Boolean.TRUE.equals(trigger.isFinal());
if (!hidden) {
EvaluatedTriggerDto newTriggerDto = new EvaluatedTriggerDto(trigger, highlighted);
if (triggersAlreadyShown != null && alreadyShown(triggersAlreadyShown, newTriggerDto)) {
return;
}
resultList.add(newTriggerDto);
resultList = newTriggerDto.getChildren().getTriggers();
}
if (!isFinal) { // it's possible that this was pre-filtered e.g. by policy enforcer hook
for (EvaluatedPolicyRuleTriggerType innerTrigger : getChildTriggers(trigger)) {
create(resultList, innerTrigger, highlighted, triggersAlreadyShown);
}
}
}

private static boolean alreadyShown(List<AlreadyShownTriggerRecord> triggersAlreadyShown, EvaluatedTriggerDto newTriggerDto) {
EvaluatedPolicyRuleTriggerType anonymizedTrigger = newTriggerDto.trigger.clone().ruleName(null);
for (AlreadyShownTriggerRecord alreadyShown : triggersAlreadyShown) {
if (alreadyShown.anonymizedTrigger.equals(anonymizedTrigger)) {
if (newTriggerDto.highlighted) {
alreadyShown.originalTriggerDto.highlighted = true;
}
return true;
}
}
triggersAlreadyShown.add(new AlreadyShownTriggerRecord(newTriggerDto, anonymizedTrigger));
return false;
}

private static List<EvaluatedPolicyRuleTriggerType> getChildTriggers(EvaluatedPolicyRuleTriggerType trigger) {
if (trigger instanceof EvaluatedEmbeddingTriggerType) {
return ((EvaluatedEmbeddingTriggerType) trigger).getEmbedded();
} else if (trigger instanceof EvaluatedSituationTriggerType) {
List<EvaluatedPolicyRuleTriggerType> rv = new ArrayList<>();
for (EvaluatedPolicyRuleType rule : ((EvaluatedSituationTriggerType) trigger).getSourceRule()) {
rv.addAll(rule.getTrigger());
}
return rv;
} else {
return Collections.emptyList();
}
}

public boolean isHighlighted() {
return highlighted;
}
Expand Down
Expand Up @@ -16,7 +16,10 @@

package com.evolveum.midpoint.web.page.admin.workflow.dto;

import com.evolveum.midpoint.model.api.util.EvaluatedPolicyRuleUtil;
import com.evolveum.midpoint.model.api.util.EvaluatedPolicyRuleUtil.AugmentedTrigger;
import com.evolveum.midpoint.util.LocalizableMessage;
import com.evolveum.midpoint.util.TreeNode;
import com.evolveum.midpoint.xml.ns._public.common.common_3.EvaluatedPolicyRuleTriggerType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.EvaluatedPolicyRuleType;
import org.jetbrains.annotations.NotNull;
Expand All @@ -25,6 +28,8 @@
import java.util.ArrayList;
import java.util.List;

import static com.evolveum.midpoint.model.api.util.EvaluatedPolicyRuleUtil.arrangeForPresentationExt;

/**
* @author mederly
*/
Expand All @@ -37,8 +42,12 @@ public class EvaluatedTriggerGroupDto implements Serializable {

@NotNull private final List<EvaluatedTriggerDto> triggers = new ArrayList<>();

public EvaluatedTriggerGroupDto(LocalizableMessage title) {
EvaluatedTriggerGroupDto(LocalizableMessage title,
List<TreeNode<AugmentedTrigger<HighlightingInformation>>> processedTriggers) {
this.title = title;
for (TreeNode<AugmentedTrigger<HighlightingInformation>> processedTrigger : processedTriggers) {
this.triggers.add(new EvaluatedTriggerDto(processedTrigger));
}
}

public LocalizableMessage getTitle() {
Expand All @@ -50,13 +59,56 @@ public List<EvaluatedTriggerDto> getTriggers() {
return triggers;
}

public static EvaluatedTriggerGroupDto createFrom(List<EvaluatedPolicyRuleType> rules, boolean highlighted, List<AlreadyShownTriggerRecord> triggersAlreadyShown) {
EvaluatedTriggerGroupDto group = new EvaluatedTriggerGroupDto(null);
public static EvaluatedTriggerGroupDto initializeFromRules(List<EvaluatedPolicyRuleType> rules, boolean highlighted,
UniquenessFilter uniquenessFilter) {
List<AugmentedTrigger<HighlightingInformation>> augmentedTriggers = new ArrayList<>();
for (EvaluatedPolicyRuleType rule : rules) {
for (EvaluatedPolicyRuleTriggerType trigger : rule.getTrigger()) {
EvaluatedTriggerDto.create(group.getTriggers(), trigger, highlighted, triggersAlreadyShown);
augmentedTriggers.add(new AugmentedTrigger<>(trigger, new HighlightingInformation(highlighted)));
}
}
List<TreeNode<AugmentedTrigger<HighlightingInformation>>> triggerTrees = arrangeForPresentationExt(augmentedTriggers, uniquenessFilter);
return new EvaluatedTriggerGroupDto(null, triggerTrees);
}

public static class UniquenessFilter implements EvaluatedPolicyRuleUtil.AdditionalFilter<HighlightingInformation> {

private static class AlreadyShownTriggerRecord<AD extends EvaluatedPolicyRuleUtil.AdditionalData> {
final AugmentedTrigger<AD> augmentedTrigger;
final EvaluatedPolicyRuleTriggerType anonymizedTrigger;

AlreadyShownTriggerRecord(AugmentedTrigger<AD> augmentedTrigger,
EvaluatedPolicyRuleTriggerType anonymizedTrigger) {
this.augmentedTrigger = augmentedTrigger;
this.anonymizedTrigger = anonymizedTrigger;
}
}

List<AlreadyShownTriggerRecord<HighlightingInformation>> triggersAlreadyShown = new ArrayList<>();

@Override
public boolean accepts(AugmentedTrigger<HighlightingInformation> newAugmentedTrigger) {
EvaluatedPolicyRuleTriggerType anonymizedTrigger = newAugmentedTrigger.trigger.clone().ruleName(null);
for (AlreadyShownTriggerRecord<HighlightingInformation> alreadyShown : triggersAlreadyShown) {
if (alreadyShown.anonymizedTrigger.equals(anonymizedTrigger)) {
alreadyShown.augmentedTrigger.additionalData.merge(newAugmentedTrigger.additionalData);
return false;
}
}
triggersAlreadyShown.add(new AlreadyShownTriggerRecord<>(newAugmentedTrigger, anonymizedTrigger));
return true;
}
}

public static class HighlightingInformation implements EvaluatedPolicyRuleUtil.AdditionalData {
boolean value;

HighlightingInformation(boolean value) {
this.value = value;
}

public void merge(EvaluatedPolicyRuleUtil.AdditionalData other) {
value = value | ((HighlightingInformation) other).value;
}
return group;
}
}
Expand Up @@ -384,12 +384,12 @@ public static List<EvaluatedTriggerGroupDto> computeTriggers(WfContextType wfc)
if (wfc == null) {
return triggers;
}
List<AlreadyShownTriggerRecord> triggersAlreadyShown = new ArrayList<>();
EvaluatedTriggerGroupDto.UniquenessFilter uniquenessFilter = new EvaluatedTriggerGroupDto.UniquenessFilter();
List<List<EvaluatedPolicyRuleType>> rulesPerStageList = WfContextUtil.getRulesPerStage(wfc);
for (int i = 0; i < rulesPerStageList.size(); i++) {
Integer stageNumber = i + 1;
boolean highlighted = stageNumber.equals(wfc.getStageNumber());
EvaluatedTriggerGroupDto group = EvaluatedTriggerGroupDto.createFrom(rulesPerStageList.get(i), highlighted, triggersAlreadyShown);
EvaluatedTriggerGroupDto group = EvaluatedTriggerGroupDto.initializeFromRules(rulesPerStageList.get(i), highlighted, uniquenessFilter);
triggers.add(group);
}
return triggers;
Expand Down
2 changes: 1 addition & 1 deletion infra/common/src/main/resources/ctx-common.xml
Expand Up @@ -39,6 +39,6 @@
</property>
</bean>

<bean class="com.evolveum.midpoint.common.LocalizationServiceImpl" init-method="init"/>
<bean id="localizationService" class="com.evolveum.midpoint.common.LocalizationServiceImpl" init-method="init"/>

</beans>
Expand Up @@ -448,4 +448,8 @@ public static <T extends Objectable> List<T> asObjectableList(@NotNull List<Pris
.map(PrismObject::asObjectable)
.collect(Collectors.toList());
}

public static PrismObject<?> asPrismObject(Objectable o) {
return o != null ? o.asPrismObject() : null;
}
}
Expand Up @@ -532,11 +532,15 @@ public abstract class SchemaConstants {
public static final String TOKEN = "token";

public static final String OBJECT_TYPE_KEY_PREFIX = "ObjectType.";
public static final String OBJECT_TYPE_LOWERCASE_KEY_PREFIX = "ObjectTypeLowercase.";
public static final String DEFAULT_POLICY_CONSTRAINT_KEY_PREFIX = "DefaultPolicyConstraint.";
public static final String DEFAULT_POLICY_CONSTRAINT_SHORT_MESSAGE_KEY_PREFIX = "DefaultPolicyConstraint.Short.";
public static final String POLICY_CONSTRAINT_KEY_PREFIX = "PolicyConstraint.";
public static final String POLICY_CONSTRAINT_SHORT_MESSAGE_KEY_PREFIX = "PolicyConstraint.Short.";
public static final String POLICY_CONSTRAINTS_BEFORE_KEY = "PolicyConstraints.before";
public static final String POLICY_CONSTRAINTS_AFTER_KEY = "PolicyConstraints.after";
public static final String TECHNICAL_OBJECT_SPECIFICATION_KEY = "TechnicalObjectSpecification";
public static final String OBJECT_SPECIFICATION_KEY = "ObjectSpecification";
public static final String POLICY_VIOLATION_EXCEPTION_AGGREGATE_KEY = "PolicyViolationException.message.aggregate";

// // resetPassword
Expand Down
Expand Up @@ -27,6 +27,8 @@
import com.evolveum.midpoint.prism.util.ItemPathUtil;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.util.LocalizableMessage;
import com.evolveum.midpoint.util.LocalizableMessageBuilder;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
Expand Down Expand Up @@ -745,4 +747,40 @@ public static void mergeExtension(PrismContainerValue<?> dstExtensionContainerVa
}
}
}

public static LocalizableMessage createTechnicalObjectSpecification(PrismObject<?> object) {
if (object != null) {
return new LocalizableMessageBuilder()
.key(SchemaConstants.TECHNICAL_OBJECT_SPECIFICATION_KEY)
.arg(createObjectTypeSpecification(object.asObjectable().getClass().getSimpleName()))
.arg(object.asObjectable().getName())
.arg(object.getOid())
.build();
} else {
return LocalizableMessageBuilder.buildFallbackMessage("?"); // should not really occur!
}
}

public static LocalizableMessage createObjectSpecification(PrismObject<?> object) {
if (object != null) {
return new LocalizableMessageBuilder()
.key(SchemaConstants.OBJECT_SPECIFICATION_KEY)
.arg(createObjectTypeSpecification(object.asObjectable().getClass().getSimpleName()))
.arg(object.asObjectable().getName())
.build();
} else {
return LocalizableMessageBuilder.buildFallbackMessage("?"); // should not really occur!
}
}

public static LocalizableMessage createObjectTypeSpecification(QName type) {
return createObjectTypeSpecification(type != null ? type.getLocalPart() : null);
}

public static LocalizableMessage createObjectTypeSpecification(String objectClassName) {
return new LocalizableMessageBuilder()
.key(SchemaConstants.OBJECT_TYPE_LOWERCASE_KEY_PREFIX + objectClassName)
.fallbackMessage(objectClassName)
.build();
}
}

0 comments on commit 9e5df26

Please sign in to comment.