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.framework.document.search;
17  
18  import javax.xml.bind.annotation.XmlEnum;
19  import javax.xml.bind.annotation.XmlEnumValue;
20  import javax.xml.bind.annotation.XmlRootElement;
21  import javax.xml.bind.annotation.XmlType;
22  import java.util.Arrays;
23  import java.util.Collections;
24  import java.util.HashSet;
25  import java.util.Set;
26  
27  /**
28   * An enumeration which defines fields that are used on the document search screen and subject to customization by
29   * specific document types which configure such customizations via the document search framework.
30   *
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  @XmlRootElement(name = "documentSearchResultField")
34  @XmlType(name = "DocumentSearchResultFieldType")
35  @XmlEnum
36  public enum StandardResultField {
37  
38      @XmlEnumValue("documentId") DOCUMENT_ID("documentId"),
39      @XmlEnumValue("status") STATUS("status", "statusLabel"),
40      @XmlEnumValue("documentType") DOCUMENT_TYPE("documentType", "documentTypeLabel"),
41      @XmlEnumValue("title") TITLE("title"),
42      @XmlEnumValue("initiator") INITIATOR("initiator", "initiatorDisplayName"),
43      @XmlEnumValue("dateCreated") DATE_CREATED("dateCreated"),
44      @XmlEnumValue("routeLog") ROUTE_LOG("routeLog");
45  
46      private final String standardFieldName;
47      private final Set<String> additionalFieldNames;
48  
49      private StandardResultField(String standardFieldName, String... additionalFieldNames) {
50          this.standardFieldName = standardFieldName;
51          Set<String> additionalFieldNameSet = new HashSet<String>(Arrays.asList(additionalFieldNames));
52          this.additionalFieldNames = Collections.unmodifiableSet(additionalFieldNameSet);
53      }
54  
55      /**
56       * Returns the standard field name of this standard result field as a string.
57       *
58       * @return the standard result field name
59       */
60      public String getStandardFieldName() {
61          return standardFieldName;
62      }
63  
64      /**
65       * Returns additional field names that are valid and can be used to represent this standard result field as a string.
66       *
67       * @return a set of additional field names
68       */
69      public Set<String> getAdditionalFieldNames() {
70          return additionalFieldNames;
71      }
72  
73      /**
74       * Returns true if the given field name represents a valid field name for this standard result field.  The given
75       * field name is valid if it is the "standard" field name for this result field, or if it is contained withint the
76       * set of additional field names.
77       *
78       * @param fieldName the field name to check
79       *
80       * @return true if the field name is valid for this result field, false otherwise
81       */
82      public boolean isFieldNameValid(String fieldName) {
83          return fieldName.equals(standardFieldName) || additionalFieldNames.contains(fieldName);
84      }
85  
86      public static StandardResultField fromFieldName(String fieldName) {
87  		if (fieldName == null) {
88  			return null;
89  		}
90  		for (StandardResultField resultField : values()) {
91              if (resultField.isFieldNameValid(fieldName)) {
92                  return resultField;
93              }
94  		}
95  		throw new IllegalArgumentException("Failed to locate the StandardResultField with the field name: " + fieldName);
96  	}
97  
98  }