View Javadoc
1   /*
2    * Copyright 2008-2009 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.module.purap.document.validation.impl;
17  
18  import org.kuali.ole.module.purap.PurapConstants;
19  import org.kuali.ole.module.purap.document.BulkReceivingDocument;
20  import org.kuali.ole.module.purap.document.service.BulkReceivingService;
21  import org.kuali.ole.sys.context.SpringContext;
22  import org.kuali.rice.kns.rules.PromptBeforeValidationBase;
23  import org.kuali.rice.krad.document.Document;
24  
25  import java.util.HashMap;
26  import java.util.Iterator;
27  
28  public class BulkReceivingDocumentPreRules extends PromptBeforeValidationBase {
29  
30      public boolean doPrompts(Document document) {
31  
32          BulkReceivingDocument bulkReceivingDocument = (BulkReceivingDocument) document;
33  
34          HashMap<String, String> duplicateMessages = SpringContext.getBean(BulkReceivingService.class).bulkReceivingDuplicateMessages(bulkReceivingDocument);
35  
36          if (duplicateMessages != null && !duplicateMessages.isEmpty()) {
37              Iterator iterator = duplicateMessages.values().iterator();
38              StringBuffer msg = new StringBuffer();
39              while (iterator.hasNext()) {
40                  msg.append(iterator.next());
41              }
42              boolean proceed = super.askOrAnalyzeYesNoQuestion(PurapConstants.BulkReceivingDocumentStrings.DUPLICATE_BULK_RECEIVING_DOCUMENT_QUESTION, msg.toString());
43              if (!proceed) {
44                  abortRulesCheck();
45              }
46          }
47  
48          return true;
49      }
50  
51  
52  }