1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
package org.kuali.student.core.statement.service.impl; |
10 | |
|
11 | |
import java.util.ArrayList; |
12 | |
import java.util.HashMap; |
13 | |
import java.util.List; |
14 | |
import java.util.Map; |
15 | |
import java.util.Set; |
16 | |
|
17 | |
import org.kuali.student.common.dictionary.old.dto.FieldDescriptor; |
18 | |
import org.kuali.student.common.exceptions.DoesNotExistException; |
19 | |
import org.kuali.student.common.exceptions.InvalidParameterException; |
20 | |
import org.kuali.student.common.exceptions.MissingParameterException; |
21 | |
import org.kuali.student.common.exceptions.OperationFailedException; |
22 | |
import org.kuali.student.common.exceptions.VersionMismatchException; |
23 | |
import org.kuali.student.common.service.impl.BaseAssembler; |
24 | |
import org.kuali.student.core.statement.dao.StatementDao; |
25 | |
import org.kuali.student.core.statement.dto.AbstractStatementInfo; |
26 | |
import org.kuali.student.core.statement.dto.NlUsageTypeInfo; |
27 | |
import org.kuali.student.core.statement.dto.RefStatementRelationInfo; |
28 | |
import org.kuali.student.core.statement.dto.RefStatementRelationTypeInfo; |
29 | |
import org.kuali.student.core.statement.dto.ReqCompFieldInfo; |
30 | |
import org.kuali.student.core.statement.dto.ReqCompFieldTypeInfo; |
31 | |
import org.kuali.student.core.statement.dto.ReqComponentInfo; |
32 | |
import org.kuali.student.core.statement.dto.ReqComponentTypeInfo; |
33 | |
import org.kuali.student.core.statement.dto.StatementInfo; |
34 | |
import org.kuali.student.core.statement.dto.StatementTreeViewInfo; |
35 | |
import org.kuali.student.core.statement.dto.StatementTypeInfo; |
36 | |
import org.kuali.student.core.statement.entity.NlUsageType; |
37 | |
import org.kuali.student.core.statement.entity.ObjectSubType; |
38 | |
import org.kuali.student.core.statement.entity.ObjectType; |
39 | |
import org.kuali.student.core.statement.entity.OrderedReqComponentType; |
40 | |
import org.kuali.student.core.statement.entity.OrderedStatementType; |
41 | |
import org.kuali.student.core.statement.entity.RefStatementRelation; |
42 | |
import org.kuali.student.core.statement.entity.RefStatementRelationAttribute; |
43 | |
import org.kuali.student.core.statement.entity.RefStatementRelationType; |
44 | |
import org.kuali.student.core.statement.entity.ReqComponent; |
45 | |
import org.kuali.student.core.statement.entity.ReqComponentField; |
46 | |
import org.kuali.student.core.statement.entity.ReqComponentFieldType; |
47 | |
import org.kuali.student.core.statement.entity.ReqComponentType; |
48 | |
import org.kuali.student.core.statement.entity.Statement; |
49 | |
import org.kuali.student.core.statement.entity.StatementAttribute; |
50 | |
import org.kuali.student.core.statement.entity.StatementRichText; |
51 | |
import org.kuali.student.core.statement.entity.StatementType; |
52 | |
import org.kuali.student.core.statement.naturallanguage.NaturalLanguageTranslator; |
53 | |
import org.springframework.beans.BeanUtils; |
54 | |
|
55 | 0 | public class StatementAssembler extends BaseAssembler { |
56 | |
|
57 | |
private StatementDao statementDao; |
58 | |
private NaturalLanguageTranslator naturalLanguageTranslator; |
59 | |
|
60 | |
public void setStatementDao(StatementDao dao) { |
61 | 0 | this.statementDao = dao; |
62 | 0 | } |
63 | |
|
64 | |
public void setNaturalLanguageTranslator(final NaturalLanguageTranslator translator) { |
65 | 0 | this.naturalLanguageTranslator = translator; |
66 | 0 | } |
67 | |
|
68 | |
public static List<RefStatementRelationInfo> toRefStatementRelationInfos(List<RefStatementRelation> entities) { |
69 | 0 | List<RefStatementRelationInfo> list = new ArrayList<RefStatementRelationInfo>(); |
70 | 0 | for (RefStatementRelation entity : entities) { |
71 | 0 | list.add(toRefStatementRelationInfo(entity)); |
72 | |
} |
73 | 0 | return list; |
74 | |
} |
75 | |
|
76 | |
public static RefStatementRelationInfo toRefStatementRelationInfo(RefStatementRelation entity) { |
77 | 0 | RefStatementRelationInfo dto = new RefStatementRelationInfo(); |
78 | |
|
79 | 0 | BeanUtils.copyProperties(entity, dto, new String[]{"refStatementRelationType", "statement", "attributes", "metaInfo"}); |
80 | |
|
81 | |
|
82 | 0 | dto.setAttributes(toAttributeMap(entity.getAttributes())); |
83 | 0 | dto.setMetaInfo(toMetaInfo(entity.getMeta(), entity.getVersionNumber())); |
84 | 0 | dto.setStatementId(entity.getStatement().getId()); |
85 | 0 | dto.setType(entity.getRefStatementRelationType().getId()); |
86 | |
|
87 | |
|
88 | 0 | return dto; |
89 | |
} |
90 | |
|
91 | |
public static List<RefStatementRelationTypeInfo> toRefStatementRelationTypeInfos(List<RefStatementRelationType> entities) { |
92 | 0 | List<RefStatementRelationTypeInfo> list = new ArrayList<RefStatementRelationTypeInfo>(); |
93 | 0 | for (RefStatementRelationType entity : entities) { |
94 | 0 | list.add(toRefStatementRelationTypeInfo(entity)); |
95 | |
} |
96 | 0 | return list; |
97 | |
} |
98 | |
|
99 | |
public static RefStatementRelationTypeInfo toRefStatementRelationTypeInfo(RefStatementRelationType entity) { |
100 | 0 | RefStatementRelationTypeInfo dto = new RefStatementRelationTypeInfo(); |
101 | |
|
102 | 0 | BeanUtils.copyProperties(entity, dto, new String[]{"attributes", "metaInfo", "objectSubTypeList", "statementTypeList"}); |
103 | |
|
104 | 0 | dto.setAttributes(toAttributeMap(entity.getAttributes())); |
105 | 0 | dto.setDesc(entity.getDescr()); |
106 | |
|
107 | 0 | return dto; |
108 | |
} |
109 | |
|
110 | |
public static List<String> toRefObjectSubTypeIds(ObjectType objectType) { |
111 | 0 | List<String> ids = new ArrayList<String>(); |
112 | 0 | for (ObjectSubType objectSubType : objectType.getObjectSubTypes()) { |
113 | 0 | ids.add(objectSubType.getId()); |
114 | |
} |
115 | 0 | return ids; |
116 | |
} |
117 | |
|
118 | |
public static NlUsageTypeInfo toNlUsageTypeInfo(NlUsageType entity) throws OperationFailedException { |
119 | 0 | NlUsageTypeInfo info = toGenericTypeInfo(NlUsageTypeInfo.class, entity); |
120 | 0 | return info; |
121 | |
} |
122 | |
|
123 | |
public static List<NlUsageTypeInfo> toNlUsageTypeInfos(List<NlUsageType> entities) throws OperationFailedException { |
124 | 0 | List<NlUsageTypeInfo> infoList = new ArrayList<NlUsageTypeInfo>(); |
125 | 0 | for (NlUsageType entity : entities) { |
126 | 0 | NlUsageTypeInfo info = toNlUsageTypeInfo(entity); |
127 | 0 | infoList.add(info); |
128 | 0 | } |
129 | 0 | return infoList; |
130 | |
} |
131 | |
|
132 | |
public ReqComponent toReqComponentRelation(boolean isUpdate, ReqComponentInfo reqCompInfo) throws DoesNotExistException, VersionMismatchException, InvalidParameterException { |
133 | |
ReqComponent reqComp; |
134 | 0 | if (isUpdate) { |
135 | 0 | reqComp = this.statementDao.fetch(ReqComponent.class, reqCompInfo.getId()); |
136 | 0 | if (reqComp == null) { |
137 | 0 | throw new DoesNotExistException("ReqComponent does not exist for id: " + reqCompInfo.getId()); |
138 | |
} |
139 | 0 | if (!String.valueOf(reqComp.getVersionNumber()).equals(reqCompInfo.getMetaInfo().getVersionInd())) { |
140 | 0 | throw new VersionMismatchException("ReqComponent to be updated is not the current version"); |
141 | |
} |
142 | 0 | for (ReqComponentField reqCompField : reqComp.getReqComponentFields()) { |
143 | 0 | this.statementDao.delete(reqCompField); |
144 | |
} |
145 | |
} else { |
146 | 0 | reqComp = new ReqComponent(); |
147 | |
} |
148 | |
|
149 | 0 | BeanUtils.copyProperties(reqCompInfo, reqComp, new String[]{"requiredComponentType", "reqCompField", "metaInfo", "type"}); |
150 | |
|
151 | |
|
152 | 0 | ReqComponentType reqCompType = this.statementDao.fetch(ReqComponentType.class, reqCompInfo.getType()); |
153 | 0 | if (reqCompType == null) { |
154 | 0 | throw new InvalidParameterException("ReqComponentType does not exist for id: " + reqCompInfo.getType()); |
155 | |
} |
156 | 0 | reqComp.setRequiredComponentType(reqCompType); |
157 | |
|
158 | |
|
159 | 0 | List<ReqComponentField> reqCompFieldList = new ArrayList<ReqComponentField>(); |
160 | 0 | for (ReqCompFieldInfo reqCompFieldInfo : reqCompInfo.getReqCompFields()) { |
161 | 0 | ReqComponentField reqCompField = new ReqComponentField(); |
162 | |
|
163 | 0 | reqCompField.setType(reqCompFieldInfo.getType()); |
164 | 0 | reqCompField.setValue(reqCompFieldInfo.getValue()); |
165 | 0 | reqCompFieldList.add(reqCompField); |
166 | 0 | } |
167 | 0 | reqComp.setReqComponentFields(reqCompFieldList); |
168 | |
|
169 | 0 | reqComp.setDescr(toRichText(StatementRichText.class, reqCompInfo.getDesc())); |
170 | |
|
171 | 0 | return reqComp; |
172 | |
} |
173 | |
|
174 | |
public List<ReqComponentInfo> toReqComponentInfos(List<ReqComponent> entities, String nlUsageTypeKey, String language) throws DoesNotExistException, OperationFailedException { |
175 | 0 | List<ReqComponentInfo> dtos = new ArrayList<ReqComponentInfo>(entities.size()); |
176 | 0 | for (ReqComponent entity : entities) { |
177 | 0 | dtos.add(toReqComponentInfo(entity, nlUsageTypeKey, language)); |
178 | |
} |
179 | 0 | return dtos; |
180 | |
|
181 | |
} |
182 | |
|
183 | |
public static ReqComponentInfo toReqComponentInfo(ReqComponent entity) { |
184 | 53 | ReqComponentInfo dto = new ReqComponentInfo(); |
185 | |
|
186 | 53 | BeanUtils.copyProperties(entity, dto, new String[]{"requiredComponentType", "reqCompField", "metaInfo"}); |
187 | |
|
188 | 53 | dto.setType(entity.getRequiredComponentType().getId()); |
189 | 53 | dto.setReqCompFields(toReqCompFieldInfos(entity.getReqComponentFields())); |
190 | |
|
191 | 53 | dto.setMetaInfo(toMetaInfo(entity)); |
192 | 53 | dto.setDesc(toRichTextInfo(entity.getDescr())); |
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | 53 | return dto; |
198 | |
} |
199 | |
|
200 | |
public ReqComponentInfo toReqComponentInfo(ReqComponent entity, String nlUsageTypeKey, String language) throws DoesNotExistException, OperationFailedException { |
201 | 0 | ReqComponentInfo dto = toReqComponentInfo(entity); |
202 | 0 | if (nlUsageTypeKey != null && language != null) { |
203 | 0 | String nl = this.naturalLanguageTranslator.translateReqComponent(entity, nlUsageTypeKey, language); |
204 | 0 | dto.setNaturalLanguageTranslation(nl); |
205 | |
} |
206 | 0 | return dto; |
207 | |
} |
208 | |
|
209 | |
public static List<ReqComponentTypeInfo> toReqComponentTypeInfos(List<ReqComponentType> entities) { |
210 | 0 | List<ReqComponentTypeInfo> dtos = new ArrayList<ReqComponentTypeInfo>(entities.size()); |
211 | 0 | for (ReqComponentType entity : entities) { |
212 | 0 | dtos.add(toReqComponentTypeInfo(entity)); |
213 | |
} |
214 | 0 | return dtos; |
215 | |
|
216 | |
} |
217 | |
|
218 | |
public static List<ReqComponentTypeInfo> toReqComponentTypeInfosOrdered(List<OrderedReqComponentType> entities) { |
219 | 0 | List<ReqComponentTypeInfo> dtos = new ArrayList<ReqComponentTypeInfo>(entities.size()); |
220 | 0 | for (OrderedReqComponentType entity : entities) { |
221 | 0 | dtos.add(toReqComponentTypeInfo(entity.getReqComponentType())); |
222 | |
} |
223 | 0 | return dtos; |
224 | |
|
225 | |
} |
226 | |
|
227 | |
public static ReqComponentTypeInfo toReqComponentTypeInfo(ReqComponentType entity) { |
228 | 0 | ReqComponentTypeInfo dto = toGenericTypeInfo(ReqComponentTypeInfo.class, entity); |
229 | 0 | dto.setReqCompFieldTypeInfos(toReqCompFieldTypeInfos(entity.getReqCompFieldTypes())); |
230 | 0 | dto.setDescr(entity.getDescr()); |
231 | 0 | return dto; |
232 | |
} |
233 | |
|
234 | |
public static List<ReqCompFieldTypeInfo> toReqCompFieldTypeInfos(List<ReqComponentFieldType> entities) { |
235 | 0 | List<ReqCompFieldTypeInfo> dtos = new ArrayList<ReqCompFieldTypeInfo>(entities.size()); |
236 | 0 | for (ReqComponentFieldType entity : entities) { |
237 | 0 | dtos.add(toReqCompFieldTypeInfo(entity)); |
238 | |
} |
239 | 0 | return dtos; |
240 | |
} |
241 | |
|
242 | |
public static ReqCompFieldTypeInfo toReqCompFieldTypeInfo(ReqComponentFieldType entity) { |
243 | 0 | ReqCompFieldTypeInfo dto = new ReqCompFieldTypeInfo(); |
244 | |
|
245 | 0 | BeanUtils.copyProperties(entity, dto, new String[]{"fieldDescriptor"}); |
246 | |
|
247 | 0 | FieldDescriptor fDTO = new FieldDescriptor(); |
248 | 0 | BeanUtils.copyProperties(entity.getFieldDescriptor(), fDTO); |
249 | 0 | fDTO.setDesc(entity.getFieldDescriptor().getDescr()); |
250 | 0 | dto.setFieldDescriptor(fDTO); |
251 | |
|
252 | 0 | return dto; |
253 | |
} |
254 | |
|
255 | |
public static List<ReqCompFieldInfo> toReqCompFieldInfos(List<ReqComponentField> entities) { |
256 | 53 | if (entities == null) { |
257 | 1 | return null; |
258 | |
} |
259 | 52 | List<ReqCompFieldInfo> dtos = new ArrayList<ReqCompFieldInfo>(entities.size()); |
260 | 52 | for (ReqComponentField entity : entities) { |
261 | 153 | dtos.add(toReqCompFieldInfo(entity)); |
262 | |
} |
263 | 52 | return dtos; |
264 | |
} |
265 | |
|
266 | |
public static ReqCompFieldInfo toReqCompFieldInfo(ReqComponentField entity) { |
267 | 153 | if (null == entity) { |
268 | 0 | return null; |
269 | |
} |
270 | |
|
271 | 153 | ReqCompFieldInfo dto = new ReqCompFieldInfo(); |
272 | 153 | dto.setId(entity.getId()); |
273 | 153 | dto.setType(entity.getType()); |
274 | 153 | dto.setValue(entity.getValue()); |
275 | 153 | return dto; |
276 | |
} |
277 | |
|
278 | |
public RefStatementRelation toRefStatementRelation(boolean isUpdate, RefStatementRelationInfo refStatementRelationInfo) throws DoesNotExistException, VersionMismatchException, InvalidParameterException { |
279 | |
RefStatementRelation refStatement; |
280 | 0 | if (isUpdate) { |
281 | 0 | refStatement = this.statementDao.fetch(RefStatementRelation.class, refStatementRelationInfo.getId()); |
282 | 0 | if (refStatement == null) { |
283 | 0 | throw new DoesNotExistException("RefStatementRelation does not exist for id: " + refStatementRelationInfo.getId()); |
284 | |
} |
285 | 0 | if (!String.valueOf(refStatement.getVersionNumber()).equals(refStatementRelationInfo.getMetaInfo().getVersionInd())) { |
286 | 0 | throw new VersionMismatchException("RefStatementRelation to be updated is not the current version"); |
287 | |
} |
288 | |
} else { |
289 | 0 | refStatement = new RefStatementRelation(); |
290 | |
} |
291 | |
|
292 | 0 | BeanUtils.copyProperties(refStatementRelationInfo, refStatement, new String[]{"attributes", "metaInfo", "type", "statementId"}); |
293 | |
|
294 | |
|
295 | 0 | this.statementDao.fetch(ObjectType.class, refStatementRelationInfo.getRefObjectTypeKey()); |
296 | |
|
297 | |
|
298 | 0 | refStatement.setAttributes(toGenericAttributes(RefStatementRelationAttribute.class, refStatementRelationInfo.getAttributes(), refStatement, this.statementDao)); |
299 | 0 | RefStatementRelationType type = this.statementDao.fetch(RefStatementRelationType.class, refStatementRelationInfo.getType()); |
300 | |
|
301 | 0 | refStatement.setRefStatementRelationType(type); |
302 | 0 | Statement statement = this.statementDao.fetch(Statement.class, refStatementRelationInfo.getStatementId()); |
303 | 0 | refStatement.setStatement(statement); |
304 | |
|
305 | 0 | return refStatement; |
306 | |
} |
307 | |
|
308 | |
public Statement toStatementFromTree(Statement stmt, StatementTreeViewInfo treeView, Set<String> statementIdsToDelete, List<Statement> statementsToUpdate, List<ReqComponent> reqCompsToCreate) throws DoesNotExistException, VersionMismatchException, InvalidParameterException { |
309 | |
|
310 | |
|
311 | 0 | BeanUtils.copyProperties(treeView, stmt, new String[]{"cluIds", "statementIds", "reqComponentIds", |
312 | |
"attributes", "metaInfo", "type", "parent", "children", "requiredComponents", "statementType", "id"}); |
313 | |
|
314 | |
|
315 | 0 | stmt.setAttributes(toGenericAttributes(StatementAttribute.class, treeView.getAttributes(), stmt, this.statementDao)); |
316 | |
|
317 | |
|
318 | 0 | StatementType stmtType = this.statementDao.fetch(StatementType.class, treeView.getType()); |
319 | 0 | if (stmtType == null) { |
320 | 0 | throw new InvalidParameterException("StatementType does not exist for id: " + treeView.getType()); |
321 | |
} |
322 | 0 | stmt.setStatementType(stmtType); |
323 | |
|
324 | |
|
325 | 0 | List<ReqComponent> reqCompList = new ArrayList<ReqComponent>(); |
326 | 0 | for (ReqComponentInfo reqCompInfo : treeView.getReqComponents()) { |
327 | |
|
328 | 0 | boolean isUpdate = (reqCompInfo.getId() != null); |
329 | |
|
330 | 0 | ReqComponent reqComp = toReqComponentRelation(isUpdate, reqCompInfo); |
331 | |
|
332 | 0 | if (!isUpdate) { |
333 | 0 | reqCompsToCreate.add(reqComp); |
334 | |
} |
335 | |
|
336 | 0 | reqCompList.add(reqComp); |
337 | 0 | } |
338 | |
|
339 | 0 | stmt.setRequiredComponents(reqCompList); |
340 | |
|
341 | 0 | stmt.setDescr(toRichText(StatementRichText.class, treeView.getDesc())); |
342 | |
|
343 | 0 | Map<String, Statement> stmtsToDelete = new HashMap<String, Statement>(); |
344 | 0 | if (stmt.getChildren() != null) { |
345 | 0 | for (Statement childStmt : stmt.getChildren()) { |
346 | 0 | stmtsToDelete.put(childStmt.getId(), childStmt); |
347 | |
} |
348 | 0 | stmt.getChildren().clear(); |
349 | |
} else { |
350 | 0 | stmt.setChildren(new ArrayList<Statement>()); |
351 | |
} |
352 | 0 | for (StatementTreeViewInfo childTreeView : treeView.getStatements()) { |
353 | |
Statement childStmt; |
354 | 0 | if (childTreeView.getId() != null && stmtsToDelete.containsKey(childTreeView.getId())) { |
355 | 0 | childStmt = stmtsToDelete.remove(childTreeView.getId()); |
356 | |
} else { |
357 | 0 | childStmt = new Statement(); |
358 | |
} |
359 | 0 | childStmt = toStatementFromTree(childStmt, childTreeView, statementIdsToDelete, statementsToUpdate, reqCompsToCreate); |
360 | 0 | stmt.getChildren().add(childStmt); |
361 | 0 | } |
362 | 0 | for (Statement statementToDelete : stmtsToDelete.values()) { |
363 | 0 | deleteStatementsRecursively(statementToDelete, statementIdsToDelete, statementsToUpdate); |
364 | |
} |
365 | 0 | statementIdsToDelete.addAll(stmtsToDelete.keySet()); |
366 | 0 | return stmt; |
367 | |
} |
368 | |
|
369 | |
|
370 | |
|
371 | |
|
372 | |
private void deleteStatementsRecursively(Statement statementToDelete, Set<String> statementIdsToDelete, List<Statement> statementsToUpdate) { |
373 | 0 | if (statementToDelete.getChildren() != null) { |
374 | 0 | for (Statement childStatement : statementToDelete.getChildren()) { |
375 | 0 | deleteStatementsRecursively(childStatement, statementIdsToDelete, statementsToUpdate); |
376 | |
} |
377 | 0 | statementToDelete.getChildren().clear(); |
378 | 0 | statementsToUpdate.add(statementToDelete); |
379 | |
} |
380 | 0 | statementIdsToDelete.add(statementToDelete.getId()); |
381 | 0 | } |
382 | |
|
383 | |
public Statement toStatementRelation(boolean isUpdate, StatementInfo stmtInfo) throws DoesNotExistException, VersionMismatchException, InvalidParameterException, OperationFailedException { |
384 | |
Statement stmt; |
385 | 0 | if (isUpdate) { |
386 | 0 | stmt = this.statementDao.fetch(Statement.class, stmtInfo.getId()); |
387 | 0 | if (stmt == null) { |
388 | 0 | throw new DoesNotExistException("Statement does not exist for id: " + stmtInfo.getId()); |
389 | |
} |
390 | 0 | if (!String.valueOf(stmt.getVersionNumber()).equals(stmtInfo.getMetaInfo().getVersionInd())) { |
391 | 0 | throw new VersionMismatchException("Statement to be updated is not the current version"); |
392 | |
} |
393 | |
} else { |
394 | 0 | stmt = new Statement(); |
395 | |
} |
396 | |
|
397 | 0 | BeanUtils.copyProperties(stmtInfo, stmt, new String[]{"cluIds", "statementIds", "reqComponentIds", "attributes", "metaInfo", "type", "parent", "children", "requiredComponents", "statementType"}); |
398 | |
|
399 | |
|
400 | 0 | stmt.setAttributes(toGenericAttributes(StatementAttribute.class, stmtInfo.getAttributes(), stmt, this.statementDao)); |
401 | |
|
402 | |
|
403 | 0 | StatementType stmtType = this.statementDao.fetch(StatementType.class, stmtInfo.getType()); |
404 | 0 | if (stmtType == null) { |
405 | 0 | throw new InvalidParameterException("StatementType does not exist for id: " + stmtInfo.getType()); |
406 | |
} |
407 | 0 | stmt.setStatementType(stmtType); |
408 | |
|
409 | |
|
410 | |
|
411 | 0 | List<Statement> stmtList = new ArrayList<Statement>(); |
412 | 0 | for (String stmtId : stmtInfo.getStatementIds()) { |
413 | 0 | if (stmtId.equals(stmtInfo.getId())) { |
414 | 0 | throw new OperationFailedException("Statement nested within itself. Statement Id: " + stmtInfo.getId()); |
415 | |
} |
416 | |
|
417 | 0 | Statement nestedStmt = this.statementDao.fetch(Statement.class, stmtId); |
418 | 0 | if (null == nestedStmt) { |
419 | 0 | throw new DoesNotExistException("Nested Statement does not exist for id: " + stmtId + ". Parent Statement: " + stmtInfo.getId()); |
420 | |
} |
421 | |
|
422 | 0 | stmtList.add(nestedStmt); |
423 | 0 | } |
424 | 0 | stmt.setChildren(stmtList); |
425 | |
|
426 | |
|
427 | 0 | List<ReqComponent> reqCompList = new ArrayList<ReqComponent>(); |
428 | 0 | for (String reqId : stmtInfo.getReqComponentIds()) { |
429 | 0 | ReqComponent reqComp = this.statementDao.fetch(ReqComponent.class, reqId); |
430 | |
|
431 | 0 | if (null == reqComp) { |
432 | 0 | throw new DoesNotExistException("Nested Requirement does not exist for id: " + reqId + ". Parent Statement Id: " + stmtInfo.getId()); |
433 | |
} |
434 | |
|
435 | 0 | reqCompList.add(reqComp); |
436 | 0 | } |
437 | 0 | stmt.setRequiredComponents(reqCompList); |
438 | |
|
439 | 0 | stmt.setDescr(toRichText(StatementRichText.class, stmtInfo.getDesc())); |
440 | |
|
441 | 0 | return stmt; |
442 | |
} |
443 | |
|
444 | |
public static StatementInfo toStatementInfo(Statement entity) { |
445 | 0 | if (entity == null) { |
446 | 0 | return null; |
447 | |
} |
448 | 0 | StatementInfo dto = new StatementInfo(); |
449 | |
|
450 | 0 | BeanUtils.copyProperties(entity, dto, new String[]{"parent", "children", "requiredComponents", "statementType", "attributes", "metaInfo"}); |
451 | |
|
452 | 0 | List<String> statementIds = new ArrayList<String>(entity.getChildren().size()); |
453 | 0 | for (Statement statement : entity.getChildren()) { |
454 | 0 | statementIds.add(statement.getId()); |
455 | |
} |
456 | 0 | dto.setStatementIds(statementIds); |
457 | |
|
458 | 0 | List<String> componentIds = new ArrayList<String>(entity.getRequiredComponents().size()); |
459 | 0 | for (ReqComponent reqComponent : entity.getRequiredComponents()) { |
460 | 0 | componentIds.add(reqComponent.getId()); |
461 | |
} |
462 | 0 | dto.setReqComponentIds(componentIds); |
463 | 0 | dto.setType(entity.getStatementType().getId()); |
464 | 0 | dto.setAttributes(toAttributeMap(entity.getAttributes())); |
465 | 0 | dto.setMetaInfo(toMetaInfo(entity.getMeta(), entity.getVersionNumber())); |
466 | 0 | dto.setName(entity.getName()); |
467 | 0 | dto.setOperator(entity.getOperator()); |
468 | 0 | dto.setDesc(toRichTextInfo(entity.getDescr())); |
469 | 0 | return dto; |
470 | |
} |
471 | |
|
472 | |
public static List<StatementInfo> toStatementInfos(List<Statement> entities) { |
473 | 0 | List<StatementInfo> dtos = new ArrayList<StatementInfo>(entities.size()); |
474 | 0 | for (Statement entity : entities) { |
475 | 0 | dtos.add(toStatementInfo(entity)); |
476 | |
} |
477 | 0 | return dtos; |
478 | |
|
479 | |
} |
480 | |
|
481 | |
public static List<StatementTypeInfo> toStatementTypeInfos(List<StatementType> entities) { |
482 | 0 | List<StatementTypeInfo> list = new ArrayList<StatementTypeInfo>(); |
483 | 0 | for (StatementType type : entities) { |
484 | 0 | StatementTypeInfo dto = toStatementTypeInfo(type); |
485 | 0 | list.add(dto); |
486 | 0 | } |
487 | 0 | return list; |
488 | |
} |
489 | |
|
490 | |
public static StatementTypeInfo toStatementTypeInfo(StatementType entity) { |
491 | 0 | if (entity == null) { |
492 | 0 | return null; |
493 | |
} |
494 | 0 | StatementTypeInfo stmtTypeInfo = toGenericTypeInfo(StatementTypeInfo.class, entity); |
495 | |
|
496 | |
|
497 | 0 | List<String> reqTypeIds = new ArrayList<String>(entity.getAllowedReqComponentTypes().size()); |
498 | 0 | for (OrderedReqComponentType reqComponentTypeOrder : entity.getAllowedReqComponentTypes()) { |
499 | 0 | reqTypeIds.add(reqComponentTypeOrder.getReqComponentType().getId()); |
500 | |
} |
501 | 0 | stmtTypeInfo.setAllowedReqComponentTypes(reqTypeIds); |
502 | |
|
503 | |
|
504 | 0 | List<String> stmtIds = new ArrayList<String>(entity.getAllowedStatementTypes().size()); |
505 | 0 | for (OrderedStatementType stmtType : entity.getAllowedStatementTypes()) { |
506 | 0 | stmtIds.add(stmtType.getChildStatementType().getId()); |
507 | |
} |
508 | 0 | stmtTypeInfo.setAllowedStatementTypes(stmtIds); |
509 | |
|
510 | |
|
511 | |
|
512 | |
|
513 | 0 | stmtTypeInfo.setDescr(entity.getDescr()); |
514 | |
|
515 | 0 | return stmtTypeInfo; |
516 | |
} |
517 | |
|
518 | |
public StatementInfo toStatementInfo(final StatementTreeViewInfo statementTreeViewInfo) { |
519 | 0 | StatementInfo statementInfo = null; |
520 | 0 | if (statementTreeViewInfo == null) |
521 | 0 | return null; |
522 | 0 | statementInfo = new StatementInfo(); |
523 | 0 | copyValues(statementInfo, statementTreeViewInfo); |
524 | |
|
525 | 0 | if (statementTreeViewInfo.getReqComponents() != null) { |
526 | 0 | List<String> reqCompIds = new ArrayList<String>(7); |
527 | 0 | for (ReqComponentInfo reqComponentInfo : statementTreeViewInfo.getReqComponents()) { |
528 | 0 | reqCompIds.add(reqComponentInfo.getId()); |
529 | |
} |
530 | 0 | statementInfo.setReqComponentIds(reqCompIds); |
531 | |
} |
532 | 0 | statementInfo.setState(statementTreeViewInfo.getState()); |
533 | |
|
534 | 0 | if (statementTreeViewInfo.getStatements() != null) { |
535 | 0 | List<String> statementIds = new ArrayList<String>(7); |
536 | 0 | for (StatementTreeViewInfo subStatementTreeViewInfo : statementTreeViewInfo.getStatements()) { |
537 | 0 | statementIds.add(subStatementTreeViewInfo.getId()); |
538 | |
} |
539 | 0 | statementInfo.setStatementIds(statementIds); |
540 | |
} |
541 | 0 | statementInfo.setType(statementTreeViewInfo.getType()); |
542 | 0 | return statementInfo; |
543 | |
} |
544 | |
|
545 | |
|
546 | |
|
547 | |
|
548 | |
|
549 | |
|
550 | |
|
551 | |
public void copyValues(final AbstractStatementInfo toStatementInfo, AbstractStatementInfo fromStatementInfo) { |
552 | 0 | toStatementInfo.setAttributes(fromStatementInfo.getAttributes()); |
553 | 0 | toStatementInfo.setDesc(fromStatementInfo.getDesc()); |
554 | 0 | toStatementInfo.setId(fromStatementInfo.getId()); |
555 | 0 | toStatementInfo.setMetaInfo(fromStatementInfo.getMetaInfo()); |
556 | 0 | toStatementInfo.setName(fromStatementInfo.getName()); |
557 | 0 | toStatementInfo.setOperator(fromStatementInfo.getOperator()); |
558 | 0 | toStatementInfo.setState(fromStatementInfo.getState()); |
559 | 0 | toStatementInfo.setType(fromStatementInfo.getType()); |
560 | 0 | } |
561 | |
|
562 | |
public Statement toStatement(final StatementTreeViewInfo statementTreeViewInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, VersionMismatchException { |
563 | 0 | return toCustomLuStatementInfo(statementTreeViewInfo); |
564 | |
} |
565 | |
|
566 | |
|
567 | |
|
568 | |
|
569 | |
|
570 | |
|
571 | |
|
572 | |
|
573 | |
|
574 | |
|
575 | |
|
576 | |
|
577 | |
|
578 | |
|
579 | |
|
580 | |
|
581 | |
public Statement toCustomLuStatementInfo(final StatementTreeViewInfo statementInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, VersionMismatchException { |
582 | 0 | Statement stmt = new Statement(); |
583 | 0 | stmt.setName(statementInfo.getName()); |
584 | 0 | stmt.setOperator(statementInfo.getOperator()); |
585 | |
|
586 | |
|
587 | |
|
588 | 0 | StatementType type = this.statementDao.fetch(StatementType.class, statementInfo.getType()); |
589 | 0 | stmt.setStatementType(type); |
590 | |
|
591 | 0 | if (statementInfo.getStatements() == null || statementInfo.getStatements().isEmpty()) { |
592 | |
|
593 | 0 | List<ReqComponent> customReqList = toReqComponents(statementInfo.getReqComponents()); |
594 | 0 | stmt.setRequiredComponents(customReqList); |
595 | 0 | } else { |
596 | 0 | createStatement(statementInfo, stmt); |
597 | |
} |
598 | |
|
599 | 0 | return stmt; |
600 | |
} |
601 | |
|
602 | |
|
603 | |
|
604 | |
|
605 | |
|
606 | |
|
607 | |
|
608 | |
|
609 | |
|
610 | |
|
611 | |
|
612 | |
private void createStatement(final StatementTreeViewInfo stmtInfo, Statement rootLuStatement) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, VersionMismatchException { |
613 | 0 | for (StatementTreeViewInfo luNlStmt : stmtInfo.getStatements()) { |
614 | 0 | Statement stmt = new Statement(); |
615 | 0 | stmt.setName(luNlStmt.getName()); |
616 | 0 | stmt.setOperator(luNlStmt.getOperator()); |
617 | 0 | if (luNlStmt.getType() != null) { |
618 | |
|
619 | |
|
620 | 0 | StatementType type = this.statementDao.fetch(StatementType.class, luNlStmt.getType()); |
621 | 0 | stmt.setStatementType(type); |
622 | |
} |
623 | |
|
624 | 0 | if (rootLuStatement.getChildren() == null) { |
625 | 0 | rootLuStatement.setChildren(new ArrayList<Statement>()); |
626 | |
} |
627 | 0 | rootLuStatement.getChildren().add(stmt); |
628 | 0 | if (luNlStmt.getStatements() == null || luNlStmt.getStatements().isEmpty()) { |
629 | 0 | List<ReqComponentInfo> children = luNlStmt.getReqComponents(); |
630 | |
|
631 | 0 | List<ReqComponent> customReqList = toReqComponents(children); |
632 | 0 | stmt.setRequiredComponents(customReqList); |
633 | 0 | } else { |
634 | 0 | createStatement(luNlStmt, stmt); |
635 | |
} |
636 | 0 | } |
637 | 0 | } |
638 | |
|
639 | |
private List<ReqComponent> toReqComponents(List<ReqComponentInfo> reqComponentInfoList) throws DoesNotExistException, VersionMismatchException, InvalidParameterException { |
640 | 0 | List<ReqComponent> list = new ArrayList<ReqComponent>(); |
641 | 0 | for (ReqComponentInfo info : reqComponentInfoList) { |
642 | 0 | ReqComponent req = toReqComponentRelation(false, info); |
643 | 0 | list.add(req); |
644 | 0 | } |
645 | 0 | return list; |
646 | |
} |
647 | |
|
648 | |
public StatementTreeViewInfo toStatementTreeViewInfo(Statement stmt) { |
649 | 0 | StatementTreeViewInfo treeView = new StatementTreeViewInfo(); |
650 | 0 | treeView.setAttributes(toAttributeMap(stmt.getAttributes())); |
651 | 0 | treeView.setDesc(toRichTextInfo(stmt.getDescr())); |
652 | 0 | treeView.setId(stmt.getId()); |
653 | 0 | treeView.setMetaInfo(toMetaInfo(stmt.getMeta(), stmt.getVersionNumber())); |
654 | 0 | treeView.setName(stmt.getName()); |
655 | 0 | treeView.setType(stmt.getStatementType().getId()); |
656 | 0 | treeView.setState(stmt.getState()); |
657 | 0 | for (ReqComponent reqComp : stmt.getRequiredComponents()) { |
658 | 0 | treeView.getReqComponents().add(toReqComponentInfo(reqComp)); |
659 | |
} |
660 | 0 | treeView.setOperator(stmt.getOperator()); |
661 | 0 | for (Statement childStmt : stmt.getChildren()) { |
662 | 0 | treeView.getStatements().add(toStatementTreeViewInfo(childStmt)); |
663 | |
} |
664 | |
|
665 | 0 | return treeView; |
666 | |
} |
667 | |
} |