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
katkav committed Mar 11, 2020
2 parents 06472b8 + 9ff6a2b commit 9d7c749
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 32 deletions.
Expand Up @@ -27,7 +27,8 @@
import com.evolveum.midpoint.web.util.OnePageParameterEncoder;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyRuleEnforcerHookPreviewOutputType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyRuleEnforcerPreviewOutputType;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.tabs.ITab;
import org.apache.wicket.markup.html.WebMarkupContainer;
Expand Down Expand Up @@ -115,8 +116,8 @@ public void onClick(AjaxRequestTarget target) {
//TODO relocate the logic from the loop to some util method, code repeats in PreviewChangesTabPanel
private boolean violationsEmpty() {
for (ModelContext<O> modelContext : modelContextMap.values()) {
PolicyRuleEnforcerHookPreviewOutputType enforcements = modelContext != null
? modelContext.getHookPreviewResult(PolicyRuleEnforcerHookPreviewOutputType.class)
PolicyRuleEnforcerPreviewOutputType enforcements = modelContext != null
? modelContext.getPolicyRuleEnforcerPreviewOutput()
: null;
List<EvaluatedTriggerGroupDto> triggerGroups = enforcements != null
? Collections.singletonList(EvaluatedTriggerGroupDto.initializeFromRules(enforcements.getRule(), false, null))
Expand Down
Expand Up @@ -30,7 +30,8 @@
import com.evolveum.midpoint.web.page.admin.workflow.dto.EvaluatedTriggerGroupDto;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ApprovalSchemaExecutionInformationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyRuleEnforcerHookPreviewOutputType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyRuleEnforcerPreviewOutputType;

import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
Expand Down Expand Up @@ -126,8 +127,8 @@ public SceneDto getObject() {
}
};

PolicyRuleEnforcerHookPreviewOutputType enforcements = modelContext != null
? modelContext.getHookPreviewResult(PolicyRuleEnforcerHookPreviewOutputType.class)
PolicyRuleEnforcerPreviewOutputType enforcements = modelContext != null
? modelContext.getPolicyRuleEnforcerPreviewOutput()
: null;
List<EvaluatedTriggerGroupDto> triggerGroups = enforcements != null
? Collections.singletonList(EvaluatedTriggerGroupDto.initializeFromRules(enforcements.getRule(), false, null))
Expand Down
Expand Up @@ -2111,7 +2111,7 @@
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="PolicyRuleEnforcerHookPreviewOutputType">
<xsd:complexType name="PolicyRuleEnforcerPreviewOutputType">
<xsd:annotation>
<xsd:documentation>
TODO
Expand Down
Expand Up @@ -24,6 +24,7 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PartialProcessingOptionsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyRuleEnforcerPreviewOutputType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -83,7 +84,7 @@ default String dumpFocusPolicyRules(int indent) {
<T> List<T> getHookPreviewResults(@NotNull Class<T> clazz);

@Nullable
<T> T getHookPreviewResult(@NotNull Class<T> clazz);
PolicyRuleEnforcerPreviewOutputType getPolicyRuleEnforcerPreviewOutput();

boolean isPreview();

Expand Down
Expand Up @@ -52,7 +52,7 @@
* @author semancik
*
*/
public class LensContext<F extends ObjectType> implements ModelContext<F> {
public class LensContext<F extends ObjectType> implements ModelContext<F>, Cloneable {

private static final long serialVersionUID = -778283437426659540L;
private static final String DOT_CLASS = LensContext.class.getName() + ".";
Expand Down Expand Up @@ -203,6 +203,8 @@ public enum ExportType {

transient private Map<String,Collection<Containerable>> hookPreviewResultsMap;

transient private PolicyRuleEnforcerPreviewOutputType policyRuleEnforcerPreviewOutput;

@NotNull transient private final List<ObjectReferenceType> operationApprovedBy = new ArrayList<>();
@NotNull transient private final List<String> operationApproverComments = new ArrayList<>();

Expand Down Expand Up @@ -849,6 +851,7 @@ public void normalize() {
}
}

@SuppressWarnings("MethodDoesntCallSuperMethod")
public LensContext<F> clone() {
LensContext<F> clone = new LensContext<>(focusClass, prismContext, provisioningService);
copyValues(clone);
Expand Down Expand Up @@ -1389,10 +1392,11 @@ public void addHookPreviewResults(String hookUri, Collection<Containerable> resu
@Override
public <T> List<T> getHookPreviewResults(@NotNull Class<T> clazz) {
List<T> rv = new ArrayList<>();
for (Collection<Containerable> collection : getHookPreviewResultsMap().values()) {
for (Containerable item : CollectionUtils.emptyIfNull(collection)) {
if (item != null && clazz.isAssignableFrom(item.getClass())) {
rv.add((T) item);
for (Collection<Containerable> previewResults : getHookPreviewResultsMap().values()) {
for (Containerable previewResult : CollectionUtils.emptyIfNull(previewResults)) {
if (previewResult != null && clazz.isAssignableFrom(previewResult.getClass())) {
//noinspection unchecked
rv.add((T) previewResult);
}
}
}
Expand All @@ -1401,15 +1405,12 @@ public <T> List<T> getHookPreviewResults(@NotNull Class<T> clazz) {

@Nullable
@Override
public <T> T getHookPreviewResult(@NotNull Class<T> clazz) {
List<T> results = getHookPreviewResults(clazz);
if (results.size() > 1) {
throw new IllegalStateException("More than one preview result of type " + clazz);
} else if (results.size() == 1) {
return results.get(0);
} else {
return null;
}
public PolicyRuleEnforcerPreviewOutputType getPolicyRuleEnforcerPreviewOutput() {
return policyRuleEnforcerPreviewOutput;
}

public void setPolicyRuleEnforcerPreviewOutput(PolicyRuleEnforcerPreviewOutputType policyRuleEnforcerPreviewOutput) {
this.policyRuleEnforcerPreviewOutput = policyRuleEnforcerPreviewOutput;
}

public int getConflictResolutionAttemptNumber() {
Expand Down
Expand Up @@ -47,7 +47,7 @@
* @author semancik
*
*/
public abstract class LensElementContext<O extends ObjectType> implements ModelElementContext<O> {
public abstract class LensElementContext<O extends ObjectType> implements ModelElementContext<O>, Cloneable {

private static final long serialVersionUID = 1649567559396392861L;

Expand Down
Expand Up @@ -75,10 +75,9 @@ private void executeRegular(EvaluationContext evalCtx)
}

private void executePreview(@NotNull ModelContext<? extends ObjectType> context, EvaluationContext evalCtx) {
PolicyRuleEnforcerHookPreviewOutputType output = new PolicyRuleEnforcerHookPreviewOutputType(prismContext);
PolicyRuleEnforcerPreviewOutputType output = new PolicyRuleEnforcerPreviewOutputType(prismContext);
output.getRule().addAll(evalCtx.rules);
// deprecated
((LensContext) context).addHookPreviewResults(HOOK_URI, Collections.singletonList(output));
((LensContext) context).setPolicyRuleEnforcerPreviewOutput(output);
}

@NotNull
Expand Down
Expand Up @@ -52,8 +52,6 @@
* Role21 - uses default approval (org:approver)
* Role22 - uses metarole 1 'default' induced approval (org:special-approver)
* Role23 - uses both metarole 'default' and 'security' induced approval (org:special-approver and org:security-approver)
*
* @author mederly
*/
@ContextConfiguration(locations = {"classpath:ctx-workflow-test-main.xml"})
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
Expand Down Expand Up @@ -1248,9 +1246,9 @@ private void previewAssignRolesToJack(boolean immediate, boolean also24) throws
.previewChanges(singleton(primaryDelta), options, task, result);

List<ApprovalSchemaExecutionInformationType> approvalInfo = modelContext.getHookPreviewResults(ApprovalSchemaExecutionInformationType.class);
List<PolicyRuleEnforcerHookPreviewOutputType> enforceInfo = modelContext.getHookPreviewResults(PolicyRuleEnforcerHookPreviewOutputType.class);
PolicyRuleEnforcerPreviewOutputType enforceInfo = modelContext.getPolicyRuleEnforcerPreviewOutput();
displayContainerablesCollection("Approval infos", approvalInfo);
displayContainerablesCollection("Enforce infos", enforceInfo);
display("Enforce info", enforceInfo);
result.computeStatus();
//noinspection ConstantConditions
if (TRACE) {
Expand All @@ -1260,8 +1258,8 @@ private void previewAssignRolesToJack(boolean immediate, boolean also24) throws
// we do not assert success here, because there are (intentional) exceptions in some of the expressions

assertEquals("Wrong # of schema execution information pieces", also24 ? 5 : 4, approvalInfo.size());
assertEquals("Wrong # of enforcement hook preview output items", 1, enforceInfo.size());
List<EvaluatedPolicyRuleType> enforcementRules = enforceInfo.get(0).getRule();
assertNotNull("No enforcement preview output", enforceInfo);
List<EvaluatedPolicyRuleType> enforcementRules = enforceInfo.getRule();
if (also24) {
assertEquals("Wrong # of enforcement rules", 1, enforcementRules.size());
} else {
Expand Down

0 comments on commit 9d7c749

Please sign in to comment.