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