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.api.action;
17  
18  import java.io.Serializable;
19  import java.util.Collection;
20  
21  import javax.xml.bind.annotation.XmlAccessType;
22  import javax.xml.bind.annotation.XmlAccessorType;
23  import javax.xml.bind.annotation.XmlAnyElement;
24  import javax.xml.bind.annotation.XmlElement;
25  import javax.xml.bind.annotation.XmlRootElement;
26  import javax.xml.bind.annotation.XmlType;
27  
28  import org.apache.commons.lang.StringUtils;
29  import org.kuali.rice.core.api.CoreConstants;
30  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
31  import org.kuali.rice.core.api.mo.ModelBuilder;
32  import org.kuali.rice.kew.api.document.DocumentContentUpdate;
33  import org.kuali.rice.kew.api.document.DocumentUpdate;
34  import org.w3c.dom.Element;
35  
36  @XmlRootElement(name = DocumentActionParameters.Constants.ROOT_ELEMENT_NAME)
37  @XmlAccessorType(XmlAccessType.NONE)
38  @XmlType(name = DocumentActionParameters.Constants.TYPE_NAME, propOrder = {
39          DocumentActionParameters.Elements.DOCUMENT_ID,
40          DocumentActionParameters.Elements.PRINCIPAL_ID,
41          DocumentActionParameters.Elements.ANNOTATION,
42          DocumentActionParameters.Elements.DOCUMENT_UPDATE,
43          DocumentActionParameters.Elements.DOCUMENT_CONTENT_UPDATE,
44          CoreConstants.CommonElements.FUTURE_ELEMENTS
45  })
46  public final class DocumentActionParameters extends AbstractDataTransferObject {
47  
48      private static final long serialVersionUID = -7589214734683758734L;
49  
50      @XmlElement(name = Elements.DOCUMENT_ID, required = true)
51      private final String documentId;
52  
53      @XmlElement(name = Elements.PRINCIPAL_ID, required = true)
54      private final String principalId;
55  
56      @XmlElement(name = Elements.ANNOTATION, required = false)
57      private final String annotation;
58  
59      @XmlElement(name = Elements.DOCUMENT_UPDATE, required = false)
60      private final DocumentUpdate documentUpdate;
61  
62      @XmlElement(name = Elements.DOCUMENT_CONTENT_UPDATE, required = false)
63      private final DocumentContentUpdate documentContentUpdate;
64  
65      @SuppressWarnings("unused")
66      @XmlAnyElement
67      private final Collection<Element> _futureElements = null;
68  
69      private DocumentActionParameters() {
70          this.documentId = null;
71          this.principalId = null;
72          this.annotation = null;
73          this.documentUpdate = null;
74          this.documentContentUpdate = null;
75      }
76  
77      private DocumentActionParameters(Builder builder) {
78          this.documentId = builder.getDocumentId();
79          this.principalId = builder.getPrincipalId();
80          this.annotation = builder.getAnnotation();
81          this.documentUpdate = builder.getDocumentUpdate();
82          this.documentContentUpdate = builder.getDocumentContentUpdate();
83      }
84  
85      public static DocumentActionParameters create(String documentId, String principalId) {
86          return create(documentId, principalId, "");
87      }
88  
89      public static DocumentActionParameters create(String documentId, String principalId, String annotation) {
90          Builder builder = Builder.create(documentId, principalId);
91          builder.setAnnotation(annotation);
92          return builder.build();
93      }
94  
95      public String getDocumentId() {
96          return documentId;
97      }
98  
99      public String getPrincipalId() {
100         return principalId;
101     }
102 
103     public String getAnnotation() {
104         return annotation;
105     }
106 
107     public DocumentUpdate getDocumentUpdate() {
108         return documentUpdate;
109     }
110 
111     public DocumentContentUpdate getDocumentContentUpdate() {
112         return documentContentUpdate;
113     }
114 
115     /**
116      * A builder which can be used to construct {@link DocumentActionParameters} instances.
117      * 
118      */
119     public final static class Builder implements Serializable, ModelBuilder {
120 
121         private static final long serialVersionUID = -9209748637365086000L;
122 
123         private String documentId;
124         private String principalId;
125         private String annotation;
126         private DocumentUpdate documentUpdate;
127         private DocumentContentUpdate documentContentUpdate;
128 
129         private Builder(String documentId, String principalId) {
130             setDocumentId(documentId);
131             setPrincipalId(principalId);
132         }
133 
134         public static Builder create(String documentId, String principalId) {
135             return new Builder(documentId, principalId);
136         }
137 
138         public DocumentActionParameters build() {
139             return new DocumentActionParameters(this);
140         }
141 
142         public String getDocumentId() {
143             return documentId;
144         }
145 
146         public void setDocumentId(String documentId) {
147             if (StringUtils.isBlank(documentId)) {
148                 throw new IllegalArgumentException("documentId was null or blank");
149             }
150             this.documentId = documentId;
151         }
152 
153         public String getPrincipalId() {
154             return principalId;
155         }
156 
157         public void setPrincipalId(String principalId) {
158             if (StringUtils.isBlank(principalId)) {
159                 throw new IllegalArgumentException("principalId was null or blank");
160             }
161             this.principalId = principalId;
162         }
163 
164         public String getAnnotation() {
165             return annotation;
166         }
167 
168         public void setAnnotation(String annotation) {
169             this.annotation = annotation;
170         }
171 
172         public DocumentUpdate getDocumentUpdate() {
173             return documentUpdate;
174         }
175 
176         public void setDocumentUpdate(DocumentUpdate documentUpdate) {
177             this.documentUpdate = documentUpdate;
178         }
179 
180         public DocumentContentUpdate getDocumentContentUpdate() {
181             return documentContentUpdate;
182         }
183 
184         public void setDocumentContentUpdate(DocumentContentUpdate documentContentUpdate) {
185             this.documentContentUpdate = documentContentUpdate;
186         }
187 
188     }
189 
190     /**
191      * Defines some internal constants used on this class.
192      */
193     static class Constants {
194         final static String ROOT_ELEMENT_NAME = "documentActionParameters";
195         final static String TYPE_NAME = "DocumentActionParametersType";
196     }
197 
198     /**
199      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
200      */
201     static class Elements {
202         final static String DOCUMENT_ID = "documentId";
203         final static String PRINCIPAL_ID = "principalId";
204         final static String ANNOTATION = "annotation";
205         final static String DOCUMENT_UPDATE = "documentUpdate";
206         final static String DOCUMENT_CONTENT_UPDATE = "documentContentUpdate";
207     }
208 
209 }