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