1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.rice.kim.util;
20
21 import java.util.Map;
22 import java.util.Set;
23
24 import org.apache.commons.beanutils.PropertyUtils;
25 import org.apache.commons.lang.StringUtils;
26 import org.kuali.kfs.sys.context.SpringContext;
27 import org.kuali.rice.core.api.config.property.ConfigurationService;
28 import org.kuali.rice.kew.api.KewApiServiceLocator;
29 import org.kuali.rice.kew.api.doctype.DocumentType;
30 import org.kuali.rice.kim.api.KimConstants;
31
32
33
34
35
36
37
38
39 public class KimCommonUtils {
40 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KimCommonUtils.class);
41
42 public static String getClosestParentDocumentTypeName( DocumentType documentType, Set<String> potentialParentDocumentTypeNames) {
43 if ( potentialParentDocumentTypeNames == null || documentType == null ) {
44 return null;
45 }
46 if (potentialParentDocumentTypeNames.contains(documentType.getName())) {
47 return documentType.getName();
48 } else {
49 if ( StringUtils.isBlank(documentType.getParentId())
50 || StringUtils.equals( documentType.getParentId(), documentType.getId() ) ) {
51 return null;
52 } else {
53 return getClosestParentDocumentTypeName(KewApiServiceLocator.getDocumentTypeService().getDocumentTypeById(documentType.getParentId()), potentialParentDocumentTypeNames);
54 }
55 }
56 }
57
58 public static boolean storedValueNotSpecifiedOrInputValueMatches(Map<String,String> storedValues, Map<String,String> inputValues, String attributeName) {
59 return ((storedValues == null)
60 || (inputValues == null))
61 || storedValues.isEmpty()
62 || inputValues.isEmpty()
63 || !storedValues.containsKey(attributeName)
64 || StringUtils.equals( storedValues.get(attributeName), inputValues.get(attributeName));
65 }
66
67 public static boolean doesPropertyNameMatch(
68 String requestedDetailsPropertyName,
69 String permissionDetailsPropertyName) {
70 if (StringUtils.isBlank(permissionDetailsPropertyName)) {
71 return true;
72 }
73 return StringUtils.equals(requestedDetailsPropertyName, permissionDetailsPropertyName)
74 || (StringUtils.startsWith(requestedDetailsPropertyName,permissionDetailsPropertyName+"."));
75 }
76
77 public static String getComponentSimpleName(Class<? extends Object> clazz) {
78 return clazz.getSimpleName();
79 }
80
81 public static String getComponentFullName(Class<? extends Object> clazz) {
82 return clazz.getName();
83 }
84
85 public static void copyProperties(Object targetToCopyTo, Object sourceToCopyFrom){
86 if(targetToCopyTo!=null && sourceToCopyFrom!=null) {
87 try{
88 PropertyUtils.copyProperties(targetToCopyTo, sourceToCopyFrom);
89 } catch(Exception ex){
90 throw new RuntimeException("Failed to copy from source object: "+sourceToCopyFrom.getClass()+" to target object: "+targetToCopyTo,ex);
91 }
92 }
93 }
94
95 public static String getKimBasePath(){
96 String kimBaseUrl = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(KimConstants.KimUIConstants.KIM_URL_KEY);
97 if (!kimBaseUrl.endsWith(KimConstants.KimUIConstants.URL_SEPARATOR)) {
98 kimBaseUrl = kimBaseUrl + KimConstants.KimUIConstants.URL_SEPARATOR;
99 }
100 return kimBaseUrl;
101 }
102
103 public static String getPathWithKimContext(String path, String kimActionName){
104 String kimContext = KimConstants.KimUIConstants.KIM_APPLICATION+KimConstants.KimUIConstants.URL_SEPARATOR;
105 String kimContextParameterized = KimConstants.KimUIConstants.KIM_APPLICATION+KimConstants.KimUIConstants.PARAMETERIZED_URL_SEPARATOR;
106 if(path.contains(kimActionName) && !path.contains(kimContext + kimActionName)
107 && !path.contains(kimContextParameterized + kimActionName)) {
108 path = path.replace(kimActionName, kimContext+kimActionName);
109 }
110 return path;
111 }
112
113 }