Coverage Report - org.kuali.rice.kew.impl.doctype.DocumentTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentTypeServiceImpl
0%
0/94
0%
0/68
5.308
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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/ecl1.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.kew.impl.doctype;
 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.api.exception.RiceIllegalArgumentException;
 23  
 import org.kuali.rice.kew.api.doctype.DocumentType;
 24  
 import org.kuali.rice.kew.api.doctype.DocumentTypeService;
 25  
 import org.kuali.rice.kew.api.doctype.Process;
 26  
 import org.kuali.rice.kew.api.doctype.RoutePath;
 27  
 import org.kuali.rice.kew.doctype.dao.DocumentTypeDAO;
 28  
 import org.kuali.rice.kew.engine.node.RouteNode;
 29  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 30  
 
 31  
 /**
 32  
  * Reference implementation of the {@link DocumentTypeService}.
 33  
  * 
 34  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 35  
  * 
 36  
  */
 37  0
 public class DocumentTypeServiceImpl implements DocumentTypeService {
 38  
 
 39  0
     private static final Logger LOG = Logger.getLogger(DocumentTypeServiceImpl.class);
 40  
 
 41  
     private DocumentTypeDAO documentTypeDao;
 42  
 
 43  
     @Override
 44  
     public String getIdByName(String documentTypeName) {
 45  0
         if (StringUtils.isBlank(documentTypeName)) {
 46  0
             throw new RiceIllegalArgumentException("documentTypeName was null or blank");
 47  
         }
 48  0
         return documentTypeDao.findDocumentTypeIdByName(documentTypeName);
 49  
     }
 50  
 
 51  
     @Override
 52  
     public String getNameById(String documentTypeId) {
 53  0
         if (StringUtils.isBlank(documentTypeId)) {
 54  0
             throw new RiceIllegalArgumentException("documentTypeId was null or blank");
 55  
         }
 56  0
         return documentTypeDao.findDocumentTypeNameById(documentTypeId);
 57  
     }
 58  
 
 59  
     @Override
 60  
     public DocumentType getDocumentTypeById(String documentTypeId) {
 61  0
         if (StringUtils.isBlank(documentTypeId)) {
 62  0
             throw new RiceIllegalArgumentException("documentTypeId was null or blank");
 63  
         }
 64  0
         org.kuali.rice.kew.doctype.bo.DocumentType documentTypeBo = documentTypeDao.findById(documentTypeId);
 65  0
         return org.kuali.rice.kew.doctype.bo.DocumentType.to(documentTypeBo);
 66  
     }
 67  
 
 68  
     @Override
 69  
     public org.kuali.rice.kew.api.doctype.DocumentType getDocumentTypeByName(String documentTypeName) {
 70  0
         if (StringUtils.isBlank(documentTypeName)) {
 71  0
             throw new RiceIllegalArgumentException("documentTypeName was null or blank");
 72  
         }
 73  0
         org.kuali.rice.kew.doctype.bo.DocumentType documentTypeBo = documentTypeDao.findByName(documentTypeName);
 74  0
         return org.kuali.rice.kew.doctype.bo.DocumentType.to(documentTypeBo);
 75  
     }
 76  
 
 77  
     @Override
 78  
     public boolean isSuperUserForDocumentTypeId(String principalId, String documentTypeId) {
 79  0
         if (LOG.isDebugEnabled()) {
 80  0
             LOG.debug("Determining super user status [principalId=" + principalId + ", documentTypeId="
 81  
                     + documentTypeId + "]");
 82  
         }
 83  0
         if (StringUtils.isBlank(principalId)) {
 84  0
             throw new RiceIllegalArgumentException("principalId was null or blank");
 85  
         }
 86  0
         if (StringUtils.isBlank(documentTypeId)) {
 87  0
             throw new RiceIllegalArgumentException("documentTypeId was null or blank");
 88  
         }
 89  0
         org.kuali.rice.kew.doctype.bo.DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findById(documentTypeId);
 90  0
         boolean isSuperUser = KEWServiceLocator.getDocumentTypePermissionService().canAdministerRouting(principalId,
 91  
                 documentType);
 92  0
         if (LOG.isDebugEnabled()) {
 93  0
             LOG.debug("Super user status is " + isSuperUser + ".");
 94  
         }
 95  0
         return isSuperUser;
 96  
 
 97  
     }
 98  
 
 99  
     @Override
 100  
     public boolean isSuperUserForDocumentTypeName(String principalId, String documentTypeName) {
 101  0
         if (LOG.isDebugEnabled()) {
 102  0
             LOG.debug("Determining super user status [principalId=" + principalId + ", documentTypeName="
 103  
                     + documentTypeName + "]");
 104  
         }
 105  0
         if (StringUtils.isBlank(principalId)) {
 106  0
             throw new RiceIllegalArgumentException("principalId was null or blank");
 107  
         }
 108  0
         if (StringUtils.isBlank(documentTypeName)) {
 109  0
             throw new RiceIllegalArgumentException("documentTypeId was null or blank");
 110  
         }
 111  0
         org.kuali.rice.kew.doctype.bo.DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName);
 112  0
         boolean isSuperUser = KEWServiceLocator.getDocumentTypePermissionService().canAdministerRouting(principalId,
 113  
                 documentType);
 114  0
         if (LOG.isDebugEnabled()) {
 115  0
             LOG.debug("Super user status is " + isSuperUser + ".");
 116  
         }
 117  0
         return isSuperUser;
 118  
 
 119  
     }
 120  
 
 121  
     @Override
 122  
     public boolean hasRouteNodeForDocumentTypeName(String routeNodeName, String documentTypeName)
 123  
             throws RiceIllegalArgumentException {
 124  0
         if (StringUtils.isBlank(routeNodeName)) {
 125  0
             throw new RiceIllegalArgumentException("routeNodeName was null or blank");
 126  
         }
 127  0
         if (StringUtils.isBlank(documentTypeName)) {
 128  0
             throw new RiceIllegalArgumentException("documentTypeName was null or blank");
 129  
         }
 130  
 
 131  0
         DocumentType documentType = getDocumentTypeByName(documentTypeName);
 132  0
         if (documentType == null) {
 133  0
             throw new RiceIllegalArgumentException("Failed to locate a document type for the given name: " + documentTypeName);
 134  
         }
 135  0
         RouteNode routeNode = KEWServiceLocator.getRouteNodeService().findRouteNodeByName(documentType.getId(), routeNodeName);
 136  
 
 137  0
         if (routeNode == null) {
 138  0
             if (documentType.getParentId() == null) {
 139  0
                 return false;
 140  
             } else {
 141  0
                 return hasRouteNodeForDocumentTypeId(routeNodeName, documentType.getParentId());
 142  
             }
 143  
         } else {
 144  0
             return true;
 145  
         }
 146  
     }
 147  
     
 148  
     @Override
 149  
     public boolean hasRouteNodeForDocumentTypeId(String routeNodeName, String documentTypeId)
 150  
             throws RiceIllegalArgumentException {
 151  0
         if (StringUtils.isBlank(routeNodeName)) {
 152  0
             throw new RiceIllegalArgumentException("routeNodeName was null or blank");
 153  
         }
 154  0
         if (StringUtils.isBlank(documentTypeId)) {
 155  0
             throw new RiceIllegalArgumentException("documentTypeId was null or blank");
 156  
         }
 157  
 
 158  0
         DocumentType documentType = getDocumentTypeById(documentTypeId);
 159  0
         if (documentType == null) {
 160  0
             throw new RiceIllegalArgumentException("Failed to locate a document type for the given id: " + documentTypeId);
 161  
         }
 162  0
         RouteNode routeNode = KEWServiceLocator.getRouteNodeService().findRouteNodeByName(documentType.getId(), routeNodeName);
 163  
 
 164  0
         if (routeNode == null) {
 165  0
             if (documentType.getParentId() == null) {
 166  0
                 return false;
 167  
             } else {
 168  0
                 return hasRouteNodeForDocumentTypeId(routeNodeName, documentType.getParentId());
 169  
             }
 170  
         } else {
 171  0
             return true;
 172  
         }
 173  
     }
 174  
     
 175  
     @Override
 176  
     public boolean isActiveById(String documentTypeId) {
 177  0
         if (StringUtils.isBlank(documentTypeId)) {
 178  0
             throw new RiceIllegalArgumentException("documentTypeId was null or blank");
 179  
         }
 180  0
         org.kuali.rice.kew.doctype.bo.DocumentType docType = KEWServiceLocator.getDocumentTypeService().findById(documentTypeId);
 181  0
         return docType != null && docType.isActive();
 182  
     }
 183  
 
 184  
     @Override
 185  
     public boolean isActiveByName(String documentTypeName) {
 186  0
         if (StringUtils.isBlank(documentTypeName)) {
 187  0
             throw new RiceIllegalArgumentException("documentTypeName was null or blank");
 188  
         }
 189  0
         org.kuali.rice.kew.doctype.bo.DocumentType docType = KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName);
 190  0
         return docType != null && docType.isActive();
 191  
     }
 192  
     
 193  
     @Override
 194  
     public RoutePath getRoutePathForDocumentTypeId(String documentTypeId) {
 195  0
         if (StringUtils.isBlank(documentTypeId)) {
 196  0
             throw new RiceIllegalArgumentException("documentTypeId was null or blank");
 197  
         }
 198  0
         org.kuali.rice.kew.doctype.bo.DocumentType docType = KEWServiceLocator.getDocumentTypeService().findById(documentTypeId);
 199  0
         if (docType == null) {
 200  0
             return null;
 201  
         }
 202  0
         RoutePath.Builder builder = RoutePath.Builder.create();
 203  0
         List<org.kuali.rice.kew.engine.node.Process> processes = docType.getProcesses();
 204  0
         for (org.kuali.rice.kew.engine.node.Process process : processes) {
 205  0
             builder.getProcesses().add(Process.Builder.create(process));
 206  
         }
 207  0
         return builder.build();
 208  
     }
 209  
     
 210  
     @Override
 211  
     public RoutePath getRoutePathForDocumentTypeName(String documentTypeName) {
 212  0
         if (StringUtils.isBlank(documentTypeName)) {
 213  0
             throw new RiceIllegalArgumentException("documentTypeName was null or blank");
 214  
         }
 215  0
         org.kuali.rice.kew.doctype.bo.DocumentType docType = KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName);
 216  0
         if (docType == null) {
 217  0
             return null;
 218  
         }
 219  0
         RoutePath.Builder builder = RoutePath.Builder.create();
 220  0
         List<org.kuali.rice.kew.engine.node.Process> processes = docType.getProcesses();
 221  0
         for (org.kuali.rice.kew.engine.node.Process process : processes) {
 222  0
             builder.getProcesses().add(Process.Builder.create(process));
 223  
         }
 224  0
         return builder.build();
 225  
 
 226  
     }
 227  
 
 228  
     public void setDocumentTypeDao(DocumentTypeDAO documentTypeDao) {
 229  0
         this.documentTypeDao = documentTypeDao;
 230  0
     }
 231  
 
 232  
 }