1 | |
package org.kuali.student.enrollment.class2.courseoffering.service.assembler; |
2 | |
|
3 | |
import org.kuali.student.enrollment.class2.courseoffering.service.transformer.ActivityOfferingTransformer; |
4 | |
import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo; |
5 | |
import org.kuali.student.enrollment.courseoffering.dto.OfferingInstructorInfo; |
6 | |
import org.kuali.student.enrollment.lpr.dto.LuiPersonRelationInfo; |
7 | |
import org.kuali.student.enrollment.lpr.service.LuiPersonRelationService; |
8 | |
import org.kuali.student.enrollment.lui.dto.LuiInfo; |
9 | |
import org.kuali.student.r2.common.assembler.AssemblyException; |
10 | |
import org.kuali.student.r2.common.assembler.DTOAssembler; |
11 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
12 | |
import org.kuali.student.r2.common.exceptions.*; |
13 | |
import org.kuali.student.r2.common.util.constants.LuiPersonRelationServiceConstants; |
14 | |
|
15 | |
import java.util.ArrayList; |
16 | |
import java.util.List; |
17 | |
|
18 | 0 | public class ActivityOfferingAssembler implements DTOAssembler<ActivityOfferingInfo, LuiInfo> { |
19 | |
|
20 | |
private LuiPersonRelationService lprService; |
21 | |
|
22 | |
private ActivityOfferingTransformer activityTransformer; |
23 | |
|
24 | |
public ActivityOfferingTransformer getActivityTransformer() { |
25 | 0 | return activityTransformer; |
26 | |
} |
27 | |
|
28 | |
public void setActivityTransformer(ActivityOfferingTransformer activityTransformer) { |
29 | 0 | this.activityTransformer = activityTransformer; |
30 | 0 | } |
31 | |
|
32 | |
public LuiPersonRelationService getLprService() { |
33 | 0 | return lprService; |
34 | |
} |
35 | |
|
36 | |
public void setLprService(LuiPersonRelationService lprService) { |
37 | 0 | this.lprService = lprService; |
38 | 0 | } |
39 | |
|
40 | |
@Override |
41 | |
public ActivityOfferingInfo assemble(LuiInfo lui, ContextInfo context) throws AssemblyException { |
42 | 0 | ActivityOfferingInfo ao = activityTransformer.transform(lui); |
43 | |
|
44 | 0 | assembleInstructors(ao, lui.getId(), context); |
45 | |
|
46 | 0 | return ao; |
47 | |
|
48 | |
} |
49 | |
|
50 | |
private void assembleInstructors(ActivityOfferingInfo ao, String luiId, ContextInfo context) throws AssemblyException { |
51 | 0 | List<LuiPersonRelationInfo> lprs = null; |
52 | |
; |
53 | |
try { |
54 | 0 | lprs = lprService.getLprsByLui(luiId, context); |
55 | 0 | } catch (DoesNotExistException e) { |
56 | 0 | throw new AssemblyException("DoesNotExistException: " + e.getMessage()); |
57 | 0 | } catch (InvalidParameterException e) { |
58 | 0 | throw new AssemblyException("InvalidParameterException: " + e.getMessage()); |
59 | 0 | } catch (MissingParameterException e) { |
60 | 0 | throw new AssemblyException("MissingParameterException: " + e.getMessage()); |
61 | 0 | } catch (OperationFailedException e) { |
62 | 0 | throw new AssemblyException("OperationFailedException: " + e.getMessage()); |
63 | 0 | } catch (PermissionDeniedException e) { |
64 | 0 | throw new AssemblyException("PermissionDeniedException: " + e.getMessage()); |
65 | 0 | } |
66 | |
|
67 | 0 | if (lprs != null && !lprs.isEmpty()) { |
68 | 0 | List<OfferingInstructorInfo> instructors = new ArrayList<OfferingInstructorInfo>(); |
69 | 0 | for (LuiPersonRelationInfo lpr : lprs) { |
70 | 0 | if (lpr != null && lpr.getTypeKey() != null && lpr.getTypeKey().equals(LuiPersonRelationServiceConstants.INSTRUCTOR_MAIN_TYPE_KEY)) { |
71 | 0 | instructors.add( activityTransformer.transformInstructorForActivityOffering(lpr)); |
72 | |
} |
73 | |
} |
74 | 0 | ao.setInstructors(instructors); |
75 | |
} |
76 | |
|
77 | 0 | } |
78 | |
|
79 | |
@Override |
80 | |
public LuiInfo disassemble(ActivityOfferingInfo ao, ContextInfo context) throws AssemblyException { |
81 | |
|
82 | 0 | LuiInfo lui = activityTransformer.transformActivityOfferingToLui(ao); |
83 | 0 | return lui; |
84 | |
|
85 | |
} |
86 | |
|
87 | |
} |