Skip to content

Commit

Permalink
Fixed random reordering of approval schema levels.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jun 10, 2016
1 parent ae287b0 commit 8c0f716
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
Expand Up @@ -63,11 +63,12 @@ public String getObject() {
} else {
String name = WebComponentUtil.getName(value);
if (selectableBean.getResult() != null){
StringBuilder complexName = new StringBuilder(name);
StringBuilder complexName = new StringBuilder();
complexName.append(name);
complexName.append(" (");
complexName.append(selectableBean.getResult().getStatus());
complexName.append(")");
return complexName.toString();
return complexName.toString();
}
return name;

Expand Down
Expand Up @@ -7755,14 +7755,21 @@
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="order" type="xsd:int" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Order of this approval level. (Marked as optional only to ensure backward compatibility. Will change to 'required' eventually.)
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="name" type="xsd:string" minOccurs="0"/>
<xsd:element name="description" type="xsd:string" minOccurs="0"/>
<xsd:element name="approverRef" type="c:ObjectReferenceType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Instruction to approve something, by a user (if this points to a User object) or
by someone from a group of users (if this points to a Role or Org object; representing
all users that possess that role or belong to that OU).
by someone from a group of users (if this points to a Org object; representing
all users that belong to that OU).
</xsd:documentation>
</xsd:annotation>
</xsd:element>
Expand Down
Expand Up @@ -40,10 +40,11 @@ public class ApprovalLevelImpl implements ApprovalLevel, Serializable {

private static final long serialVersionUID = 1989606281279792045L;

private final int order;
private String name;
private String description;
private List<LightweightObjectRefImpl> approverRefs = new ArrayList<LightweightObjectRefImpl>();
private List<SerializationSafeContainer<ExpressionType>> approverExpressions = new ArrayList<SerializationSafeContainer<ExpressionType>>();
private List<LightweightObjectRefImpl> approverRefs = new ArrayList<>();
private List<SerializationSafeContainer<ExpressionType>> approverExpressions = new ArrayList<>();
private LevelEvaluationStrategyType evaluationStrategy;
private SerializationSafeContainer<ExpressionType> automaticallyApproved;

Expand All @@ -53,6 +54,7 @@ public ApprovalLevelImpl(ApprovalLevelType levelType, PrismContext prismContext)

Validate.notNull(prismContext, "prismContext must not be null");

this.order = levelType.getOrder() != null ? levelType.getOrder() : 0;
this.name = levelType.getName();
this.description = levelType.getDescription();

Expand All @@ -75,6 +77,8 @@ public ApprovalLevelImpl(List<ObjectReferenceType> approverRefList, List<Express

setPrismContext(prismContext);

order = 0;

if (approverRefList != null) {
for (ObjectReferenceType approverRef : approverRefList) {
addApproverRef(approverRef);
Expand Down Expand Up @@ -114,7 +118,7 @@ public List<? extends LightweightObjectRef> getApproverRefs() {

@Override
public List<ExpressionType> getApproverExpressions() {
List<ExpressionType> retval = new ArrayList<ExpressionType>();
List<ExpressionType> retval = new ArrayList<>();
for (SerializationSafeContainer<ExpressionType> approverExpression : approverExpressions) {
retval.add(approverExpression.getValue());
}
Expand Down Expand Up @@ -142,10 +146,14 @@ public ExpressionType getAutomaticallyApproved() {
}

public void setAutomaticallyApproved(ExpressionType automaticallyApproved) {
this.automaticallyApproved = new SingleItemSerializationSafeContainerImpl<ExpressionType>(automaticallyApproved, prismContext);
this.automaticallyApproved = new SingleItemSerializationSafeContainerImpl<>(automaticallyApproved, prismContext);
}

@Override
public int getOrder() {
return order;
}

@Override
public PrismContext getPrismContext() {
return prismContext;
}
Expand All @@ -158,6 +166,7 @@ public void setPrismContext(PrismContext prismContext) {
@Override
public ApprovalLevelType toApprovalLevelType(PrismContext prismContext) {
ApprovalLevelType levelType = new ApprovalLevelType(); // is this ok?
levelType.setOrder(getOrder());
levelType.setName(getName());
levelType.setDescription(getDescription());
levelType.setAutomaticallyApproved(getAutomaticallyApproved());
Expand Down
Expand Up @@ -21,6 +21,8 @@

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

/**
Expand All @@ -32,10 +34,11 @@ public class ApprovalSchemaImpl implements ApprovalSchema, Serializable {

private String name;
private String description;
private List<ApprovalLevelImpl> levels = new ArrayList<ApprovalLevelImpl>();
private final List<ApprovalLevelImpl> levels = new ArrayList<>();

private transient PrismContext prismContext;

@SuppressWarnings("unused") // TODO check if not called from dynamic code
public ApprovalSchemaImpl(ApprovalSchemaType approvalSchemaType, PrismContext prismContext) {
setPrismContext(prismContext);
initFromApprovalSchemaType(approvalSchemaType);
Expand Down Expand Up @@ -81,11 +84,14 @@ public void setDescription(String description) {

@Override
public List<? extends ApprovalLevel> getLevels() {
return levels;
}

public void setLevels(List<ApprovalLevelImpl> levels) {
this.levels = levels;
List<ApprovalLevelImpl> rv = new ArrayList<>(levels);
Collections.sort(rv, new Comparator<ApprovalLevelImpl>() {
@Override
public int compare(ApprovalLevelImpl o1, ApprovalLevelImpl o2) {
return Integer.compare(o1.getOrder(), o2.getOrder());
}
});
return Collections.unmodifiableList(rv);
}

@Override
Expand Down Expand Up @@ -121,7 +127,7 @@ public void addLevel(ApprovalLevelImpl level) {
}

public void addLevel(ApprovalLevelType levelType) {
levels.add(new ApprovalLevelImpl(levelType, prismContext));
addLevel(new ApprovalLevelImpl(levelType, prismContext));
}

@Override
Expand Down

0 comments on commit 8c0f716

Please sign in to comment.