View Javadoc

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