View Javadoc

1   /**
2    * Copyright 2005-2012 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  import javax.xml.bind.annotation.XmlAccessType;
21  import javax.xml.bind.annotation.XmlAccessorType;
22  import javax.xml.bind.annotation.XmlAnyElement;
23  import javax.xml.bind.annotation.XmlElement;
24  import javax.xml.bind.annotation.XmlRootElement;
25  import javax.xml.bind.annotation.XmlType;
26  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
27  
28  import org.apache.commons.lang.StringUtils;
29  import org.joda.time.DateTime;
30  import org.kuali.rice.core.api.CoreConstants;
31  import org.kuali.rice.core.api.delegation.DelegationType;
32  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
33  import org.kuali.rice.core.api.mo.ModelBuilder;
34  import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
35  import org.w3c.dom.Element;
36  
37  @XmlRootElement(name = ActionItem.Constants.ROOT_ELEMENT_NAME)
38  @XmlAccessorType(XmlAccessType.NONE)
39  @XmlType(name = ActionItem.Constants.TYPE_NAME, propOrder = {
40      ActionItem.Elements.ID,
41      ActionItem.Elements.DATE_TIME_ASSIGNED,
42      ActionItem.Elements.ACTION_REQUEST_CD,
43      ActionItem.Elements.ACTION_REQUEST_ID,
44      ActionItem.Elements.DOCUMENT_ID,
45      ActionItem.Elements.DOC_TITLE,
46      ActionItem.Elements.DOC_LABEL,
47      ActionItem.Elements.DOC_HANDLER_U_R_L,
48      ActionItem.Elements.DOC_NAME,
49      ActionItem.Elements.RESPONSIBILITY_ID,
50      ActionItem.Elements.ROLE_NAME,
51      ActionItem.Elements.DATE_ASSIGNED_STRING,
52      ActionItem.Elements.ACTION_TO_TAKE,
53      ActionItem.Elements.DELEGATION_TYPE,
54      ActionItem.Elements.ACTION_ITEM_INDEX,
55      ActionItem.Elements.GROUP_ID,
56      ActionItem.Elements.PRINCIPAL_ID,
57      ActionItem.Elements.DELEGATOR_GROUP_ID,
58      ActionItem.Elements.DELEGATOR_PRINCIPAL_ID,
59      CoreConstants.CommonElements.FUTURE_ELEMENTS
60  })
61  public final class ActionItem
62      extends AbstractDataTransferObject
63      implements ActionItemContract
64  {
65  
66      @XmlElement(name = Elements.ID, required = false)
67      private final String id;
68      @XmlElement(name = Elements.DATE_TIME_ASSIGNED, required = true)
69      @XmlJavaTypeAdapter(DateTimeAdapter.class)
70      private final DateTime dateTimeAssigned;
71      @XmlElement(name = Elements.ACTION_REQUEST_CD, required = true)
72      private final String actionRequestCd;
73      @XmlElement(name = Elements.ACTION_REQUEST_ID, required = true)
74      private final String actionRequestId;
75      @XmlElement(name = Elements.DOCUMENT_ID, required = true)
76      private final String documentId;
77      @XmlElement(name = Elements.DOC_TITLE, required = false)
78      private final String docTitle;
79      @XmlElement(name = Elements.DOC_LABEL, required = true)
80      private final String docLabel;
81      @XmlElement(name = Elements.DOC_HANDLER_U_R_L, required = true)
82      private final String docHandlerURL;
83      @XmlElement(name = Elements.DOC_NAME, required = true)
84      private final String docName;
85      @XmlElement(name = Elements.RESPONSIBILITY_ID, required = true)
86      private final String responsibilityId;
87      @XmlElement(name = Elements.ROLE_NAME, required = false)
88      private final String roleName;
89      @XmlElement(name = Elements.DATE_ASSIGNED_STRING, required = false)
90      private final String dateAssignedString;
91      @XmlElement(name = Elements.ACTION_TO_TAKE, required = false)
92      private final String actionToTake;
93      @XmlElement(name = Elements.DELEGATION_TYPE, required = false)
94      private final String delegationType;
95      @XmlElement(name = Elements.ACTION_ITEM_INDEX, required = false)
96      private final Integer actionItemIndex;
97      @XmlElement(name = Elements.GROUP_ID, required = false)
98      private final String groupId;
99      @XmlElement(name = Elements.PRINCIPAL_ID, required = true)
100     private final String principalId;
101     @XmlElement(name = Elements.DELEGATOR_GROUP_ID, required = false)
102     private final String delegatorGroupId;
103     @XmlElement(name = Elements.DELEGATOR_PRINCIPAL_ID, required = false)
104     private final String delegatorPrincipalId;
105     @SuppressWarnings("unused")
106     @XmlAnyElement
107     private final Collection<Element> _futureElements = null;
108 
109     /**
110      * Private constructor used only by JAXB.
111      * 
112      */
113     private ActionItem() {
114         this.id = null;
115         this.dateTimeAssigned = null;
116         this.actionRequestCd = null;
117         this.actionRequestId = null;
118         this.documentId = null;
119         this.docTitle = null;
120         this.docLabel = null;
121         this.docHandlerURL = null;
122         this.docName = null;
123         this.responsibilityId = null;
124         this.roleName = null;
125         this.dateAssignedString = null;
126         this.actionToTake = null;
127         this.delegationType = null;
128         this.actionItemIndex = null;
129         this.groupId = null;
130         this.principalId = null;
131         this.delegatorGroupId = null;
132         this.delegatorPrincipalId = null;
133     }
134 
135     private ActionItem(Builder builder) {
136         this.id = builder.getId();
137         this.dateTimeAssigned = builder.getDateTimeAssigned();
138         this.actionRequestCd = builder.getActionRequestCd();
139         this.actionRequestId = builder.getActionRequestId();
140         this.documentId = builder.getDocumentId();
141         this.docTitle = builder.getDocTitle();
142         this.docLabel = builder.getDocLabel();
143         this.docHandlerURL = builder.getDocHandlerURL();
144         this.docName = builder.getDocName();
145         this.responsibilityId = builder.getResponsibilityId();
146         this.roleName = builder.getRoleName();
147         this.dateAssignedString = builder.getDateAssignedString();
148         this.actionToTake = builder.getActionToTake();
149         this.delegationType = builder.getDelegationType() != null ? builder.getDelegationType().getCode() : null;
150         this.actionItemIndex = builder.getActionItemIndex();
151         this.groupId = builder.getGroupId();
152         this.principalId = builder.getPrincipalId();
153         this.delegatorGroupId = builder.getDelegatorGroupId();
154         this.delegatorPrincipalId = builder.getDelegatorPrincipalId();
155     }
156 
157     @Override
158     public String getId() {
159         return this.id;
160     }
161 
162     @Override
163     public DateTime getDateTimeAssigned() {
164         return this.dateTimeAssigned;
165     }
166 
167     @Override
168     public String getActionRequestCd() {
169         return this.actionRequestCd;
170     }
171 
172     @Override
173     public String getActionRequestId() {
174         return this.actionRequestId;
175     }
176 
177     @Override
178     public String getDocumentId() {
179         return this.documentId;
180     }
181 
182     @Override
183     public String getDocTitle() {
184         return this.docTitle;
185     }
186 
187     @Override
188     public String getDocLabel() {
189         return this.docLabel;
190     }
191 
192     @Override
193     public String getDocHandlerURL() {
194         return this.docHandlerURL;
195     }
196 
197     @Override
198     public String getDocName() {
199         return this.docName;
200     }
201 
202     @Override
203     public String getResponsibilityId() {
204         return this.responsibilityId;
205     }
206 
207     @Override
208     public String getRoleName() {
209         return this.roleName;
210     }
211 
212     @Override
213     public String getDateAssignedString() {
214         return this.dateAssignedString;
215     }
216 
217     @Override
218     public String getActionToTake() {
219         return this.actionToTake;
220     }
221 
222     @Override
223     public DelegationType getDelegationType() {
224         return DelegationType.fromCode(this.delegationType);
225     }
226 
227     @Override
228     public Integer getActionItemIndex() {
229         return this.actionItemIndex;
230     }
231 
232     @Override
233     public String getGroupId() {
234         return this.groupId;
235     }
236 
237     @Override
238     public String getPrincipalId() {
239         return this.principalId;
240     }
241 
242     @Override
243     public String getDelegatorGroupId() {
244         return this.delegatorGroupId;
245     }
246 
247     @Override
248     public String getDelegatorPrincipalId() {
249         return this.delegatorPrincipalId;
250     }
251 
252 
253     /**
254      * A builder which can be used to construct {@link ActionItem} instances.  Enforces the constraints of the {@link ActionItemContract}.
255      * 
256      */
257     public final static class Builder
258         implements Serializable, ModelBuilder, ActionItemContract
259     {
260 
261         private String id;
262         private DateTime dateTimeAssigned;
263         private String actionRequestCd;
264         private String actionRequestId;
265         private String documentId;
266         private String docTitle;
267         private String docLabel;
268         private String docHandlerURL;
269         private String docName;
270         private String responsibilityId;
271         private String roleName;
272         private String dateAssignedString;
273         private String actionToTake;
274         private DelegationType delegationType;
275         private Integer actionItemIndex;
276         private String groupId;
277         private String principalId;
278         private String delegatorGroupId;
279         private String delegatorPrincipalId;
280 
281         private Builder(String documentId, String actionRequestCd, String actionRequestId,
282                 DateTime dateTimeAssigned, String docLabel, String docHanderlURL,
283                 String docName, String responsibilityId, String principalId) {
284             setDocumentId(documentId);
285             setActionRequestCd(actionRequestCd);
286             setActionRequestId(actionRequestId);
287             setDateTimeAssigned(dateTimeAssigned);
288             setDocLabel(docLabel);
289             setDocHandlerURL(docHanderlURL);
290             setDocName(docName);
291             setResponsibilityId(responsibilityId);
292             setPrincipalId(principalId);
293         }
294 
295         public static Builder create(String documentId, String actionRequestCd, String actionRequestId,
296                 DateTime dateTimeAssigned, String docLabel, String docHanderlURL,
297                 String docName, String responsibilityId, String principalId) {
298             return new Builder(documentId, actionRequestCd, actionRequestId, dateTimeAssigned, docLabel,
299                     docHanderlURL, docName, responsibilityId, principalId);
300         }
301 
302         public static Builder create(ActionItemContract contract) {
303             if (contract == null) {
304                 throw new IllegalArgumentException("contract was null");
305             }
306             Builder builder = create(contract.getDocumentId(), contract.getActionRequestCd(), contract.getActionRequestId(),
307                     contract.getDateTimeAssigned(), contract.getDocLabel(), contract.getDocHandlerURL(), contract.getDocName(),
308                     contract.getResponsibilityId(), contract.getPrincipalId());
309             builder.setId(contract.getId());
310             builder.setRoleName(contract.getRoleName());
311             builder.setDocTitle(contract.getDocTitle());
312             builder.setDateAssignedString(contract.getDateAssignedString());
313             builder.setActionToTake(contract.getActionToTake());
314             builder.setDelegationType(contract.getDelegationType());
315             builder.setActionItemIndex(contract.getActionItemIndex());
316             builder.setGroupId(contract.getGroupId());
317             builder.setPrincipalId(contract.getPrincipalId());
318             builder.setDelegatorGroupId(contract.getDelegatorGroupId());
319             builder.setDelegatorPrincipalId(contract.getDelegatorPrincipalId());
320             return builder;
321         }
322 
323         public ActionItem build() {
324             return new ActionItem(this);
325         }
326 
327         @Override
328         public String getId() {
329             return this.id;
330         }
331 
332         @Override
333         public DateTime getDateTimeAssigned() {
334             return this.dateTimeAssigned;
335         }
336 
337         @Override
338         public String getActionRequestCd() {
339             return this.actionRequestCd;
340         }
341 
342         @Override
343         public String getActionRequestId() {
344             return this.actionRequestId;
345         }
346 
347         @Override
348         public String getDocumentId() {
349             return this.documentId;
350         }
351 
352         @Override
353         public String getDocTitle() {
354             return this.docTitle;
355         }
356 
357         @Override
358         public String getDocLabel() {
359             return this.docLabel;
360         }
361 
362         @Override
363         public String getDocHandlerURL() {
364             return this.docHandlerURL;
365         }
366 
367         @Override
368         public String getDocName() {
369             return this.docName;
370         }
371 
372         @Override
373         public String getResponsibilityId() {
374             return this.responsibilityId;
375         }
376 
377         @Override
378         public String getRoleName() {
379             return this.roleName;
380         }
381 
382         @Override
383         public String getDateAssignedString() {
384             return this.dateAssignedString;
385         }
386 
387         @Override
388         public String getActionToTake() {
389             return this.actionToTake;
390         }
391 
392         @Override
393         public DelegationType getDelegationType() {
394             return this.delegationType;
395         }
396 
397         @Override
398         public Integer getActionItemIndex() {
399             return this.actionItemIndex;
400         }
401 
402         @Override
403         public String getGroupId() {
404             return this.groupId;
405         }
406 
407         @Override
408         public String getPrincipalId() {
409             return this.principalId;
410         }
411 
412         @Override
413         public String getDelegatorGroupId() {
414             return this.delegatorGroupId;
415         }
416 
417         @Override
418         public String getDelegatorPrincipalId() {
419             return this.delegatorPrincipalId;
420         }
421 
422         public void setId(String id) {
423             if (StringUtils.isWhitespace(id)) {
424                 throw new IllegalArgumentException("id is blank");
425             }
426             this.id = id;
427         }
428 
429         public void setDateTimeAssigned(DateTime dateTimeAssigned) {
430             if (dateTimeAssigned == null) {
431                 throw new IllegalArgumentException("dateTimeAssigned is null");
432             }
433             this.dateTimeAssigned = dateTimeAssigned;
434         }
435 
436         public void setActionRequestCd(String actionRequestCd) {
437             if (StringUtils.isBlank(actionRequestCd)) {
438                 throw new IllegalArgumentException("actionRequestCd is blank");
439             }
440             this.actionRequestCd = actionRequestCd;
441         }
442 
443         public void setActionRequestId(String actionRequestId) {
444             if (StringUtils.isBlank(actionRequestId)) {
445                 throw new IllegalArgumentException("actionRequestId is blank");
446             }
447             this.actionRequestId = actionRequestId;
448         }
449 
450         public void setDocumentId(String documentId) {
451             if (StringUtils.isBlank(documentId)) {
452                 throw new IllegalArgumentException("documentId is blank");
453             }
454             this.documentId = documentId;
455         }
456 
457         public void setDocTitle(String docTitle) {
458             this.docTitle = docTitle;
459         }
460 
461         public void setDocLabel(String docLabel) {
462             if (StringUtils.isBlank(docLabel)) {
463                 throw new IllegalArgumentException("docLabel is blank");
464             }
465             this.docLabel = docLabel;
466         }
467 
468         public void setDocHandlerURL(String docHandlerURL) {
469             // can be empty, but not null
470             if (docHandlerURL == null) {
471                 throw new IllegalArgumentException("docHandlerURL is null");
472             }
473             this.docHandlerURL = docHandlerURL;
474         }
475 
476         public void setDocName(String docName) {
477             if (StringUtils.isBlank(docName)) {
478                 throw new IllegalArgumentException("docName is blank");
479             }
480             this.docName = docName;
481         }
482 
483         public void setResponsibilityId(String responsibilityId) {
484             if (StringUtils.isBlank(responsibilityId)) {
485                 throw new IllegalArgumentException("responsibilityId is blank");
486             }
487             this.responsibilityId = responsibilityId;
488         }
489 
490         public void setRoleName(String roleName) {
491             this.roleName = roleName;
492         }
493 
494         public void setDateAssignedString(String dateAssignedString) {
495             this.dateAssignedString = dateAssignedString;
496         }
497 
498         public void setActionToTake(String actionToTake) {
499             this.actionToTake = actionToTake;
500         }
501 
502         public void setDelegationType(DelegationType delegationType) {
503             this.delegationType = delegationType;
504         }
505 
506         public void setActionItemIndex(Integer actionItemIndex) {
507             this.actionItemIndex = actionItemIndex;
508         }
509 
510         public void setGroupId(String groupId) {
511             this.groupId = groupId;
512         }
513 
514         public void setPrincipalId(String principalId) {
515             if (StringUtils.isBlank(principalId)) {
516                 throw new IllegalArgumentException("principalId is blank");
517             }
518             this.principalId = principalId;
519         }
520 
521         public void setDelegatorGroupId(String delegatorGroupId) {
522             this.delegatorGroupId = delegatorGroupId;
523         }
524 
525         public void setDelegatorPrincipalId(String delegatorPrincipalId) {
526             this.delegatorPrincipalId = delegatorPrincipalId;
527         }
528 
529     }
530 
531 
532     /**
533      * Defines some internal constants used on this class.
534      * 
535      */
536     static class Constants {
537 
538         final static String ROOT_ELEMENT_NAME = "actionItem";
539         final static String TYPE_NAME = "ActionItemType";
540 
541     }
542 
543 
544     /**
545      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
546      * 
547      */
548     static class Elements {
549 
550         final static String ID = "id";
551         final static String DATE_TIME_ASSIGNED = "dateTimeAssigned";
552         final static String ACTION_REQUEST_CD = "actionRequestCd";
553         final static String ACTION_REQUEST_ID = "actionRequestId";
554         final static String DOCUMENT_ID = "documentId";
555         final static String DOC_TITLE = "docTitle";
556         final static String DOC_LABEL = "docLabel";
557         final static String DOC_HANDLER_U_R_L = "docHandlerURL";
558         final static String DOC_NAME = "docName";
559         final static String RESPONSIBILITY_ID = "responsibilityId";
560         final static String ROLE_NAME = "roleName";
561         final static String DATE_ASSIGNED_STRING = "dateAssignedString";
562         final static String ACTION_TO_TAKE = "actionToTake";
563         final static String DELEGATION_TYPE = "delegationType";
564         final static String ACTION_ITEM_INDEX = "actionItemIndex";
565         final static String GROUP_ID = "groupId";
566         final static String PRINCIPAL_ID = "principalId";
567         final static String DELEGATOR_GROUP_ID = "delegatorGroupId";
568         final static String DELEGATOR_PRINCIPAL_ID = "delegatorPrincipalId";
569 
570     }
571 
572 }