1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.core.enumerationmanagement.service.impl; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Date; |
20 | |
import java.util.List; |
21 | |
|
22 | |
import javax.jws.WebService; |
23 | |
import javax.jws.soap.SOAPBinding; |
24 | |
|
25 | |
import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition; |
26 | |
import org.kuali.student.common.dto.StatusInfo; |
27 | |
import org.kuali.student.common.exceptions.AlreadyExistsException; |
28 | |
import org.kuali.student.common.exceptions.DoesNotExistException; |
29 | |
import org.kuali.student.common.exceptions.InvalidParameterException; |
30 | |
import org.kuali.student.common.exceptions.MissingParameterException; |
31 | |
import org.kuali.student.common.exceptions.OperationFailedException; |
32 | |
import org.kuali.student.common.exceptions.PermissionDeniedException; |
33 | |
import org.kuali.student.common.search.dto.SearchCriteriaTypeInfo; |
34 | |
import org.kuali.student.common.search.dto.SearchRequest; |
35 | |
import org.kuali.student.common.search.dto.SearchResult; |
36 | |
import org.kuali.student.common.search.dto.SearchResultTypeInfo; |
37 | |
import org.kuali.student.common.search.dto.SearchTypeInfo; |
38 | |
import org.kuali.student.common.search.service.SearchManager; |
39 | |
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
40 | |
import org.kuali.student.core.enumerationmanagement.EnumerationException; |
41 | |
import org.kuali.student.core.enumerationmanagement.dao.EnumerationManagementDAO; |
42 | |
import org.kuali.student.core.enumerationmanagement.dto.EnumeratedValueInfo; |
43 | |
import org.kuali.student.core.enumerationmanagement.dto.EnumerationInfo; |
44 | |
import org.kuali.student.core.enumerationmanagement.entity.EnumeratedValue; |
45 | |
import org.kuali.student.core.enumerationmanagement.entity.Enumeration; |
46 | |
import org.kuali.student.core.enumerationmanagement.service.EnumerationManagementService; |
47 | |
import org.kuali.student.core.enumerationmanagement.service.impl.util.EnumerationAssembler; |
48 | |
import org.slf4j.Logger; |
49 | |
import org.slf4j.LoggerFactory; |
50 | |
import org.springframework.transaction.annotation.Transactional; |
51 | |
|
52 | |
@WebService(endpointInterface = "org.kuali.student.core.enumerationmanagement.service.EnumerationManagementService", serviceName = "EnumerationManagementService", portName = "EnumerationManagementService", targetNamespace = "http://student.kuali.org/wsdl/EnumerationManagementService") |
53 | |
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED) |
54 | |
public class EnumerationManagementServiceImpl implements EnumerationManagementService{ |
55 | |
|
56 | 1 | final static Logger logger = LoggerFactory.getLogger(EnumerationManagementServiceImpl.class); |
57 | |
|
58 | |
private SearchManager searchManager; |
59 | |
|
60 | |
private EnumerationManagementDAO enumDAO; |
61 | |
|
62 | 9 | public EnumerationManagementServiceImpl() {} |
63 | |
|
64 | |
private List<ValidationResultInfo> validateEnumeratedValue(EnumeratedValueInfo value){ |
65 | 0 | return null; |
66 | |
} |
67 | |
|
68 | |
@Override |
69 | |
@Transactional(readOnly=true) |
70 | |
public EnumerationInfo getEnumeration(String enumerationKey) |
71 | |
throws DoesNotExistException, InvalidParameterException, |
72 | |
MissingParameterException, OperationFailedException { |
73 | |
|
74 | 0 | Enumeration enumerationMetaEntity = null; |
75 | 0 | if (enumerationKey != null) |
76 | 0 | enumerationMetaEntity = enumDAO.fetch(Enumeration.class, enumerationKey); |
77 | 0 | EnumerationInfo enumerationMeta = null; |
78 | 0 | if(enumerationMetaEntity != null){ |
79 | 0 | enumerationMeta = new EnumerationInfo(); |
80 | 0 | EnumerationAssembler.toEnumerationInfo(enumerationMetaEntity, enumerationMeta); |
81 | |
} |
82 | 0 | return enumerationMeta; |
83 | |
} |
84 | |
|
85 | |
@Override |
86 | |
@Transactional(readOnly=true) |
87 | |
public List<EnumerationInfo> getEnumerations() |
88 | |
throws OperationFailedException { |
89 | 0 | List<Enumeration> entities = this.enumDAO.findEnumerations(); |
90 | |
|
91 | 0 | List<EnumerationInfo> dtos = EnumerationAssembler.toEnumerationMetaList(entities); |
92 | |
|
93 | 0 | return dtos; |
94 | |
} |
95 | |
|
96 | |
@Override |
97 | |
@Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
98 | |
public EnumeratedValueInfo addEnumeratedValue(String enumerationKey, |
99 | |
EnumeratedValueInfo enumeratedValue) throws AlreadyExistsException, |
100 | |
InvalidParameterException, MissingParameterException, |
101 | |
OperationFailedException, PermissionDeniedException { |
102 | |
Enumeration meta; |
103 | |
try { |
104 | 0 | meta = enumDAO.fetch(Enumeration.class, enumeratedValue.getEnumerationKey()); |
105 | 0 | } catch (DoesNotExistException e) { |
106 | 0 | throw new InvalidParameterException("Enumeration does not exist for key:"+enumerationKey); |
107 | 0 | } |
108 | |
|
109 | 0 | if(meta != null){ |
110 | 0 | List<ValidationResultInfo> results = this.validateEnumeratedValue(enumeratedValue); |
111 | |
|
112 | 0 | if(null != results) { |
113 | 0 | for(ValidationResultInfo result:results){ |
114 | 0 | if(result !=null && ValidationResultInfo.ErrorLevel.ERROR.equals(result.getErrorLevel())){ |
115 | 0 | throw new EnumerationException("addEnumeratedValue failed because the EnumeratdValue failed to pass validation against its EnumerationMeta - With Messages: " + result.toString()); |
116 | |
} |
117 | |
} |
118 | |
} |
119 | |
} |
120 | |
|
121 | 0 | EnumeratedValue valueEntity = new EnumeratedValue(); |
122 | 0 | EnumerationAssembler.toEnumeratedValueEntity(enumeratedValue, valueEntity); |
123 | 0 | valueEntity.setEnumeration(meta); |
124 | |
|
125 | 0 | enumDAO.addEnumeratedValue(enumerationKey, valueEntity); |
126 | |
|
127 | |
|
128 | 0 | return enumeratedValue; |
129 | |
} |
130 | |
|
131 | |
@Override |
132 | |
@Transactional(readOnly=true) |
133 | |
public List<EnumeratedValueInfo> getEnumeratedValues(String enumerationKey, |
134 | |
String contextType, String contextValue, Date contextDate) |
135 | |
throws DoesNotExistException, InvalidParameterException, |
136 | |
MissingParameterException, OperationFailedException { |
137 | |
|
138 | 0 | List<EnumeratedValue> enumeratedValueEntityList = new ArrayList<EnumeratedValue>(); |
139 | 0 | if(enumerationKey != null && contextType != null && contextValue != null && contextDate != null){ |
140 | 0 | enumeratedValueEntityList = enumDAO.fetchEnumeratedValuesWithContextAndDate(enumerationKey, contextType, contextValue, contextDate); |
141 | |
} |
142 | 0 | else if(enumerationKey != null && contextType != null && contextValue != null){ |
143 | 0 | enumeratedValueEntityList = enumDAO.fetchEnumeratedValuesWithContext(enumerationKey, contextType, contextValue); |
144 | |
} |
145 | 0 | else if(enumerationKey != null && contextDate != null){ |
146 | 0 | enumeratedValueEntityList = enumDAO.fetchEnumeratedValuesWithDate(enumerationKey, contextDate); |
147 | |
} |
148 | 0 | else if(enumerationKey != null){ |
149 | 0 | enumeratedValueEntityList = enumDAO.fetchEnumeratedValues(enumerationKey); |
150 | |
} |
151 | |
|
152 | 0 | List<EnumeratedValueInfo> enumeratedValueList = EnumerationAssembler.toEnumeratedValueList(enumeratedValueEntityList); |
153 | 0 | return enumeratedValueList; |
154 | |
} |
155 | |
|
156 | |
|
157 | |
@Override |
158 | |
@Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
159 | |
public EnumeratedValueInfo updateEnumeratedValue(String enumerationKey, |
160 | |
String code, EnumeratedValueInfo enumeratedValue) |
161 | |
throws DoesNotExistException, InvalidParameterException, |
162 | |
MissingParameterException, OperationFailedException, |
163 | |
PermissionDeniedException { |
164 | |
|
165 | |
Enumeration meta; |
166 | |
try { |
167 | 0 | meta = enumDAO.fetch(Enumeration.class, enumeratedValue.getEnumerationKey()); |
168 | 0 | } catch (DoesNotExistException e) { |
169 | 0 | throw new InvalidParameterException("Enumeration does not exist for key:"+enumerationKey); |
170 | 0 | } |
171 | |
|
172 | 0 | if(meta != null){ |
173 | 0 | List<ValidationResultInfo> results = this.validateEnumeratedValue(enumeratedValue); |
174 | |
|
175 | 0 | if(null != results) { |
176 | 0 | for(ValidationResultInfo result:results){ |
177 | 0 | if(result !=null && ValidationResultInfo.ErrorLevel.ERROR.equals(result.getErrorLevel())){ |
178 | 0 | throw new EnumerationException("addEnumeratedValue failed because the EnumeratdValue failed to pass validation against its EnumerationMeta - With Messages: " + result.toString()); |
179 | |
} |
180 | |
} |
181 | |
} |
182 | |
} |
183 | |
|
184 | 0 | EnumeratedValue enumeratedValueEntity = new EnumeratedValue(); |
185 | 0 | EnumerationAssembler.toEnumeratedValueEntity(enumeratedValue, enumeratedValueEntity); |
186 | 0 | enumeratedValueEntity = enumDAO.updateEnumeratedValue(meta, code, enumeratedValueEntity); |
187 | 0 | EnumerationAssembler.toEnumeratedValueInfo(enumeratedValueEntity, enumeratedValue); |
188 | |
|
189 | 0 | return enumeratedValue; |
190 | |
} |
191 | |
|
192 | |
@Override |
193 | |
@Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
194 | |
public StatusInfo removeEnumeratedValue(String enumerationKey, String code) { |
195 | 0 | enumDAO.removeEnumeratedValue(enumerationKey, code); |
196 | 0 | return new StatusInfo(); |
197 | |
} |
198 | |
|
199 | |
|
200 | |
@Override |
201 | |
public SearchCriteriaTypeInfo getSearchCriteriaType( |
202 | |
String searchCriteriaTypeKey) throws DoesNotExistException, |
203 | |
InvalidParameterException, MissingParameterException, |
204 | |
OperationFailedException { |
205 | |
|
206 | 0 | return searchManager.getSearchCriteriaType(searchCriteriaTypeKey); |
207 | |
} |
208 | |
|
209 | |
@Override |
210 | |
public List<SearchCriteriaTypeInfo> getSearchCriteriaTypes() |
211 | |
throws OperationFailedException { |
212 | 0 | return searchManager.getSearchCriteriaTypes(); |
213 | |
} |
214 | |
|
215 | |
@Override |
216 | |
public SearchResultTypeInfo getSearchResultType(String searchResultTypeKey) |
217 | |
throws DoesNotExistException, InvalidParameterException, |
218 | |
MissingParameterException, OperationFailedException { |
219 | 0 | checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey"); |
220 | 0 | return searchManager.getSearchResultType(searchResultTypeKey); |
221 | |
} |
222 | |
|
223 | |
@Override |
224 | |
public List<SearchResultTypeInfo> getSearchResultTypes() |
225 | |
throws OperationFailedException { |
226 | 0 | return searchManager.getSearchResultTypes(); |
227 | |
} |
228 | |
|
229 | |
@Override |
230 | |
public SearchTypeInfo getSearchType(String searchTypeKey) |
231 | |
throws DoesNotExistException, InvalidParameterException, |
232 | |
MissingParameterException, OperationFailedException { |
233 | 0 | checkForMissingParameter(searchTypeKey, "searchTypeKey"); |
234 | 0 | return searchManager.getSearchType(searchTypeKey); |
235 | |
} |
236 | |
|
237 | |
@Override |
238 | |
public List<SearchTypeInfo> getSearchTypes() |
239 | |
throws OperationFailedException { |
240 | 0 | return searchManager.getSearchTypes(); |
241 | |
} |
242 | |
|
243 | |
@Override |
244 | |
public List<SearchTypeInfo> getSearchTypesByCriteria( |
245 | |
String searchCriteriaTypeKey) throws DoesNotExistException, |
246 | |
InvalidParameterException, MissingParameterException, |
247 | |
OperationFailedException { |
248 | 0 | checkForMissingParameter(searchCriteriaTypeKey, "searchCriteriaTypeKey"); |
249 | 0 | return searchManager.getSearchTypesByCriteria(searchCriteriaTypeKey); |
250 | |
} |
251 | |
|
252 | |
@Override |
253 | |
public List<SearchTypeInfo> getSearchTypesByResult( |
254 | |
String searchResultTypeKey) throws DoesNotExistException, |
255 | |
InvalidParameterException, MissingParameterException, |
256 | |
OperationFailedException { |
257 | 0 | checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey"); |
258 | 0 | return searchManager.getSearchTypesByResult(searchResultTypeKey); |
259 | |
} |
260 | |
|
261 | |
@Override |
262 | |
public SearchResult search(SearchRequest searchRequest) throws MissingParameterException { |
263 | 0 | return searchManager.search(searchRequest, enumDAO); |
264 | |
} |
265 | |
|
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
private void checkForMissingParameter(Object param, String paramName) |
274 | |
throws MissingParameterException { |
275 | 0 | if (param == null) { |
276 | 0 | throw new MissingParameterException(paramName + " can not be null"); |
277 | |
} |
278 | 0 | } |
279 | |
|
280 | |
public void setSearchManager(SearchManager searchManager) { |
281 | 0 | this.searchManager = searchManager; |
282 | 0 | } |
283 | |
|
284 | |
public void setEnumDAO(EnumerationManagementDAO enumDAO) { |
285 | 0 | this.enumDAO = enumDAO; |
286 | 0 | } |
287 | |
|
288 | |
@Override |
289 | |
public ObjectStructureDefinition getObjectStructure(String objectTypeKey) { |
290 | |
|
291 | 0 | return null; |
292 | |
} |
293 | |
|
294 | |
@Override |
295 | |
public List<String> getObjectTypes() { |
296 | |
|
297 | 0 | return null; |
298 | |
} |
299 | |
} |