001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kew.framework.document.search; 017 018import javax.xml.bind.annotation.XmlEnum; 019import javax.xml.bind.annotation.XmlEnumValue; 020import javax.xml.bind.annotation.XmlRootElement; 021import javax.xml.bind.annotation.XmlType; 022import java.util.Arrays; 023import java.util.Collections; 024import java.util.HashSet; 025import java.util.Set; 026 027/** 028 * An enumeration which defines fields that are used on the document search screen and subject to customization by 029 * specific document types which configure such customizations via the document search framework. 030 * 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 */ 033@XmlRootElement(name = "documentSearchResultField") 034@XmlType(name = "DocumentSearchResultFieldType") 035@XmlEnum 036public enum StandardResultField { 037 038 @XmlEnumValue("documentId") DOCUMENT_ID("documentId"), 039 @XmlEnumValue("status") STATUS("status", "statusLabel"), 040 @XmlEnumValue("documentType") DOCUMENT_TYPE("documentType", "documentTypeLabel"), 041 @XmlEnumValue("title") TITLE("title"), 042 @XmlEnumValue("initiator") INITIATOR("initiator", "initiatorDisplayName"), 043 @XmlEnumValue("dateCreated") DATE_CREATED("dateCreated"), 044 @XmlEnumValue("routeLog") ROUTE_LOG("routeLog"); 045 046 private final String standardFieldName; 047 private final Set<String> additionalFieldNames; 048 049 private StandardResultField(String standardFieldName, String... additionalFieldNames) { 050 this.standardFieldName = standardFieldName; 051 Set<String> additionalFieldNameSet = new HashSet<String>(Arrays.asList(additionalFieldNames)); 052 this.additionalFieldNames = Collections.unmodifiableSet(additionalFieldNameSet); 053 } 054 055 /** 056 * Returns the standard field name of this standard result field as a string. 057 * 058 * @return the standard result field name 059 */ 060 public String getStandardFieldName() { 061 return standardFieldName; 062 } 063 064 /** 065 * Returns additional field names that are valid and can be used to represent this standard result field as a string. 066 * 067 * @return a set of additional field names 068 */ 069 public Set<String> getAdditionalFieldNames() { 070 return additionalFieldNames; 071 } 072 073 /** 074 * Returns true if the given field name represents a valid field name for this standard result field. The given 075 * field name is valid if it is the "standard" field name for this result field, or if it is contained withint the 076 * set of additional field names. 077 * 078 * @param fieldName the field name to check 079 * 080 * @return true if the field name is valid for this result field, false otherwise 081 */ 082 public boolean isFieldNameValid(String fieldName) { 083 return fieldName.equals(standardFieldName) || additionalFieldNames.contains(fieldName); 084 } 085 086 public static StandardResultField fromFieldName(String fieldName) { 087 if (fieldName == null) { 088 return null; 089 } 090 for (StandardResultField resultField : values()) { 091 if (resultField.isFieldNameValid(fieldName)) { 092 return resultField; 093 } 094 } 095 throw new IllegalArgumentException("Failed to locate the StandardResultField with the field name: " + fieldName); 096 } 097 098}