1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.enrollment.lpr.service.adapter.calculations; |
17 | |
|
18 | |
import org.kuali.student.common.exceptions.*; |
19 | |
import javax.servlet.http.HttpServletRequest; |
20 | |
import java.util.List; |
21 | |
import org.kuali.rice.kim.bo.entity.dto.KimPrincipalInfo; |
22 | |
import org.kuali.rice.kim.service.IdentityService; |
23 | |
import org.kuali.student.common.dto.ContextInfo; |
24 | |
import org.kuali.student.common.dto.StatusInfo; |
25 | |
import org.kuali.student.common.infc.HoldsIdentityService; |
26 | |
import org.kuali.student.enrollment.lpr.dto.LuiPersonRelationInfo; |
27 | |
import org.kuali.student.enrollment.lpr.service.decorators.LuiPersonRelationServiceDecorator; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public class LuiPersonRelationDefaultContextFromRequestAdapter |
38 | |
extends LuiPersonRelationServiceDecorator |
39 | |
implements HoldsIdentityService { |
40 | |
|
41 | |
private HttpServletRequest request; |
42 | |
private IdentityService identityService; |
43 | |
|
44 | |
|
45 | |
public HttpServletRequest getRequest() { |
46 | 0 | return request; |
47 | |
} |
48 | |
|
49 | |
public void setRequest(HttpServletRequest request) { |
50 | 0 | this.request = request; |
51 | 0 | } |
52 | |
|
53 | |
@Override |
54 | |
public IdentityService getIdentityService() { |
55 | 0 | return identityService; |
56 | |
} |
57 | |
|
58 | |
@Override |
59 | |
public void setIdentityService(IdentityService identityService) { |
60 | 0 | this.identityService = identityService; |
61 | 0 | } |
62 | |
|
63 | |
private ContextInfo defaultContext(ContextInfo context) { |
64 | 0 | if (context == null) { |
65 | 0 | context = new ContextInfo.Builder().build(); |
66 | |
} |
67 | 0 | if (context.getPrincipalId() == null) { |
68 | 0 | KimPrincipalInfo principalInfo = identityService.getPrincipalByPrincipalName(request.getRemoteUser()); |
69 | 0 | context = new ContextInfo.Builder(context).principalId(principalInfo.getPrincipalId()).build(); |
70 | |
} |
71 | 0 | if (context.getLocaleLanguage() == null) { |
72 | 0 | context = new ContextInfo.Builder(context).localeLanguage(request.getLocale().getLanguage()).build(); |
73 | |
} |
74 | |
|
75 | 0 | if (context.getLocaleRegion() == null) { |
76 | 0 | context = new ContextInfo.Builder(context).localeLanguage(request.getLocale().getCountry()).build(); |
77 | |
} |
78 | 0 | if (context.getLocaleVariant() == null) { |
79 | 0 | context = new ContextInfo.Builder(context).localeLanguage(request.getLocale().getVariant()).build(); |
80 | |
} |
81 | |
|
82 | 0 | return context; |
83 | |
} |
84 | |
|
85 | |
@Override |
86 | |
public String createLuiPersonRelation(String personId, |
87 | |
String luiId, |
88 | |
String luiPersonRelationType, |
89 | |
LuiPersonRelationInfo luiPersonRelationInfo, |
90 | |
ContextInfo context) |
91 | |
throws DataValidationErrorException, |
92 | |
AlreadyExistsException, |
93 | |
DoesNotExistException, |
94 | |
DisabledIdentifierException, |
95 | |
ReadOnlyException, |
96 | |
InvalidParameterException, |
97 | |
MissingParameterException, OperationFailedException, |
98 | |
PermissionDeniedException { |
99 | 0 | context = defaultContext(context); |
100 | 0 | return (getLprService().createLuiPersonRelation(personId, |
101 | |
luiId, |
102 | |
luiPersonRelationType, |
103 | |
luiPersonRelationInfo, |
104 | |
context)); |
105 | |
} |
106 | |
|
107 | |
@Override |
108 | |
public List<String> createBulkRelationshipsForPerson(String personId, |
109 | |
List<String> luiIdList, |
110 | |
String relationState, |
111 | |
String luiPersonRelationType, |
112 | |
LuiPersonRelationInfo luiPersonRelationInfo, |
113 | |
ContextInfo context) |
114 | |
throws DataValidationErrorException, |
115 | |
AlreadyExistsException, |
116 | |
DoesNotExistException, |
117 | |
DisabledIdentifierException, |
118 | |
ReadOnlyException, |
119 | |
InvalidParameterException, |
120 | |
MissingParameterException, |
121 | |
OperationFailedException, |
122 | |
PermissionDeniedException { |
123 | 0 | context = defaultContext(context); |
124 | 0 | return (getLprService().createBulkRelationshipsForPerson(personId, luiIdList, |
125 | |
relationState, |
126 | |
luiPersonRelationType, |
127 | |
luiPersonRelationInfo, |
128 | |
context)); |
129 | |
} |
130 | |
|
131 | |
@Override |
132 | |
public LuiPersonRelationInfo updateLuiPersonRelation( |
133 | |
String luiPersonRelationId, |
134 | |
LuiPersonRelationInfo luiPersonRelationInfo, |
135 | |
ContextInfo context) |
136 | |
throws DataValidationErrorException, |
137 | |
DoesNotExistException, |
138 | |
InvalidParameterException, |
139 | |
MissingParameterException, |
140 | |
ReadOnlyException, |
141 | |
OperationFailedException, |
142 | |
PermissionDeniedException, |
143 | |
VersionMismatchException { |
144 | 0 | context = defaultContext(context); |
145 | 0 | return (getLprService().updateLuiPersonRelation(luiPersonRelationId, |
146 | |
luiPersonRelationInfo, |
147 | |
context)); |
148 | |
} |
149 | |
|
150 | |
@Override |
151 | |
public StatusInfo deleteLuiPersonRelation(String luiPersonRelationId, |
152 | |
ContextInfo context) throws |
153 | |
DoesNotExistException, InvalidParameterException, MissingParameterException, |
154 | |
OperationFailedException, |
155 | |
PermissionDeniedException { |
156 | 0 | context = defaultContext(context); |
157 | 0 | return (getLprService().deleteLuiPersonRelation(luiPersonRelationId, context)); |
158 | |
} |
159 | |
|
160 | |
|
161 | |
|
162 | |
} |