1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.lum.program.service.assembler; |
17 | |
|
18 | |
import static org.apache.commons.lang.StringUtils.isEmpty; |
19 | |
|
20 | |
import java.util.ArrayList; |
21 | |
import java.util.HashMap; |
22 | |
import java.util.Iterator; |
23 | |
import java.util.List; |
24 | |
import java.util.Map; |
25 | |
|
26 | |
import org.kuali.student.common.assembly.BaseDTOAssemblyNode; |
27 | |
import org.kuali.student.common.assembly.BaseDTOAssemblyNode.NodeOperation; |
28 | |
import org.kuali.student.common.assembly.data.AssemblyException; |
29 | |
import org.kuali.student.common.dto.DtoConstants; |
30 | |
import org.kuali.student.common.dto.RichTextInfo; |
31 | |
import org.kuali.student.common.exceptions.DoesNotExistException; |
32 | |
import org.kuali.student.common.exceptions.InvalidParameterException; |
33 | |
import org.kuali.student.common.exceptions.MissingParameterException; |
34 | |
import org.kuali.student.common.exceptions.OperationFailedException; |
35 | |
import org.kuali.student.common.util.UUIDHelper; |
36 | |
import org.kuali.student.lum.lu.dto.AdminOrgInfo; |
37 | |
import org.kuali.student.lum.lu.dto.CluCluRelationInfo; |
38 | |
import org.kuali.student.lum.lu.dto.CluIdentifierInfo; |
39 | |
import org.kuali.student.lum.lu.dto.CluInfo; |
40 | |
import org.kuali.student.lum.lu.dto.CluPublicationInfo; |
41 | |
import org.kuali.student.lum.lu.dto.CluResultInfo; |
42 | |
import org.kuali.student.lum.lu.dto.FieldInfo; |
43 | |
import org.kuali.student.lum.lu.dto.LuCodeInfo; |
44 | |
import org.kuali.student.lum.lu.service.LuService; |
45 | |
import org.kuali.student.lum.program.dto.CredentialProgramInfo; |
46 | |
import org.kuali.student.lum.program.dto.assembly.ProgramAtpAssembly; |
47 | |
import org.kuali.student.lum.program.dto.assembly.ProgramBasicOrgAssembly; |
48 | |
import org.kuali.student.lum.program.dto.assembly.ProgramCodeAssembly; |
49 | |
import org.kuali.student.lum.program.dto.assembly.ProgramCommonAssembly; |
50 | |
import org.kuali.student.lum.program.dto.assembly.ProgramCredentialAssembly; |
51 | |
import org.kuali.student.lum.program.dto.assembly.ProgramFullOrgAssembly; |
52 | |
import org.kuali.student.lum.program.dto.assembly.ProgramIdentifierAssembly; |
53 | |
import org.kuali.student.lum.program.dto.assembly.ProgramPublicationAssembly; |
54 | |
import org.kuali.student.lum.program.dto.assembly.ProgramRequirementAssembly; |
55 | |
import org.kuali.student.lum.service.assembler.CluAssemblerUtils; |
56 | |
|
57 | 1 | public class ProgramAssemblerUtils { |
58 | |
|
59 | |
private LuService luService; |
60 | |
private CluAssemblerUtils cluAssemblerUtils; |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public ProgramCommonAssembly assembleBasics(CluInfo clu, ProgramCommonAssembly program) throws AssemblyException { |
71 | |
|
72 | 135 | if (program instanceof CredentialProgramInfo) { |
73 | 6 | ((CredentialProgramInfo)program).setCredentialProgramType(clu.getType()); |
74 | |
} |
75 | |
else { |
76 | 129 | program.setType(clu.getType()); |
77 | |
} |
78 | 135 | program.setState(clu.getState()); |
79 | 135 | program.setMetaInfo(clu.getMetaInfo()); |
80 | 135 | program.setAttributes(clu.getAttributes()); |
81 | 135 | program.setId(clu.getId()); |
82 | |
|
83 | 135 | return program; |
84 | |
} |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
public CluInfo disassembleBasics(CluInfo clu, ProgramCommonAssembly program) throws AssemblyException { |
96 | |
|
97 | 61 | if (program instanceof CredentialProgramInfo) { |
98 | 2 | clu.setType (((CredentialProgramInfo)program).getCredentialProgramType()); |
99 | |
} |
100 | |
else { |
101 | 59 | clu.setType(program.getType()); |
102 | |
} |
103 | 61 | clu.setId(UUIDHelper.genStringUUID(program.getId())); |
104 | |
|
105 | |
|
106 | 61 | clu.setState(program.getState()); |
107 | 61 | clu.setMetaInfo(program.getMetaInfo()); |
108 | 61 | clu.setAttributes(program.getAttributes()); |
109 | 61 | return clu; |
110 | |
|
111 | |
} |
112 | |
|
113 | |
|
114 | |
public ProgramRequirementAssembly assembleRequirements(CluInfo clu, ProgramRequirementAssembly program) throws AssemblyException { |
115 | |
|
116 | |
try { |
117 | 78 | List<String> requirements = luService.getRelatedCluIdsByCluId(clu.getId(), ProgramAssemblerConstants.HAS_PROGRAM_REQUIREMENT); |
118 | 78 | if (requirements != null && requirements.size() > 0) { |
119 | 7 | program.setProgramRequirements(requirements); |
120 | |
} |
121 | |
} |
122 | 0 | catch (Exception e) |
123 | |
{ |
124 | 0 | throw new AssemblyException("Error assembling program requirements", e); |
125 | 78 | } |
126 | |
|
127 | 78 | return program; |
128 | |
} |
129 | |
|
130 | |
|
131 | |
public CluInfo disassembleRequirements(CluInfo clu, ProgramRequirementAssembly program, NodeOperation operation, BaseDTOAssemblyNode<?, ?> result, boolean stateChanged) throws AssemblyException { |
132 | |
try { |
133 | 14 | List<String> requirements = program.getProgramRequirements (); |
134 | |
|
135 | 14 | if (requirements != null && !requirements.isEmpty()) { |
136 | 14 | if (stateChanged){ |
137 | 0 | addUpdateRequirementStateNodes(requirements, program.getState(), result); |
138 | |
} |
139 | |
|
140 | 14 | Map<String, String> currentRelations = null; |
141 | |
|
142 | 14 | if (!NodeOperation.CREATE.equals(operation)) { |
143 | 2 | currentRelations = getCluCluRelations(clu.getId(), ProgramAssemblerConstants.HAS_PROGRAM_REQUIREMENT); |
144 | |
} |
145 | |
|
146 | 14 | for (String requirementId : requirements){ |
147 | 27 | List<BaseDTOAssemblyNode<?, ?>> reqResults = addAllRelationNodes(clu.getId(), requirementId, ProgramAssemblerConstants.HAS_PROGRAM_REQUIREMENT, operation, currentRelations); |
148 | 27 | if (reqResults != null && reqResults.size()> 0) { |
149 | 26 | result.getChildNodes().addAll(reqResults); |
150 | |
} |
151 | 27 | } |
152 | |
|
153 | 14 | if(currentRelations != null && currentRelations.size() > 0){ |
154 | 1 | for (Map.Entry<String, String> entry : currentRelations.entrySet()) { |
155 | |
|
156 | |
|
157 | 2 | CluCluRelationInfo relationToDelete = new CluCluRelationInfo(); |
158 | 2 | relationToDelete.setId( entry.getValue() ); |
159 | 2 | BaseDTOAssemblyNode<Object, CluCluRelationInfo> relationToDeleteNode = new BaseDTOAssemblyNode<Object, CluCluRelationInfo>( |
160 | |
null); |
161 | 2 | relationToDeleteNode.setNodeData(relationToDelete); |
162 | 2 | relationToDeleteNode.setOperation(NodeOperation.DELETE); |
163 | 2 | result.getChildNodes().add(relationToDeleteNode); |
164 | 2 | } |
165 | |
} |
166 | |
} |
167 | 0 | } catch (Exception e) { |
168 | 0 | throw new AssemblyException("Error while disassembling program requirements", e); |
169 | 14 | } |
170 | |
|
171 | 14 | return clu; |
172 | |
|
173 | |
} |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
private void addUpdateRequirementStateNodes(List<String> requirements, String state, BaseDTOAssemblyNode<?, ?> result) throws InvalidParameterException, MissingParameterException, OperationFailedException { |
185 | 0 | for (String requirementId:requirements){ |
186 | |
try { |
187 | 0 | CluInfo requirementClu = luService.getClu(requirementId); |
188 | 0 | requirementClu.setState(state); |
189 | 0 | BaseDTOAssemblyNode<Object, CluInfo> reqCluNode = new BaseDTOAssemblyNode<Object, CluInfo>(null); |
190 | 0 | reqCluNode.setNodeData(requirementClu); |
191 | 0 | reqCluNode.setOperation(NodeOperation.UPDATE); |
192 | 0 | result.getChildNodes().add(reqCluNode); |
193 | 0 | } catch (DoesNotExistException e){ |
194 | |
|
195 | 0 | } |
196 | |
} |
197 | 0 | } |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
public ProgramIdentifierAssembly assembleIdentifiers(CluInfo clu, ProgramIdentifierAssembly program) throws AssemblyException { |
208 | |
|
209 | 135 | if (clu.getOfficialIdentifier() != null) { |
210 | 135 | if (clu.getOfficialIdentifier().getShortName() != null) { |
211 | 135 | program.setShortTitle(clu.getOfficialIdentifier().getShortName()); |
212 | |
} |
213 | 135 | if (clu.getOfficialIdentifier().getLongName() != null) { |
214 | 135 | program.setLongTitle(clu.getOfficialIdentifier().getLongName()); |
215 | |
} |
216 | 135 | if (clu.getOfficialIdentifier().getCode() != null) { |
217 | 135 | program.setCode(clu.getOfficialIdentifier().getCode()); |
218 | |
} |
219 | |
} |
220 | 135 | if (clu.getAlternateIdentifiers() != null) { |
221 | 135 | for (CluIdentifierInfo cluIdInfo : clu.getAlternateIdentifiers()) { |
222 | 224 | String idInfoType = cluIdInfo.getType(); |
223 | 224 | if (ProgramAssemblerConstants.TRANSCRIPT.equals(idInfoType)) { |
224 | 130 | program.setTranscriptTitle(cluIdInfo.getShortName()); |
225 | 94 | } else if (ProgramAssemblerConstants.DIPLOMA.equals(idInfoType)) { |
226 | 72 | program.setDiplomaTitle(cluIdInfo.getShortName()); |
227 | |
} |
228 | 224 | } |
229 | |
} |
230 | 135 | return program; |
231 | |
} |
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
public CluInfo disassembleIdentifiers(CluInfo clu, ProgramIdentifierAssembly program, NodeOperation operation) throws AssemblyException { |
244 | |
|
245 | 52 | CluIdentifierInfo official = null != clu.getOfficialIdentifier() ? clu.getOfficialIdentifier() : new CluIdentifierInfo(); |
246 | |
|
247 | 52 | official.setCode(program.getCode()); |
248 | 52 | official.setLongName(program.getLongTitle()); |
249 | 52 | official.setShortName(program.getShortTitle()); |
250 | 52 | official.setState(program.getState()); |
251 | |
|
252 | 52 | official.setType(ProgramAssemblerConstants.OFFICIAL); |
253 | |
|
254 | 52 | if (program instanceof CredentialProgramInfo) { |
255 | 2 | CredentialProgramInfo cred = (CredentialProgramInfo)program; |
256 | 2 | official.setLevel(cred.getProgramLevel()); |
257 | |
} |
258 | |
|
259 | 52 | clu.setOfficialIdentifier(official); |
260 | |
|
261 | |
|
262 | 52 | CluIdentifierInfo diplomaInfo = null; |
263 | 52 | CluIdentifierInfo transcriptInfo = null; |
264 | 52 | for(Iterator<CluIdentifierInfo> iter = clu.getAlternateIdentifiers().iterator();iter.hasNext();){ |
265 | 59 | CluIdentifierInfo cluIdentifier = iter.next(); |
266 | 59 | if (ProgramAssemblerConstants.DIPLOMA.equals(cluIdentifier.getType())) { |
267 | 19 | diplomaInfo = cluIdentifier; |
268 | 19 | diplomaInfo.setState(program.getState()); |
269 | 40 | } else if (ProgramAssemblerConstants.TRANSCRIPT.equals(cluIdentifier.getType())) { |
270 | 34 | transcriptInfo = cluIdentifier; |
271 | 34 | transcriptInfo.setState(program.getState()); |
272 | |
} |
273 | 59 | } |
274 | |
|
275 | 52 | if (program.getDiplomaTitle() != null) { |
276 | 29 | if (diplomaInfo == null) { |
277 | 10 | diplomaInfo = new CluIdentifierInfo(); |
278 | 10 | diplomaInfo.setState(program.getState()); |
279 | 10 | clu.getAlternateIdentifiers().add(diplomaInfo); |
280 | |
} |
281 | 29 | diplomaInfo.setCode(official.getCode()); |
282 | 29 | diplomaInfo.setShortName(program.getDiplomaTitle()); |
283 | 29 | diplomaInfo.setType(ProgramAssemblerConstants.DIPLOMA); |
284 | |
} |
285 | |
|
286 | 52 | if (program.getTranscriptTitle() != null) { |
287 | 51 | if (transcriptInfo == null) { |
288 | 17 | transcriptInfo = new CluIdentifierInfo(); |
289 | 17 | transcriptInfo.setState(program.getState()); |
290 | 17 | clu.getAlternateIdentifiers().add(transcriptInfo); |
291 | |
} |
292 | 51 | transcriptInfo.setCode(official.getCode()); |
293 | 51 | transcriptInfo.setShortName(program.getTranscriptTitle()); |
294 | 51 | transcriptInfo.setType(ProgramAssemblerConstants.TRANSCRIPT); |
295 | |
} |
296 | 52 | return clu; |
297 | |
} |
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | |
public ProgramCodeAssembly assembleLuCodes(CluInfo clu, ProgramCodeAssembly program) throws AssemblyException { |
308 | |
|
309 | 135 | if (clu.getLuCodes() != null) { |
310 | 135 | for (LuCodeInfo codeInfo : clu.getLuCodes()) { |
311 | 506 | if (ProgramAssemblerConstants.CIP_2000.equals(codeInfo.getType())) { |
312 | 94 | program.setCip2000Code(codeInfo.getValue()); |
313 | 412 | } else if (ProgramAssemblerConstants.CIP_2010.equals(codeInfo.getType())) { |
314 | 94 | program.setCip2010Code(codeInfo.getValue()); |
315 | 318 | } else if (ProgramAssemblerConstants.HEGIS.equals(codeInfo.getType())) { |
316 | 94 | program.setHegisCode(codeInfo.getValue()); |
317 | 224 | } else if (ProgramAssemblerConstants.UNIVERSITY_CLASSIFICATION.equals(codeInfo.getType())) { |
318 | 130 | program.setUniversityClassification(codeInfo.getValue()); |
319 | 94 | } else if (ProgramAssemblerConstants.SELECTIVE_ENROLLMENT.equals(codeInfo.getType())) { |
320 | 94 | program.setSelectiveEnrollmentCode(codeInfo.getValue()); |
321 | |
} |
322 | |
} |
323 | |
} |
324 | |
|
325 | 135 | return program; |
326 | |
} |
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | |
public CluInfo disassembleLuCodes(CluInfo clu, ProgramCodeAssembly program, NodeOperation operation) throws AssemblyException { |
338 | |
|
339 | 52 | clu.setLuCodes(new ArrayList<LuCodeInfo>()); |
340 | |
|
341 | 52 | addLuCodeFromProgram(ProgramAssemblerConstants.CIP_2000, program.getCip2000Code(), clu.getLuCodes()); |
342 | 52 | addLuCodeFromProgram(ProgramAssemblerConstants.CIP_2010, program.getCip2010Code(), clu.getLuCodes()); |
343 | 52 | addLuCodeFromProgram(ProgramAssemblerConstants.HEGIS, program.getHegisCode(), clu.getLuCodes()); |
344 | 52 | addLuCodeFromProgram(ProgramAssemblerConstants.UNIVERSITY_CLASSIFICATION, program.getUniversityClassification(), clu.getLuCodes()); |
345 | 52 | addLuCodeFromProgram(ProgramAssemblerConstants.SELECTIVE_ENROLLMENT, program.getSelectiveEnrollmentCode(), clu.getLuCodes()); |
346 | |
|
347 | 52 | return clu; |
348 | |
|
349 | |
} |
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | |
|
358 | |
|
359 | |
public ProgramBasicOrgAssembly assembleBasicAdminOrgs(CluInfo clu, ProgramBasicOrgAssembly program) throws AssemblyException { |
360 | |
|
361 | 135 | if (clu.getAdminOrgs() != null) { |
362 | 135 | clearProgramAdminOrgs(program); |
363 | 135 | for (AdminOrgInfo cluOrg : clu.getAdminOrgs()) { |
364 | 1465 | if (cluOrg.getType().equals(ProgramAssemblerConstants.CURRICULUM_OVERSIGHT_DIVISION)) { |
365 | 169 | program.getDivisionsContentOwner().add(cluOrg.getOrgId()); |
366 | |
} |
367 | 1296 | else if (cluOrg.getType().equals(ProgramAssemblerConstants.STUDENT_OVERSIGHT_DIVISION)) { |
368 | 169 | program.getDivisionsStudentOversight().add(cluOrg.getOrgId()) ; |
369 | |
} |
370 | 1127 | else if (cluOrg.getType().equals(ProgramAssemblerConstants.CURRICULUM_OVERSIGHT_UNIT)) { |
371 | 169 | program.getUnitsContentOwner().add(cluOrg.getOrgId()) ; |
372 | |
} |
373 | 958 | else if (cluOrg.getType().equals(ProgramAssemblerConstants.STUDENT_OVERSIGHT_UNIT)) { |
374 | 220 | program.getUnitsStudentOversight().add(cluOrg.getOrgId()) ; |
375 | |
} |
376 | |
} |
377 | |
} |
378 | 135 | return program; |
379 | |
} |
380 | |
|
381 | |
public ProgramFullOrgAssembly assembleFullOrgs(CluInfo clu, ProgramFullOrgAssembly program) throws AssemblyException { |
382 | |
|
383 | 94 | clearFullAdminOrgs(program); |
384 | 94 | for (AdminOrgInfo cluOrg : clu.getAdminOrgs()) { |
385 | 1259 | if (cluOrg.getType().equals(ProgramAssemblerConstants.DEPLOYMENT_DIVISION)) { |
386 | 119 | program.getDivisionsDeployment().add(cluOrg.getOrgId()) ; |
387 | |
} |
388 | 1140 | else if (cluOrg.getType().equals(ProgramAssemblerConstants.FINANCIAL_RESOURCES_DIVISION)) { |
389 | 119 | program.getDivisionsFinancialResources().add(cluOrg.getOrgId()) ; |
390 | |
} |
391 | 1021 | else if (cluOrg.getType().equals(ProgramAssemblerConstants.FINANCIAL_CONTROL_DIVISION)) { |
392 | 119 | program.getDivisionsFinancialControl().add(cluOrg.getOrgId()) ; |
393 | |
} |
394 | 902 | else if (cluOrg.getType().equals(ProgramAssemblerConstants.DEPLOYMENT_UNIT)) { |
395 | 119 | program.getUnitsDeployment().add(cluOrg.getOrgId()) ; |
396 | |
} |
397 | 783 | else if (cluOrg.getType().equals(ProgramAssemblerConstants.FINANCIAL_RESOURCES_UNIT)) { |
398 | 119 | program.getUnitsFinancialResources().add(cluOrg.getOrgId()) ; |
399 | |
} |
400 | 664 | else if (cluOrg.getType().equals(ProgramAssemblerConstants.FINANCIAL_CONTROL_UNIT)) { |
401 | 137 | program.getUnitsFinancialControl().add(cluOrg.getOrgId()) ; |
402 | |
} |
403 | |
} |
404 | 94 | return program; |
405 | |
} |
406 | |
|
407 | |
private void clearProgramAdminOrgs(ProgramBasicOrgAssembly program) { |
408 | 135 | program.setDivisionsContentOwner(new ArrayList<String>()); |
409 | 135 | program.setDivisionsStudentOversight(new ArrayList<String>()); |
410 | 135 | program.setUnitsContentOwner(new ArrayList<String>()); |
411 | 135 | program.setUnitsStudentOversight(new ArrayList<String>()); |
412 | 135 | } |
413 | |
|
414 | |
private void clearFullAdminOrgs(ProgramFullOrgAssembly program) { |
415 | 94 | program.setDivisionsDeployment(new ArrayList<String>()); |
416 | 94 | program.setDivisionsFinancialResources(new ArrayList<String>()); |
417 | 94 | program.setDivisionsFinancialControl(new ArrayList<String>()); |
418 | 94 | program.setUnitsDeployment(new ArrayList<String>()); |
419 | 94 | program.setUnitsFinancialResources(new ArrayList<String>()); |
420 | 94 | program.setUnitsFinancialControl(new ArrayList<String>()); |
421 | 94 | } |
422 | |
|
423 | |
|
424 | |
|
425 | |
|
426 | |
|
427 | |
|
428 | |
|
429 | |
|
430 | |
public CluInfo disassembleAdminOrgs(CluInfo clu, ProgramBasicOrgAssembly program, NodeOperation operation){ |
431 | |
|
432 | |
|
433 | 52 | clu.setAdminOrgs(new ArrayList<AdminOrgInfo>()); |
434 | |
|
435 | 52 | newBuildAdminOrgs(clu, program.getDivisionsContentOwner(), ProgramAssemblerConstants.CURRICULUM_OVERSIGHT_DIVISION); |
436 | 52 | newBuildAdminOrgs(clu, program.getDivisionsStudentOversight(), ProgramAssemblerConstants.STUDENT_OVERSIGHT_DIVISION ); |
437 | 52 | newBuildAdminOrgs(clu, program.getUnitsContentOwner(), ProgramAssemblerConstants.CURRICULUM_OVERSIGHT_UNIT); |
438 | 52 | newBuildAdminOrgs(clu, program.getUnitsStudentOversight(), ProgramAssemblerConstants.STUDENT_OVERSIGHT_UNIT ); |
439 | 52 | if (program instanceof CredentialProgramInfo) { |
440 | 2 | List<String> institutionOrgs = new ArrayList<String>(); |
441 | 2 | institutionOrgs.add(((CredentialProgramInfo)program).getInstitution().getOrgId()); |
442 | 2 | newBuildAdminOrgs(clu, institutionOrgs , ProgramAssemblerConstants.INSTITUTION) ; |
443 | |
} |
444 | 52 | if (program instanceof ProgramFullOrgAssembly) { |
445 | 35 | ProgramFullOrgAssembly fullOrg = (ProgramFullOrgAssembly) program; |
446 | 35 | newBuildAdminOrgs(clu, fullOrg.getDivisionsDeployment(), ProgramAssemblerConstants.DEPLOYMENT_DIVISION); |
447 | 35 | newBuildAdminOrgs(clu, fullOrg.getDivisionsFinancialResources(), ProgramAssemblerConstants.FINANCIAL_RESOURCES_DIVISION); |
448 | 35 | newBuildAdminOrgs(clu, fullOrg.getDivisionsFinancialControl(), ProgramAssemblerConstants.FINANCIAL_CONTROL_DIVISION); |
449 | 35 | newBuildAdminOrgs(clu, fullOrg.getUnitsDeployment(), ProgramAssemblerConstants.DEPLOYMENT_UNIT); |
450 | 35 | newBuildAdminOrgs(clu, fullOrg.getUnitsFinancialResources(), ProgramAssemblerConstants.FINANCIAL_RESOURCES_UNIT); |
451 | 35 | newBuildAdminOrgs(clu, fullOrg.getUnitsFinancialControl(), ProgramAssemblerConstants.FINANCIAL_CONTROL_UNIT); |
452 | |
|
453 | |
} |
454 | 52 | return clu; |
455 | |
|
456 | |
} |
457 | |
|
458 | |
private CluInfo newBuildAdminOrgs(CluInfo clu, List<String> orgIds, String type) { |
459 | |
|
460 | 420 | if (null != orgIds) { |
461 | 420 | for (String orgId : orgIds) { |
462 | 622 | AdminOrgInfo subjectOrg = new AdminOrgInfo(); |
463 | 622 | subjectOrg.setType(type); |
464 | 622 | subjectOrg.setOrgId(orgId); |
465 | 622 | clu.getAdminOrgs().add(subjectOrg); |
466 | 622 | } |
467 | |
} |
468 | 420 | return clu; |
469 | |
} |
470 | |
|
471 | |
|
472 | |
|
473 | |
|
474 | |
|
475 | |
|
476 | |
|
477 | |
|
478 | |
|
479 | |
public List<String> assembleResultOptions(String cluId) throws AssemblyException { |
480 | 60 | List<String> resultOptions = null; |
481 | |
try{ |
482 | 60 | List<CluResultInfo> cluResults = luService.getCluResultByClu(cluId); |
483 | |
|
484 | 60 | List<String> resultTypes = new ArrayList<String>(); |
485 | 60 | resultTypes.add(ProgramAssemblerConstants.DEGREE_RESULTS); |
486 | 60 | resultTypes.add(ProgramAssemblerConstants.CERTIFICATE_RESULTS); |
487 | |
|
488 | 60 | resultOptions = cluAssemblerUtils.assembleCluResults(resultTypes, cluResults); |
489 | |
|
490 | 0 | } catch (DoesNotExistException e){ |
491 | 0 | } catch (Exception e) { |
492 | 0 | throw new AssemblyException("Error getting major results", e); |
493 | 60 | } |
494 | 60 | return resultOptions; |
495 | |
} |
496 | |
|
497 | |
|
498 | |
|
499 | |
|
500 | |
|
501 | |
|
502 | |
|
503 | |
|
504 | |
|
505 | |
public ProgramAtpAssembly assembleAtps(CluInfo clu, ProgramAtpAssembly program) throws AssemblyException { |
506 | |
|
507 | 135 | if (clu.getExpectedFirstAtp() != null) { |
508 | 114 | program.setStartTerm(clu.getExpectedFirstAtp()); |
509 | |
} |
510 | 135 | if (clu.getLastAtp() != null) { |
511 | 114 | program.setEndTerm(clu.getLastAtp()); |
512 | |
} |
513 | 135 | if (clu.getLastAdmitAtp() != null) { |
514 | 114 | program.setEndProgramEntryTerm(clu.getLastAdmitAtp()); |
515 | |
} |
516 | 135 | return program; |
517 | |
} |
518 | |
|
519 | |
|
520 | |
|
521 | |
|
522 | |
|
523 | |
|
524 | |
|
525 | |
|
526 | |
|
527 | |
|
528 | |
public CluInfo disassembleAtps(CluInfo clu, ProgramAtpAssembly program, NodeOperation operation) throws AssemblyException { |
529 | |
|
530 | 52 | clu.setExpectedFirstAtp(program.getStartTerm()); |
531 | 52 | clu.setLastAtp(program.getEndTerm()); |
532 | 52 | clu.setLastAdmitAtp(program.getEndProgramEntryTerm()); |
533 | |
|
534 | 52 | return clu; |
535 | |
|
536 | |
} |
537 | |
|
538 | |
|
539 | |
|
540 | |
|
541 | |
|
542 | |
|
543 | |
|
544 | |
|
545 | |
|
546 | |
public ProgramPublicationAssembly assemblePublications(CluInfo clu, ProgramPublicationAssembly program) throws AssemblyException { |
547 | |
|
548 | |
|
549 | 116 | if (clu.getReferenceURL() != null) { |
550 | 116 | program.setReferenceURL(clu.getReferenceURL()); |
551 | |
} |
552 | |
|
553 | |
try { |
554 | 116 | List<CluPublicationInfo> cluPublications = luService.getCluPublicationsByCluId(clu.getId()); |
555 | |
|
556 | 116 | List<String> targets = new ArrayList<String>(); |
557 | |
|
558 | 116 | for (CluPublicationInfo cluPublication : cluPublications) { |
559 | 104 | if (cluPublication.getType().equals(ProgramAssemblerConstants.CATALOG)) { |
560 | 83 | assembleCatalogDescr(program, cluPublication); |
561 | |
} |
562 | |
else { |
563 | 21 | targets.add(cluPublication.getType()); |
564 | |
} |
565 | |
} |
566 | |
|
567 | 116 | if (targets != null && !targets.isEmpty()) { |
568 | 12 | program.setCatalogPublicationTargets(targets); |
569 | |
} |
570 | 0 | } catch (DoesNotExistException e) { |
571 | 0 | } catch (InvalidParameterException e) { |
572 | 0 | } catch (MissingParameterException e) { |
573 | 0 | } catch (OperationFailedException e) { |
574 | 0 | throw new AssemblyException("Error getting publication targets", e); |
575 | 116 | } |
576 | 116 | return program; |
577 | |
} |
578 | |
|
579 | |
private void assembleCatalogDescr(ProgramPublicationAssembly program, CluPublicationInfo cluPublication) { |
580 | |
|
581 | 83 | for (FieldInfo fieldInfo : cluPublication.getVariants()) { |
582 | 73 | if (fieldInfo.getId().equals(ProgramAssemblerConstants.CATALOG_DESCR)) { |
583 | 73 | RichTextInfo desc = new RichTextInfo(); |
584 | 73 | desc.setPlain(fieldInfo.getValue()); |
585 | 73 | desc.setFormatted(fieldInfo.getValue()); |
586 | 73 | program.setCatalogDescr(desc); |
587 | 73 | break; |
588 | |
} |
589 | |
} |
590 | 83 | } |
591 | |
|
592 | |
private List<BaseDTOAssemblyNode<?, ?>> disassembleCatalogDescr(ProgramPublicationAssembly program, NodeOperation operation) throws AssemblyException { |
593 | |
|
594 | 50 | List<BaseDTOAssemblyNode<?, ?>> results = new ArrayList<BaseDTOAssemblyNode<?, ?>>(); |
595 | |
|
596 | 50 | CluPublicationInfo currentPubInfo = null; |
597 | |
|
598 | |
try { |
599 | |
|
600 | |
|
601 | 50 | if (!NodeOperation.CREATE.equals(operation)) { |
602 | 34 | List<CluPublicationInfo> pubs = luService.getCluPublicationsByCluId(program.getId()); |
603 | 34 | for (CluPublicationInfo pubInfo : pubs) { |
604 | 30 | if (pubInfo.getType().equals(ProgramAssemblerConstants.CATALOG)) { |
605 | 19 | currentPubInfo = pubInfo; |
606 | |
} |
607 | |
} |
608 | |
} |
609 | |
|
610 | 50 | if (program.getCatalogDescr() != null) { |
611 | |
|
612 | 43 | if (NodeOperation.CREATE == operation |
613 | |
|| (NodeOperation.UPDATE == operation && currentPubInfo == null )) { |
614 | |
|
615 | 24 | CluPublicationInfo pubInfo = buildCluPublicationInfo(program.getId(), ProgramAssemblerConstants.CATALOG); |
616 | 24 | pubInfo.setState(program.getState()); |
617 | 24 | FieldInfo variant = new FieldInfo(); |
618 | 24 | variant.setId(ProgramAssemblerConstants.CATALOG_DESCR); |
619 | 24 | variant.setValue(program.getCatalogDescr() .getPlain()); |
620 | 24 | pubInfo.getVariants().add(variant); |
621 | |
|
622 | 24 | BaseDTOAssemblyNode<Object, CluPublicationInfo> pubNode = new BaseDTOAssemblyNode<Object, CluPublicationInfo>( |
623 | |
null); |
624 | 24 | pubNode.setNodeData(pubInfo); |
625 | 24 | pubNode.setOperation(NodeOperation.CREATE); |
626 | |
|
627 | 24 | results.add(pubNode); |
628 | 24 | } else if (NodeOperation.UPDATE == operation |
629 | |
&& currentPubInfo != null) { |
630 | |
|
631 | 19 | CluPublicationInfo pubInfo = currentPubInfo; |
632 | 19 | pubInfo.setState(program.getState()); |
633 | 19 | for (FieldInfo fieldInfo : pubInfo.getVariants()) { |
634 | 19 | if (fieldInfo.getId().equals(ProgramAssemblerConstants.CATALOG_DESCR)) { |
635 | 19 | fieldInfo.setValue(program.getCatalogDescr() .getPlain()); |
636 | 19 | break; |
637 | |
} |
638 | |
} |
639 | |
|
640 | 19 | BaseDTOAssemblyNode<Object, CluPublicationInfo> pubNode = new BaseDTOAssemblyNode<Object, CluPublicationInfo>( |
641 | |
null); |
642 | 19 | pubNode.setNodeData(pubInfo); |
643 | 19 | pubNode.setOperation(NodeOperation.UPDATE); |
644 | |
|
645 | 19 | results.add(pubNode); |
646 | |
|
647 | 19 | } |
648 | 0 | else if (NodeOperation.DELETE == operation ) { |
649 | |
|
650 | 0 | deletePublicationInfo(results, currentPubInfo); |
651 | |
} |
652 | |
} |
653 | 0 | } catch (Exception e) { |
654 | 0 | throw new AssemblyException(e); |
655 | 50 | } |
656 | 50 | return results; |
657 | |
} |
658 | |
|
659 | |
private void deletePublicationInfo(List<BaseDTOAssemblyNode<?, ?>> results, CluPublicationInfo currentPubInfo) { |
660 | 0 | CluPublicationInfo descrToDelete = new CluPublicationInfo(); |
661 | 0 | descrToDelete.setId(currentPubInfo.getId()); |
662 | 0 | BaseDTOAssemblyNode<Object, CluPublicationInfo> pubToDeleteNode = new BaseDTOAssemblyNode<Object, CluPublicationInfo>( |
663 | |
null); |
664 | 0 | pubToDeleteNode.setNodeData(descrToDelete); |
665 | 0 | pubToDeleteNode.setOperation(NodeOperation.DELETE); |
666 | 0 | results.add(pubToDeleteNode); |
667 | 0 | } |
668 | |
|
669 | |
|
670 | |
|
671 | |
|
672 | |
|
673 | |
|
674 | |
|
675 | |
|
676 | |
|
677 | |
|
678 | |
public CluInfo disassemblePublications(CluInfo clu, ProgramPublicationAssembly program, NodeOperation operation, BaseDTOAssemblyNode<?, ?> result) throws AssemblyException { |
679 | |
|
680 | 50 | clu.setReferenceURL(program.getReferenceURL()); |
681 | 50 | clu.setState(program.getState()); |
682 | |
|
683 | 50 | List<BaseDTOAssemblyNode<?, ?>> targetResults = disassemblePublicationTargets(program, operation); |
684 | 50 | if (targetResults != null && targetResults.size()> 0) { |
685 | 21 | result.getChildNodes().addAll(targetResults); |
686 | |
} |
687 | |
|
688 | 50 | List<BaseDTOAssemblyNode<?, ?>> descrResults = disassembleCatalogDescr(program, operation) ; |
689 | 50 | if (descrResults != null && descrResults.size()> 0) { |
690 | 43 | result.getChildNodes().addAll(descrResults); |
691 | |
} |
692 | |
|
693 | 50 | return clu; |
694 | |
|
695 | |
} |
696 | |
|
697 | |
|
698 | |
|
699 | |
|
700 | |
|
701 | |
|
702 | |
|
703 | |
|
704 | |
|
705 | |
|
706 | |
public List<BaseDTOAssemblyNode<?,?>> disassembleCredentialProgram(ProgramCredentialAssembly program, NodeOperation operation, String relationType) throws AssemblyException { |
707 | |
|
708 | 11 | List<BaseDTOAssemblyNode<?, ?>> results = new ArrayList<BaseDTOAssemblyNode<?, ?>>(); |
709 | |
|
710 | |
try { |
711 | 11 | CluInfo credentialClu = luService.getClu(program.getCredentialProgramId()); |
712 | 0 | } catch (DoesNotExistException e) { |
713 | 0 | } catch (Exception e) { |
714 | 0 | throw new AssemblyException("Credential Clu does not exist for " + program.getCredentialProgramId()); |
715 | 11 | } |
716 | |
|
717 | 11 | Map<String, String> currentRelations = new HashMap<String, String>(); |
718 | |
|
719 | 11 | if (!NodeOperation.CREATE.equals(operation)) { |
720 | |
try { |
721 | 8 | List<CluCluRelationInfo> cluRelations = luService.getCluCluRelationsByClu(program.getId()); |
722 | 8 | for (CluCluRelationInfo cluRelation : cluRelations) { |
723 | 32 | if (relationType.equals(cluRelation.getType()) ) { |
724 | 6 | currentRelations.put(cluRelation.getRelatedCluId(), cluRelation.getId()); |
725 | |
} |
726 | |
} |
727 | 0 | } catch (DoesNotExistException e) { |
728 | 0 | } catch (InvalidParameterException e) { |
729 | 0 | } catch (MissingParameterException e) { |
730 | 0 | } catch (OperationFailedException e) { |
731 | 0 | throw new AssemblyException("Error getting related clus", e); |
732 | 8 | } |
733 | |
} |
734 | |
|
735 | |
|
736 | |
|
737 | 11 | if (NodeOperation.CREATE == operation |
738 | |
|| (NodeOperation.UPDATE == operation && !currentRelations.containsKey(program.getCredentialProgramId()) )) { |
739 | |
|
740 | 11 | CluCluRelationInfo relation = new CluCluRelationInfo(); |
741 | 11 | relation.setCluId(program.getCredentialProgramId()); |
742 | 11 | relation.setRelatedCluId(program.getId()); |
743 | 11 | relation.setType(relationType); |
744 | |
|
745 | |
|
746 | 11 | relation.setState(DtoConstants.STATE_ACTIVE); |
747 | |
|
748 | 11 | BaseDTOAssemblyNode<Object, CluCluRelationInfo> relationNode = new BaseDTOAssemblyNode<Object, CluCluRelationInfo>( |
749 | |
null); |
750 | 11 | relationNode.setNodeData(relation); |
751 | 11 | relationNode.setOperation(NodeOperation.CREATE); |
752 | |
|
753 | 11 | results.add(relationNode); |
754 | 11 | } else if (NodeOperation.UPDATE == operation |
755 | |
&& currentRelations.containsKey(program.getCredentialProgramId())) { |
756 | |
|
757 | |
|
758 | |
|
759 | |
|
760 | 0 | currentRelations.remove(program.getCredentialProgramId()); |
761 | 0 | } else if (NodeOperation.DELETE == operation |
762 | |
&& currentRelations.containsKey(program.getId())) { |
763 | |
|
764 | 0 | CluCluRelationInfo relationToDelete = new CluCluRelationInfo(); |
765 | 0 | relationToDelete.setId( currentRelations.get(program.getId()) ); |
766 | 0 | BaseDTOAssemblyNode<Object, CluCluRelationInfo> relationToDeleteNode = new BaseDTOAssemblyNode<Object, CluCluRelationInfo>( |
767 | |
null); |
768 | 0 | relationToDeleteNode.setNodeData(relationToDelete); |
769 | 0 | relationToDeleteNode.setOperation(NodeOperation.DELETE); |
770 | 0 | results.add(relationToDeleteNode); |
771 | |
|
772 | |
|
773 | |
|
774 | 0 | currentRelations.remove(program.getId()); |
775 | |
} |
776 | |
|
777 | 11 | if(currentRelations != null && currentRelations.size() > 0){ |
778 | 6 | for (Map.Entry<String, String> entry : currentRelations.entrySet()) { |
779 | |
|
780 | |
|
781 | 6 | CluCluRelationInfo relationToDelete = new CluCluRelationInfo(); |
782 | 6 | relationToDelete.setId( entry.getValue() ); |
783 | 6 | BaseDTOAssemblyNode<Object, CluCluRelationInfo> relationToDeleteNode = new BaseDTOAssemblyNode<Object, CluCluRelationInfo>( |
784 | |
null); |
785 | 6 | relationToDeleteNode.setNodeData(relationToDelete); |
786 | 6 | relationToDeleteNode.setOperation(NodeOperation.DELETE); |
787 | 6 | results.add(relationToDeleteNode); |
788 | 6 | } |
789 | |
} |
790 | 11 | return results; |
791 | |
} |
792 | |
|
793 | |
public List<BaseDTOAssemblyNode<?, ?>> addRelationNodes(String cluId, String relatedCluId, String relationType, NodeOperation operation)throws AssemblyException{ |
794 | 0 | Map<String, String> currentRelations = null; |
795 | 0 | List<BaseDTOAssemblyNode<?, ?>> results = new ArrayList<BaseDTOAssemblyNode<?, ?>>(); |
796 | |
|
797 | 0 | if (!NodeOperation.CREATE.equals(operation)) { |
798 | 0 | currentRelations = getCluCluRelations(cluId, relationType); |
799 | |
} |
800 | |
|
801 | |
|
802 | 0 | if (NodeOperation.CREATE == operation |
803 | |
|| (NodeOperation.UPDATE == operation && !currentRelations.containsKey(relatedCluId) )) { |
804 | |
|
805 | 0 | addCreateRelationNode(cluId, relatedCluId, relationType, results); |
806 | 0 | } else if (NodeOperation.UPDATE == operation |
807 | |
&& currentRelations.containsKey(relatedCluId)) { |
808 | |
|
809 | |
|
810 | |
|
811 | |
|
812 | 0 | currentRelations.remove(relatedCluId); |
813 | 0 | } else if (NodeOperation.DELETE == operation |
814 | |
&& currentRelations.containsKey(relatedCluId)) { |
815 | |
|
816 | 0 | addDeleteRelationNodes(currentRelations, results); |
817 | |
|
818 | |
|
819 | |
|
820 | 0 | currentRelations.remove(relatedCluId); |
821 | |
} |
822 | |
|
823 | 0 | if(currentRelations != null && currentRelations.size() > 0){ |
824 | 0 | for (Map.Entry<String, String> entry : currentRelations.entrySet()) { |
825 | |
|
826 | |
|
827 | 0 | CluCluRelationInfo relationToDelete = new CluCluRelationInfo(); |
828 | 0 | relationToDelete.setId( entry.getValue() ); |
829 | 0 | BaseDTOAssemblyNode<Object, CluCluRelationInfo> relationToDeleteNode = new BaseDTOAssemblyNode<Object, CluCluRelationInfo>( |
830 | |
null); |
831 | 0 | relationToDeleteNode.setNodeData(relationToDelete); |
832 | 0 | relationToDeleteNode.setOperation(NodeOperation.DELETE); |
833 | 0 | results.add(relationToDeleteNode); |
834 | 0 | } |
835 | |
} |
836 | 0 | return results; |
837 | |
} |
838 | |
public List<BaseDTOAssemblyNode<?, ?>> addAllRelationNodes(String cluId, String relatedCluId, String relationType, NodeOperation operation, Map<String, String> currentRelations)throws AssemblyException{ |
839 | 29 | List<BaseDTOAssemblyNode<?, ?>> results = new ArrayList<BaseDTOAssemblyNode<?, ?>>(); |
840 | |
|
841 | 29 | if (NodeOperation.CREATE == operation |
842 | |
|| (NodeOperation.UPDATE == operation && !currentRelations.containsKey(relatedCluId) )) { |
843 | |
|
844 | 27 | addCreateRelationNode(cluId, relatedCluId, relationType, results); |
845 | 2 | } else if (NodeOperation.UPDATE == operation |
846 | |
&& currentRelations.containsKey(relatedCluId)) { |
847 | |
|
848 | |
|
849 | |
|
850 | |
|
851 | 2 | currentRelations.remove(relatedCluId); |
852 | 0 | } else if (NodeOperation.DELETE == operation |
853 | |
&& currentRelations.containsKey(relatedCluId)) { |
854 | |
|
855 | 0 | addDeleteRelationNodes(currentRelations, results); |
856 | |
|
857 | |
|
858 | |
|
859 | 0 | currentRelations.remove(relatedCluId); |
860 | |
} |
861 | |
|
862 | 29 | return results; |
863 | |
} |
864 | |
public Map<String, String> getCluCluRelations(String cluId, String relationType) throws AssemblyException{ |
865 | 3 | Map<String, String> currentRelations = new HashMap<String, String>(); |
866 | |
|
867 | |
try { |
868 | 3 | List<CluCluRelationInfo> cluRelations = luService.getCluCluRelationsByClu(cluId); |
869 | |
|
870 | 3 | for (CluCluRelationInfo cluRelation : cluRelations) { |
871 | 13 | if (relationType.equals(cluRelation.getType())) { |
872 | 4 | currentRelations.put(cluRelation.getRelatedCluId(), cluRelation.getId()); |
873 | |
} |
874 | |
} |
875 | 0 | } catch (DoesNotExistException e) { |
876 | 0 | } catch (InvalidParameterException e) { |
877 | 0 | } catch (MissingParameterException e) { |
878 | 0 | } catch (OperationFailedException e) { |
879 | 0 | throw new AssemblyException("Error getting related clus", e); |
880 | 3 | } |
881 | |
|
882 | 3 | return currentRelations; |
883 | |
} |
884 | |
|
885 | |
public Map<String, CluCluRelationInfo> getCluCluActiveRelations(String cluId, String relationType) throws AssemblyException{ |
886 | 22 | Map<String, CluCluRelationInfo> currentRelations = new HashMap<String, CluCluRelationInfo>(); |
887 | |
|
888 | |
try { |
889 | 22 | List<CluCluRelationInfo> cluRelations = luService.getCluCluRelationsByClu(cluId); |
890 | |
|
891 | 22 | for (CluCluRelationInfo cluRelation : cluRelations) { |
892 | 97 | if (relationType.equals(cluRelation.getType()) && (!cluRelation.getState().isEmpty() && cluRelation.getState().equalsIgnoreCase(DtoConstants.STATE_ACTIVE))) { |
893 | 47 | currentRelations.put(cluRelation.getRelatedCluId(), cluRelation); |
894 | |
} |
895 | |
} |
896 | 0 | } catch (DoesNotExistException e) { |
897 | 0 | } catch (InvalidParameterException e) { |
898 | 0 | } catch (MissingParameterException e) { |
899 | 0 | } catch (OperationFailedException e) { |
900 | 0 | throw new AssemblyException("Error getting related clus", e); |
901 | 22 | } |
902 | |
|
903 | 22 | return currentRelations; |
904 | |
} |
905 | |
|
906 | |
public void addCreateRelationNode(String cluId, String relatedCluId, String relationType, List<BaseDTOAssemblyNode<?, ?>> results){ |
907 | 34 | CluCluRelationInfo relation = new CluCluRelationInfo(); |
908 | 34 | relation.setCluId(cluId); |
909 | 34 | relation.setRelatedCluId(relatedCluId); |
910 | 34 | relation.setType(relationType); |
911 | |
|
912 | |
|
913 | |
|
914 | |
|
915 | 34 | relation.setState(DtoConstants.STATE_ACTIVE); |
916 | |
|
917 | 34 | BaseDTOAssemblyNode<Object, CluCluRelationInfo> relationNode = new BaseDTOAssemblyNode<Object, CluCluRelationInfo>( |
918 | |
null); |
919 | 34 | relationNode.setNodeData(relation); |
920 | 34 | relationNode.setOperation(NodeOperation.CREATE); |
921 | |
|
922 | 34 | results.add(relationNode); |
923 | |
|
924 | 34 | } |
925 | |
|
926 | |
public void addDeleteRelationNodes(Map<String, String> currentRelations, List<BaseDTOAssemblyNode<?, ?>> results){ |
927 | 0 | for (Map.Entry<String, String> entry : currentRelations.entrySet()) { |
928 | |
|
929 | |
|
930 | 0 | CluCluRelationInfo relationToDelete = new CluCluRelationInfo(); |
931 | 0 | relationToDelete.setId( entry.getValue() ); |
932 | 0 | BaseDTOAssemblyNode<Object, CluCluRelationInfo> relationToDeleteNode = new BaseDTOAssemblyNode<Object, CluCluRelationInfo>( |
933 | |
null); |
934 | 0 | relationToDeleteNode.setNodeData(relationToDelete); |
935 | 0 | relationToDeleteNode.setOperation(NodeOperation.DELETE); |
936 | 0 | results.add(relationToDeleteNode); |
937 | 0 | } |
938 | 0 | } |
939 | |
|
940 | |
public void addSuspendedRelationNodes(Map<String, CluCluRelationInfo> currentRelations, List<BaseDTOAssemblyNode<?, ?>> results){ |
941 | 1 | for (Map.Entry<String, CluCluRelationInfo> entry : currentRelations.entrySet()) { |
942 | 1 | CluCluRelationInfo suspendedRelation = new CluCluRelationInfo(); |
943 | 1 | suspendedRelation = entry.getValue(); |
944 | 1 | suspendedRelation.setState(DtoConstants.STATE_SUSPENDED); |
945 | 1 | BaseDTOAssemblyNode<Object, CluCluRelationInfo> suspendedRelationNode = new BaseDTOAssemblyNode<Object, CluCluRelationInfo>( |
946 | |
null); |
947 | 1 | suspendedRelationNode.setNodeData(suspendedRelation); |
948 | 1 | suspendedRelationNode.setOperation(NodeOperation.UPDATE); |
949 | 1 | results.add(suspendedRelationNode); |
950 | 1 | } |
951 | 1 | } |
952 | |
|
953 | |
private void addLuCodeFromProgram(String type, String value, List<LuCodeInfo> list) throws AssemblyException { |
954 | |
|
955 | 260 | if (value != null && !value.isEmpty()) { |
956 | 191 | LuCodeInfo code = new LuCodeInfo(); |
957 | 191 | code.setType(type); |
958 | 191 | code.setValue(value); |
959 | 191 | code.setAttributes(new HashMap<String, String>()); |
960 | 191 | list.add(code); |
961 | |
} |
962 | 260 | } |
963 | |
|
964 | |
|
965 | |
|
966 | |
|
967 | |
|
968 | |
|
969 | |
|
970 | |
|
971 | |
|
972 | |
|
973 | |
private List<BaseDTOAssemblyNode<?, ?>> disassemblePublicationTargets(ProgramPublicationAssembly program, NodeOperation operation) throws AssemblyException { |
974 | |
|
975 | 50 | List<BaseDTOAssemblyNode<?, ?>> results = new ArrayList<BaseDTOAssemblyNode<?, ?>>(); |
976 | |
|
977 | 50 | Map<String, CluPublicationInfo> currentPubs = new HashMap<String, CluPublicationInfo>(); |
978 | 50 | if (!NodeOperation.CREATE.equals(operation)) { |
979 | |
|
980 | |
|
981 | |
try { |
982 | 34 | List<CluPublicationInfo> cluPubs = luService.getCluPublicationsByCluId(program.getId()); |
983 | 34 | for(CluPublicationInfo cluPub : cluPubs){ |
984 | 30 | cluPub.setState(program.getState()); |
985 | 30 | if (!cluPub.getType().equals(ProgramAssemblerConstants.CATALOG)) { |
986 | 11 | currentPubs.put(cluPub.getType(), cluPub); |
987 | |
} |
988 | |
} |
989 | 0 | } catch (DoesNotExistException e) { |
990 | 0 | } catch (Exception e) { |
991 | 0 | throw new AssemblyException("Error finding publications"); |
992 | 34 | } |
993 | |
} |
994 | |
|
995 | 50 | if (program.getCatalogPublicationTargets() != null && !program.getCatalogPublicationTargets().isEmpty()) { |
996 | 21 | for (String publicationType : program.getCatalogPublicationTargets()) { |
997 | |
|
998 | 42 | if (NodeOperation.CREATE == operation |
999 | |
|| (NodeOperation.UPDATE == operation && !currentPubs.containsKey(publicationType) )) { |
1000 | |
|
1001 | 31 | CluPublicationInfo pubInfo = buildCluPublicationInfo(program.getId(), publicationType); |
1002 | |
|
1003 | |
|
1004 | 31 | pubInfo.setState(program.getState()); |
1005 | 31 | BaseDTOAssemblyNode<Object, CluPublicationInfo> pubNode = new BaseDTOAssemblyNode<Object, CluPublicationInfo>( |
1006 | |
null); |
1007 | 31 | pubNode.setNodeData(pubInfo); |
1008 | 31 | pubNode.setOperation(NodeOperation.CREATE); |
1009 | |
|
1010 | 31 | results.add(pubNode); |
1011 | 31 | } else if (NodeOperation.UPDATE == operation |
1012 | |
&& currentPubs.containsKey(publicationType)) { |
1013 | |
|
1014 | |
|
1015 | |
|
1016 | 11 | CluPublicationInfo pubInfo = currentPubs.remove(publicationType); |
1017 | 11 | pubInfo.setState(program.getState()); |
1018 | 11 | BaseDTOAssemblyNode<Object, CluPublicationInfo> pubNode = new BaseDTOAssemblyNode<Object, CluPublicationInfo>( |
1019 | |
null); |
1020 | 11 | pubNode.setNodeData(pubInfo); |
1021 | 11 | pubNode.setOperation(NodeOperation.UPDATE); |
1022 | 11 | results.add(pubNode); |
1023 | 11 | } else if (NodeOperation.DELETE == operation |
1024 | |
&& currentPubs.containsKey(publicationType)) { |
1025 | |
|
1026 | 0 | CluPublicationInfo pubToDelete = new CluPublicationInfo(); |
1027 | 0 | pubToDelete.setId(publicationType); |
1028 | 0 | BaseDTOAssemblyNode<Object, CluPublicationInfo> pubToDeleteNode = new BaseDTOAssemblyNode<Object, CluPublicationInfo>( |
1029 | |
null); |
1030 | 0 | pubToDeleteNode.setNodeData(pubToDelete); |
1031 | 0 | pubToDeleteNode.setOperation(NodeOperation.DELETE); |
1032 | 0 | results.add(pubToDeleteNode); |
1033 | |
|
1034 | 0 | currentPubs.remove(publicationType); |
1035 | 42 | } |
1036 | |
} |
1037 | |
} |
1038 | |
|
1039 | |
|
1040 | 50 | for (Map.Entry<String, CluPublicationInfo> entry : currentPubs.entrySet()) { |
1041 | |
|
1042 | |
|
1043 | 0 | deletePublicationInfo(results, entry.getValue()); |
1044 | |
} |
1045 | |
|
1046 | 50 | return results; |
1047 | |
} |
1048 | |
|
1049 | |
private CluPublicationInfo buildCluPublicationInfo(String programId, String publicationType) throws AssemblyException { |
1050 | |
|
1051 | 55 | CluPublicationInfo pubInfo = new CluPublicationInfo(); |
1052 | 55 | pubInfo.setType(publicationType); |
1053 | 55 | pubInfo.setCluId(programId); |
1054 | |
|
1055 | 55 | return pubInfo; |
1056 | |
} |
1057 | |
|
1058 | |
|
1059 | |
public void setLuService(LuService luService) { |
1060 | 1 | this.luService = luService; |
1061 | 1 | } |
1062 | |
|
1063 | |
public void setCluAssemblerUtils(CluAssemblerUtils cluAssemblerUtils) { |
1064 | 1 | this.cluAssemblerUtils = cluAssemblerUtils; |
1065 | 1 | } |
1066 | |
|
1067 | |
public String getCredentialProgramID(String cluId) throws AssemblyException { |
1068 | |
|
1069 | 14 | List<String> credentialProgramIDs = null; |
1070 | |
try { |
1071 | 14 | credentialProgramIDs = luService.getCluIdsByRelation(cluId, ProgramAssemblerConstants.HAS_MAJOR_PROGRAM); |
1072 | 0 | } catch (Exception e) { |
1073 | 0 | throw new AssemblyException(e); |
1074 | 14 | } |
1075 | |
|
1076 | |
|
1077 | 14 | if (null == credentialProgramIDs || credentialProgramIDs.isEmpty()) { |
1078 | 0 | throw new AssemblyException("Program with ID == " + cluId + " has no Credential Program associated with it."); |
1079 | 14 | } else if (credentialProgramIDs.size() > 1) { |
1080 | 0 | throw new AssemblyException("Program with ID == " + cluId + " has more than one Credential Program associated with it."); |
1081 | |
} |
1082 | 14 | return credentialProgramIDs.get(0); |
1083 | |
} |
1084 | |
|
1085 | |
} |