View Javadoc

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