001/* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.ole.select.document.validation.impl; 017 018import org.kuali.ole.select.document.OleOrderQueueDocument; 019import org.kuali.ole.sys.OLEConstants; 020import org.kuali.ole.sys.OLEKeyConstants; 021import org.kuali.ole.sys.document.validation.GenericValidation; 022import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent; 023import org.kuali.rice.krad.util.GlobalVariables; 024 025public class AssignOrderQueueValidation extends GenericValidation { 026 027 private OleOrderQueueDocument orderQueueForValidation; 028 029 public OleOrderQueueDocument getOrderQueueForValidation() { 030 return orderQueueForValidation; 031 } 032 033 public void setOrderQueueForValidation(OleOrderQueueDocument orderQueueForValidation) { 034 this.orderQueueForValidation = orderQueueForValidation; 035 } 036 037 @Override 038 public boolean validate(AttributedDocumentEvent event) { 039 boolean isValid = true; 040 if (orderQueueForValidation.getPrincipalName() == null) 041 isValid = false; 042 else 043 isValid = true; 044 045 if (!isValid) 046 GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.PRINCIPAL_NAME, OLEKeyConstants.ERROR_REQUIRED, "User Id"); 047 048 return isValid; 049 050 } 051 052 /*private boolean isAuthorizedToApprove(OrderQueueDocument document, String principalId){ 053 List<OleRequisitionItem> requisitions = document.getRequisitions(); 054 List<OleRequisitionItem> authorizedRequisitions = new ArrayList<OleRequisitionItem>(); 055 boolean flag = false; 056 OleRequisitionDocument requsitionDocument; 057 for(OleRequisitionItem item:requisitions){ 058 if(item.isItemAdded()){ 059 Long requisitionDocumentId = new Long(item.getRequisition().getPurapDocumentIdentifier()); 060 requsitionDocument = (OleRequisitionDocument) KNSServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(OleRequisitionDocument.class,requisitionDocumentId); 061 requsitionDocument.setDocumentHeader(KNSServiceLocator.getDocumentHeaderService().getDocumentHeaderById(item.getRequisition().getDocumentNumber())); 062 Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId()); 063 try{ 064 requsitionDocument.getDocumentHeader().setWorkflowDocument(KNSServiceLocator.getWorkflowDocumentService().createWorkflowDocument(new Long(item.getRequisition().getDocumentNumber()), principalPerson)); 065 }catch(WorkflowException we){ 066 we.printStackTrace(); 067 } 068 if (!SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer(requsitionDocument).isAuthorizedByTemplate(requsitionDocument, KRADConstants.KRAD_NAMESPACE, KimConstants.PermissionTemplateNames.APPROVE_DOCUMENT, principalId)) { 069 GlobalVariables.getMessageMap().putError("requisitions", "error.requisition.unauthorizedToApprove", new String[]{document.getSelectorUserId(),item.getRequisition().getDocumentNumber()}); 070 item.setItemAdded(false); 071 authorizedRequisitions.add(item); 072 }else{ 073 flag = true; 074 } 075 } 076 authorizedRequisitions.add(item); 077 } 078 document.setRequisitions(authorizedRequisitions); 079 if(flag) 080 return true; 081 else 082 return false; 083 }*/ 084 085}