001 /*
002 * Copyright 2011 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/ecl1.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 */
016 package org.kuali.rice.kew.api.document;
017
018 import java.io.Serializable;
019 import java.util.ArrayList;
020 import java.util.Collection;
021 import java.util.Collections;
022 import java.util.List;
023
024 import javax.xml.bind.annotation.XmlAccessType;
025 import javax.xml.bind.annotation.XmlAccessorType;
026 import javax.xml.bind.annotation.XmlAnyElement;
027 import javax.xml.bind.annotation.XmlElement;
028 import javax.xml.bind.annotation.XmlElementWrapper;
029 import javax.xml.bind.annotation.XmlRootElement;
030 import javax.xml.bind.annotation.XmlType;
031
032 import org.apache.commons.lang.builder.EqualsBuilder;
033 import org.apache.commons.lang.builder.HashCodeBuilder;
034 import org.apache.commons.lang.builder.ToStringBuilder;
035 import org.kuali.rice.core.api.CoreConstants;
036 import org.kuali.rice.core.api.mo.ModelBuilder;
037 import org.w3c.dom.Element;
038
039 /**
040 * Defines an update to document content on a particular workflow document.
041 * Contains general application content as well as a list of attribute
042 * definitions and searchable definitions. When passed to the appropriate
043 * workflow services to perform an update on document content, if any of the
044 * internal content or definitions on this object have not been set then they
045 * will not be updated. This allows for this data structure to be used to only
046 * update the portion of the document content that is desired to be updated.
047 *
048 * @author Kuali Rice Team (rice.collab@kuali.org)
049 *
050 */
051 @XmlRootElement(name = DocumentContentUpdate.Constants.ROOT_ELEMENT_NAME)
052 @XmlAccessorType(XmlAccessType.NONE)
053 @XmlType(name = DocumentContentUpdate.Constants.TYPE_NAME, propOrder = {
054 DocumentContentUpdate.Elements.APPLICATION_CONTENT,
055 DocumentContentUpdate.Elements.ATTRIBUTE_CONTENT,
056 DocumentContentUpdate.Elements.SEARCHABLE_CONTENT,
057 DocumentContentUpdate.Elements.ATTRIBUTE_DEFINITIONS,
058 DocumentContentUpdate.Elements.SEARCHABLE_DEFINITIONS,
059 CoreConstants.CommonElements.FUTURE_ELEMENTS
060 })
061 public final class DocumentContentUpdate implements Serializable {
062
063 private static final long serialVersionUID = -7386661044232391889L;
064
065 @XmlElement(name = Elements.APPLICATION_CONTENT, required = false)
066 private final String applicationContent;
067
068 @XmlElement(name = Elements.ATTRIBUTE_CONTENT, required = false)
069 private final String attributeContent;
070
071 @XmlElement(name = Elements.SEARCHABLE_CONTENT, required = false)
072 private final String searchableContent;
073
074 @XmlElementWrapper(name = Elements.ATTRIBUTE_DEFINITIONS, required = false)
075 @XmlElement(name = Elements.ATTRIBUTE_DEFINITION, required = false)
076 private List<WorkflowAttributeDefinition> attributeDefinitions;
077
078 @XmlElementWrapper(name = Elements.SEARCHABLE_DEFINITIONS, required = false)
079 @XmlElement(name = Elements.SEARCHABLE_DEFINITION, required = false)
080 private List<WorkflowAttributeDefinition> searchableDefinitions;
081
082 @SuppressWarnings("unused")
083 @XmlAnyElement
084 private final Collection<Element> _futureElements = null;
085
086 /**
087 * Private constructor used only by JAXB.
088 */
089 private DocumentContentUpdate() {
090 this.applicationContent = null;
091 this.attributeContent = null;
092 this.searchableContent = null;
093 this.attributeDefinitions = null;
094 this.searchableDefinitions = null;
095 }
096
097 private DocumentContentUpdate(Builder builder) {
098 this.applicationContent = builder.getApplicationContent();
099 this.attributeContent = builder.getAttributeContent();
100 this.searchableContent = builder.getSearchableContent();
101 if (builder.getAttributeDefinitions() != null) {
102 this.attributeDefinitions = new ArrayList<WorkflowAttributeDefinition>(builder.getAttributeDefinitions());
103 } else {
104 this.attributeDefinitions = new ArrayList<WorkflowAttributeDefinition>();
105 }
106 if (builder.getSearchableDefinitions() != null) {
107 this.searchableDefinitions = new ArrayList<WorkflowAttributeDefinition>(builder.getSearchableDefinitions());
108 } else {
109 this.searchableDefinitions = new ArrayList<WorkflowAttributeDefinition>();
110 }
111 }
112
113 public String getApplicationContent() {
114 return applicationContent;
115 }
116
117 public String getAttributeContent() {
118 return attributeContent;
119 }
120
121 public String getSearchableContent() {
122 return searchableContent;
123 }
124
125 public List<WorkflowAttributeDefinition> getAttributeDefinitions() {
126 return Collections.unmodifiableList(attributeDefinitions);
127 }
128
129 public List<WorkflowAttributeDefinition> getSearchableDefinitions() {
130 return Collections.unmodifiableList(searchableDefinitions);
131 }
132
133 @Override
134 public int hashCode() {
135 return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
136 }
137
138 @Override
139 public boolean equals(Object object) {
140 return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
141 }
142
143 @Override
144 public String toString() {
145 return ToStringBuilder.reflectionToString(this);
146 }
147
148 /**
149 * A builder which can be used to construct {@link DocumentContentUpdate} instances.
150 */
151 public final static class Builder implements Serializable, ModelBuilder {
152
153 private static final long serialVersionUID = -1680695196516508680L;
154
155 private String attributeContent;
156 private String applicationContent;
157 private String searchableContent;
158 private List<WorkflowAttributeDefinition> attributeDefinitions;
159 private List<WorkflowAttributeDefinition> searchableDefinitions;
160
161 private Builder() {
162 this.attributeContent = "";
163 this.applicationContent = "";
164 this.searchableContent = "";
165 this.attributeDefinitions = new ArrayList<WorkflowAttributeDefinition>();
166 this.searchableDefinitions = new ArrayList<WorkflowAttributeDefinition>();
167 }
168
169 public static Builder create() {
170 return new Builder();
171 }
172
173 public static Builder create(DocumentContent documentContent) {
174 if (documentContent == null) {
175 throw new IllegalArgumentException("documentContent was null");
176 }
177 Builder builder = create();
178 builder.setAttributeContent(documentContent.getAttributeContent());
179 builder.setApplicationContent(documentContent.getApplicationContent());
180 builder.setSearchableContent(documentContent.getSearchableContent());
181 return builder;
182 }
183
184 public static Builder create(DocumentContentUpdate documentContentUpdate) {
185 if (documentContentUpdate == null) {
186 throw new IllegalArgumentException("documentContentUpdate was null");
187 }
188 Builder builder = create();
189 builder.setAttributeContent(documentContentUpdate.getAttributeContent());
190 builder.setApplicationContent(documentContentUpdate.getApplicationContent());
191 builder.setSearchableContent(documentContentUpdate.getSearchableContent());
192 builder.setAttributeDefinitions(documentContentUpdate.getAttributeDefinitions());
193 builder.setSearchableDefinitions(documentContentUpdate.getSearchableDefinitions());
194 return builder;
195 }
196
197 public DocumentContentUpdate build() {
198 return new DocumentContentUpdate(this);
199 }
200
201 public String getAttributeContent() {
202 return attributeContent;
203 }
204
205 public void setAttributeContent(String attributeContent) {
206 this.attributeContent = attributeContent;
207 }
208
209 public String getApplicationContent() {
210 return applicationContent;
211 }
212
213 public void setApplicationContent(String applicationContent) {
214 this.applicationContent = applicationContent;
215 }
216
217 public String getSearchableContent() {
218 return searchableContent;
219 }
220
221 public void setSearchableContent(String searchableContent) {
222 this.searchableContent = searchableContent;
223 }
224
225 public List<WorkflowAttributeDefinition> getAttributeDefinitions() {
226 return attributeDefinitions;
227 }
228
229 public void setAttributeDefinitions(List<WorkflowAttributeDefinition> attributeDefinitions) {
230 this.attributeDefinitions = attributeDefinitions;
231 }
232
233 public List<WorkflowAttributeDefinition> getSearchableDefinitions() {
234 return searchableDefinitions;
235 }
236
237 public void setSearchableDefinitions(List<WorkflowAttributeDefinition> searchableDefinitions) {
238 this.searchableDefinitions = searchableDefinitions;
239 }
240
241 }
242
243 /**
244 * Defines some internal constants used on this class.
245 */
246 static class Constants {
247 final static String ROOT_ELEMENT_NAME = "documentContentUpdate";
248 final static String TYPE_NAME = "DocumentContentUpdateType";
249 final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] { CoreConstants.CommonElements.FUTURE_ELEMENTS };
250 }
251
252 /**
253 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
254 */
255 static class Elements {
256 final static String APPLICATION_CONTENT = "applicationContent";
257 final static String ATTRIBUTE_CONTENT = "attributeContent";
258 final static String SEARCHABLE_CONTENT = "searchableContent";
259 final static String ATTRIBUTE_DEFINITION = "attributeDefinition";
260 final static String ATTRIBUTE_DEFINITIONS = "attributeDefinitions";
261 final static String SEARCHABLE_DEFINITION = "searchableDefinition";
262 final static String SEARCHABLE_DEFINITIONS = "searchableDefinitions";
263 }
264
265 }