| 1 | |
package org.kuali.student.r2.common.criteria.transform; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.List; |
| 5 | |
import java.util.Set; |
| 6 | |
|
| 7 | |
import org.kuali.rice.core.api.criteria.CriteriaValue; |
| 8 | |
import org.kuali.rice.core.api.criteria.MultiValuedPredicate; |
| 9 | |
import org.kuali.rice.core.api.criteria.Predicate; |
| 10 | |
import org.kuali.rice.core.api.criteria.SingleValuedPredicate; |
| 11 | |
import org.kuali.student.r2.common.criteria.LookupCustomizer.PredicateTransform; |
| 12 | |
|
| 13 | |
import static org.kuali.rice.core.api.criteria.PredicateFactory.*; |
| 14 | |
|
| 15 | |
public abstract class BaseTransform implements PredicateTransform { |
| 16 | |
|
| 17 | 0 | public BaseTransform() { |
| 18 | |
|
| 19 | 0 | } |
| 20 | |
|
| 21 | |
public Predicate createPredicate(final Predicate input, String path) { |
| 22 | |
final Predicate attrValue; |
| 23 | 0 | if (input instanceof SingleValuedPredicate) { |
| 24 | 0 | final CriteriaValue<?> value = ((SingleValuedPredicate) input).getValue(); |
| 25 | 0 | attrValue = dynConstruct(input.getClass().getSimpleName(), path, value.getValue()); |
| 26 | 0 | } else if (input instanceof MultiValuedPredicate) { |
| 27 | 0 | final Set<? extends CriteriaValue<?>> values = ((MultiValuedPredicate) input).getValues(); |
| 28 | 0 | List<Object> l = new ArrayList<Object>(); |
| 29 | 0 | for (CriteriaValue<?> v : values) { |
| 30 | 0 | l.add(v.getValue()); |
| 31 | |
} |
| 32 | |
|
| 33 | 0 | attrValue = dynConstruct(input.getClass().getSimpleName(), path, l.toArray()); |
| 34 | 0 | } else { |
| 35 | 0 | attrValue = dynConstruct(input.getClass().getSimpleName(), path); |
| 36 | |
} |
| 37 | 0 | return attrValue; |
| 38 | |
|
| 39 | |
} |
| 40 | |
} |