Coverage Report - org.kuali.student.core.comments.ui.server.CommentRpcGwtServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
CommentRpcGwtServlet
0%
0/35
0%
0/24
2.182
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.core.comments.ui.server;
 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.IdentityManagementService;
 24  
 import org.kuali.student.common.dto.StatusInfo;
 25  
 import org.kuali.student.common.rice.StudentIdentityConstants;
 26  
 import org.kuali.student.common.rice.authorization.PermissionType;
 27  
 import org.kuali.student.common.ui.server.gwt.BaseRpcGwtServletAbstract;
 28  
 import org.kuali.student.core.comment.dto.CommentInfo;
 29  
 import org.kuali.student.core.comment.dto.CommentTypeInfo;
 30  
 import org.kuali.student.core.comment.service.CommentService;
 31  
 import org.kuali.student.core.comments.ui.client.service.CommentRpcService;
 32  
 
 33  0
 public class CommentRpcGwtServlet extends BaseRpcGwtServletAbstract<CommentService> implements CommentRpcService {
 34  
 
 35  
         private static final long serialVersionUID = 1L;
 36  
         private IdentityManagementService identityService;
 37  
         
 38  
         public IdentityManagementService getIdentityService() {
 39  0
         return identityService;
 40  
     }
 41  
 
 42  
     public void setIdentityService(IdentityManagementService identityService) {
 43  0
         this.identityService = identityService;
 44  0
     }
 45  
 
 46  
     @Override
 47  
         public CommentInfo addComment(String referenceId, String referenceTypeKey,
 48  
                         CommentInfo commentInfo) throws Exception {
 49  0
                 return service.addComment(referenceId, referenceTypeKey, commentInfo);
 50  
         }
 51  
 
 52  
         @Override
 53  
         public List<CommentInfo> getComments(String referenceId,
 54  
                         String referenceTypeKey) throws Exception {
 55  0
                 return service.getComments(referenceId, referenceTypeKey);
 56  
         }
 57  
 
 58  
         @Override
 59  
         public List<CommentInfo> getCommentsByType(String referenceId,
 60  
                         String referenceTypeKey, String commentTypeKey) throws Exception {
 61  0
                 return service.getCommentsByType(referenceId, referenceTypeKey, commentTypeKey);
 62  
         }
 63  
 
 64  
         @Override
 65  
         public CommentInfo updateComment(String referenceId,
 66  
                         String referenceTypeKey, CommentInfo commentInfo) throws Exception {
 67  0
                 return service.updateComment(referenceId, referenceTypeKey, commentInfo);
 68  
         }
 69  
 
 70  
         @Override
 71  
         public StatusInfo removeComment(String commentId, String referenceId,
 72  
                         String referenceTypeKey) throws Exception {
 73  0
                 return service.removeComment(commentId, referenceId, referenceTypeKey);
 74  
         }
 75  
 
 76  
         @Override
 77  
         public List<CommentTypeInfo> getCommentTypesForReferenceType(String referenceTypeKey) throws Exception {
 78  0
                 return service.getCommentTypesForReferenceType(referenceTypeKey);
 79  
         }
 80  
 
 81  
         @Override
 82  
     public Boolean isAuthorizedAddComment(String id, String referenceTypeKey) {
 83  0
                 if (id != null && (!"".equals(id.trim()))) {
 84  0
                         AttributeSet permissionDetails = new AttributeSet(StudentIdentityConstants.KS_REFERENCE_TYPE_KEY, referenceTypeKey);
 85  0
                         if (getPermissionService().isPermissionDefinedForTemplateName(PermissionType.ADD_COMMENT.getPermissionNamespace(), PermissionType.ADD_COMMENT.getPermissionTemplateName(), permissionDetails)) {
 86  0
                     AttributeSet roleQuals = new AttributeSet();
 87  0
                     roleQuals.put(referenceTypeKey, id);
 88  0
                     return Boolean.valueOf(getPermissionService().isAuthorizedByTemplateName(getCurrentUser(), PermissionType.ADD_COMMENT.getPermissionNamespace(), PermissionType.ADD_COMMENT.getPermissionTemplateName(), permissionDetails, roleQuals));
 89  
                         }
 90  
                 }
 91  0
                 return Boolean.TRUE;
 92  
     }
 93  
         
 94  
         private String nvl(String inString) {
 95  0
             return (inString == null)? "" : inString;
 96  
         }
 97  
 
 98  
     @Override
 99  
     public String getUserRealName(String principalName) {
 100  0
         KimEntityInfo kimEntityInfo = identityService.getEntityInfoByPrincipalName(principalName);
 101  0
         KimEntityNameInfo kimEntityNameInfo = (kimEntityInfo == null)? null : kimEntityInfo.getDefaultName();
 102  0
         StringBuilder name = new StringBuilder(); 
 103  0
         if (kimEntityNameInfo != null) {
 104  0
             if (!nvl(kimEntityNameInfo.getFirstName()).trim().isEmpty()) {
 105  0
                 if (!name.toString().isEmpty()) {
 106  0
                     name.append(" ");
 107  
                 }
 108  0
                 name.append(nvl(kimEntityNameInfo.getFirstName()));
 109  
             }
 110  
             
 111  0
             if (!nvl(kimEntityNameInfo.getMiddleName()).trim().isEmpty()) {
 112  0
                 if (!name.toString().isEmpty()) {
 113  0
                     name.append(" ");
 114  
                 }
 115  0
                 name.append(nvl(kimEntityNameInfo.getMiddleName()));
 116  
             }
 117  0
             if (!nvl(kimEntityNameInfo.getLastName()).trim().isEmpty()) {
 118  0
                 if (!name.toString().isEmpty()) {
 119  0
                     name.append(" ");
 120  
                 }
 121  0
                 name.append(nvl(kimEntityNameInfo.getLastName()));
 122  
             }
 123  
         }
 124  0
         return name.toString();
 125  
     }
 126  
 
 127  
 }