View Javadoc

1   /**
2    * Copyright 2005-2014 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.rice.kew.impl.document.search;
17  
18  import org.kuali.rice.core.api.util.ConcreteKeyValue;
19  import org.kuali.rice.core.api.util.KeyValue;
20  import org.kuali.rice.kew.api.document.DocumentStatus;
21  import org.kuali.rice.kew.api.document.DocumentStatusCategory;
22  import org.kuali.rice.krad.keyvalues.KeyValuesBase;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  import java.util.Set;
27  
28  /**
29   * A values finder implementation that loads the various workflow document status categories and their individual
30   * statuses.
31   *
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public class DocumentStatusValuesFinder extends KeyValuesBase {
35  
36      private static final String CATEGORY_CODE_PREFIX = "category:";
37  
38      @Override
39      public List<KeyValue> getKeyValues() {
40          List<KeyValue> statuses = new ArrayList<KeyValue>();
41          addCategory(statuses, DocumentStatusCategory.PENDING);
42          addCategory(statuses, DocumentStatusCategory.SUCCESSFUL);
43          addCategory(statuses, DocumentStatusCategory.UNSUCCESSFUL);
44          return statuses;
45      }
46  
47      private void addCategory(List<KeyValue> statuses, DocumentStatusCategory category) {
48          statuses.add(new ConcreteKeyValue(CATEGORY_CODE_PREFIX + category.getCode(), category.getLabel() + " Statuses"));
49          Set<DocumentStatus> documentStatuses = DocumentStatus.getStatusesForCategory(category);
50          for (DocumentStatus documentStatus : documentStatuses) {
51              statuses.add(new ConcreteKeyValue(documentStatus.getCode(), "- " + documentStatus.getLabel()));
52          }
53      }
54  }