| 1 | |
package org.kuali.student.process.poc.evaluator; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.List; |
| 5 | |
|
| 6 | |
import org.kuali.student.process.poc.context.SubProcessCheckContext; |
| 7 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
| 8 | |
import org.kuali.student.r2.common.dto.ValidationResultInfo; |
| 9 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
| 10 | |
import org.kuali.student.r2.core.process.dto.InstructionInfo; |
| 11 | |
|
| 12 | 0 | public class SubProcessCheckEvaluator implements CheckEvaluator<SubProcessCheckContext> { |
| 13 | |
|
| 14 | |
@Override |
| 15 | |
public List<ValidationResultInfo> evaluate(SubProcessCheckContext checkContext, ContextInfo context) throws OperationFailedException { |
| 16 | 0 | List<ValidationResultInfo> vrs = new ArrayList<ValidationResultInfo>(); |
| 17 | 0 | ValidationResultInfo vr = null; |
| 18 | |
|
| 19 | |
|
| 20 | 0 | String oldProcessKey = null; |
| 21 | |
try { |
| 22 | 0 | oldProcessKey = checkContext.getProcessContext().getProcessKey(); |
| 23 | 0 | checkContext.getProcessContext().setProcessKey(checkContext.getCheck().getProcessKey()); |
| 24 | 0 | vrs = checkContext.getProcessEvaluator().evaluate(checkContext.getProcessContext(), context); |
| 25 | |
} finally { |
| 26 | |
|
| 27 | 0 | checkContext.getProcessContext().setProcessKey(oldProcessKey); |
| 28 | 0 | } |
| 29 | |
|
| 30 | 0 | if (hasErrors(vrs)) { |
| 31 | 0 | vr = initInfo(checkContext.getInstruction()); |
| 32 | 0 | vrs.add(vr); |
| 33 | 0 | vr.setMessage("you have errors in the subprocess"); |
| 34 | 0 | return vrs; |
| 35 | |
} |
| 36 | 0 | vr = initInfo(checkContext.getInstruction()); |
| 37 | 0 | vrs.add(vr); |
| 38 | 0 | vr.setMessage("no errors were found in the subprocess"); |
| 39 | 0 | return vrs; |
| 40 | |
} |
| 41 | |
|
| 42 | |
public static boolean hasErrors(List<ValidationResultInfo> vrs) { |
| 43 | 0 | for (ValidationResultInfo vr : vrs) { |
| 44 | 0 | if (vr.isError()) { |
| 45 | 0 | return true; |
| 46 | |
} |
| 47 | 0 | if (vr.isWarn()) { |
| 48 | 0 | return true; |
| 49 | |
} |
| 50 | |
} |
| 51 | 0 | return false; |
| 52 | |
} |
| 53 | |
|
| 54 | |
private static ValidationResultInfo initError(InstructionInfo instruction) { |
| 55 | 0 | return MilestoneCheckEvaluator.initError(instruction); |
| 56 | |
} |
| 57 | |
|
| 58 | |
private static ValidationResultInfo initInfo(InstructionInfo instruction) { |
| 59 | 0 | return MilestoneCheckEvaluator.initInfo(instruction); |
| 60 | |
} |
| 61 | |
} |