Coverage Report - org.kuali.student.core.document.ui.server.DocumentRpcGwtServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentRpcGwtServlet
0%
0/25
0%
0/10
1.7
 
 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.document.ui.server;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import org.kuali.rice.kim.bo.types.dto.AttributeSet;
 21  
 import org.kuali.student.common.dto.StatusInfo;
 22  
 import org.kuali.student.common.exceptions.DoesNotExistException;
 23  
 import org.kuali.student.common.rice.StudentIdentityConstants;
 24  
 import org.kuali.student.common.rice.authorization.PermissionType;
 25  
 import org.kuali.student.common.ui.server.gwt.BaseRpcGwtServletAbstract;
 26  
 import org.kuali.student.core.document.dto.DocumentInfo;
 27  
 import org.kuali.student.core.document.dto.RefDocRelationInfo;
 28  
 import org.kuali.student.core.document.service.DocumentService;
 29  
 import org.kuali.student.core.document.ui.client.service.DocumentRpcService;
 30  
 
 31  0
 public class DocumentRpcGwtServlet extends BaseRpcGwtServletAbstract<DocumentService> implements DocumentRpcService{
 32  
         private static final long serialVersionUID = 1L;
 33  
         
 34  
         public DocumentInfo getDocument(String documentId) throws Exception{
 35  0
                 return service.getDocument(documentId);
 36  
         }
 37  
         
 38  
         public List<DocumentInfo> getDocumentsByIdList(List<String> documentIdList)throws Exception{
 39  0
                 return service.getDocumentsByIdList(documentIdList);
 40  
         }
 41  
         
 42  
         public StatusInfo deleteDocument(String documentId) throws Exception{
 43  0
                 return service.deleteDocument(documentId);
 44  
         }
 45  
         
 46  
     public DocumentInfo updateDocument(String documentId, DocumentInfo documentInfo) throws Exception{
 47  0
             return service.updateDocument(documentId, documentInfo);
 48  
     }
 49  
         
 50  
         public StatusInfo addDocumentCategoryToDocument(String documentId, String documentCategoryKey) throws Exception{
 51  0
                 return service.addDocumentCategoryToDocument(documentId, documentCategoryKey);
 52  
         }
 53  
         
 54  
     public StatusInfo removeDocumentCategoryFromDocument(String documentId, String documentCategoryKey) throws Exception{
 55  0
             return service.removeDocumentCategoryFromDocument(documentId, documentCategoryKey);
 56  
     }
 57  
 
 58  
         @Override
 59  
     public Boolean isAuthorizedUploadDocuments(String id, String referenceTypeKey) {
 60  0
                 if (id != null && (!"".equals(id.trim()))) {
 61  0
                         String user = getCurrentUser();
 62  0
             AttributeSet permissionDetails = new AttributeSet(StudentIdentityConstants.KS_REFERENCE_TYPE_KEY, referenceTypeKey);
 63  0
                 if (getPermissionService().isPermissionDefinedForTemplateName(PermissionType.UPLOAD_DOCUMENTS.getPermissionNamespace(), PermissionType.UPLOAD_DOCUMENTS.getPermissionTemplateName(), permissionDetails)) {
 64  0
                     AttributeSet roleQuals = new AttributeSet();
 65  0
                     roleQuals.put(referenceTypeKey, id);
 66  0
                     return Boolean.valueOf(getPermissionService().isAuthorizedByTemplateName(user, PermissionType.UPLOAD_DOCUMENTS.getPermissionNamespace(), PermissionType.UPLOAD_DOCUMENTS.getPermissionTemplateName(), permissionDetails, roleQuals));
 67  
                 }
 68  
                 }
 69  0
                 return Boolean.TRUE;
 70  
     }
 71  
 
 72  
         @Override
 73  
         public StatusInfo deleteRefDocRelation(String documentId) throws Exception {
 74  0
                 return service.deleteRefDocRelation(documentId);
 75  
         }
 76  
 
 77  
         @Override
 78  
         public List<RefDocRelationInfo> getRefDocIdsForRef(String refObjectTypeKey, String refObjectId) throws Exception{
 79  0
                 return service.getRefDocRelationsByRef(refObjectTypeKey, refObjectId);
 80  
         }
 81  
 
 82  
         @Override
 83  
         public StatusInfo deleteRefDocRelationAndOrphanedDoc(String docRelationId, String documentId) throws Exception {
 84  
                 
 85  
                 //Delete the relation
 86  0
                 service.deleteRefDocRelation(docRelationId);
 87  
                 
 88  
                 //Also delete the document if there are no more relations to it
 89  
                 try{
 90  0
                         List<RefDocRelationInfo> allRelations = service.getRefDocRelationsByDoc(documentId);
 91  0
                         if(allRelations == null || allRelations.isEmpty()){
 92  0
                                 service.deleteDocument(documentId);
 93  
                         }
 94  0
                 }catch(DoesNotExistException e){
 95  0
                         service.deleteDocument(documentId);
 96  0
                 }
 97  0
                 return new StatusInfo();
 98  
         }
 99  
 }