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