1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.ole.module.purap.document.validation.impl;
17  
18  import org.kuali.ole.module.purap.PurapConstants;
19  import org.kuali.ole.module.purap.PurapKeyConstants;
20  import org.kuali.ole.module.purap.document.InvoiceDocument;
21  import org.kuali.ole.sys.document.validation.GenericValidation;
22  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
23  import org.kuali.rice.kew.api.WorkflowDocument;
24  import org.kuali.rice.krad.bo.Note;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  import org.kuali.rice.krad.util.KRADConstants;
27  import org.kuali.rice.krad.util.ObjectUtils;
28  
29  import java.util.List;
30  import java.util.Set;
31  
32  public class InvoiceImageAttachmentValidation extends GenericValidation {
33  
34      public boolean validate(AttributedDocumentEvent event) {
35          boolean valid = true;
36          InvoiceDocument document = (InvoiceDocument) event.getDocument();
37          GlobalVariables.getMessageMap().clearErrorPath();
38  
39          if (isDocumentStoppedInRouteNode(document, "ImageAttachment")) {
40              
41              valid = false;
42  
43              
44              List boNotes = document.getNotes();
45              if (ObjectUtils.isNotNull(boNotes)) {
46                  for (Object obj : boNotes) {
47                      Note note = (Note) obj;
48  
49                      note.refreshReferenceObject("attachment");
50                      if (ObjectUtils.isNotNull(note.getAttachment()) && PurapConstants.AttachmentTypeCodes.ATTACHMENT_TYPE_INVOICE_IMAGE.equals(note.getAttachment().getAttachmentTypeCode())) {
51                          valid = true;
52                          break;
53                      }
54                  }
55              }
56  
57              if (valid == false) {
58                  GlobalVariables.getMessageMap().putError(KRADConstants.NEW_DOCUMENT_NOTE_PROPERTY_NAME, PurapKeyConstants.ERROR_PAYMENT_REQUEST_INVOICE_REQUIRED);
59              }
60          }
61  
62          GlobalVariables.getMessageMap().clearErrorPath();
63  
64          return valid;
65      }
66  
67      
68  
69  
70  
71  
72      protected boolean isDocumentStoppedInRouteNode(InvoiceDocument document, String nodeName) {
73          WorkflowDocument workflowDoc = document.getDocumentHeader().getWorkflowDocument();
74          Set<String> currentRouteLevels = workflowDoc.getCurrentNodeNames();
75          if (currentRouteLevels.contains(nodeName) && workflowDoc.isApprovalRequested()) {
76              return true;
77          }
78          return false;
79      }
80  }