1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.core.statement.service.impl; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.HashSet; |
20 | |
import java.util.Iterator; |
21 | |
import java.util.List; |
22 | |
import java.util.Set; |
23 | |
|
24 | |
import javax.jws.WebService; |
25 | |
|
26 | |
import org.kuali.student.common.validator.Validator; |
27 | |
import org.kuali.student.common.validator.ValidatorFactory; |
28 | |
import org.kuali.student.core.dictionary.dto.ObjectStructureDefinition; |
29 | |
import org.kuali.student.core.dictionary.service.DictionaryService; |
30 | |
import org.kuali.student.core.dto.StatusInfo; |
31 | |
import org.kuali.student.core.exceptions.AlreadyExistsException; |
32 | |
import org.kuali.student.core.exceptions.CircularReferenceException; |
33 | |
import org.kuali.student.core.exceptions.DataValidationErrorException; |
34 | |
import org.kuali.student.core.exceptions.DoesNotExistException; |
35 | |
import org.kuali.student.core.exceptions.InvalidParameterException; |
36 | |
import org.kuali.student.core.exceptions.MissingParameterException; |
37 | |
import org.kuali.student.core.exceptions.OperationFailedException; |
38 | |
import org.kuali.student.core.exceptions.PermissionDeniedException; |
39 | |
import org.kuali.student.core.exceptions.VersionMismatchException; |
40 | |
import org.kuali.student.core.search.dto.SearchCriteriaTypeInfo; |
41 | |
import org.kuali.student.core.search.dto.SearchRequest; |
42 | |
import org.kuali.student.core.search.dto.SearchResult; |
43 | |
import org.kuali.student.core.search.dto.SearchResultTypeInfo; |
44 | |
import org.kuali.student.core.search.dto.SearchTypeInfo; |
45 | |
import org.kuali.student.core.search.service.SearchManager; |
46 | |
import org.kuali.student.core.statement.dao.StatementDao; |
47 | |
import org.kuali.student.core.statement.dto.NlUsageTypeInfo; |
48 | |
import org.kuali.student.core.statement.dto.RefStatementRelationInfo; |
49 | |
import org.kuali.student.core.statement.dto.RefStatementRelationTypeInfo; |
50 | |
import org.kuali.student.core.statement.dto.ReqComponentInfo; |
51 | |
import org.kuali.student.core.statement.dto.ReqComponentTypeInfo; |
52 | |
import org.kuali.student.core.statement.dto.StatementInfo; |
53 | |
import org.kuali.student.core.statement.dto.StatementTreeViewInfo; |
54 | |
import org.kuali.student.core.statement.dto.StatementTypeInfo; |
55 | |
import org.kuali.student.core.statement.entity.NlUsageType; |
56 | |
import org.kuali.student.core.statement.entity.ObjectType; |
57 | |
import org.kuali.student.core.statement.entity.RefStatementRelation; |
58 | |
import org.kuali.student.core.statement.entity.RefStatementRelationAttribute; |
59 | |
import org.kuali.student.core.statement.entity.RefStatementRelationType; |
60 | |
import org.kuali.student.core.statement.entity.ReqComponent; |
61 | |
import org.kuali.student.core.statement.entity.ReqComponentType; |
62 | |
import org.kuali.student.core.statement.entity.Statement; |
63 | |
import org.kuali.student.core.statement.entity.StatementType; |
64 | |
import org.kuali.student.core.statement.naturallanguage.NaturalLanguageTranslator; |
65 | |
import org.kuali.student.core.statement.naturallanguage.translators.ReqComponentTranslator; |
66 | |
import org.kuali.student.core.statement.service.StatementService; |
67 | |
import org.kuali.student.core.validation.dto.ValidationResultInfo; |
68 | |
import org.slf4j.Logger; |
69 | |
import org.slf4j.LoggerFactory; |
70 | |
import org.springframework.beans.BeanUtils; |
71 | |
import org.springframework.transaction.annotation.Transactional; |
72 | |
|
73 | |
@WebService(endpointInterface = "org.kuali.student.core.statement.service.StatementService", serviceName = "StatementService", portName = "StatementService", targetNamespace = "http://student.kuali.org/wsdl/statement") |
74 | |
@Transactional(readOnly=true,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
75 | 4 | public class StatementServiceImpl implements StatementService { |
76 | |
|
77 | 1 | private final static Logger logger = LoggerFactory.getLogger(ReqComponentTranslator.class); |
78 | |
|
79 | |
private StatementDao statementDao; |
80 | |
private NaturalLanguageTranslator naturalLanguageTranslator; |
81 | |
private SearchManager searchManager; |
82 | |
private DictionaryService dictionaryServiceDelegate; |
83 | |
private StatementAssembler statementAssembler; |
84 | |
private ValidatorFactory validatorFactory; |
85 | |
|
86 | |
|
87 | |
public void setStatementAssembler(StatementAssembler statementAssembler) { |
88 | 2 | this.statementAssembler = statementAssembler; |
89 | 2 | } |
90 | |
|
91 | |
public SearchManager getSearchManager() { |
92 | 0 | return searchManager; |
93 | |
} |
94 | |
|
95 | |
public void setSearchManager(final SearchManager searchManager) { |
96 | 2 | this.searchManager = searchManager; |
97 | 2 | } |
98 | |
|
99 | |
public DictionaryService getDictionaryServiceDelegate() { |
100 | 0 | return dictionaryServiceDelegate; |
101 | |
} |
102 | |
|
103 | |
public void setDictionaryServiceDelegate(final DictionaryService dictionaryServiceDelegate) { |
104 | 2 | this.dictionaryServiceDelegate = dictionaryServiceDelegate; |
105 | 2 | } |
106 | |
|
107 | |
public StatementDao getStatementDao() { |
108 | 0 | return statementDao; |
109 | |
} |
110 | |
|
111 | |
public void setStatementDao(final StatementDao statementDao) { |
112 | 2 | this.statementDao = statementDao; |
113 | 2 | } |
114 | |
|
115 | |
public NaturalLanguageTranslator getNaturalLanguageTranslator() { |
116 | 0 | return naturalLanguageTranslator; |
117 | |
} |
118 | |
|
119 | |
public void setNaturalLanguageTranslator(final NaturalLanguageTranslator translator) { |
120 | 2 | this.naturalLanguageTranslator = translator; |
121 | 2 | } |
122 | |
|
123 | |
public NlUsageTypeInfo getNlUsageType(final String nlUsageTypeKey) |
124 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
125 | |
|
126 | 11 | checkForNullOrEmptyParameter(nlUsageTypeKey, "nlUsageTypeKey"); |
127 | 11 | checkForEmptyParameter(nlUsageTypeKey, "nlUsageTypeKey"); |
128 | |
|
129 | 11 | NlUsageType entity = this.statementDao.fetch(NlUsageType.class, nlUsageTypeKey); |
130 | 9 | NlUsageTypeInfo info = StatementAssembler.toNlUsageTypeInfo(entity); |
131 | 9 | return info; |
132 | |
} |
133 | |
|
134 | |
public List<NlUsageTypeInfo> getNlUsageTypes() |
135 | |
throws OperationFailedException { |
136 | |
|
137 | 1 | List<NlUsageType> entities = this.statementDao.find(NlUsageType.class); |
138 | 1 | List<NlUsageTypeInfo> infos = StatementAssembler.toNlUsageTypeInfos(entities); |
139 | 1 | return infos; |
140 | |
} |
141 | |
|
142 | |
public List<String> getRefObjectTypes() throws OperationFailedException { |
143 | 1 | List<ObjectType> objectTypes = this.statementDao.find(ObjectType.class); |
144 | 1 | List<String> ids = new ArrayList<String>(); |
145 | 1 | for(ObjectType objectType : objectTypes) { |
146 | 1 | ids.add(objectType.getId()); |
147 | |
} |
148 | 1 | return ids; |
149 | |
} |
150 | |
|
151 | |
public List<String> getRefObjectSubTypes(final String objectTypeKey) |
152 | |
throws DoesNotExistException, |
153 | |
InvalidParameterException, MissingParameterException, |
154 | |
OperationFailedException { |
155 | |
|
156 | 1 | checkForNullOrEmptyParameter(objectTypeKey, "objectTypeKey"); |
157 | 1 | checkForEmptyParameter(objectTypeKey, "objectTypeKey"); |
158 | |
|
159 | 1 | ObjectType objectType = this.statementDao.fetch(ObjectType.class, objectTypeKey); |
160 | 1 | List<String> ids = StatementAssembler.toRefObjectSubTypeIds(objectType); |
161 | 1 | return ids; |
162 | |
} |
163 | |
|
164 | |
public RefStatementRelationInfo getRefStatementRelation(final String refStatementRelationId) |
165 | |
throws DoesNotExistException, InvalidParameterException, |
166 | |
MissingParameterException, OperationFailedException { |
167 | |
|
168 | 1 | checkForNullOrEmptyParameter(refStatementRelationId, "refStatementRelationId"); |
169 | 1 | checkForEmptyParameter(refStatementRelationId, "refStatementRelationId"); |
170 | |
|
171 | 1 | RefStatementRelation entity = this.statementDao.fetch(RefStatementRelation.class, refStatementRelationId); |
172 | 1 | RefStatementRelationInfo dto = StatementAssembler.toRefStatementRelationInfo(entity); |
173 | 1 | return dto; |
174 | |
} |
175 | |
|
176 | |
public List<RefStatementRelationInfo> getRefStatementRelationsByRef(final String refObjectTypeKey, final String refObjectId) |
177 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
178 | 0 | checkForNullOrEmptyParameter(refObjectTypeKey, "refObjectTypeKey"); |
179 | 0 | checkForEmptyParameter(refObjectId, "refObjectId"); |
180 | |
|
181 | 0 | List<RefStatementRelation> references = this.statementDao.getRefStatementRelations( |
182 | |
refObjectTypeKey, refObjectId); |
183 | 0 | List<RefStatementRelationInfo> referenceInfos = null; |
184 | 0 | if (references != null) { |
185 | 0 | for (RefStatementRelation reference : references) { |
186 | 0 | RefStatementRelationInfo dto = StatementAssembler.toRefStatementRelationInfo(reference); |
187 | 0 | referenceInfos = (referenceInfos == null)? new ArrayList<RefStatementRelationInfo>(7) : referenceInfos; |
188 | 0 | referenceInfos.add(dto); |
189 | 0 | } |
190 | |
} |
191 | 0 | return referenceInfos; |
192 | |
} |
193 | |
|
194 | |
public List<RefStatementRelationInfo> getRefStatementRelationsByStatement(final String statementId) |
195 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
196 | |
|
197 | 3 | checkForNullOrEmptyParameter(statementId, "statementId"); |
198 | |
|
199 | 1 | Statement statement = this.statementDao.fetch(Statement.class, statementId); |
200 | 1 | List<RefStatementRelation> entities = statement.getRefStatementRelations(); |
201 | 1 | List<RefStatementRelationInfo> dtoList = StatementAssembler.toRefStatementRelationInfos(entities); |
202 | 1 | return dtoList; |
203 | |
} |
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
public String getNaturalLanguageForReqComponent(final String reqComponentId, final String nlUsageTypeKey, final String language) |
221 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
222 | |
|
223 | 8 | checkForNullOrEmptyParameter(reqComponentId, "reqComponentId"); |
224 | 8 | checkForNullOrEmptyParameter(nlUsageTypeKey, "nlUsageTypeKey"); |
225 | 8 | checkForEmptyParameter(language, "language"); |
226 | |
|
227 | |
|
228 | 8 | getNlUsageType(nlUsageTypeKey); |
229 | |
|
230 | 7 | ReqComponent reqComponent = this.statementDao.fetch(ReqComponent.class, reqComponentId); |
231 | 7 | String nl = this.naturalLanguageTranslator.translateReqComponent(reqComponent, nlUsageTypeKey, language); |
232 | |
|
233 | 7 | if(logger.isInfoEnabled()) { |
234 | 0 | logger.info("reqComponentId="+reqComponentId); |
235 | 0 | logger.info("nlUsageTypeKey="+nlUsageTypeKey); |
236 | 0 | logger.info("language="+language); |
237 | 0 | logger.info("ReqComponent translation="+nl); |
238 | |
} |
239 | |
|
240 | 7 | return nl; |
241 | |
} |
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
public String getNaturalLanguageForStatement(final String statementId, final String nlUsageTypeKey, final String language) |
267 | |
throws DoesNotExistException, InvalidParameterException, |
268 | |
MissingParameterException, OperationFailedException { |
269 | |
|
270 | 1 | checkForNullOrEmptyParameter(statementId, "statementId"); |
271 | 1 | checkForNullOrEmptyParameter(nlUsageTypeKey, "nlUsageTypeKey"); |
272 | 1 | checkForEmptyParameter(language, "language"); |
273 | |
|
274 | 1 | Statement statement = this.statementDao.fetch(Statement.class, statementId); |
275 | 1 | String nl = this.naturalLanguageTranslator.translateStatement(statement, nlUsageTypeKey, language); |
276 | |
|
277 | 1 | if(logger.isInfoEnabled()) { |
278 | 0 | logger.info("statementId="+statementId); |
279 | 0 | logger.info("nlUsageTypeKey="+nlUsageTypeKey); |
280 | 0 | logger.info("language="+language); |
281 | 0 | logger.info("Statement translation="+nl); |
282 | |
} |
283 | |
|
284 | 1 | return nl; |
285 | |
} |
286 | |
|
287 | |
public String getNaturalLanguageForRefStatementRelation(final String refStatementRelationId, final String nlUsageTypeKey, final String language) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
288 | 1 | checkForNullOrEmptyParameter(refStatementRelationId, "refStatementRelationId"); |
289 | 1 | checkForNullOrEmptyParameter(nlUsageTypeKey, "nlUsageTypeKey"); |
290 | 1 | checkForEmptyParameter(language, "language"); |
291 | |
|
292 | 1 | RefStatementRelation refStatementRelation = this.statementDao.fetch(RefStatementRelation.class, refStatementRelationId); |
293 | 1 | Statement statement = refStatementRelation.getStatement(); |
294 | 1 | String nl = this.naturalLanguageTranslator.translateStatement(statement, nlUsageTypeKey, language); |
295 | |
|
296 | 1 | if(logger.isInfoEnabled()) { |
297 | 0 | logger.info("refStatementRelationId="+refStatementRelationId); |
298 | 0 | logger.info("nlUsageTypeKey="+nlUsageTypeKey); |
299 | 0 | logger.info("language="+language); |
300 | 0 | logger.info("Statement translation="+nl); |
301 | |
} |
302 | |
|
303 | 1 | return nl; |
304 | |
} |
305 | |
|
306 | |
@Override |
307 | |
public String translateReqComponentToNL(final ReqComponentInfo reqComponentInfo, final String nlUsageTypeKey, final String language) |
308 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException { |
309 | 1 | checkForMissingParameter(reqComponentInfo, "reqComponentInfo"); |
310 | 1 | checkForNullOrEmptyParameter(nlUsageTypeKey, "nlUsageTypeKey"); |
311 | 1 | checkForEmptyParameter(language, "language"); |
312 | |
|
313 | |
try { |
314 | |
|
315 | 1 | getNlUsageType(nlUsageTypeKey); |
316 | 1 | ReqComponent req = statementAssembler.toReqComponentRelation(false, reqComponentInfo); |
317 | 1 | String nl = this.naturalLanguageTranslator.translateReqComponent(req, nlUsageTypeKey, language); |
318 | |
|
319 | 1 | if(logger.isInfoEnabled()) { |
320 | 0 | logger.info("ReqComponent translation="+nl); |
321 | |
} |
322 | |
|
323 | 1 | return nl; |
324 | 0 | } catch (DoesNotExistException e) { |
325 | 0 | throw new OperationFailedException("Requirement component translation failed: " + e.getMessage()); |
326 | 0 | } catch (VersionMismatchException e) { |
327 | 0 | throw new OperationFailedException("Requirement component translation failed: " + e.getMessage()); |
328 | |
} |
329 | |
} |
330 | |
|
331 | |
@Override |
332 | |
public String translateStatementTreeViewToNL(final StatementTreeViewInfo statementTreeViewInfo, final String nlUsageTypeKey, final String language) |
333 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException { |
334 | 0 | checkForMissingParameter(statementTreeViewInfo, "statementTreeViewInfo"); |
335 | 0 | checkForNullOrEmptyParameter(nlUsageTypeKey, "nlUsageTypeKey"); |
336 | 0 | checkForEmptyParameter(language, "language"); |
337 | |
|
338 | |
try { |
339 | 0 | Statement statement = statementAssembler.toStatement(statementTreeViewInfo); |
340 | |
|
341 | 0 | String nl = this.naturalLanguageTranslator.translateStatement(statement, nlUsageTypeKey, language); |
342 | |
|
343 | 0 | if(logger.isInfoEnabled()) { |
344 | 0 | logger.info("StatementTreeView translation="+nl); |
345 | |
} |
346 | |
|
347 | 0 | return nl; |
348 | 0 | } catch (DoesNotExistException e) { |
349 | 0 | throw new OperationFailedException("Statement tree view translation failed: " + e.getMessage()); |
350 | 0 | } catch (VersionMismatchException e) { |
351 | 0 | throw new OperationFailedException("Statement tree view translation failed: " + e.getMessage()); |
352 | |
} |
353 | |
} |
354 | |
|
355 | |
|
356 | |
|
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
|
362 | |
private void checkForMissingParameter(Object param, String paramName) |
363 | |
throws MissingParameterException { |
364 | 83 | if (param == null) { |
365 | 0 | throw new MissingParameterException(paramName + " can not be null"); |
366 | |
} |
367 | 83 | } |
368 | |
|
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
|
377 | |
private void checkForNullOrEmptyParameter(String param, String paramName) |
378 | |
throws MissingParameterException, InvalidParameterException { |
379 | 58 | if (param == null) { |
380 | 2 | throw new MissingParameterException(paramName + " can not be null"); |
381 | 56 | } else if (param.trim().isEmpty()) { |
382 | 2 | throw new InvalidParameterException(paramName + " can not be empty"); |
383 | |
} |
384 | 54 | } |
385 | |
|
386 | |
|
387 | |
|
388 | |
|
389 | |
|
390 | |
|
391 | |
|
392 | |
|
393 | |
private void checkForEmptyParameter(String param, String paramName) |
394 | |
throws MissingParameterException, InvalidParameterException { |
395 | 24 | if (param != null && param.trim().isEmpty()) { |
396 | 0 | throw new InvalidParameterException(paramName + " can not be empty"); |
397 | |
} |
398 | 24 | } |
399 | |
|
400 | |
@Override |
401 | |
@Transactional(readOnly=false) |
402 | |
public ReqComponentInfo createReqComponent(final String reqComponentType, final ReqComponentInfo reqComponentInfo) throws AlreadyExistsException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
403 | 5 | checkForMissingParameter(reqComponentType, "reqComponentType"); |
404 | 5 | checkForMissingParameter(reqComponentInfo, "reqComponentInfo"); |
405 | |
|
406 | 5 | ReqComponent reqComp = null; |
407 | |
|
408 | |
try { |
409 | 5 | reqComp = statementAssembler.toReqComponentRelation(false, reqComponentInfo); |
410 | 0 | } catch (VersionMismatchException e) { |
411 | 0 | throw new OperationFailedException("Version Mismatch.", e); |
412 | 5 | } |
413 | |
|
414 | 5 | reqComp = statementDao.create(reqComp); |
415 | |
|
416 | 5 | return statementAssembler.toReqComponentInfo(reqComp, null, null); |
417 | |
} |
418 | |
|
419 | |
@Override |
420 | |
@Transactional(readOnly=false) |
421 | |
public StatementInfo createStatement(final String statementType, final StatementInfo statementInfo) throws AlreadyExistsException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
422 | 4 | checkForMissingParameter(statementType, "statementType"); |
423 | 4 | checkForMissingParameter(statementInfo, "statementInfo"); |
424 | |
|
425 | 4 | Statement statement = null; |
426 | |
|
427 | |
try { |
428 | 4 | statement = statementAssembler.toStatementRelation(false, statementInfo); |
429 | 0 | } catch (VersionMismatchException e) { |
430 | 0 | throw new OperationFailedException("Version Mismatch.", e); |
431 | 4 | } |
432 | |
|
433 | 4 | statementDao.create(statement); |
434 | |
|
435 | 4 | StatementInfo info = StatementAssembler.toStatementInfo(statement); |
436 | |
|
437 | 4 | return info; |
438 | |
} |
439 | |
|
440 | |
@Override |
441 | |
@Transactional(readOnly=false) |
442 | |
public StatementTreeViewInfo createStatementTreeView(final StatementTreeViewInfo statementTreeViewInfo) throws AlreadyExistsException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, CircularReferenceException { |
443 | |
try { |
444 | |
|
445 | 1 | updateSTVHelperCreateStatements(statementTreeViewInfo); |
446 | |
|
447 | 1 | updateStatementTreeViewHelper(statementTreeViewInfo); |
448 | 1 | StatementTreeViewInfo test = getStatementTreeView(statementTreeViewInfo.getId()); |
449 | |
|
450 | 1 | return test; |
451 | 0 | } catch (VersionMismatchException e) { |
452 | 0 | throw new OperationFailedException("Create failed.", e); |
453 | |
} |
454 | |
} |
455 | |
|
456 | |
|
457 | |
@Override |
458 | |
@Transactional(readOnly=false) |
459 | |
public StatusInfo deleteReqComponent(final String reqComponentId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
460 | 1 | checkForMissingParameter(reqComponentId, "reqComponentId"); |
461 | |
|
462 | 1 | ReqComponent reqComp = statementDao.fetch(ReqComponent.class, reqComponentId); |
463 | |
|
464 | 1 | if(reqComp==null){ |
465 | 0 | throw new DoesNotExistException("ReqComponent does not exist for id: "+reqComponentId); |
466 | |
} |
467 | |
|
468 | 1 | statementDao.delete(reqComp); |
469 | |
|
470 | 1 | StatusInfo statusInfo = new StatusInfo(); |
471 | 1 | statusInfo.setSuccess(true); |
472 | 1 | statusInfo.setMessage("Requirement component successfully deleted"); |
473 | 1 | return statusInfo; |
474 | |
} |
475 | |
|
476 | |
@Override |
477 | |
@Transactional(readOnly=false) |
478 | |
public StatusInfo deleteStatement(final String statementId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
479 | 1 | checkForMissingParameter(statementId, "statementId"); |
480 | |
|
481 | 1 | Statement stmt = statementDao.fetch(Statement.class, statementId); |
482 | 1 | if(stmt==null){ |
483 | 0 | throw new DoesNotExistException("Statement does not exist for id: "+statementId); |
484 | |
} |
485 | |
|
486 | |
|
487 | |
try { |
488 | 1 | Statement parent = statementDao.getParentStatement(statementId); |
489 | 1 | List<Statement> children = parent.getChildren(); |
490 | 1 | for (int i = 0; i < children.size(); i++) { |
491 | 1 | if (children.get(i).getId().equals(statementId)) { |
492 | 1 | children.remove(i); |
493 | 1 | break; |
494 | |
} |
495 | |
} |
496 | 1 | statementDao.update(parent); |
497 | 0 | } catch (DoesNotExistException e) { |
498 | |
|
499 | 1 | } |
500 | |
|
501 | 1 | statementDao.delete(stmt); |
502 | |
|
503 | 1 | StatusInfo statusInfo = new StatusInfo(); |
504 | 1 | statusInfo.setSuccess(true); |
505 | 1 | statusInfo.setMessage("Statement successfully deleted"); |
506 | 1 | return statusInfo; |
507 | |
} |
508 | |
|
509 | |
@Override |
510 | |
@Transactional(readOnly=false) |
511 | |
public StatusInfo deleteStatementTreeView(final String statementId) throws DoesNotExistException{ |
512 | 1 | Statement stmt = statementDao.fetch(Statement.class, statementId); |
513 | |
|
514 | |
try{ |
515 | 1 | Statement parent = statementDao.getParentStatement(statementId); |
516 | |
|
517 | |
|
518 | 0 | if(parent.getChildren()!=null){ |
519 | 0 | for(Iterator<Statement> iter = parent.getChildren().iterator();iter.hasNext();){ |
520 | 0 | Statement childStmt = iter.next(); |
521 | 0 | if(stmt.getId().equals(childStmt.getId())){ |
522 | 0 | iter.remove(); |
523 | 0 | break; |
524 | |
} |
525 | 0 | } |
526 | |
} |
527 | 0 | statementDao.update(parent); |
528 | 1 | }catch(DoesNotExistException e){ |
529 | |
|
530 | 0 | } |
531 | |
|
532 | |
|
533 | 1 | deleteRecursively(stmt); |
534 | |
|
535 | 1 | StatusInfo statusInfo = new StatusInfo(); |
536 | 1 | statusInfo.setSuccess(true); |
537 | 1 | statusInfo.setMessage("Statement Tree successfully deleted"); |
538 | 1 | return statusInfo; |
539 | |
} |
540 | |
|
541 | |
private void deleteRecursively(Statement stmt) { |
542 | 3 | if(stmt.getChildren()!=null){ |
543 | 3 | List<Statement> childStmts = new ArrayList<Statement>(stmt.getChildren()); |
544 | 3 | stmt.getChildren().clear(); |
545 | 3 | stmt = statementDao.update(stmt); |
546 | 3 | for(Statement childStmt:childStmts){ |
547 | 2 | deleteRecursively(childStmt); |
548 | |
} |
549 | |
} |
550 | 3 | statementDao.delete(stmt); |
551 | 3 | } |
552 | |
|
553 | |
@Override |
554 | |
public ReqComponentInfo getReqComponent(final String reqComponentId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
555 | 10 | return statementAssembler.toReqComponentInfo(statementDao.fetch(ReqComponent.class, reqComponentId), null, null); |
556 | |
} |
557 | |
|
558 | |
@Override |
559 | |
public List<ReqComponentInfo> getReqComponentsByType(final String reqComponentTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
560 | 2 | checkForMissingParameter(reqComponentTypeKey, "reqComponentTypeKey"); |
561 | |
|
562 | 2 | List<ReqComponent> reqComponents = statementDao.getReqComponentsByType(reqComponentTypeKey); |
563 | 2 | return statementAssembler.toReqComponentInfos(reqComponents, null, null); |
564 | |
} |
565 | |
|
566 | |
@Override |
567 | |
public StatementInfo getStatement(final String statementId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
568 | 17 | StatementInfo statementInfo = null; |
569 | 17 | checkForMissingParameter(statementId, "statementId"); |
570 | 17 | statementInfo = StatementAssembler.toStatementInfo(statementDao.fetch(Statement.class, statementId)); |
571 | 12 | return statementInfo; |
572 | |
} |
573 | |
|
574 | |
@Override |
575 | |
public List<StatementInfo> getStatementsByType(final String statementTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
576 | 2 | checkForMissingParameter(statementTypeKey, "statementTypeKey"); |
577 | |
|
578 | 2 | List<Statement> statements = statementDao.getStatementsForStatementType(statementTypeKey); |
579 | 2 | return StatementAssembler.toStatementInfos(statements); |
580 | |
} |
581 | |
|
582 | |
@Override |
583 | |
public List<StatementInfo> getStatementsUsingReqComponent(final String reqComponentId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
584 | 1 | checkForNullOrEmptyParameter(reqComponentId, "reqComponentId"); |
585 | |
|
586 | 1 | List<Statement> list = statementDao.getStatementsForReqComponent(reqComponentId); |
587 | 1 | return StatementAssembler.toStatementInfos(list); |
588 | |
} |
589 | |
|
590 | |
|
591 | |
|
592 | |
|
593 | |
|
594 | |
|
595 | |
|
596 | |
|
597 | |
|
598 | |
|
599 | |
|
600 | |
public List<StatementInfo> getStatementsUsingStatement(final String statementId) |
601 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
602 | 1 | checkForNullOrEmptyParameter(statementId, "statementId"); |
603 | |
|
604 | 1 | Statement statement = statementDao.fetch(Statement.class, statementId); |
605 | 1 | List<StatementInfo> list = StatementAssembler.toStatementInfos(statement.getChildren()); |
606 | 1 | return list; |
607 | |
} |
608 | |
|
609 | |
@Override |
610 | |
@Transactional(readOnly=false) |
611 | |
public StatementInfo updateStatement(final String statementId, final StatementInfo statementInfo) throws CircularReferenceException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
612 | |
|
613 | 5 | checkForMissingParameter(statementId, "statementId"); |
614 | 5 | checkForMissingParameter(statementInfo, "statementInfo"); |
615 | |
|
616 | |
|
617 | 5 | statementInfo.setId(statementId); |
618 | |
|
619 | |
|
620 | 5 | Statement stmt = statementAssembler.toStatementRelation(true, statementInfo); |
621 | |
|
622 | |
|
623 | 4 | Statement updatedStmt = statementDao.update(stmt); |
624 | |
|
625 | |
|
626 | 4 | StatementInfo updStatementInfo = StatementAssembler.toStatementInfo(updatedStmt); |
627 | 4 | return updStatementInfo; |
628 | |
} |
629 | |
|
630 | |
@Override |
631 | |
public List<ValidationResultInfo> validateReqComponent(final String validationType, final ReqComponentInfo reqComponentInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
632 | 3 | checkForMissingParameter(validationType, "validationType"); |
633 | 3 | checkForMissingParameter(reqComponentInfo, "reqComponentInfo"); |
634 | |
|
635 | 3 | ObjectStructureDefinition objStructure = this.getObjectStructure(ReqComponentInfo.class.getName()); |
636 | 3 | Validator defaultValidator = validatorFactory.getValidator(); |
637 | 3 | List<ValidationResultInfo> validationResults = defaultValidator.validateObject(reqComponentInfo, objStructure); |
638 | |
|
639 | 3 | return validationResults; |
640 | |
} |
641 | |
|
642 | |
@Override |
643 | |
public List<ValidationResultInfo> validateStatement(final String validationType, final StatementInfo statementInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
644 | 0 | checkForMissingParameter(validationType, "validationType"); |
645 | 0 | checkForMissingParameter(statementInfo, "statementInfo"); |
646 | |
|
647 | 0 | ObjectStructureDefinition objStructure = this.getObjectStructure(StatementInfo.class.getName()); |
648 | 0 | Validator defaultValidator = validatorFactory.getValidator(); |
649 | 0 | List<ValidationResultInfo> validationResults = defaultValidator.validateObject(statementInfo, objStructure); |
650 | |
|
651 | 0 | return validationResults; |
652 | |
} |
653 | |
|
654 | |
@Override |
655 | |
public ObjectStructureDefinition getObjectStructure(String objectTypeKey) { |
656 | 8 | return dictionaryServiceDelegate.getObjectStructure(objectTypeKey); |
657 | |
} |
658 | |
|
659 | |
@Override |
660 | |
public SearchCriteriaTypeInfo getSearchCriteriaType(final String searchCriteriaTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
661 | 0 | return searchManager.getSearchCriteriaType(searchCriteriaTypeKey); |
662 | |
} |
663 | |
|
664 | |
@Override |
665 | |
public List<SearchCriteriaTypeInfo> getSearchCriteriaTypes() throws OperationFailedException { |
666 | 0 | return searchManager.getSearchCriteriaTypes(); |
667 | |
} |
668 | |
|
669 | |
@Override |
670 | |
public SearchResultTypeInfo getSearchResultType(final String searchResultTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
671 | 0 | checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey"); |
672 | 0 | return searchManager.getSearchResultType(searchResultTypeKey); |
673 | |
} |
674 | |
|
675 | |
@Override |
676 | |
public List<SearchResultTypeInfo> getSearchResultTypes() throws OperationFailedException { |
677 | 0 | return searchManager.getSearchResultTypes(); |
678 | |
} |
679 | |
|
680 | |
@Override |
681 | |
public SearchTypeInfo getSearchType(final String searchTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
682 | 0 | checkForMissingParameter(searchTypeKey, "searchTypeKey"); |
683 | 0 | return searchManager.getSearchType(searchTypeKey); |
684 | |
} |
685 | |
|
686 | |
@Override |
687 | |
public List<SearchTypeInfo> getSearchTypes() throws OperationFailedException { |
688 | 0 | return searchManager.getSearchTypes(); |
689 | |
} |
690 | |
|
691 | |
@Override |
692 | |
public List<SearchTypeInfo> getSearchTypesByCriteria(final String searchCriteriaTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
693 | 0 | checkForMissingParameter(searchCriteriaTypeKey, "searchCriteriaTypeKey"); |
694 | 0 | return searchManager.getSearchTypesByCriteria(searchCriteriaTypeKey); |
695 | |
} |
696 | |
|
697 | |
@Override |
698 | |
public List<SearchTypeInfo> getSearchTypesByResult(final String searchResultTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
699 | 0 | checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey"); |
700 | 0 | return searchManager.getSearchTypesByResult(searchResultTypeKey); |
701 | |
} |
702 | |
|
703 | |
@Override |
704 | |
public SearchResult search(final SearchRequest searchRequest) throws MissingParameterException { |
705 | 1 | checkForMissingParameter(searchRequest, "searchRequest"); |
706 | 1 | return searchManager.search(searchRequest, statementDao); |
707 | |
} |
708 | |
|
709 | |
@Override |
710 | |
public List<String> getObjectTypes() { |
711 | 0 | return dictionaryServiceDelegate.getObjectTypes(); |
712 | |
} |
713 | |
|
714 | |
@Override |
715 | |
public StatementTypeInfo getStatementType(final String statementTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
716 | 1 | return StatementAssembler.toStatementTypeInfo(statementDao.fetch(StatementType.class, statementTypeKey)); |
717 | |
} |
718 | |
|
719 | |
@Override |
720 | |
public List<StatementTypeInfo> getStatementTypes() throws OperationFailedException { |
721 | 1 | return StatementAssembler.toStatementTypeInfos(statementDao.find(StatementType.class)); |
722 | |
} |
723 | |
|
724 | |
public List<String> getStatementTypesForStatementType(final String statementTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
725 | 1 | StatementTypeInfo type = StatementAssembler.toStatementTypeInfo(statementDao.fetch(StatementType.class, statementTypeKey)); |
726 | 1 | return type.getAllowedStatementTypes(); |
727 | |
} |
728 | |
|
729 | |
@Override |
730 | |
public List<ReqComponentTypeInfo> getReqComponentTypes() throws OperationFailedException { |
731 | 1 | return StatementAssembler.toReqComponentTypeInfos(statementDao.find(ReqComponentType.class)); |
732 | |
} |
733 | |
|
734 | |
@Override |
735 | |
public ReqComponentTypeInfo getReqComponentType(final String reqComponentTypeKey) |
736 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
737 | 3 | return StatementAssembler.toReqComponentTypeInfo(statementDao.fetch(ReqComponentType.class, reqComponentTypeKey)); |
738 | |
} |
739 | |
|
740 | |
@Override |
741 | |
public List<ReqComponentTypeInfo> getReqComponentTypesForStatementType(final String statementTypeKey) |
742 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
743 | 1 | checkForMissingParameter(statementTypeKey, "statementTypeKey"); |
744 | |
|
745 | 1 | StatementType stmtType = statementDao.fetch(StatementType.class, statementTypeKey); |
746 | 1 | if(null == stmtType) { |
747 | 0 | throw new DoesNotExistException("Statement Type: " + statementTypeKey + " does not exist."); |
748 | |
} |
749 | |
|
750 | 1 | return StatementAssembler.toReqComponentTypeInfosOrdered( stmtType.getAllowedReqComponentTypes() ); |
751 | |
} |
752 | |
|
753 | |
@Override |
754 | |
@Transactional(readOnly=false) |
755 | |
public ReqComponentInfo updateReqComponent(final String reqComponentId, final ReqComponentInfo reqComponentInfo) |
756 | |
throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
757 | |
|
758 | 7 | checkForMissingParameter(reqComponentId, "reqComponentId"); |
759 | 7 | checkForMissingParameter(reqComponentInfo, "reqComponentInfo"); |
760 | |
|
761 | |
|
762 | 7 | reqComponentInfo.setId(reqComponentId); |
763 | |
|
764 | 7 | ReqComponent reqComp = null; |
765 | |
|
766 | |
|
767 | 7 | reqComp = statementAssembler.toReqComponentRelation(true, reqComponentInfo); |
768 | |
|
769 | |
|
770 | 6 | ReqComponent updatedReqComp = statementDao.update(reqComp); |
771 | |
|
772 | |
|
773 | 6 | ReqComponentInfo updReqCompInfo = StatementAssembler.toReqComponentInfo(updatedReqComp); |
774 | 6 | return updReqCompInfo; |
775 | |
} |
776 | |
|
777 | |
@Transactional(readOnly=false) |
778 | |
public RefStatementRelationInfo createRefStatementRelation(final RefStatementRelationInfo refStatementRelationInfo) |
779 | |
throws AlreadyExistsException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
780 | 6 | checkForMissingParameter(refStatementRelationInfo, "refStatementRelationInfo"); |
781 | |
|
782 | 6 | Statement statement = this.statementDao.fetch(Statement.class, refStatementRelationInfo.getStatementId()); |
783 | 6 | RefStatementRelationType type = this.statementDao.fetch(RefStatementRelationType.class, refStatementRelationInfo.getType()); |
784 | |
|
785 | |
|
786 | 6 | this.statementDao.fetch(ObjectType.class, refStatementRelationInfo.getRefObjectTypeKey()); |
787 | |
|
788 | 6 | RefStatementRelation entity = new RefStatementRelation(); |
789 | |
|
790 | 6 | BeanUtils.copyProperties(refStatementRelationInfo, entity, new String[] { |
791 | |
"statementId", "attributes", "metaInfo", "type", "id"}); |
792 | |
|
793 | 6 | entity.setRefStatementRelationType(type); |
794 | 6 | entity.setStatement(statement); |
795 | |
|
796 | 6 | List<RefStatementRelationAttribute> attributes = StatementAssembler.toGenericAttributes(RefStatementRelationAttribute.class, refStatementRelationInfo.getAttributes(), entity, this.statementDao); |
797 | 6 | entity.setAttributes(attributes); |
798 | |
|
799 | 6 | RefStatementRelation newEntity = this.statementDao.create(entity); |
800 | |
|
801 | 6 | RefStatementRelationInfo newDto = StatementAssembler.toRefStatementRelationInfo(newEntity); |
802 | |
|
803 | 6 | return newDto; |
804 | |
} |
805 | |
|
806 | |
@Override |
807 | |
@Transactional(readOnly=false) |
808 | |
public RefStatementRelationInfo updateRefStatementRelation(final String refStatementRelationId, final RefStatementRelationInfo refStatementRelationInfo) |
809 | |
throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
810 | 3 | checkForNullOrEmptyParameter(refStatementRelationId, "refStatementRelationId"); |
811 | 3 | checkForMissingParameter(refStatementRelationInfo, "refStatementRelationInfo"); |
812 | |
|
813 | 3 | refStatementRelationInfo.setId(refStatementRelationId); |
814 | 3 | RefStatementRelation refStatementRel = statementAssembler.toRefStatementRelation(true, refStatementRelationInfo); |
815 | 1 | RefStatementRelation updatedRefStatementRel = statementDao.update(refStatementRel); |
816 | |
|
817 | 1 | RefStatementRelationInfo dto = StatementAssembler.toRefStatementRelationInfo(updatedRefStatementRel); |
818 | 1 | return dto; |
819 | |
} |
820 | |
|
821 | |
@Override |
822 | |
@Transactional(readOnly=false) |
823 | |
public StatusInfo deleteRefStatementRelation(final String refStatementRelationId) |
824 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
825 | 10 | checkForNullOrEmptyParameter(refStatementRelationId, "refStatementRelationId"); |
826 | 8 | this.statementDao.delete(RefStatementRelation.class, refStatementRelationId); |
827 | |
|
828 | 6 | StatusInfo statusInfo = new StatusInfo(); |
829 | 6 | statusInfo.setSuccess(true); |
830 | 6 | statusInfo.setMessage("Reference statement relation successfully deleted"); |
831 | 6 | return statusInfo; |
832 | |
} |
833 | |
|
834 | |
@Override |
835 | |
public List<ValidationResultInfo> validateRefStatementRelation(final String validationType, RefStatementRelationInfo refStatementRelationInfo) |
836 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
837 | 1 | ObjectStructureDefinition objStructure = this.getObjectStructure(RefStatementRelationInfo.class.getName()); |
838 | 1 | Validator defaultValidator = validatorFactory.getValidator(); |
839 | 1 | List<ValidationResultInfo> validationResults = defaultValidator.validateObject(refStatementRelationInfo, objStructure); |
840 | |
|
841 | 1 | return validationResults; |
842 | |
} |
843 | |
|
844 | |
@Override |
845 | |
public StatementTreeViewInfo getStatementTreeView(final String statementId) |
846 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
847 | 5 | checkForNullOrEmptyParameter("statementId", statementId); |
848 | |
|
849 | 5 | return getStatementTreeView(statementId, null, null); |
850 | |
} |
851 | |
|
852 | |
@Override |
853 | |
public StatementTreeViewInfo getStatementTreeViewForNlUsageType(final String statementId, final String nlUsageTypeKey, final String language) |
854 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
855 | 0 | checkForNullOrEmptyParameter("statementId", statementId); |
856 | 0 | checkForNullOrEmptyParameter("nlUsageTypeKey", nlUsageTypeKey); |
857 | 0 | checkForNullOrEmptyParameter("language", language); |
858 | |
|
859 | 0 | return getStatementTreeView(statementId, nlUsageTypeKey, language); |
860 | |
} |
861 | |
|
862 | |
private StatementTreeViewInfo getStatementTreeView(final String statementId, final String nlUsageTypeKey, final String language) |
863 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
864 | 5 | StatementTreeViewInfo statementTreeViewInfo = null; |
865 | 5 | StatementInfo statementInfo = getStatement(statementId); |
866 | 2 | if (statementInfo == null) return null; |
867 | 2 | statementTreeViewInfo = new StatementTreeViewInfo(); |
868 | 2 | getStatementTreeViewHelper(statementInfo, statementTreeViewInfo, nlUsageTypeKey, language); |
869 | 2 | return statementTreeViewInfo; |
870 | |
|
871 | |
|
872 | |
|
873 | |
|
874 | |
|
875 | |
|
876 | |
|
877 | |
|
878 | |
|
879 | |
|
880 | |
|
881 | |
|
882 | |
|
883 | |
|
884 | |
} |
885 | |
|
886 | |
|
887 | |
|
888 | |
|
889 | |
|
890 | |
|
891 | |
|
892 | |
|
893 | |
|
894 | |
|
895 | |
|
896 | |
private List<ReqComponentInfo> getReqComponentInfos(final StatementInfo statementInfo, final String nlUsageTypeKey, final String language) |
897 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
898 | 6 | List<ReqComponentInfo> reqComponentInfos = new ArrayList<ReqComponentInfo>(); |
899 | 6 | if (statementInfo == null) return null; |
900 | 6 | if (statementInfo.getReqComponentIds() != null) { |
901 | 6 | for (String reqComponentId : statementInfo.getReqComponentIds()) { |
902 | |
|
903 | 8 | ReqComponentInfo reqCompInfo = statementAssembler.toReqComponentInfo(statementDao.fetch(ReqComponent.class, reqComponentId), nlUsageTypeKey, language); |
904 | 8 | reqComponentInfos.add(reqCompInfo); |
905 | 8 | } |
906 | |
} |
907 | 6 | return reqComponentInfos; |
908 | |
} |
909 | |
|
910 | |
|
911 | |
|
912 | |
|
913 | |
|
914 | |
|
915 | |
|
916 | |
|
917 | |
|
918 | |
|
919 | |
|
920 | |
|
921 | |
|
922 | |
private void getStatementTreeViewHelper(final StatementInfo statementInfo, final StatementTreeViewInfo statementTreeViewInfo, |
923 | |
final String nlUsageTypeKey, final String language) |
924 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
925 | 6 | if (statementInfo == null) return; |
926 | |
|
927 | 6 | statementAssembler.copyValues(statementTreeViewInfo, statementInfo); |
928 | 6 | statementTreeViewInfo.setReqComponents(getReqComponentInfos(statementInfo, nlUsageTypeKey, language)); |
929 | |
|
930 | 6 | if (statementInfo.getStatementIds() != null) { |
931 | 6 | for (String statementId : statementInfo.getStatementIds()) { |
932 | 4 | StatementInfo subStatement = getStatement(statementId); |
933 | |
|
934 | 4 | List<StatementTreeViewInfo> statements = |
935 | |
(statementTreeViewInfo.getStatements() == null) ? new ArrayList<StatementTreeViewInfo>() : statementTreeViewInfo.getStatements(); |
936 | 4 | StatementTreeViewInfo subStatementTreeViewInfo = new StatementTreeViewInfo(); |
937 | |
|
938 | |
|
939 | 4 | getStatementTreeViewHelper(subStatement, subStatementTreeViewInfo, nlUsageTypeKey, language); |
940 | 4 | statements.add(subStatementTreeViewInfo); |
941 | 4 | statementTreeViewInfo.setStatements(statements); |
942 | 4 | } |
943 | |
} |
944 | 6 | } |
945 | |
|
946 | |
@Override |
947 | |
@Transactional(readOnly=false) |
948 | |
public StatementTreeViewInfo updateStatementTreeView(final String statementId, final StatementTreeViewInfo statementTreeViewInfo) |
949 | |
throws CircularReferenceException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
950 | |
|
951 | 0 | Statement stmt = this.statementDao.fetch(Statement.class, statementTreeViewInfo.getId()); |
952 | 0 | if (stmt == null) { |
953 | 0 | throw new DoesNotExistException("Statement does not exist for id: " + statementTreeViewInfo.getId()); |
954 | |
} |
955 | 0 | if (!String.valueOf(stmt.getVersionNumber()).equals(statementTreeViewInfo.getMetaInfo().getVersionInd())) { |
956 | 0 | throw new VersionMismatchException("Statement to be updated is not the current version"); |
957 | |
} |
958 | |
|
959 | 0 | Set<String> statementIdsToDelete = new HashSet<String>(); |
960 | 0 | List<ReqComponent> requirementComponentsToCreate = new ArrayList<ReqComponent>(); |
961 | 0 | List<Statement> statmentsToUpdate = new ArrayList<Statement>(); |
962 | |
|
963 | |
|
964 | 0 | stmt = statementAssembler.toStatementFromTree(stmt, statementTreeViewInfo, statementIdsToDelete, statmentsToUpdate, requirementComponentsToCreate); |
965 | |
|
966 | |
|
967 | 0 | for(ReqComponent reqComponent:requirementComponentsToCreate){ |
968 | 0 | statementDao.create(reqComponent); |
969 | |
} |
970 | |
|
971 | |
|
972 | 0 | stmt = statementDao.update(stmt); |
973 | |
|
974 | |
|
975 | |
|
976 | |
|
977 | 0 | for(String statementIdToDelete:statementIdsToDelete){ |
978 | 0 | statementDao.delete(Statement.class, statementIdToDelete); |
979 | |
} |
980 | |
|
981 | |
|
982 | 0 | StatementTreeViewInfo result = statementAssembler.toStatementTreeViewInfo(stmt); |
983 | |
|
984 | 0 | return result; |
985 | |
|
986 | |
|
987 | |
} |
988 | |
|
989 | |
|
990 | |
|
991 | |
|
992 | |
|
993 | |
|
994 | |
|
995 | |
|
996 | |
|
997 | |
|
998 | |
|
999 | |
|
1000 | |
|
1001 | |
|
1002 | |
|
1003 | |
|
1004 | |
|
1005 | |
|
1006 | |
|
1007 | |
|
1008 | |
|
1009 | |
|
1010 | |
|
1011 | |
|
1012 | |
|
1013 | |
|
1014 | |
|
1015 | |
|
1016 | |
|
1017 | |
|
1018 | |
|
1019 | |
|
1020 | |
|
1021 | |
|
1022 | |
|
1023 | |
|
1024 | |
private void updateStatementTreeViewHelper(StatementTreeViewInfo statementTreeViewInfo) throws CircularReferenceException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
1025 | 3 | if (statementTreeViewInfo.getStatements() != null) { |
1026 | 3 | for (StatementTreeViewInfo subStatement : statementTreeViewInfo.getStatements()) { |
1027 | 2 | updateStatementTreeViewHelper(subStatement); |
1028 | |
} |
1029 | |
} |
1030 | 3 | if (statementTreeViewInfo.getReqComponents() != null) { |
1031 | 3 | List<ReqComponentInfo> updatedReqComponentInfos = new ArrayList<ReqComponentInfo>(7); |
1032 | 3 | for (ReqComponentInfo reqComponentInfo : statementTreeViewInfo.getReqComponents()) { |
1033 | 4 | ReqComponentInfo updatedReqComponentInfo = updateReqComponent(reqComponentInfo.getId(), reqComponentInfo); |
1034 | 4 | updatedReqComponentInfos.add(updatedReqComponentInfo); |
1035 | 4 | } |
1036 | 3 | statementTreeViewInfo.setReqComponents(updatedReqComponentInfos); |
1037 | |
} |
1038 | 3 | StatementInfo updatedStatementInfo = updateStatement(statementTreeViewInfo.getId(), statementAssembler.toStatementInfo( |
1039 | |
statementTreeViewInfo)); |
1040 | 3 | statementAssembler.copyValues(statementTreeViewInfo, updatedStatementInfo); |
1041 | 3 | } |
1042 | |
|
1043 | |
private void updateSTVHelperCreateStatements(StatementTreeViewInfo statementTreeViewInfo) throws CircularReferenceException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
1044 | 3 | String statementId = null; |
1045 | 3 | StatementInfo origStatementInfo = null; |
1046 | 3 | StatementInfo newStatementInfo = null; |
1047 | 3 | if (statementTreeViewInfo.getStatements() != null) { |
1048 | 3 | for (StatementTreeViewInfo subTreeInfo : statementTreeViewInfo.getStatements()) { |
1049 | 2 | updateSTVHelperCreateStatements(subTreeInfo); |
1050 | |
} |
1051 | |
} |
1052 | 3 | if (statementTreeViewInfo.getReqComponents() != null) { |
1053 | 3 | List<ReqComponentInfo> rcsAfterInserts = new ArrayList<ReqComponentInfo>(7); |
1054 | 3 | for (ReqComponentInfo reqComponentInfo : statementTreeViewInfo.getReqComponents()) { |
1055 | 4 | String reqComponentId = reqComponentInfo.getId(); |
1056 | 4 | ReqComponentInfo origReqComponentInfo = null; |
1057 | 4 | ReqComponentInfo rcAfterInsert = null; |
1058 | |
|
1059 | 4 | if (reqComponentId != null) { |
1060 | |
try { |
1061 | 0 | origReqComponentInfo = getReqComponent(reqComponentId); |
1062 | 0 | } catch (DoesNotExistException dnee) { |
1063 | 0 | origReqComponentInfo = null; |
1064 | 0 | } |
1065 | |
} |
1066 | 4 | if (origReqComponentInfo == null) { |
1067 | |
|
1068 | |
|
1069 | |
|
1070 | 4 | reqComponentInfo.setId(null); |
1071 | |
try { |
1072 | 4 | rcAfterInsert = createReqComponent(reqComponentInfo.getType(), reqComponentInfo); |
1073 | 0 | } catch (AlreadyExistsException e) { |
1074 | |
|
1075 | |
|
1076 | 0 | throw new OperationFailedException("Tried to create a reqComponent that already exists"); |
1077 | 4 | } |
1078 | |
} else { |
1079 | 0 | rcAfterInsert = reqComponentInfo; |
1080 | |
} |
1081 | 4 | rcsAfterInserts.add(rcAfterInsert); |
1082 | 4 | } |
1083 | 3 | statementTreeViewInfo.setReqComponents(rcsAfterInserts); |
1084 | |
} |
1085 | |
|
1086 | 3 | statementId = statementTreeViewInfo.getId(); |
1087 | 3 | if (statementId != null) { |
1088 | |
try { |
1089 | 0 | origStatementInfo = getStatement(statementId); |
1090 | 0 | } catch(DoesNotExistException dnee) { |
1091 | 0 | origStatementInfo = null; |
1092 | 0 | } |
1093 | |
} |
1094 | 3 | if (origStatementInfo == null) { |
1095 | |
|
1096 | |
|
1097 | |
|
1098 | 3 | newStatementInfo = statementAssembler.toStatementInfo(statementTreeViewInfo); |
1099 | |
try { |
1100 | 3 | newStatementInfo = createStatement(newStatementInfo.getType(), newStatementInfo); |
1101 | 0 | } catch (AlreadyExistsException e) { |
1102 | |
|
1103 | |
|
1104 | 0 | throw new OperationFailedException("Tried to create a statement that already exists"); |
1105 | 3 | } |
1106 | 3 | statementAssembler.copyValues(statementTreeViewInfo, newStatementInfo); |
1107 | |
} |
1108 | 3 | } |
1109 | |
|
1110 | |
|
1111 | |
|
1112 | |
|
1113 | |
|
1114 | |
@Override |
1115 | |
public RefStatementRelationTypeInfo getRefStatementRelationType(final String refStatementRelationTypeKey) |
1116 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
1117 | 1 | checkForNullOrEmptyParameter(refStatementRelationTypeKey, "refStatementRelationTypeKey"); |
1118 | |
|
1119 | 1 | RefStatementRelationType type = this.statementDao.fetch(RefStatementRelationType.class, refStatementRelationTypeKey); |
1120 | |
|
1121 | 1 | return StatementAssembler.toRefStatementRelationTypeInfo(type); |
1122 | |
} |
1123 | |
|
1124 | |
@Override |
1125 | |
public List<RefStatementRelationTypeInfo> getRefStatementRelationTypes() |
1126 | |
throws OperationFailedException { |
1127 | 1 | List<RefStatementRelationType> entities = this.statementDao.find(RefStatementRelationType.class); |
1128 | 1 | return StatementAssembler.toRefStatementRelationTypeInfos(entities); |
1129 | |
} |
1130 | |
|
1131 | |
@Override |
1132 | |
public List<String> getRefStatementRelationTypesForRefObjectSubType(final String refSubTypeKey) |
1133 | |
throws DoesNotExistException,InvalidParameterException, MissingParameterException, OperationFailedException { |
1134 | 0 | throw new UnsupportedOperationException("Method not yet implemented!"); |
1135 | |
} |
1136 | |
|
1137 | |
@Override |
1138 | |
public List<String> getStatementTypesForRefStatementRelationType(final String refStatementRelationTypeKey) |
1139 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
1140 | 0 | throw new UnsupportedOperationException("Method not yet implemented!"); |
1141 | |
} |
1142 | |
|
1143 | |
public void setValidatorFactory(ValidatorFactory validatorFactory) { |
1144 | 2 | this.validatorFactory = validatorFactory; |
1145 | 2 | } |
1146 | |
} |