View Javadoc

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      public BaseTransform() {
18  
19      }
20  
21      public Predicate createPredicate(final Predicate input, String path) {
22          final Predicate attrValue;
23          if (input instanceof SingleValuedPredicate) {
24              final CriteriaValue<?> value = ((SingleValuedPredicate) input).getValue();
25              attrValue = dynConstruct(input.getClass().getSimpleName(), path, value.getValue());
26          } else if (input instanceof MultiValuedPredicate) {
27              final Set<? extends CriteriaValue<?>> values = ((MultiValuedPredicate) input).getValues();
28              List<Object> l = new ArrayList<Object>();
29              for (CriteriaValue<?> v : values) {
30                  l.add(v.getValue());
31              }
32  
33              attrValue = dynConstruct(input.getClass().getSimpleName(), path, l.toArray());
34          } else {
35              attrValue = dynConstruct(input.getClass().getSimpleName(), path);
36          }
37          return attrValue;
38  
39      }
40  }