Skip to content

Commit

Permalink
Continuing with refactoring wf decision list -> events list
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Feb 3, 2017
1 parent 145cb40 commit a924cfd
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 79 deletions.
Expand Up @@ -17,12 +17,12 @@
package com.evolveum.midpoint.web.component.wf.processes.itemApproval;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.schema.util.WfContextUtil;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.wf.DecisionsPanel;
import com.evolveum.midpoint.web.page.admin.workflow.dto.DecisionDto;
import com.evolveum.midpoint.web.session.UserProfileStorage;
import com.evolveum.midpoint.xml.ns._public.common.common_3.DecisionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ItemApprovalProcessStateType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType;
import org.apache.wicket.model.AbstractReadOnlyModel;
Expand All @@ -31,6 +31,8 @@
import java.util.ArrayList;
import java.util.List;

import static org.apache.commons.collections.CollectionUtils.addIgnoreNull;

/**
* @author mederly
*/
Expand All @@ -55,13 +57,13 @@ public List<DecisionDto> getObject() {
if (wfContextType == null) {
return rv;
}
ItemApprovalProcessStateType instanceState = (ItemApprovalProcessStateType) wfContextType.getProcessSpecificState();
List<DecisionType> allDecisions = instanceState.getDecisions();
if (allDecisions == null) {
return rv;
}
for (DecisionType decision : allDecisions) {
rv.add(new DecisionDto(decision));
if (!wfContextType.getEvent().isEmpty()) {
wfContextType.getEvent().forEach(e -> addIgnoreNull(rv, DecisionDto.create(e)));
} else {
ItemApprovalProcessStateType instanceState = WfContextUtil.getItemApprovalProcessInfo(wfContextType);
if (instanceState != null) {
instanceState.getDecisions().forEach(d -> addIgnoreNull(rv, DecisionDto.create(d)));
}
}
return rv;
}
Expand Down
Expand Up @@ -19,6 +19,9 @@
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.web.component.util.Selectable;
import com.evolveum.midpoint.xml.ns._public.common.common_3.DecisionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.WfProcessEventType;
import org.jetbrains.annotations.Nullable;

import java.util.Date;

Expand All @@ -39,27 +42,25 @@ public class DecisionDto extends Selectable {
private String comment;
private Date time;

public DecisionDto(DecisionType decision) {
if (decision.getApproverRef() != null) {
if (decision.getApproverRef().getTargetName() != null) {
this.user = decision.getApproverRef().getTargetName().getOrig();
} else {
this.user = decision.getApproverRef().getOid();
}
}
if (decision.getStageDisplayName() != null) {
stage = decision.getStageDisplayName();
} else if (decision.getStageName() != null) {
stage = decision.getStageName();
} else if (decision.getStageNumber() != null) {
stage = String.valueOf(decision.getStageNumber());
}
private DecisionDto(DecisionType decision) {
this.user = getNameFromRef(decision.getApproverRef());
outcome = decision.isApproved();
this.comment = decision.getComment();
this.time = XmlTypeConverter.toDate(decision.getDateTime());
}

public String getTime() {
// TODO deduplicate
private String getNameFromRef(ObjectReferenceType ref) {
if (ref == null) {
return null;
} else if (ref.getTargetName() != null) {
return ref.getTargetName().getOrig();
} else {
return ref.getOid();
}
}

public String getTime() {
return time.toLocaleString(); // todo formatting
}

Expand All @@ -78,4 +79,21 @@ public Boolean getOutcome() {
public String getComment() {
return comment;
}

public static DecisionDto create(DecisionType d) {
return new DecisionDto(d);
}

@Nullable
public static DecisionDto create(WfProcessEventType e) {
e.getInitiatorRef()
if (decision.getStageDisplayName() != null) {
stage = decision.getStageDisplayName();
} else if (decision.getStageName() != null) {
stage = decision.getStageName();
} else if (decision.getStageNumber() != null) {
stage = String.valueOf(decision.getStageNumber());
}

}
}

0 comments on commit a924cfd

Please sign in to comment.