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