Coverage Report - org.kuali.student.common.ui.server.gwt.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.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  0
 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  0
         return identityService;
 39  
     }
 40  
 
 41  
     public void setIdentityService(IdentityService identityService) {
 42  0
         this.identityService = identityService;
 43  0
     }
 44  
 
 45  
     @Override
 46  
         public CommentInfo addComment(String referenceId, String referenceTypeKey,
 47  
                         CommentInfo commentInfo) throws Exception {
 48  0
                 return service.addComment(referenceId, referenceTypeKey, commentInfo);
 49  
         }
 50  
 
 51  
         @Override
 52  
         public List<CommentInfo> getComments(String referenceId,
 53  
                         String referenceTypeKey) throws Exception {
 54  0
                 return service.getComments(referenceId, referenceTypeKey);
 55  
         }
 56  
 
 57  
         @Override
 58  
         public List<CommentInfo> getCommentsByType(String referenceId,
 59  
                         String referenceTypeKey, String commentTypeKey) throws Exception {
 60  0
                 return service.getCommentsByType(referenceId, referenceTypeKey, commentTypeKey);
 61  
         }
 62  
 
 63  
         @Override
 64  
         public CommentInfo updateComment(String referenceId,
 65  
                         String referenceTypeKey, CommentInfo commentInfo) throws Exception {
 66  0
                 return service.updateComment(referenceId, referenceTypeKey, commentInfo);
 67  
         }
 68  
 
 69  
         @Override
 70  
         public StatusInfo removeComment(String commentId, String referenceId,
 71  
                         String referenceTypeKey) throws Exception {
 72  0
                 return service.removeComment(commentId, referenceId, referenceTypeKey);
 73  
         }
 74  
 
 75  
         @Override
 76  
         public List<CommentTypeInfo> getCommentTypesForReferenceType(String referenceTypeKey) throws Exception {
 77  0
                 return service.getCommentTypesForReferenceType(referenceTypeKey);
 78  
         }
 79  
 
 80  
         @Override
 81  
     public Boolean isAuthorizedAddComment(String id, String referenceTypeKey) {
 82  0
                 if (id != null && (!"".equals(id.trim()))) {
 83  0
                         AttributeSet permissionDetails = new AttributeSet(StudentIdentityConstants.KS_REFERENCE_TYPE_KEY, referenceTypeKey);
 84  0
                         if (getPermissionService().isPermissionDefinedForTemplateName(PermissionType.ADD_COMMENT.getPermissionNamespace(), PermissionType.ADD_COMMENT.getPermissionTemplateName(), permissionDetails)) {
 85  0
                     AttributeSet roleQuals = new AttributeSet();
 86  0
                     roleQuals.put(referenceTypeKey, id);
 87  0
                     return Boolean.valueOf(getPermissionService().isAuthorizedByTemplateName(getCurrentUser(), PermissionType.ADD_COMMENT.getPermissionNamespace(), PermissionType.ADD_COMMENT.getPermissionTemplateName(), permissionDetails, roleQuals));
 88  
                         }
 89  
                 }
 90  0
                 return Boolean.TRUE;
 91  
     }
 92  
         
 93  
         private String nvl(String inString) {
 94  0
             return (inString == null)? "" : inString;
 95  
         }
 96  
 
 97  
     @Override
 98  
     public String getUserRealName(String userId) {
 99  0
         KimEntityInfo kimEntityInfo = identityService.getEntityInfoByPrincipalId(userId);
 100  0
         KimEntityNameInfo kimEntityNameInfo = (kimEntityInfo == null)? null : kimEntityInfo.getDefaultName();
 101  0
         StringBuilder name = new StringBuilder(); 
 102  0
         if (kimEntityNameInfo != null) {
 103  0
             if (!nvl(kimEntityNameInfo.getFirstName()).trim().isEmpty()) {
 104  0
                 if (!name.toString().isEmpty()) {
 105  0
                     name.append(" ");
 106  
                 }
 107  0
                 name.append(nvl(kimEntityNameInfo.getFirstName()));
 108  
             }
 109  
             
 110  0
             if (!nvl(kimEntityNameInfo.getMiddleName()).trim().isEmpty()) {
 111  0
                 if (!name.toString().isEmpty()) {
 112  0
                     name.append(" ");
 113  
                 }
 114  0
                 name.append(nvl(kimEntityNameInfo.getMiddleName()));
 115  
             }
 116  0
             if (!nvl(kimEntityNameInfo.getLastName()).trim().isEmpty()) {
 117  0
                 if (!name.toString().isEmpty()) {
 118  0
                     name.append(" ");
 119  
                 }
 120  0
                 name.append(nvl(kimEntityNameInfo.getLastName()));
 121  
             }
 122  
         }
 123  0
         return name.toString();
 124  
     }
 125  
 
 126  
 }