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