1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.service.impl;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.log4j.Logger;
20 import org.kuali.rice.core.api.CoreApiServiceLocator;
21 import org.kuali.rice.core.api.config.ConfigurationException;
22 import org.kuali.rice.core.api.config.module.RunMode;
23 import org.kuali.rice.core.api.config.property.ConfigContext;
24 import org.kuali.rice.krad.bo.ExternalizableBusinessObject;
25 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
26 import org.kuali.rice.krad.service.ModuleService;
27 import org.kuali.rice.krad.util.KRADConstants;
28 import org.kuali.rice.krad.util.UrlFactory;
29
30 import java.util.List;
31 import java.util.Map;
32 import java.util.Properties;
33
34
35
36
37
38
39 public class ModuleServiceBase extends RemoteModuleServiceBase implements ModuleService {
40
41 protected static final Logger LOG = Logger.getLogger(ModuleServiceBase.class);
42
43
44
45 public <T extends ExternalizableBusinessObject> T getExternalizableBusinessObject(Class<T> businessObjectClass,
46 Map<String, Object> fieldValues) {
47 Class<? extends ExternalizableBusinessObject> implementationClass =
48 getExternalizableBusinessObjectImplementation(businessObjectClass);
49 ExternalizableBusinessObject businessObject =
50 (ExternalizableBusinessObject) getLegacyDataAdapter().findByPrimaryKey(implementationClass, fieldValues);
51 return (T) businessObject;
52 }
53
54
55
56
57 public <T extends ExternalizableBusinessObject> List<T> getExternalizableBusinessObjectsList(
58 Class<T> externalizableBusinessObjectClass, Map<String, Object> fieldValues) {
59 Class<? extends ExternalizableBusinessObject> implementationClass =
60 getExternalizableBusinessObjectImplementation(externalizableBusinessObjectClass);
61 return (List<T>) getLegacyDataAdapter().findMatching(implementationClass, fieldValues);
62 }
63
64
65
66 @Deprecated
67 public String getExternalizableBusinessObjectInquiryUrl(Class inquiryBusinessObjectClass,
68 Map<String, String[]> parameters) {
69 if (!isExternalizable(inquiryBusinessObjectClass)) {
70 return KRADConstants.EMPTY_STRING;
71 }
72 String businessObjectClassAttribute;
73
74 Class implementationClass = getExternalizableBusinessObjectImplementation(inquiryBusinessObjectClass);
75 if (implementationClass == null) {
76 LOG.error("Can't find ExternalizableBusinessObject implementation class for " + inquiryBusinessObjectClass
77 .getName());
78 throw new RuntimeException("Can't find ExternalizableBusinessObject implementation class for interface "
79 + inquiryBusinessObjectClass.getName());
80 }
81 businessObjectClassAttribute = implementationClass.getName();
82 return UrlFactory.parameterizeUrl(getInquiryUrl(inquiryBusinessObjectClass), getUrlParameters(
83 businessObjectClassAttribute, parameters));
84 }
85
86 @Deprecated
87 @Override
88 protected String getInquiryUrl(Class inquiryBusinessObjectClass) {
89
90 String riceBaseUrl = "";
91 String potentialUrlAddition = "";
92
93 if (goToCentralRiceForInquiry()) {
94 riceBaseUrl = CoreApiServiceLocator.getKualiConfigurationService().getPropertyValueAsString(KRADConstants.KUALI_RICE_URL_KEY);
95 } else {
96 riceBaseUrl = CoreApiServiceLocator.getKualiConfigurationService().getPropertyValueAsString(KRADConstants.APPLICATION_URL_KEY);
97 potentialUrlAddition = "kr/";
98 }
99
100 String inquiryUrl = riceBaseUrl;
101 if (!inquiryUrl.endsWith("/")) {
102 inquiryUrl = inquiryUrl + "/";
103 }
104 return inquiryUrl + potentialUrlAddition + KRADConstants.INQUIRY_ACTION;
105 }
106
107 @Override
108 public boolean isExternalizableBusinessObjectLookupable(Class boClass) {
109 Class<? extends ExternalizableBusinessObject> implementationClass = getExternalizableBusinessObjectImplementation(boClass);
110 return KRADServiceLocatorWeb.getLegacyDataAdapter().hasLocalLookup(implementationClass);
111 }
112
113 @Override
114 public boolean isExternalizableBusinessObjectInquirable(Class boClass) {
115 return KRADServiceLocatorWeb.getLegacyDataAdapter().hasLocalInquiry(boClass);
116 }
117
118
119
120
121
122
123
124 @Deprecated
125 @Override
126 public String getExternalizableBusinessObjectLookupUrl(Class inquiryBusinessObjectClass,
127 Map<String, String> parameters) {
128 Properties urlParameters = new Properties();
129
130 String riceBaseUrl = "";
131 String potentialUrlAddition = "";
132
133 if (goToCentralRiceForInquiry()) {
134 riceBaseUrl = CoreApiServiceLocator.getKualiConfigurationService().getPropertyValueAsString(KRADConstants.KUALI_RICE_URL_KEY);
135 } else {
136 riceBaseUrl = CoreApiServiceLocator.getKualiConfigurationService().getPropertyValueAsString(KRADConstants.APPLICATION_URL_KEY);
137 potentialUrlAddition = "kr/";
138 }
139
140 String lookupUrl = riceBaseUrl;
141 if (!lookupUrl.endsWith("/")) {
142 lookupUrl = lookupUrl + "/";
143 }
144
145 if (parameters.containsKey(KRADConstants.MULTIPLE_VALUE)) {
146 lookupUrl = lookupUrl + potentialUrlAddition + KRADConstants.MULTIPLE_VALUE_LOOKUP_ACTION;
147 }
148 else {
149 lookupUrl = lookupUrl + potentialUrlAddition + KRADConstants.LOOKUP_ACTION;
150 }
151
152 for (String paramName : parameters.keySet()) {
153 urlParameters.put(paramName, parameters.get(paramName));
154 }
155
156
157
158 Class clazz = getExternalizableBusinessObjectImplementation(inquiryBusinessObjectClass);
159
160
161
162 urlParameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, clazz == null ? "" : clazz.getName());
163
164 return UrlFactory.parameterizeUrl(lookupUrl, urlParameters);
165 }
166
167 public boolean goToCentralRiceForInquiry() {
168 return false;
169 }
170
171
172
173
174
175
176 @Override
177 protected String getBaseLookupUrl() {
178 if (goToCentralRiceForInquiry()) {
179 return BaseLookupUrlsHolder.remoteKradBaseLookupUrl;
180 } else {
181 return BaseLookupUrlsHolder.localKradBaseLookupUrl;
182 }
183 }
184
185 protected RunMode getRunMode(String module) {
186 String propertyName = module + ".mode";
187 String runMode = ConfigContext.getCurrentContextConfig().getProperty(propertyName);
188 if (StringUtils.isBlank(runMode)) {
189 throw new ConfigurationException("Failed to determine run mode for module '" + module + "'. Please be sure to set configuration parameter '" + propertyName + "'");
190 }
191 return RunMode.valueOf(runMode.toUpperCase());
192 }
193 }
194