1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.core.statement.ui.client.widgets.rules; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.HashMap; |
20 | |
import java.util.List; |
21 | |
import java.util.Map; |
22 | |
|
23 | |
import org.kuali.student.common.dto.MetaInfo; |
24 | |
import org.kuali.student.core.statement.dto.ReqCompFieldInfo; |
25 | |
import org.kuali.student.core.statement.dto.ReqCompFieldTypeInfo; |
26 | |
import org.kuali.student.core.statement.dto.ReqComponentInfo; |
27 | |
import org.kuali.student.core.statement.dto.ReqComponentTypeInfo; |
28 | |
import org.kuali.student.core.statement.dto.StatementInfo; |
29 | |
import org.kuali.student.core.statement.dto.StatementTreeViewInfo; |
30 | |
|
31 | 0 | public class RulesUtil { |
32 | |
|
33 | |
public static StatementVO clone(StatementVO inStatementVO) { |
34 | 0 | StatementVO cloned = doClone(inStatementVO); |
35 | 0 | return cloned; |
36 | |
} |
37 | |
|
38 | |
private static StatementVO doClone(StatementVO inStatementVO) { |
39 | 0 | StatementVO cloned = null; |
40 | 0 | StatementInfo clonedLuStatementInfo = null; |
41 | |
|
42 | 0 | if (inStatementVO != null) { |
43 | 0 | cloned = new StatementVO(); |
44 | 0 | clonedLuStatementInfo = clone(inStatementVO.getStatementInfo()); |
45 | 0 | cloned.setStatementInfo(clonedLuStatementInfo); |
46 | 0 | if (inStatementVO != null) { |
47 | 0 | for (ReqComponentVO reqComponentVO : inStatementVO.getReqComponentVOs()) { |
48 | 0 | cloned.addReqComponentVO(clone(reqComponentVO)); |
49 | |
} |
50 | |
} |
51 | 0 | if (inStatementVO != null) { |
52 | 0 | for (StatementVO statementVO : inStatementVO.getStatementVOs()) { |
53 | 0 | cloned.addStatementVO(doClone(statementVO)); |
54 | |
} |
55 | |
} |
56 | 0 | cloned.setCheckBoxOn(inStatementVO.isCheckBoxOn()); |
57 | |
} |
58 | 0 | return cloned; |
59 | |
} |
60 | |
|
61 | |
public static StatementInfo clone(StatementInfo inStatementInfo) { |
62 | 0 | StatementInfo clonedLuStatementInfo = null; |
63 | 0 | if (inStatementInfo != null) { |
64 | 0 | clonedLuStatementInfo = new StatementInfo(); |
65 | 0 | clonedLuStatementInfo.setName(inStatementInfo.getName()); |
66 | 0 | clonedLuStatementInfo.setDesc(inStatementInfo.getDesc()); |
67 | 0 | clonedLuStatementInfo.setOperator(inStatementInfo.getOperator()); |
68 | 0 | clonedLuStatementInfo.setStatementIds(new ArrayList<String>(inStatementInfo.getStatementIds())); |
69 | 0 | clonedLuStatementInfo.setReqComponentIds(new ArrayList<String>(inStatementInfo.getReqComponentIds())); |
70 | 0 | clonedLuStatementInfo.setAttributes(clone(inStatementInfo.getAttributes())); |
71 | 0 | clonedLuStatementInfo.setMetaInfo(clone(inStatementInfo.getMetaInfo())); |
72 | 0 | clonedLuStatementInfo.setType(inStatementInfo.getType()); |
73 | 0 | clonedLuStatementInfo.setState(inStatementInfo.getState()); |
74 | 0 | clonedLuStatementInfo.setId(inStatementInfo.getId()); |
75 | |
} |
76 | 0 | return clonedLuStatementInfo; |
77 | |
} |
78 | |
|
79 | |
private static Map<String, String> clone(Map<String, String> inAttributes) { |
80 | 0 | Map<String, String> clonedAttributes = null; |
81 | 0 | if (inAttributes != null) { |
82 | 0 | clonedAttributes = new HashMap<String, String>(); |
83 | 0 | inAttributes.putAll(inAttributes); |
84 | |
} |
85 | 0 | return clonedAttributes; |
86 | |
} |
87 | |
|
88 | |
private static MetaInfo clone(MetaInfo inMetaInfo) { |
89 | 0 | MetaInfo clonedMetaInfo = null; |
90 | 0 | if (inMetaInfo != null) { |
91 | 0 | clonedMetaInfo = new MetaInfo(); |
92 | 0 | clonedMetaInfo.setVersionInd(inMetaInfo.getVersionInd()); |
93 | 0 | if (inMetaInfo.getCreateTime() != null) { |
94 | 0 | clonedMetaInfo.setCreateTime((java.util.Date)inMetaInfo.getCreateTime().clone()); |
95 | |
} |
96 | 0 | clonedMetaInfo.setCreateId(inMetaInfo.getCreateId()); |
97 | 0 | if (inMetaInfo.getUpdateTime() != null) { |
98 | 0 | clonedMetaInfo.setUpdateTime((java.util.Date)inMetaInfo.getUpdateTime().clone()); |
99 | |
} |
100 | 0 | clonedMetaInfo.setUpdateId(inMetaInfo.getUpdateId()); |
101 | |
} |
102 | 0 | return clonedMetaInfo; |
103 | |
} |
104 | |
|
105 | |
private static ReqComponentVO clone(ReqComponentVO inReqComponentVO) { |
106 | 0 | ReqComponentVO clonedReqComponentVO = null; |
107 | 0 | if (inReqComponentVO != null) { |
108 | 0 | clonedReqComponentVO = new ReqComponentVO(); |
109 | 0 | clonedReqComponentVO.setId(inReqComponentVO.getId()); |
110 | 0 | clonedReqComponentVO.setReqComponentInfo(clone(inReqComponentVO.getReqComponentInfo())); |
111 | 0 | clonedReqComponentVO.setTypeDesc(inReqComponentVO.getTypeDesc()); |
112 | 0 | clonedReqComponentVO.setDirty(inReqComponentVO.isDirty()); |
113 | 0 | clonedReqComponentVO.setCheckBoxOn(inReqComponentVO.isCheckBoxOn()); |
114 | |
} |
115 | 0 | return clonedReqComponentVO; |
116 | |
} |
117 | |
|
118 | |
public static ReqComponentInfoUi clone(ReqComponentInfo inReqComponentInfo) { |
119 | 0 | ReqComponentInfoUi clonedReqComponentInfo = null; |
120 | 0 | if (inReqComponentInfo != null) { |
121 | 0 | clonedReqComponentInfo = new ReqComponentInfoUi(); |
122 | 0 | clonedReqComponentInfo.setDesc(inReqComponentInfo.getDesc()); |
123 | 0 | clonedReqComponentInfo.setReqCompFields(clone(inReqComponentInfo.getReqCompFields())); |
124 | 0 | if (inReqComponentInfo.getEffectiveDate() != null) { |
125 | 0 | clonedReqComponentInfo.setEffectiveDate((java.util.Date)inReqComponentInfo.getEffectiveDate().clone()); |
126 | |
} |
127 | 0 | if (inReqComponentInfo.getExpirationDate() != null) { |
128 | 0 | clonedReqComponentInfo.setExpirationDate( |
129 | |
(java.util.Date)inReqComponentInfo.getExpirationDate().clone()); |
130 | |
} |
131 | 0 | clonedReqComponentInfo.setMetaInfo(clone(inReqComponentInfo.getMetaInfo())); |
132 | 0 | clonedReqComponentInfo.setType(inReqComponentInfo.getType()); |
133 | 0 | clonedReqComponentInfo.setState(inReqComponentInfo.getState()); |
134 | 0 | clonedReqComponentInfo.setId(inReqComponentInfo.getId()); |
135 | |
|
136 | 0 | clonedReqComponentInfo.setNaturalLanguageTranslation(inReqComponentInfo.getNaturalLanguageTranslation()); |
137 | 0 | if (inReqComponentInfo instanceof ReqComponentInfoUi) { |
138 | 0 | clonedReqComponentInfo.setPreviewNaturalLanguageTranslation(((ReqComponentInfoUi)inReqComponentInfo).getPreviewNaturalLanguageTranslation()); |
139 | |
} |
140 | |
} |
141 | 0 | return clonedReqComponentInfo; |
142 | |
} |
143 | |
|
144 | |
private static List<ReqCompFieldInfo> clone(List<ReqCompFieldInfo> inReqComponentInfos) { |
145 | 0 | List<ReqCompFieldInfo> clonedFields = null; |
146 | 0 | if (inReqComponentInfos != null) { |
147 | 0 | clonedFields = new ArrayList<ReqCompFieldInfo>(); |
148 | 0 | for (ReqCompFieldInfo currField : inReqComponentInfos) { |
149 | 0 | clonedFields.add(clone(currField)); |
150 | |
} |
151 | |
} |
152 | 0 | return clonedFields; |
153 | |
} |
154 | |
|
155 | |
private static ReqCompFieldInfo clone(ReqCompFieldInfo inReqCompFieldInfo) { |
156 | 0 | ReqCompFieldInfo clonedField = null; |
157 | 0 | if (inReqCompFieldInfo != null) { |
158 | 0 | clonedField = new ReqCompFieldInfo(); |
159 | 0 | clonedField.setValue(inReqCompFieldInfo.getValue()); |
160 | 0 | clonedField.setId(inReqCompFieldInfo.getId()); |
161 | 0 | clonedField.setType(inReqCompFieldInfo.getType()); |
162 | |
} |
163 | 0 | return clonedField; |
164 | |
} |
165 | |
|
166 | |
private static ReqComponentTypeInfo clone(ReqComponentTypeInfo inReqComponentTypeInfo) { |
167 | 0 | ReqComponentTypeInfo clonedField = null; |
168 | 0 | if (inReqComponentTypeInfo != null) { |
169 | 0 | clonedField = new ReqComponentTypeInfo(); |
170 | 0 | clonedField.setId(inReqComponentTypeInfo.getId()); |
171 | |
|
172 | 0 | List<ReqCompFieldTypeInfo> clonedFieldTypeList = null; |
173 | 0 | if (inReqComponentTypeInfo.getReqCompFieldTypeInfos() != null) { |
174 | 0 | clonedFieldTypeList = new ArrayList<ReqCompFieldTypeInfo>(); |
175 | 0 | for (ReqCompFieldTypeInfo reqCompFieldTypeInfo : inReqComponentTypeInfo.getReqCompFieldTypeInfos()) { |
176 | 0 | ReqCompFieldTypeInfo clonedFieldType = new ReqCompFieldTypeInfo(); |
177 | 0 | clonedFieldType.setId(reqCompFieldTypeInfo.getId()); |
178 | |
|
179 | 0 | clonedFieldTypeList.add(clonedFieldType); |
180 | 0 | } |
181 | |
} |
182 | 0 | clonedField.setReqCompFieldTypeInfos(clonedFieldTypeList); |
183 | |
} |
184 | 0 | return clonedField; |
185 | |
} |
186 | |
|
187 | |
public static StatementTreeViewInfo clone(StatementTreeViewInfo inStatementTreeViewInfo) { |
188 | 0 | StatementTreeViewInfo clonedStatementTreeViewInfoInfo = null; |
189 | 0 | if (inStatementTreeViewInfo != null) { |
190 | 0 | clonedStatementTreeViewInfoInfo = new StatementTreeViewInfo(); |
191 | 0 | clonedStatementTreeViewInfoInfo.setName(inStatementTreeViewInfo.getName()); |
192 | 0 | clonedStatementTreeViewInfoInfo.setDesc(inStatementTreeViewInfo.getDesc()); |
193 | 0 | clonedStatementTreeViewInfoInfo.setOperator(inStatementTreeViewInfo.getOperator()); |
194 | 0 | clonedStatementTreeViewInfoInfo.setAttributes(clone(inStatementTreeViewInfo.getAttributes())); |
195 | 0 | clonedStatementTreeViewInfoInfo.setMetaInfo(clone(inStatementTreeViewInfo.getMetaInfo())); |
196 | 0 | clonedStatementTreeViewInfoInfo.setType(inStatementTreeViewInfo.getType()); |
197 | 0 | clonedStatementTreeViewInfoInfo.setState(inStatementTreeViewInfo.getState()); |
198 | 0 | clonedStatementTreeViewInfoInfo.setId(inStatementTreeViewInfo.getId()); |
199 | |
|
200 | |
|
201 | 0 | List<StatementTreeViewInfo> inStatements = inStatementTreeViewInfo.getStatements(); |
202 | 0 | List<ReqComponentInfo> inReqComponentInfos = inStatementTreeViewInfo.getReqComponents(); |
203 | |
|
204 | 0 | if ((inStatements != null) && (!inStatements.isEmpty())) { |
205 | |
|
206 | 0 | List<StatementTreeViewInfo> clonedStatementList = new ArrayList<StatementTreeViewInfo>(); |
207 | 0 | for (StatementTreeViewInfo inStatement : inStatements) { |
208 | 0 | clonedStatementList.add(clone(inStatement)); |
209 | |
} |
210 | 0 | clonedStatementTreeViewInfoInfo.setStatements(clonedStatementList); |
211 | 0 | } else if ((inReqComponentInfos != null) && (!inReqComponentInfos.isEmpty())) { |
212 | |
|
213 | 0 | List<ReqComponentInfo> clonedReqComponentList = new ArrayList<ReqComponentInfo>(); |
214 | 0 | for (ReqComponentInfo inReqComponent : inReqComponentInfos) { |
215 | 0 | clonedReqComponentList.add(RulesUtil.clone(inReqComponent)); |
216 | |
} |
217 | 0 | clonedStatementTreeViewInfoInfo.setReqComponents(clonedReqComponentList); |
218 | |
} |
219 | |
} |
220 | 0 | return clonedStatementTreeViewInfoInfo; |
221 | |
} |
222 | |
|
223 | |
|
224 | |
public static boolean isCluSetWidget(String fieldType) { |
225 | 0 | return ((fieldType.toLowerCase().indexOf("course.cluSet".toLowerCase()) > 0) || |
226 | |
(fieldType.toLowerCase().indexOf("program.cluSet".toLowerCase()) > 0)); |
227 | |
} |
228 | |
|
229 | |
public static boolean isCluWidget(String fieldType) { |
230 | 0 | return ((fieldType.toLowerCase().indexOf("course.clu".toLowerCase()) > 0) || |
231 | |
(fieldType.toLowerCase().indexOf("program.clu".toLowerCase()) > 0)); |
232 | |
} |
233 | |
|
234 | |
public static boolean isGradeWidget(String fieldType) { |
235 | 0 | return ((fieldType.toLowerCase().equals("kuali.reqComponent.field.type.grade.id".toLowerCase())) || |
236 | |
(fieldType.toLowerCase().equals("kuali.reqComponent.field.type.gradeType.id".toLowerCase()))); |
237 | |
} |
238 | |
|
239 | |
public static boolean isCourseWidget(String fieldType) { |
240 | 0 | return (fieldType.toLowerCase().equals("kuali.reqComponent.field.type.course.clu.id".toLowerCase())); |
241 | |
} |
242 | |
|
243 | |
public static boolean isProgramWidget(String fieldType) { |
244 | 0 | return (fieldType.toLowerCase().equals("kuali.reqComponent.field.type.program.clu.id".toLowerCase())); |
245 | |
} |
246 | |
} |