View Javadoc
1   /*
2    * Copyright 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.ole.select.document.validation.impl;
17  
18  import org.kuali.ole.select.document.OleOrderQueueDocument;
19  import org.kuali.ole.sys.OLEConstants;
20  import org.kuali.ole.sys.OLEKeyConstants;
21  import org.kuali.ole.sys.document.validation.GenericValidation;
22  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
23  import org.kuali.rice.krad.util.GlobalVariables;
24  
25  public class AssignOrderQueueValidation extends GenericValidation {
26  
27      private OleOrderQueueDocument orderQueueForValidation;
28  
29      public OleOrderQueueDocument getOrderQueueForValidation() {
30          return orderQueueForValidation;
31      }
32  
33      public void setOrderQueueForValidation(OleOrderQueueDocument orderQueueForValidation) {
34          this.orderQueueForValidation = orderQueueForValidation;
35      }
36  
37      @Override
38      public boolean validate(AttributedDocumentEvent event) {
39          boolean isValid = true;
40          if (orderQueueForValidation.getPrincipalName() == null)
41              isValid = false;
42          else
43              isValid = true;
44  
45          if (!isValid)
46              GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.PRINCIPAL_NAME, OLEKeyConstants.ERROR_REQUIRED, "User Id");
47  
48          return isValid;
49  
50      }
51      
52      /*private boolean isAuthorizedToApprove(OrderQueueDocument document, String principalId){
53          List<OleRequisitionItem> requisitions = document.getRequisitions();
54          List<OleRequisitionItem> authorizedRequisitions = new ArrayList<OleRequisitionItem>();
55          boolean flag = false;
56          OleRequisitionDocument requsitionDocument;
57          for(OleRequisitionItem item:requisitions){
58              if(item.isItemAdded()){
59                  Long requisitionDocumentId = new Long(item.getRequisition().getPurapDocumentIdentifier());
60                  requsitionDocument = (OleRequisitionDocument) KNSServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(OleRequisitionDocument.class,requisitionDocumentId);
61                  requsitionDocument.setDocumentHeader(KNSServiceLocator.getDocumentHeaderService().getDocumentHeaderById(item.getRequisition().getDocumentNumber()));
62                  Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
63                  try{
64                      requsitionDocument.getDocumentHeader().setWorkflowDocument(KNSServiceLocator.getWorkflowDocumentService().createWorkflowDocument(new Long(item.getRequisition().getDocumentNumber()), principalPerson));
65                  }catch(WorkflowException we){
66                     we.printStackTrace();
67                  }
68                  if (!SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer(requsitionDocument).isAuthorizedByTemplate(requsitionDocument, KRADConstants.KRAD_NAMESPACE, KimConstants.PermissionTemplateNames.APPROVE_DOCUMENT, principalId)) {
69                      GlobalVariables.getMessageMap().putError("requisitions", "error.requisition.unauthorizedToApprove", new String[]{document.getSelectorUserId(),item.getRequisition().getDocumentNumber()});
70                      item.setItemAdded(false);
71                      authorizedRequisitions.add(item);
72                  }else{
73                      flag = true;
74                  }
75              }
76              authorizedRequisitions.add(item);
77          }
78          document.setRequisitions(authorizedRequisitions);
79          if(flag)
80              return true;
81          else
82              return false;
83      }*/
84  
85  }