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 java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.List;
22  import javax.xml.bind.annotation.XmlAccessType;
23  import javax.xml.bind.annotation.XmlAccessorType;
24  import javax.xml.bind.annotation.XmlAnyElement;
25  import javax.xml.bind.annotation.XmlElement;
26  import javax.xml.bind.annotation.XmlElementWrapper;
27  import javax.xml.bind.annotation.XmlRootElement;
28  import javax.xml.bind.annotation.XmlType;
29  
30  import org.apache.commons.collections.CollectionUtils;
31  import org.kuali.rice.core.api.CoreConstants;
32  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
33  import org.kuali.rice.core.api.mo.ModelBuilder;
34  import org.kuali.rice.core.api.mo.ModelObjectUtils;
35  import org.kuali.rice.core.api.uif.RemotableAttributeFieldContract;
36  import org.kuali.rice.core.api.uif.RemotableAttributeField;
37  import org.w3c.dom.Element;
38  
39  /**
40   * An immutable data transfer object implementation of the {@link DocumentSearchResultSetConfigurationContract}.
41   * Instances of this class should be constructed using the nested {@link Builder} class.
42   *
43   * @author Kuali Rice Team (rice.collab@kuali.org)
44   */
45  @XmlRootElement(name = DocumentSearchResultSetConfiguration.Constants.ROOT_ELEMENT_NAME)
46  @XmlAccessorType(XmlAccessType.NONE)
47  @XmlType(name = DocumentSearchResultSetConfiguration.Constants.TYPE_NAME, propOrder = {
48      DocumentSearchResultSetConfiguration.Elements.OVERRIDE_SEARCHABLE_ATTRIBUTES,
49      DocumentSearchResultSetConfiguration.Elements.CUSTOM_FIELD_NAMES_TO_ADD,
50      DocumentSearchResultSetConfiguration.Elements.STANDARD_RESULT_FIELDS_TO_REMOVE,
51      DocumentSearchResultSetConfiguration.Elements.ADDITIONAL_ATTRIBUTE_FIELDS,
52      CoreConstants.CommonElements.FUTURE_ELEMENTS
53  })
54  public final class DocumentSearchResultSetConfiguration extends AbstractDataTransferObject
55          implements DocumentSearchResultSetConfigurationContract {
56  
57      @XmlElement(name = Elements.OVERRIDE_SEARCHABLE_ATTRIBUTES, required = true)
58      private final boolean overrideSearchableAttributes;
59  
60      @XmlElementWrapper(name = Elements.CUSTOM_FIELD_NAMES_TO_ADD, required = false)
61      @XmlElement(name = Elements.CUSTOM_FIELD_NAME_TO_ADD, required = false)
62      private final List<String> customFieldNamesToAdd;
63  
64      @XmlElementWrapper(name = Elements.STANDARD_RESULT_FIELDS_TO_REMOVE, required = false)
65      @XmlElement(name = Elements.STANDARD_RESULT_FIELD_TO_REMOVE, required = false)
66      private final List<StandardResultField> standardResultFieldsToRemove;
67  
68      @XmlElementWrapper(name = Elements.ADDITIONAL_ATTRIBUTE_FIELDS, required = false)
69      @XmlElement(name = Elements.ADDITIONAL_ATTRIBUTE_FIELD, required = false)
70      private final List<RemotableAttributeField> additionalAttributeFields;
71      
72      @SuppressWarnings("unused")
73      @XmlAnyElement
74      private final Collection<Element> _futureElements = null;
75  
76      /**
77       * Private constructor used only by JAXB.
78       */
79      @SuppressWarnings("unused")
80      private DocumentSearchResultSetConfiguration() {
81          this.overrideSearchableAttributes = false;
82          this.customFieldNamesToAdd = null;
83          this.standardResultFieldsToRemove = null;
84          this.additionalAttributeFields = null;
85      }
86  
87      private DocumentSearchResultSetConfiguration(Builder builder) {
88          this.overrideSearchableAttributes = builder.isOverrideSearchableAttributes();
89          this.customFieldNamesToAdd = ModelObjectUtils.createImmutableCopy(builder.getCustomFieldNamesToAdd());
90          this.standardResultFieldsToRemove =
91                  ModelObjectUtils.createImmutableCopy(builder.getStandardResultFieldsToRemove());
92          this.additionalAttributeFields = ModelObjectUtils.buildImmutableCopy(builder.getAdditionalAttributeFields());
93      }
94  
95      @Override
96      public boolean isOverrideSearchableAttributes() {
97          return this.overrideSearchableAttributes;
98      }
99  
100     @Override
101     public List<String> getCustomFieldNamesToAdd() {
102         return this.customFieldNamesToAdd;
103     }
104 
105     @Override
106     public List<StandardResultField> getStandardResultFieldsToRemove() {
107         return this.standardResultFieldsToRemove;
108     }
109 
110     @Override
111     public List<RemotableAttributeField> getAdditionalAttributeFields() {
112         return this.additionalAttributeFields;
113     }
114 
115     /**
116      * A builder which can be used to construct {@link DocumentSearchResultSetConfiguration} instances.  Enforces the
117      * constraints of the {@link DocumentSearchResultSetConfigurationContract}.
118      */
119     public final static class Builder implements Serializable, ModelBuilder, DocumentSearchResultSetConfigurationContract {
120 
121         private boolean overrideSearchableAttributes;
122         private List<String> customFieldNamesToAdd;
123         private List<StandardResultField> standardResultFieldsToRemove;
124         private List<RemotableAttributeField.Builder> additionalAttributeFields;
125 
126         private Builder() {
127             setOverrideSearchableAttributes(false);
128             setCustomFieldNamesToAdd(new ArrayList<String>());
129             setStandardResultFieldsToRemove(new ArrayList<StandardResultField>());
130             setAdditionalAttributeFields(new ArrayList<RemotableAttributeField.Builder>());
131         }
132 
133         /**
134          * Creates new empty builder instance.  The various lists on this builder are initialized to empty lists.  The
135          * {@code overrideSearchableAttribute} boolean property is initialized to "false".
136          *
137          * @return a new empty builder instance
138          */
139         public static Builder create() {
140             return new Builder();
141         }
142 
143         /**
144          * Creates a new builder instance initialized with copies of the properties from the given contract.
145          *
146          * @param contract the contract from which to copy properties
147          *
148          * @return a builder instance initialized with properties from the given contract
149          *
150          * @throws IllegalArgumentException if the given contract is null
151          */
152         public static Builder create(DocumentSearchResultSetConfigurationContract contract) {
153             if (contract == null) {
154                 throw new IllegalArgumentException("contract was null");
155             }
156             Builder builder = create();
157             builder.setOverrideSearchableAttributes(contract.isOverrideSearchableAttributes());
158             if (CollectionUtils.isNotEmpty(contract.getCustomFieldNamesToAdd())) {
159                 builder.setCustomFieldNamesToAdd(new ArrayList<String>(contract.getCustomFieldNamesToAdd()));
160             }
161             if (CollectionUtils.isNotEmpty(contract.getStandardResultFieldsToRemove())) {
162                 builder.setStandardResultFieldsToRemove(
163                         new ArrayList<StandardResultField>(contract.getStandardResultFieldsToRemove()));
164             }
165             if (CollectionUtils.isNotEmpty(contract.getAdditionalAttributeFields())) {
166                 for (RemotableAttributeFieldContract attributeField : contract.getAdditionalAttributeFields()) {
167                     builder.getAdditionalAttributeFields().add(RemotableAttributeField.Builder.create(attributeField));
168                 }
169             }
170             return builder;
171         }
172 
173         @Override
174         public DocumentSearchResultSetConfiguration build() {
175             return new DocumentSearchResultSetConfiguration(this);
176         }
177 
178         @Override
179         public boolean isOverrideSearchableAttributes() {
180             return this.overrideSearchableAttributes;
181         }
182 
183         @Override
184         public List<String> getCustomFieldNamesToAdd() {
185             return this.customFieldNamesToAdd;
186         }
187 
188         @Override
189         public List<StandardResultField> getStandardResultFieldsToRemove() {
190             return this.standardResultFieldsToRemove;
191         }
192 
193         @Override
194         public List<RemotableAttributeField.Builder> getAdditionalAttributeFields() {
195             return this.additionalAttributeFields;
196         }
197 
198         public void setOverrideSearchableAttributes(boolean overrideSearchableAttributes) {
199             this.overrideSearchableAttributes = overrideSearchableAttributes;
200         }
201 
202         public void setCustomFieldNamesToAdd(List<String> customFieldNamesToAdd) {
203             this.customFieldNamesToAdd = customFieldNamesToAdd;
204         }
205 
206         public void setStandardResultFieldsToRemove(List<StandardResultField> standardResultFieldsToRemove) {
207             this.standardResultFieldsToRemove = standardResultFieldsToRemove;
208         }
209 
210         public void setAdditionalAttributeFields(List<RemotableAttributeField.Builder> additionalAttributeFields) {
211             this.additionalAttributeFields = additionalAttributeFields;
212         }
213 
214     }
215 
216     /**
217      * Defines some internal constants used on this class.
218      */
219     static class Constants {
220         final static String ROOT_ELEMENT_NAME = "documentSearchResultSetConfiguration";
221         final static String TYPE_NAME = "DocumentSearchResultSetConfigurationType";
222     }
223 
224     /**
225      * A private class which exposes constants which define the XML element names to use when this object is marshalled
226      * to XML.
227      */
228     static class Elements {
229         final static String OVERRIDE_SEARCHABLE_ATTRIBUTES = "overrideSearchableAttributes";
230         final static String CUSTOM_FIELD_NAMES_TO_ADD = "customFieldNamesToAdd";
231         final static String CUSTOM_FIELD_NAME_TO_ADD = "customFieldNameToAdd";
232         final static String STANDARD_RESULT_FIELDS_TO_REMOVE = "standardResultFieldsToRemove";
233         final static String STANDARD_RESULT_FIELD_TO_REMOVE = "standardResultFieldToRemove";
234         final static String ADDITIONAL_ATTRIBUTE_FIELDS = "additionalAttributeFields";
235         final static String ADDITIONAL_ATTRIBUTE_FIELD = "additionalAttributeField";
236     }
237 
238 }