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