Skip to content

Commit

Permalink
Approval related triggers on PagePreviewChanges (in progress).
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Sep 18, 2017
1 parent 1ff985b commit d18042b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 4 deletions.
Expand Up @@ -24,6 +24,7 @@ <h3 class="box-title" wicket:id="name"></h3>
</div>
<div class="box-body">
<div wicket:id="preview"></div>
<div wicket:id="triggers"></div>
</div>
</div>
</div>
Expand Down
Expand Up @@ -18,11 +18,13 @@

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.web.page.admin.workflow.EvaluatedTriggerGroupPanel;
import com.evolveum.midpoint.web.page.admin.workflow.dto.ApprovalProcessExecutionInformationDto;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

import java.util.List;

Expand All @@ -34,6 +36,7 @@ public class ApprovalProcessesPreviewPanel extends BasePanel<List<ApprovalProces
private static final String ID_PROCESSES = "processes";
private static final String ID_NAME = "name";
private static final String ID_PREVIEW = "preview";
private static final String ID_TRIGGERS = "triggers";

public ApprovalProcessesPreviewPanel(String id, IModel<List<ApprovalProcessExecutionInformationDto>> model) {
super(id, model);
Expand All @@ -53,6 +56,7 @@ protected void populateItem(ListItem<ApprovalProcessExecutionInformationDto> ite
}
}, false)));
item.add(new ApprovalProcessExecutionInformationPanel(ID_PREVIEW, item.getModel()));
item.add(new EvaluatedTriggerGroupPanel(ID_TRIGGERS, new PropertyModel<>(item.getModel(), ApprovalProcessExecutionInformationDto.F_TRIGGERS)));
}
};
add(list);
Expand Down
Expand Up @@ -42,22 +42,26 @@ public class ApprovalProcessExecutionInformationDto implements Serializable {
public static final String F_PROCESS_NAME = "processName";
public static final String F_TARGET_NAME = "targetName";
public static final String F_STAGES = "stages";
public static final String F_TRIGGERS = "triggers";

private final boolean wholeProcess; // do we represent whole process or only the future stages?
private final int currentStageNumber; // current stage number (0 if there's no current stage, i.e. process has not started yet)
private final int numberOfStages;
private final String processName;
private final String targetName;
private final List<ApprovalStageExecutionInformationDto> stages = new ArrayList<>();
private final EvaluatedTriggerGroupDto triggers;
private final boolean running;

private ApprovalProcessExecutionInformationDto(boolean wholeProcess, int currentStageNumber, int numberOfStages,
String processName, String targetName, boolean running) {
String processName, String targetName,
EvaluatedTriggerGroupDto triggers, boolean running) {
this.wholeProcess = wholeProcess;
this.currentStageNumber = currentStageNumber;
this.numberOfStages = numberOfStages;
this.processName = processName;
this.targetName = targetName;
this.triggers = triggers;
this.running = running;
}

Expand All @@ -72,8 +76,10 @@ 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.create(WfContextUtil.getAllRules(info.getPolicyRules()));
ApprovalProcessExecutionInformationDto rv =
new ApprovalProcessExecutionInformationDto(wholeProcess, currentStageNumber, numberOfStages, processName, targetName, running);
new ApprovalProcessExecutionInformationDto(wholeProcess, currentStageNumber, numberOfStages, processName,
targetName, triggers, running);
int startingStageNumber = wholeProcess ? 1 : currentStageNumber+1;
boolean reachable = true;
for (int i = startingStageNumber - 1; i < numberOfStages; i++) {
Expand Down Expand Up @@ -114,4 +120,8 @@ public String getTargetName() {
public boolean isRunning() {
return running;
}

public EvaluatedTriggerGroupDto getTriggers() {
return triggers;
}
}
Expand Up @@ -222,10 +222,12 @@ private <C extends Containerable> PrismContainerValue<C> parseContainerValue(@No
if (prim.isEmpty()) {
return containerDef.createValue();
} else {
throw new IllegalArgumentException("Cannot parse container value from (non-empty) " + node);
pc.warnOrThrow(LOGGER, "Cannot parse container value from (non-empty) " + node);
return containerDef.createValue();
}
} else {
throw new IllegalArgumentException("Cannot parse container value from " + node);
pc.warnOrThrow(LOGGER, "Cannot parse container value from " + node);
return containerDef.createValue();
}
}

Expand Down
Expand Up @@ -747,4 +747,14 @@ public static String getOutcome(ApprovalSchemaExecutionInformationType info) {
WfContextType wfc = getWorkflowContext(info);
return wfc != null ? wfc.getOutcome() : null;
}

public static List<EvaluatedPolicyRuleType> getAllRules(SchemaAttachedPolicyRulesType policyRules) {
List<EvaluatedPolicyRuleType> rv = new ArrayList<>();
for (SchemaAttachedPolicyRuleType entry : policyRules.getEntry()) {
if (!rv.contains(entry.getRule())) {
rv.add(entry.getRule());
}
}
return rv;
}
}
Expand Up @@ -278,6 +278,7 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="policyRules" type="tns:SchemaAttachedPolicyRulesType"/>
</xsd:sequence>
</xsd:complexType>

Expand Down
Expand Up @@ -134,6 +134,9 @@ private ApprovalSchemaExecutionInformationType getApprovalSchemaExecutionInforma
}
rv.getStage().add(stageExecution);
}
if (itemApprovalState.getPolicyRules() != null) {
rv.setPolicyRules(itemApprovalState.getPolicyRules().clone());
}
return rv;
}

Expand Down

0 comments on commit d18042b

Please sign in to comment.