Coverage Report - org.kuali.rice.kns.service.impl.MaintenanceDocumentServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
MaintenanceDocumentServiceImpl
0%
0/45
0%
0/18
2.308
 
 1  
 /*
 2  
  * Copyright 2005-2008 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kns.service.impl;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import org.apache.commons.lang.StringUtils;
 21  
 import org.apache.log4j.Logger;
 22  
 import org.kuali.rice.core.framework.persistence.jta.TransactionalNoValidationExceptionRollback;
 23  
 import org.kuali.rice.kew.exception.WorkflowException;
 24  
 import org.kuali.rice.kns.bo.BusinessObject;
 25  
 import org.kuali.rice.kns.dao.MaintenanceDocumentDao;
 26  
 import org.kuali.rice.kns.document.MaintenanceDocument;
 27  
 import org.kuali.rice.kns.document.MaintenanceLock;
 28  
 import org.kuali.rice.kns.exception.DocumentTypeAuthorizationException;
 29  
 import org.kuali.rice.kns.maintenance.Maintainable;
 30  
 import org.kuali.rice.kns.service.BusinessObjectAuthorizationService;
 31  
 import org.kuali.rice.kns.service.DocumentService;
 32  
 import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService;
 33  
 import org.kuali.rice.kns.service.MaintenanceDocumentService;
 34  
 import org.kuali.rice.kns.util.GlobalVariables;
 35  
 import org.kuali.rice.kns.util.KNSConstants;
 36  
 
 37  
 /**
 38  
  * Service implementation for the MaintenanceDocument structure. This is the
 39  
  * default implementation, that is delivered with Kuali.
 40  
  */
 41  
 @TransactionalNoValidationExceptionRollback
 42  0
 public class MaintenanceDocumentServiceImpl implements MaintenanceDocumentService {
 43  0
         protected static final Logger LOG = Logger.getLogger(MaintenanceDocumentServiceImpl.class);
 44  
 
 45  
         private MaintenanceDocumentDao maintenanceDocumentDao;
 46  
         private MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService;
 47  
         private BusinessObjectAuthorizationService businessObjectAuthorizationService;
 48  
         private DocumentService documentService;
 49  
 
 50  
         /**
 51  
          * @see org.kuali.rice.kns.service.MaintenanceDocumentService#setupNewMaintenanceDocument(java.lang.String,
 52  
          *      java.lang.String, java.lang.String)
 53  
          */
 54  
         @SuppressWarnings("unchecked")
 55  
         public MaintenanceDocument setupNewMaintenanceDocument(String objectClassName, String documentTypeName,
 56  
                         String maintenanceAction) {
 57  0
                 if (StringUtils.isEmpty(objectClassName) && StringUtils.isEmpty(documentTypeName)) {
 58  0
                         throw new IllegalArgumentException("Document type name or bo class not given!");
 59  
                 }
 60  
 
 61  
                 // get document type if not passed
 62  0
                 if (StringUtils.isEmpty(documentTypeName)) {
 63  
                         try {
 64  0
                                 documentTypeName = maintenanceDocumentDictionaryService.getDocumentTypeName(Class
 65  
                                                 .forName(objectClassName));
 66  
                         }
 67  0
                         catch (ClassNotFoundException e) {
 68  0
                                 throw new RuntimeException(e);
 69  0
                         }
 70  
 
 71  0
                         if (StringUtils.isEmpty(documentTypeName)) {
 72  0
                                 throw new RuntimeException(
 73  
                                                 "documentTypeName is empty; does this Business Object have a maintenance document definition? "
 74  
                                                                 + objectClassName);
 75  
                         }
 76  
                 }
 77  
 
 78  
                 // check doc type allows new or copy if that action was requested
 79  0
                 if (KNSConstants.MAINTENANCE_NEW_ACTION.equals(maintenanceAction)
 80  
                                 || KNSConstants.MAINTENANCE_COPY_ACTION.equals(maintenanceAction)) {
 81  0
                         Class<? extends BusinessObject> boClass = maintenanceDocumentDictionaryService
 82  
                                         .getBusinessObjectClass(documentTypeName);
 83  0
                         boolean allowsNewOrCopy = getBusinessObjectAuthorizationService().canCreate(boClass,
 84  
                                         GlobalVariables.getUserSession().getPerson(), documentTypeName);
 85  0
                         if (!allowsNewOrCopy) {
 86  0
                                 LOG.error("Document type " + documentTypeName + " does not allow new or copy actions.");
 87  0
                                 throw new DocumentTypeAuthorizationException(GlobalVariables.getUserSession().getPerson()
 88  
                                                 .getPrincipalId(), "newOrCopy", documentTypeName);
 89  
                         }
 90  
                 }
 91  
 
 92  
                 // get new document from service
 93  
                 try {
 94  0
                         return (MaintenanceDocument) getDocumentService().getNewDocument(documentTypeName);
 95  
                 }
 96  0
                 catch (WorkflowException e) {
 97  0
                         LOG.error("Cannot get new maintenance document instance for doc type: " + documentTypeName, e);
 98  0
                         throw new RuntimeException(
 99  
                                         "Cannot get new maintenance document instance for doc type: " + documentTypeName, e);
 100  
                 }
 101  
         }
 102  
 
 103  
         /**
 104  
          * @see org.kuali.rice.kns.service.MaintenanceDocumentService#getLockingDocumentId(org.kuali.rice.kns.document.MaintenanceDocument)
 105  
          */
 106  
         public String getLockingDocumentId(MaintenanceDocument document) {
 107  0
                 return getLockingDocumentId(document.getNewMaintainableObject(), document.getDocumentNumber());
 108  
         }
 109  
 
 110  
         /**
 111  
          * @see org.kuali.rice.kns.service.MaintenanceDocumentService#getLockingDocumentId(org.kuali.rice.kns.maintenance.Maintainable,
 112  
          *      java.lang.String)
 113  
          */
 114  
         public String getLockingDocumentId(Maintainable maintainable, String documentNumber) {
 115  0
                 String lockingDocId = null;
 116  0
                 List<MaintenanceLock> maintenanceLocks = maintainable.generateMaintenanceLocks();
 117  0
                 for (MaintenanceLock maintenanceLock : maintenanceLocks) {
 118  0
                         lockingDocId = maintenanceDocumentDao.getLockingDocumentNumber(maintenanceLock.getLockingRepresentation(),
 119  
                                         documentNumber);
 120  0
                         if (StringUtils.isNotBlank(lockingDocId)) {
 121  0
                                 break;
 122  
                         }
 123  
                 }
 124  0
                 return lockingDocId;
 125  
         }
 126  
 
 127  
         /**
 128  
          * @see org.kuali.rice.kns.service.MaintenanceDocumentService#deleteLocks(String)
 129  
          */
 130  
         public void deleteLocks(String documentNumber) {
 131  0
                 maintenanceDocumentDao.deleteLocks(documentNumber);
 132  0
         }
 133  
 
 134  
         /**
 135  
          * @see org.kuali.rice.kns.service.MaintenanceDocumentService#saveLocks(List)
 136  
          */
 137  
         public void storeLocks(List<MaintenanceLock> maintenanceLocks) {
 138  0
                 maintenanceDocumentDao.storeLocks(maintenanceLocks);
 139  0
         }
 140  
 
 141  
         /**
 142  
          * @return Returns the maintenanceDocumentDao.
 143  
          */
 144  
         public MaintenanceDocumentDao getMaintenanceDocumentDao() {
 145  0
                 return maintenanceDocumentDao;
 146  
         }
 147  
 
 148  
         /**
 149  
          * @param maintenanceDocumentDao
 150  
          *            The maintenanceDocumentDao to set.
 151  
          */
 152  
         public void setMaintenanceDocumentDao(MaintenanceDocumentDao maintenanceDocumentDao) {
 153  0
                 this.maintenanceDocumentDao = maintenanceDocumentDao;
 154  0
         }
 155  
 
 156  
         protected MaintenanceDocumentDictionaryService getMaintenanceDocumentDictionaryService() {
 157  0
                 return this.maintenanceDocumentDictionaryService;
 158  
         }
 159  
 
 160  
         public void setMaintenanceDocumentDictionaryService(
 161  
                         MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService) {
 162  0
                 this.maintenanceDocumentDictionaryService = maintenanceDocumentDictionaryService;
 163  0
         }
 164  
 
 165  
         protected BusinessObjectAuthorizationService getBusinessObjectAuthorizationService() {
 166  0
                 return this.businessObjectAuthorizationService;
 167  
         }
 168  
 
 169  
         public void setBusinessObjectAuthorizationService(
 170  
                         BusinessObjectAuthorizationService businessObjectAuthorizationService) {
 171  0
                 this.businessObjectAuthorizationService = businessObjectAuthorizationService;
 172  0
         }
 173  
 
 174  
         protected DocumentService getDocumentService() {
 175  0
                 return this.documentService;
 176  
         }
 177  
 
 178  
         public void setDocumentService(DocumentService documentService) {
 179  0
                 this.documentService = documentService;
 180  0
         }
 181  
 
 182  
 }