Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl2.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.kuali.rice.kew.impl.doctype;
 
 
 import java.util.List;

Reference implementation of the org.kuali.rice.kew.api.doctype.DocumentTypeService.

Author(s):
Kuali Rice Team (rice.collab@kuali.org)
 
 public class DocumentTypeServiceImpl implements DocumentTypeService {
 
     private static final Logger LOG = Logger.getLogger(DocumentTypeServiceImpl.class);
 
     private DocumentTypeDAO documentTypeDao;
 
     @Override
     public String getIdByName(String documentTypeName) {
         if (StringUtils.isBlank(documentTypeName)) {
             throw new RiceIllegalArgumentException("documentTypeName was null or blank");
         }
         return .findDocumentTypeIdByName(documentTypeName);
     }
 
     @Override
     public String getNameById(String documentTypeId) {
         if (StringUtils.isBlank(documentTypeId)) {
             throw new RiceIllegalArgumentException("documentTypeId was null or blank");
         }
         return .findDocumentTypeNameById(documentTypeId);
     }
 
     @Override
     public DocumentType getDocumentTypeById(String documentTypeId) {
         if (StringUtils.isBlank(documentTypeId)) {
             throw new RiceIllegalArgumentException("documentTypeId was null or blank");
         }
         org.kuali.rice.kew.doctype.bo.DocumentType documentTypeBo = .findById(documentTypeId);
         return org.kuali.rice.kew.doctype.bo.DocumentType.to(documentTypeBo);
     }
 
     @Override
     public org.kuali.rice.kew.api.doctype.DocumentType getDocumentTypeByName(String documentTypeName) {
         if (StringUtils.isBlank(documentTypeName)) {
             throw new RiceIllegalArgumentException("documentTypeName was null or blank");
         }
         org.kuali.rice.kew.doctype.bo.DocumentType documentTypeBo = .findByName(documentTypeName);
         return org.kuali.rice.kew.doctype.bo.DocumentType.to(documentTypeBo);
     }
 
     @Override
         List<org.kuali.rice.kew.doctype.bo.DocumentTypedocumentTypeBos = .findAllCurrent();
         List<org.kuali.rice.kew.api.doctype.DocumentTypecurrentDocTypes = new ArrayList<org.kuali.rice.kew.api.doctype.DocumentType>();
         for (org.kuali.rice.kew.doctype.bo.DocumentType dt : documentTypeBos) {
             currentDocTypes.add(org.kuali.rice.kew.doctype.bo.DocumentType.to(dt));        
         }
         return Collections.unmodifiableList(currentDocTypes);
     }
 
     @Override
     public boolean isSuperUserForDocumentTypeId(String principalIdString documentTypeId) {
         if (.isDebugEnabled()) {
             .debug("Determining super user status [principalId=" + principalId + ", documentTypeId="
                     + documentTypeId + "]");
         }
         if (StringUtils.isBlank(principalId)) {
             throw new RiceIllegalArgumentException("principalId was null or blank");
        }
        if (StringUtils.isBlank(documentTypeId)) {
            throw new RiceIllegalArgumentException("documentTypeId was null or blank");
        }
        org.kuali.rice.kew.doctype.bo.DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findById(documentTypeId);
        boolean isSuperUser = KEWServiceLocator.getDocumentTypePermissionService().canAdministerRouting(principalId,
                documentType);
        if (.isDebugEnabled()) {
            .debug("Super user status is " + isSuperUser + ".");
        }
        return isSuperUser;
    }
    @Override
    public boolean isSuperUserForDocumentTypeName(String principalIdString documentTypeName) {
        if (.isDebugEnabled()) {
            .debug("Determining super user status [principalId=" + principalId + ", documentTypeName="
                    + documentTypeName + "]");
        }
        if (StringUtils.isBlank(principalId)) {
            throw new RiceIllegalArgumentException("principalId was null or blank");
        }
        if (StringUtils.isBlank(documentTypeName)) {
            throw new RiceIllegalArgumentException("documentTypeId was null or blank");
        }
        org.kuali.rice.kew.doctype.bo.DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName);
        boolean isSuperUser = KEWServiceLocator.getDocumentTypePermissionService().canAdministerRouting(principalId,
                documentType);
        if (.isDebugEnabled()) {
            .debug("Super user status is " + isSuperUser + ".");
        }
        return isSuperUser;
    }
    @Override
    public boolean canSuperUserApproveSingleActionRequestString principalIdString documentTypeNameList<RouteNodeInstancerouteNodeInstancesString routeStatusCode ) {
        checkSuperUserInputprincipalIddocumentTypeName );
        org.kuali.rice.kew.doctype.bo.DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName);
        List<org.kuali.rice.kew.engine.node.RouteNodeInstancecurrentNodeInstances = null;
        if (routeNodeInstances != null && !routeNodeInstances.isEmpty()) {
            currentNodeInstances = KEWServiceLocator.getRouteNodeService().getCurrentNodeInstances(routeNodeInstances.get(0).getDocumentId());
        }
        boolean isSuperUser = KEWServiceLocator.getDocumentTypePermissionService().canSuperUserApproveSingleActionRequestprincipalIddocumentType,
                currentNodeInstancesrouteStatusCode);
        if (.isDebugEnabled()) {
            .debug("Super user approve single action request status is " + isSuperUser + ".");
        }
        return isSuperUser;
    }
    @Override
    public boolean canSuperUserApproveDocumentString principalIdString documentTypeNameList<RouteNodeInstancerouteNodeInstancesString routeStatusCode ) {
        checkSuperUserInputprincipalIddocumentTypeName );
        org.kuali.rice.kew.doctype.bo.DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName);
        List<org.kuali.rice.kew.engine.node.RouteNodeInstancecurrentNodeInstances = null;
        if (routeNodeInstances != null && !routeNodeInstances.isEmpty()) {
            currentNodeInstances = KEWServiceLocator.getRouteNodeService().getCurrentNodeInstances(routeNodeInstances.get(0).getDocumentId());
        }
        boolean isSuperUser = KEWServiceLocator.getDocumentTypePermissionService().canSuperUserApproveDocument(
                principalIddocumentTypecurrentNodeInstancesrouteStatusCode);
        if (.isDebugEnabled()) {
            .debug("Super user approve document status is " + isSuperUser + ".");
        }
        return isSuperUser;
    }
    @Override
    public boolean canSuperUserDisapproveDocumentString principalIdString documentTypeNameList<RouteNodeInstancerouteNodeInstancesString routeStatusCode ) {
        checkSuperUserInputprincipalIddocumentTypeName );
        org.kuali.rice.kew.doctype.bo.DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName);
        List<org.kuali.rice.kew.engine.node.RouteNodeInstancecurrentNodeInstances = null;
        if (routeNodeInstances != null && !routeNodeInstances.isEmpty()) {
            currentNodeInstances = KEWServiceLocator.getRouteNodeService().getCurrentNodeInstances(routeNodeInstances.get(0).getDocumentId());
        }
        boolean isSuperUser = KEWServiceLocator.getDocumentTypePermissionService().canSuperUserDisapproveDocumentprincipalIddocumentType,
                currentNodeInstancesrouteStatusCode);
        if (.isDebugEnabled()) {
            .debug("Super user disapprove document status is " + isSuperUser + ".");
        }
        return isSuperUser;
    }
    private void checkSuperUserInputString principalIdString documentTypeName ) {
        if (.isDebugEnabled()) {
            .debug("Determining super user status [principalId=" + principalId + ", documentTypeName="
                    + documentTypeName + "]");
        }
        if (StringUtils.isBlank(principalId)) {
            throw new RiceIllegalArgumentException("principalId was null or blank");
        }
        if (StringUtils.isBlank(documentTypeName)) {
            throw new RiceIllegalArgumentException("documentTypeId was null or blank");
        }
    }
    @Override
    public boolean hasRouteNodeForDocumentTypeName(String routeNodeNameString documentTypeName)
            throws RiceIllegalArgumentException {
        if (StringUtils.isBlank(routeNodeName)) {
            throw new RiceIllegalArgumentException("routeNodeName was null or blank");
        }
        if (StringUtils.isBlank(documentTypeName)) {
            throw new RiceIllegalArgumentException("documentTypeName was null or blank");
        }
        DocumentType documentType = getDocumentTypeByName(documentTypeName);
        if (documentType == null) {
            throw new RiceIllegalArgumentException("Failed to locate a document type for the given name: " + documentTypeName);
        }
        RouteNode routeNode = KEWServiceLocator.getRouteNodeService().findRouteNodeByName(documentType.getId(), routeNodeName);
        if (routeNode == null) {
            if (documentType.getParentId() == null) {
                return false;
            } else {
                return hasRouteNodeForDocumentTypeId(routeNodeNamedocumentType.getParentId());
            }
        } else {
            return true;
        }
    }
    
    @Override
    public boolean hasRouteNodeForDocumentTypeId(String routeNodeNameString documentTypeId)
            throws RiceIllegalArgumentException {
        if (StringUtils.isBlank(routeNodeName)) {
            throw new RiceIllegalArgumentException("routeNodeName was null or blank");
        }
        if (StringUtils.isBlank(documentTypeId)) {
            throw new RiceIllegalArgumentException("documentTypeId was null or blank");
        }
        DocumentType documentType = getDocumentTypeById(documentTypeId);
        if (documentType == null) {
            throw new RiceIllegalArgumentException("Failed to locate a document type for the given id: " + documentTypeId);
        }
        RouteNode routeNode = KEWServiceLocator.getRouteNodeService().findRouteNodeByName(documentType.getId(), routeNodeName);
        if (routeNode == null) {
            if (documentType.getParentId() == null) {
                return false;
            } else {
                return hasRouteNodeForDocumentTypeId(routeNodeNamedocumentType.getParentId());
            }
        } else {
            return true;
        }
    }
    
    @Override
    public boolean isActiveById(String documentTypeId) {
        if (StringUtils.isBlank(documentTypeId)) {
            throw new RiceIllegalArgumentException("documentTypeId was null or blank");
        }
        org.kuali.rice.kew.doctype.bo.DocumentType docType = KEWServiceLocator.getDocumentTypeService().findById(documentTypeId);
        return docType != null && docType.isActive();
    }
    @Override
    public boolean isActiveByName(String documentTypeName) {
        if (StringUtils.isBlank(documentTypeName)) {
            throw new RiceIllegalArgumentException("documentTypeName was null or blank");
        }
        org.kuali.rice.kew.doctype.bo.DocumentType docType = KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName);
        return docType != null && docType.isActive();
    }
    
    @Override
    public RoutePath getRoutePathForDocumentTypeId(String documentTypeId) {
        if (StringUtils.isBlank(documentTypeId)) {
            throw new RiceIllegalArgumentException("documentTypeId was null or blank");
        }
        org.kuali.rice.kew.doctype.bo.DocumentType docType = KEWServiceLocator.getDocumentTypeService().findById(documentTypeId);
        if (docType == null) {
            return null;
        }
        RoutePath.Builder builder = RoutePath.Builder.create();
        List<ProcessDefinitionBoprocesses = docType.getProcesses();
        for (ProcessDefinitionBo process : processes) {
            builder.getProcessDefinitions().add(ProcessDefinition.Builder.create(process));
        }
        return builder.build();
    }
    
    @Override
    public RoutePath getRoutePathForDocumentTypeName(String documentTypeName) {
        if (StringUtils.isBlank(documentTypeName)) {
            throw new RiceIllegalArgumentException("documentTypeName was null or blank");
        }
        org.kuali.rice.kew.doctype.bo.DocumentType docType = KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName);
        if (docType == null) {
            return null;
        }
        RoutePath.Builder builder = RoutePath.Builder.create();
        List<ProcessDefinitionBoprocesses = docType.getProcesses();
        for (ProcessDefinitionBo process : processes) {
            builder.getProcessDefinitions().add(ProcessDefinition.Builder.create(process));
        }
        return builder.build();
    }
    public void setDocumentTypeDao(DocumentTypeDAO documentTypeDao) {
        this. = documentTypeDao;
    }
New to GrepCode? Check out our FAQ X