1 package org.kuali.ole.deliver.keyvalue.drools;
2
3 import org.apache.commons.collections.CollectionUtils;
4 import org.kuali.rice.core.api.criteria.Predicate;
5 import org.kuali.rice.core.api.criteria.QueryByCriteria;
6 import org.kuali.rice.core.api.util.ConcreteKeyValue;
7 import org.kuali.rice.core.api.util.KeyValue;
8 import org.kuali.rice.kim.api.KimConstants;
9 import org.kuali.rice.kim.api.common.template.Template;
10 import org.kuali.rice.kim.api.permission.Permission;
11 import org.kuali.rice.kim.api.permission.PermissionQueryResults;
12 import org.kuali.rice.kim.api.permission.PermissionService;
13 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
14 import org.kuali.rice.krad.keyvalues.KeyValuesBase;
15
16 import java.util.ArrayList;
17 import java.util.Collections;
18 import java.util.Iterator;
19 import java.util.List;
20
21 import static org.kuali.rice.core.api.criteria.PredicateFactory.and;
22 import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;
23
24
25
26
27 public class OverridePermissionsKeyValues extends KeyValuesBase {
28
29 private PermissionService permissionService;
30
31 @Override
32 public List<KeyValue> getKeyValues() {
33 List<KeyValue> keyValues = new ArrayList<>();
34 keyValues.add(new ConcreteKeyValue("", ""));
35 List<ConcreteKeyValue> concreteKeyValues = new ArrayList<ConcreteKeyValue>();
36 if (CollectionUtils.isNotEmpty(getPermissions())) {
37 for (Iterator<Permission> iterator = getPermissions().iterator(); iterator.hasNext(); ) {
38 Permission permission = iterator.next();
39 concreteKeyValues.add(new ConcreteKeyValue(permission.getName(), permission.getName()));
40 }
41
42 }
43 Collections.sort(concreteKeyValues);
44 keyValues.addAll(concreteKeyValues);
45 return keyValues;
46 }
47
48 private PermissionService getPermissionService() {
49 if (null == permissionService) {
50 permissionService = KimApiServiceLocator.getPermissionService();
51 }
52 return permissionService;
53 }
54
55 public List<Permission> getPermissions() {
56 Predicate p = and(
57 equal("namespaceCode", "OLE-DLVR"));
58 PermissionQueryResults permissionQueryResults = getPermissionService().findPermissions(QueryByCriteria.Builder.fromPredicates(p));
59 List<Permission> permissionList = permissionQueryResults.getResults();
60 return permissionList;
61 }
62
63 public void setPermissionService(PermissionService permissionService) {
64 this.permissionService = permissionService;
65 }
66
67
68 }