1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.core.comments.ui.server; |
17 | |
|
18 | |
import java.util.LinkedHashMap; |
19 | |
import java.util.List; |
20 | |
import java.util.Map; |
21 | |
import org.kuali.rice.kim.api.identity.IdentityService; |
22 | |
import org.kuali.rice.kim.api.identity.entity.Entity; |
23 | |
import org.kuali.rice.kim.api.identity.name.EntityNameContract; |
24 | |
|
25 | |
|
26 | |
import org.kuali.student.common.dto.StatusInfo; |
27 | |
import org.kuali.student.common.rice.StudentIdentityConstants; |
28 | |
import org.kuali.student.common.rice.authorization.PermissionType; |
29 | |
import org.kuali.student.common.ui.server.gwt.BaseRpcGwtServletAbstract; |
30 | |
import org.kuali.student.core.comment.dto.CommentInfo; |
31 | |
import org.kuali.student.core.comment.dto.CommentTypeInfo; |
32 | |
import org.kuali.student.core.comment.service.CommentService; |
33 | |
import org.kuali.student.core.comments.ui.client.service.CommentRpcService; |
34 | |
|
35 | 0 | public class CommentRpcGwtServlet extends BaseRpcGwtServletAbstract<CommentService> implements CommentRpcService { |
36 | |
|
37 | |
private static final long serialVersionUID = 1L; |
38 | |
private IdentityService identityService; |
39 | |
|
40 | |
public IdentityService getIdentityService() { |
41 | 0 | return identityService; |
42 | |
} |
43 | |
|
44 | |
public void setIdentityService(IdentityService identityService) { |
45 | 0 | this.identityService = identityService; |
46 | 0 | } |
47 | |
|
48 | |
@Override |
49 | |
public CommentInfo addComment(String referenceId, String referenceTypeKey, |
50 | |
CommentInfo commentInfo) throws Exception { |
51 | 0 | return service.addComment(referenceId, referenceTypeKey, commentInfo); |
52 | |
} |
53 | |
|
54 | |
@Override |
55 | |
public List<CommentInfo> getComments(String referenceId, |
56 | |
String referenceTypeKey) throws Exception { |
57 | 0 | return service.getComments(referenceId, referenceTypeKey); |
58 | |
} |
59 | |
|
60 | |
@Override |
61 | |
public List<CommentInfo> getCommentsByType(String referenceId, |
62 | |
String referenceTypeKey, String commentTypeKey) throws Exception { |
63 | 0 | return service.getCommentsByType(referenceId, referenceTypeKey, commentTypeKey); |
64 | |
} |
65 | |
|
66 | |
@Override |
67 | |
public CommentInfo updateComment(String referenceId, |
68 | |
String referenceTypeKey, CommentInfo commentInfo) throws Exception { |
69 | 0 | return service.updateComment(referenceId, referenceTypeKey, commentInfo); |
70 | |
} |
71 | |
|
72 | |
@Override |
73 | |
public StatusInfo removeComment(String commentId, String referenceId, |
74 | |
String referenceTypeKey) throws Exception { |
75 | 0 | return service.removeComment(commentId, referenceId, referenceTypeKey); |
76 | |
} |
77 | |
|
78 | |
@Override |
79 | |
public List<CommentTypeInfo> getCommentTypesForReferenceType(String referenceTypeKey) throws Exception { |
80 | 0 | return service.getCommentTypesForReferenceType(referenceTypeKey); |
81 | |
} |
82 | |
|
83 | |
@Override |
84 | |
public Boolean isAuthorizedAddComment(String id, String referenceTypeKey) { |
85 | 0 | if (id != null && (!"".equals(id.trim()))) { |
86 | 0 | Map<String,String> permissionDetails = new LinkedHashMap<String,String>(); |
87 | 0 | permissionDetails.put (StudentIdentityConstants.KS_REFERENCE_TYPE_KEY, referenceTypeKey); |
88 | 0 | if (getPermissionService().isPermissionDefinedByTemplate(PermissionType.ADD_COMMENT.getPermissionNamespace(), PermissionType.ADD_COMMENT.getPermissionTemplateName(), permissionDetails)) { |
89 | 0 | Map<String,String> roleQuals = new LinkedHashMap<String,String>(); |
90 | 0 | roleQuals.put(referenceTypeKey, id); |
91 | 0 | return Boolean.valueOf(getPermissionService().isAuthorizedByTemplate(getCurrentUser(), PermissionType.ADD_COMMENT.getPermissionNamespace(), PermissionType.ADD_COMMENT.getPermissionTemplateName(), permissionDetails, roleQuals)); |
92 | |
} |
93 | |
} |
94 | 0 | return Boolean.TRUE; |
95 | |
} |
96 | |
|
97 | |
private String nvl(String inString) { |
98 | 0 | return (inString == null)? "" : inString; |
99 | |
} |
100 | |
|
101 | |
@Override |
102 | |
public String getUserRealName(String userId) { |
103 | 0 | Entity kimEntityInfo = identityService.getEntityByPrincipalId(userId); |
104 | 0 | EntityNameContract kimEntityNameInfo = (kimEntityInfo == null)? null : kimEntityInfo.getDefaultName(); |
105 | 0 | StringBuilder name = new StringBuilder(); |
106 | 0 | if (kimEntityNameInfo != null) { |
107 | 0 | if (!nvl(kimEntityNameInfo.getFirstName()).trim().isEmpty()) { |
108 | 0 | if (!name.toString().isEmpty()) { |
109 | 0 | name.append(" "); |
110 | |
} |
111 | 0 | name.append(nvl(kimEntityNameInfo.getFirstName())); |
112 | |
} |
113 | |
|
114 | 0 | if (!nvl(kimEntityNameInfo.getMiddleName()).trim().isEmpty()) { |
115 | 0 | if (!name.toString().isEmpty()) { |
116 | 0 | name.append(" "); |
117 | |
} |
118 | 0 | name.append(nvl(kimEntityNameInfo.getMiddleName())); |
119 | |
} |
120 | 0 | if (!nvl(kimEntityNameInfo.getLastName()).trim().isEmpty()) { |
121 | 0 | if (!name.toString().isEmpty()) { |
122 | 0 | name.append(" "); |
123 | |
} |
124 | 0 | name.append(nvl(kimEntityNameInfo.getLastName())); |
125 | |
} |
126 | |
} |
127 | 0 | return name.toString(); |
128 | |
} |
129 | |
|
130 | |
} |