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 org.kuali.rice.core.api.CoreConstants;
19  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
20  import org.kuali.rice.core.api.mo.ModelBuilder;
21  import org.kuali.rice.core.api.uif.RemotableAttributeField;
22  import org.w3c.dom.Element;
23  
24  import javax.xml.bind.annotation.XmlAccessType;
25  import javax.xml.bind.annotation.XmlAccessorType;
26  import javax.xml.bind.annotation.XmlAnyElement;
27  import javax.xml.bind.annotation.XmlElement;
28  import javax.xml.bind.annotation.XmlElementWrapper;
29  import javax.xml.bind.annotation.XmlRootElement;
30  import javax.xml.bind.annotation.XmlType;
31  import java.io.Serializable;
32  import java.util.ArrayList;
33  import java.util.Collection;
34  import java.util.Collections;
35  import java.util.List;
36  
37  /**
38   * An immutable data transfer object implementation of the {@link DocumentSearchCriteriaConfigurationContract}.
39   * Instances of this class should be constructed using the nested {@link Builder} class.
40   *
41   * @author Kuali Rice Team (rice.collab@kuali.org)
42   */
43  @XmlRootElement(name = DocumentSearchCriteriaConfiguration.Constants.ROOT_ELEMENT_NAME)
44  @XmlAccessorType(XmlAccessType.NONE)
45  @XmlType(name = DocumentSearchCriteriaConfiguration.Constants.TYPE_NAME, propOrder = {
46      DocumentSearchCriteriaConfiguration.Elements.SEARCH_ATTRIBUTE_FIELDS,
47      CoreConstants.CommonElements.FUTURE_ELEMENTS
48  })
49  public final class DocumentSearchCriteriaConfiguration extends AbstractDataTransferObject implements DocumentSearchCriteriaConfigurationContract {
50  
51      private static final long serialVersionUID = -5764134034667636217L;
52  
53      @XmlElementWrapper(name = Elements.SEARCH_ATTRIBUTE_FIELDS, required = false)
54      @XmlElement(name = Elements.ATTRIBUTE_FIELDS, required = false)
55      private final List<AttributeFields> searchAttributeFields;
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 DocumentSearchCriteriaConfiguration() {
66          this.searchAttributeFields = null;
67      }
68  
69      private DocumentSearchCriteriaConfiguration(Builder builder) {
70          if (builder.getSearchAttributeFields() == null) {
71              this.searchAttributeFields = Collections.emptyList();
72          } else {
73              this.searchAttributeFields = Collections.unmodifiableList(new ArrayList<AttributeFields>(builder.getSearchAttributeFields()));
74          }
75      }
76  
77      @Override
78      public List<AttributeFields> getSearchAttributeFields() {
79          return this.searchAttributeFields;
80      }
81  
82      public List<RemotableAttributeField> getFlattenedSearchAttributeFields() {
83          List<RemotableAttributeField> searchAttributeFields = new ArrayList<RemotableAttributeField>();
84          for (AttributeFields attributeFields : getSearchAttributeFields()) {
85              searchAttributeFields.addAll(attributeFields.getRemotableAttributeFields());
86          }
87          return searchAttributeFields;
88      }
89  
90      /**
91       * A builder which can be used to construct {@link DocumentSearchCriteriaConfiguration} instances.  Enforces the
92       * constraints of the {@link DocumentSearchCriteriaConfigurationContract}.
93       */
94      public final static class Builder implements Serializable, ModelBuilder, DocumentSearchCriteriaConfigurationContract {
95  
96          private List<AttributeFields> searchAttributeFields;
97  
98          private Builder() {
99              setSearchAttributeFields(new ArrayList<AttributeFields>());
100         }
101 
102         /**
103          * Creates new empty builder instance.  The list of search attributes on this builder is intialized to an empty
104          * list.
105          *
106          * @return a new empty builder instance
107          */
108         public static Builder create() {
109             return new Builder();
110         }
111 
112         /**
113          * Creates a new builder instance initialized with copies of the properties from the given contract.
114          *
115          * @param contract the contract from which to copy properties
116          *
117          * @return a builder instance initialized with properties from the given contract
118          *
119          * @throws IllegalArgumentException if the given contract is null
120          */
121         public static Builder create(DocumentSearchCriteriaConfigurationContract contract) {
122             if (contract == null) {
123                 throw new IllegalArgumentException("contract was null");
124             }
125             Builder builder = create();
126             builder.setSearchAttributeFields(contract.getSearchAttributeFields());
127             return builder;
128         }
129 
130         @Override
131         public DocumentSearchCriteriaConfiguration build() {
132             return new DocumentSearchCriteriaConfiguration(this);
133         }
134 
135         @Override
136         public List<AttributeFields> getSearchAttributeFields() {
137             return this.searchAttributeFields;
138         }
139 
140         /**
141          * Sets the search attribute fields on this builder to the given list of attribute fields.
142          *
143          * @param searchAttributeFields the list of search attribute fields to set
144          */
145         public void setSearchAttributeFields(List<AttributeFields> searchAttributeFields) {
146             this.searchAttributeFields = searchAttributeFields;
147         }
148 
149     }
150 
151     /**
152      * Defines some internal constants used on this class.
153      */
154     static class Constants {
155         final static String ROOT_ELEMENT_NAME = "documentSearchCriteriaConfiguration";
156         final static String TYPE_NAME = "DocumentSearchCriteriaConfigurationType";
157     }
158 
159     /**
160      * A private class which exposes constants which define the XML element names to use when this object is marshalled
161      * to XML.
162      */
163     static class Elements {
164         final static String SEARCH_ATTRIBUTE_FIELDS = "searchAttributeFields";
165         final static String ATTRIBUTE_FIELDS = "attributeFields";
166     }
167 
168 }