View Javadoc

1   /**
2    * Copyright 2005-2013 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.preferences;
17  
18  import java.io.Serializable;
19  import java.util.Collection;
20  import java.util.Collections;
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  import javax.xml.bind.annotation.XmlAccessType;
25  import javax.xml.bind.annotation.XmlAccessorType;
26  import javax.xml.bind.annotation.XmlAnyElement;
27  import javax.xml.bind.annotation.XmlElement;
28  import javax.xml.bind.annotation.XmlRootElement;
29  import javax.xml.bind.annotation.XmlType;
30  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
31  
32  import org.apache.commons.lang.StringUtils;
33  import org.kuali.rice.core.api.CoreConstants;
34  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
35  import org.kuali.rice.core.api.mo.ModelBuilder;
36  import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
37  import org.kuali.rice.core.api.util.jaxb.MultiValuedStringMapAdapter;
38  import org.kuali.rice.kew.api.KewApiConstants;
39  import org.w3c.dom.Element;
40  
41  /**
42   * An immutable data transfer object implementing {@link PreferencesContract}.
43   *
44   * p>When loaded, Preferences could be in a state where they require being saved to the database.
45   * If this is the case then {{@link #requiresSave} will evaluate to true.
46   *
47   * @see PreferencesContract
48   *
49   * @author Kuali Rice Team (rice.collab@kuali.org)
50   */
51  @XmlRootElement(name = Preferences.Constants.ROOT_ELEMENT_NAME)
52  @XmlAccessorType(XmlAccessType.NONE)
53  @XmlType(name = Preferences.Constants.TYPE_NAME, propOrder = {
54          Preferences.Elements.REQUIRES_SAVE,
55          Preferences.Elements.EMAIL_NOTIFICATION,
56          Preferences.Elements.NOTIFY_PRIMARY_DELEGATION,
57          Preferences.Elements.NOTIFY_SECONDARY_DELEGATION,
58          Preferences.Elements.OPEN_NEW_WINDOW,
59          Preferences.Elements.SHOW_ACTION_REQUESTED,
60          Preferences.Elements.SHOW_DATE_CREATED,
61          Preferences.Elements.SHOW_DOCUMENT_STATUS,
62          Preferences.Elements.SHOW_APP_DOC_STATUS,
63          Preferences.Elements.SHOW_DOC_TYPE,
64          Preferences.Elements.SHOW_INITIATOR,
65          Preferences.Elements.SHOW_DOC_TITLE,
66          Preferences.Elements.SHOW_WORKGROUP_REQUEST,
67          Preferences.Elements.SHOW_DELEGATOR,
68          Preferences.Elements.SHOW_CLEAR_FYI,
69          Preferences.Elements.PAGE_SIZE,
70          Preferences.Elements.REFRESH_RATE,
71          Preferences.Elements.COLOR_SAVED,
72          Preferences.Elements.COLOR_INITIATED,
73          Preferences.Elements.COLOR_DISAPPROVED,
74          Preferences.Elements.COLOR_ENROUTE,
75          Preferences.Elements.COLOR_APPROVED,
76          Preferences.Elements.COLOR_FINAL,
77          Preferences.Elements.COLOR_DISAPPROVE_CANCEL,
78          Preferences.Elements.COLOR_PROCESSED,
79          Preferences.Elements.COLOR_EXCEPTION,
80          Preferences.Elements.COLOR_CANCELED,
81          Preferences.Elements.DELEGATOR_FILTER,
82          Preferences.Elements.USE_OUTBOX,
83          Preferences.Elements.SHOW_DATE_APPROVED,
84          Preferences.Elements.SHOW_CURRENT_NODE,
85          Preferences.Elements.PRIMARY_DELEGATE_FILTER,
86          Preferences.Elements.NOTIFY_ACKNOWLEDGE,
87          Preferences.Elements.NOTIFY_APPROVE,
88          Preferences.Elements.NOTIFY_COMPLETE,
89          Preferences.Elements.NOTIFY_FYI,
90          Preferences.Elements.DOCUMENT_TYPE_NOTIFICATION_PREFERENCES,
91          Preferences.Elements.DOCUMENT_TYPE_NOTIFICATION_PREFERENCE_MAP,
92          CoreConstants.CommonElements.FUTURE_ELEMENTS
93  })
94  public final class Preferences extends AbstractDataTransferObject implements PreferencesContract {
95  
96      private static final long serialVersionUID = 642820621349964439L;
97  
98      @XmlElement(name = Elements.REQUIRES_SAVE)
99      private final boolean requiresSave;
100     @XmlElement(name = Elements.EMAIL_NOTIFICATION)
101     private final String emailNotification;
102     @XmlElement(name = Elements.NOTIFY_PRIMARY_DELEGATION)
103     private final String notifyPrimaryDelegation;
104     @XmlElement(name = Elements.NOTIFY_SECONDARY_DELEGATION)
105     private final String notifySecondaryDelegation;
106     @XmlElement(name = Elements.OPEN_NEW_WINDOW)
107     private final String openNewWindow;
108     @XmlElement(name = Elements.SHOW_ACTION_REQUESTED)
109     private final String showActionRequested;
110     @XmlElement(name = Elements.SHOW_DATE_CREATED)
111     private final String showDateCreated;
112     @XmlElement(name = Elements.SHOW_DOCUMENT_STATUS)
113     private final String showDocumentStatus;
114     @XmlElement(name = Elements.SHOW_APP_DOC_STATUS)
115     private final String showAppDocStatus;
116     @XmlElement(name = Elements.SHOW_DOC_TYPE)
117     private final String showDocType;
118     @XmlElement(name = Elements.SHOW_INITIATOR)
119     private final String showInitiator;
120     @XmlElement(name = Elements.SHOW_DOC_TITLE)
121     private final String showDocTitle;
122     @XmlElement(name = Elements.SHOW_WORKGROUP_REQUEST)
123     private final String showWorkgroupRequest;
124     @XmlElement(name = Elements.SHOW_DELEGATOR)
125     private final String showDelegator;
126     @XmlElement(name = Elements.SHOW_CLEAR_FYI)
127     private final String showClearFyi;
128     @XmlElement(name = Elements.PAGE_SIZE)
129     private final String pageSize;
130     @XmlElement(name = Elements.REFRESH_RATE)
131     private final String refreshRate;
132     @XmlElement(name = Elements.COLOR_SAVED)
133     private final String colorSaved;
134     @XmlElement(name = Elements.COLOR_INITIATED)
135     private final String colorInitiated;
136     @XmlElement(name = Elements.COLOR_DISAPPROVED)
137     private final String colorDisapproved;
138     @XmlElement(name = Elements.COLOR_ENROUTE)
139     private final String colorEnroute;
140     @XmlElement(name = Elements.COLOR_APPROVED)
141     private final String colorApproved;
142     @XmlElement(name = Elements.COLOR_FINAL)
143     private final String colorFinal;
144     @XmlElement(name = Elements.COLOR_DISAPPROVE_CANCEL)
145     private final String colorDisapproveCancel;
146     @XmlElement(name = Elements.COLOR_PROCESSED)
147     private final String colorProcessed;
148     @XmlElement(name = Elements.COLOR_EXCEPTION)
149     private final String colorException;
150     @XmlElement(name = Elements.COLOR_CANCELED)
151     private final String colorCanceled;
152     @XmlElement(name = Elements.DELEGATOR_FILTER)
153     private final String delegatorFilter;
154     @XmlElement(name = Elements.USE_OUTBOX)
155     private final String useOutbox;
156     @XmlElement(name = Elements.SHOW_DATE_APPROVED)
157     private final String showDateApproved;
158     @XmlElement(name = Elements.SHOW_CURRENT_NODE)
159     private final String showCurrentNode;
160     @XmlElement(name = Elements.PRIMARY_DELEGATE_FILTER)
161     private final String primaryDelegateFilter;
162     @XmlElement(name = Elements.NOTIFY_ACKNOWLEDGE)
163     private final String notifyAcknowledge;
164     @XmlElement(name = Elements.NOTIFY_APPROVE)
165     private final String notifyApprove;
166 
167     //TODO: fix this type in Rice 3.0
168     @XmlElement(name = Elements.NOTIFY_COMPLETE)
169     private final String notifyCompelte;
170     @XmlElement(name = Elements.NOTIFY_FYI)
171     private final String notifyFYI;
172 
173     /*
174      * @Deprecated for 2.1.1.  Invalid @XmlJavaTypeAdapter.  Use documentTypeNotitificationPreferenceMap instead.
175      */
176     @XmlElement(name = Elements.DOCUMENT_TYPE_NOTIFICATION_PREFERENCES)
177     @XmlJavaTypeAdapter(MultiValuedStringMapAdapter.class)
178     @Deprecated
179     private Map<String, String> documentTypeNotificationPreferences;
180 
181     @XmlElement(name = Elements.DOCUMENT_TYPE_NOTIFICATION_PREFERENCE_MAP)
182     @XmlJavaTypeAdapter(MapStringStringAdapter.class)
183     private Map<String, String> documentTypeNotificationPreferenceMap;
184 
185     @SuppressWarnings("unused")
186     @XmlAnyElement
187     private final Collection<Element> _futureElements = null;
188 
189     private Preferences() {
190         this.emailNotification = null;
191         this.notifyPrimaryDelegation = null;
192         this.notifySecondaryDelegation = null;
193         this.openNewWindow = null;
194         this.showActionRequested = null;
195         this.showDateCreated = null;
196         this.showDocumentStatus = null;
197         this.showAppDocStatus = null;
198         this.showDocType = null;
199         this.showInitiator = null;
200         this.showDocTitle = null;
201         this.showWorkgroupRequest = null;
202         this.showDelegator = null;
203         this.showClearFyi = null;
204         this.pageSize = null;
205         this.refreshRate = null;
206         this.colorSaved = null;
207         this.colorInitiated = null;
208         this.colorDisapproved = null;
209         this.colorEnroute = null;
210         this.colorApproved = null;
211         this.colorFinal = null;
212         this.colorDisapproveCancel = null;
213         this.colorProcessed = null;
214         this.colorException = null;
215         this.colorCanceled = null;
216         this.delegatorFilter = null;
217         this.useOutbox = null;
218         this.showDateApproved = null;
219         this.showCurrentNode = null;
220         this.primaryDelegateFilter = null;
221         this.notifyAcknowledge = null;
222         this.notifyApprove =  null;
223         this.notifyCompelte = null;
224         this.notifyFYI = null;
225         this.documentTypeNotificationPreferences = null;
226         this.documentTypeNotificationPreferenceMap = Collections.emptyMap();
227 
228         this.requiresSave = false;
229     }
230 
231     public Preferences(Builder builder) {
232         this.emailNotification = builder.getEmailNotification();
233         this.notifyPrimaryDelegation = builder.getNotifyPrimaryDelegation();
234         this.notifySecondaryDelegation = builder.getNotifySecondaryDelegation();
235         this.openNewWindow = builder.getOpenNewWindow();
236         this.showActionRequested = builder.getShowActionRequested();
237         this.showDateCreated = builder.getShowDateCreated();
238         this.showDocumentStatus = builder.getShowDocumentStatus();
239         this.showAppDocStatus = builder.getShowAppDocStatus();
240         this.showDocType = builder.getShowDocType();
241         this.showInitiator = builder.getShowInitiator();
242         this.showDocTitle = builder.getShowDocTitle();
243         this.showWorkgroupRequest = builder.getShowWorkgroupRequest();
244         this.showDelegator = builder.getShowDelegator();
245         this.showClearFyi = builder.getShowClearFyi();
246         this.pageSize = builder.getPageSize();
247         this.refreshRate = builder.getRefreshRate();
248         this.colorSaved = builder.getColorSaved();
249         this.colorInitiated = builder.getColorInitiated();
250         this.colorDisapproved = builder.getColorDisapproved();
251         this.colorEnroute = builder.getColorEnroute();
252         this.colorApproved = builder.getColorApproved();
253         this.colorFinal = builder.getColorFinal();
254         this.colorDisapproveCancel = builder.getColorDisapproveCancel();
255         this.colorProcessed = builder.getColorProcessed();
256         this.colorException = builder.getColorException();
257         this.colorCanceled = builder.getColorCanceled();
258         this.delegatorFilter = builder.getDelegatorFilter();
259         this.useOutbox = builder.getUseOutbox();
260         this.showDateApproved = builder.getShowDateApproved();
261         this.showCurrentNode = builder.getShowCurrentNode();
262         this.primaryDelegateFilter = builder.getPrimaryDelegateFilter();
263         this.requiresSave = builder.isRequiresSave();
264         this.notifyAcknowledge = builder.getNotifyAcknowledge();
265         this.notifyApprove = builder.getNotifyApprove();
266         this.notifyCompelte = builder.getNotifyComplete();
267         this.notifyFYI = builder.getNotifyFYI();
268         this.documentTypeNotificationPreferences = null;
269         this.documentTypeNotificationPreferenceMap = builder.getDocumentTypeNotificationPreferences();
270     }
271 
272     @Override
273     public boolean isRequiresSave() {
274         return requiresSave;
275     }
276 
277     @Override
278     public String getEmailNotification() {
279         return emailNotification;
280     }
281 
282     @Override
283     public String getNotifyPrimaryDelegation() {
284         return notifyPrimaryDelegation;
285     }
286 
287     @Override
288     public String getNotifySecondaryDelegation() {
289         return notifySecondaryDelegation;
290     }
291 
292     @Override
293     public String getOpenNewWindow() {
294         return openNewWindow;
295     }
296 
297     @Override
298     public String getShowActionRequested() {
299         return showActionRequested;
300     }
301 
302     @Override
303     public String getShowDateCreated() {
304         return showDateCreated;
305     }
306 
307     @Override
308     public String getShowDocumentStatus() {
309         return showDocumentStatus;
310     }
311 
312     @Override
313     public String getShowAppDocStatus() {
314         return showAppDocStatus;
315     }
316 
317     @Override
318     public String getShowDocType() {
319         return showDocType;
320     }
321 
322     @Override
323     public String getShowInitiator() {
324         return showInitiator;
325     }
326 
327     @Override
328     public String getShowDocTitle() {
329         return showDocTitle;
330     }
331 
332     @Override
333     public String getShowWorkgroupRequest() {
334         return showWorkgroupRequest;
335     }
336 
337     @Override
338     public String getShowDelegator() {
339         return showDelegator;
340     }
341 
342     @Override
343     public String getShowClearFyi() {
344         return showClearFyi;
345     }
346 
347     @Override
348     public String getPageSize() {
349         return pageSize;
350     }
351 
352     @Override
353     public String getRefreshRate() {
354         return refreshRate;
355     }
356 
357     @Override
358     public String getColorSaved() {
359         return colorSaved;
360     }
361 
362     @Override
363     public String getColorInitiated() {
364         return colorInitiated;
365     }
366 
367     @Override
368     public String getColorDisapproved() {
369         return colorDisapproved;
370     }
371 
372     @Override
373     public String getColorEnroute() {
374         return colorEnroute;
375     }
376 
377     @Override
378     public String getColorApproved() {
379         return colorApproved;
380     }
381 
382     @Override
383     public String getColorFinal() {
384         return colorFinal;
385     }
386 
387     @Override
388     public String getColorDisapproveCancel() {
389         return colorDisapproveCancel;
390     }
391 
392     @Override
393     public String getColorProcessed() {
394         return colorProcessed;
395     }
396 
397     @Override
398     public String getColorException() {
399         return colorException;
400     }
401 
402     @Override
403     public String getColorCanceled() {
404         return colorCanceled;
405     }
406 
407     @Override
408     public String getDelegatorFilter() {
409         return delegatorFilter;
410     }
411 
412     @Override
413     public String getUseOutbox() {
414         return useOutbox;
415     }
416 
417     @Override
418     public String getShowDateApproved() {
419         return showDateApproved;
420     }
421 
422     @Override
423     public String getShowCurrentNode() {
424         return showCurrentNode;
425     }
426 
427     @Override
428     public String getPrimaryDelegateFilter() {
429         return primaryDelegateFilter;
430     }
431 
432     @Override
433     public String getNotifyComplete() {
434         return this.notifyCompelte;
435     }
436 
437     @Override
438     public String getNotifyApprove() {
439         return this.notifyApprove;
440     }
441 
442     @Override
443     public String getNotifyAcknowledge() {
444         return this.notifyAcknowledge;
445     }
446 
447     @Override
448     public String getNotifyFYI() {
449         return this.notifyFYI;
450     }
451     
452     public String getDocumentTypeNotificationPreference(String documentType) {
453         String preferenceName = documentType.replace(KewApiConstants.DOCUMENT_TYPE_NOTIFICATION_DELIMITER, ".");
454         String preferenceValue = this.getDocumentTypeNotificationPreferences().get(preferenceName);
455         if(StringUtils.isNotBlank(preferenceValue)) {
456             return preferenceValue;
457         }
458         return null;
459     }
460 
461     @Override
462     public Map<String, String> getDocumentTypeNotificationPreferences() {
463         return this.documentTypeNotificationPreferenceMap == null ? this.documentTypeNotificationPreferences : this.documentTypeNotificationPreferenceMap ;
464     }
465 
466     public boolean isUsingOutbox() {
467         if (this.getUseOutbox() != null && this.getUseOutbox().equals(Constants.PREFERENCES_YES_VAL)) {
468             return true;
469         }
470         return false;
471     }
472 
473     public final static class Builder
474             implements Serializable, ModelBuilder, PreferencesContract
475     {
476 
477         private boolean requiresSave = false;
478 
479         private String emailNotification;
480         private String notifyPrimaryDelegation;
481         private String notifySecondaryDelegation;
482         private String openNewWindow;
483         private String showActionRequested;
484         private String showDateCreated;
485         private String showDocumentStatus;
486         private String showAppDocStatus;
487         private String showDocType;
488         private String showInitiator;
489         private String showDocTitle;
490         private String showWorkgroupRequest;
491         private String showDelegator;
492         private String showClearFyi;
493         private String pageSize;
494         private String refreshRate;
495         private String colorSaved;
496         private String colorInitiated;
497         private String colorDisapproved;
498         private String colorEnroute;
499         private String colorApproved;
500         private String colorFinal;
501         private String colorDissapproveCancel;
502         private String colorProcessed;
503         private String colorException;
504         private String colorCanceled;
505         private String delegatorFilter;
506         private String useOutbox;
507         private String showDateApproved;
508         private String showCurrentNode;
509         private String primaryDelegateFilter;
510         private String notifyAcknowledge;
511         private String notifyApprove;
512         private String notifyComplete;
513         private String notifyFYI;
514         private Map<String, String> documentTypeNotificationPreferences;
515 
516         private Builder() {
517             this.documentTypeNotificationPreferences = new HashMap<String, String>();
518         }
519 
520         private Builder(String emailNotification, String notifyPrimaryDelegation, String notifySecondaryDelegation,
521                 String openNewWindow, String showActionRequested, String showDateCreated, String showDocumentStatus,
522                 String showAppDocStatus, String showDocType, String showInitiator, String showDocTitle,
523                 String showWorkgroupRequest, String showDelegator, String showClearFyi, String pageSize, String refreshRate,
524                 String colorSaved, String colorInitiated, String colorDisapproved, String colorEnroute,
525                 String colorApproved, String colorFinal, String colorDissapproveCancel, String colorProcessed,
526                 String colorException, String colorCanceled, String delegatorFilter, String useOutbox,
527                 String showDateApproved, String showCurrentNode, String primaryDelegateFilter, String notifyAcknowledge,
528                 String notifyApprove, String notifyComplete, String notifyFYI, Map<String, String> documentTypeNotificationPreferences,
529                 boolean requiresSave) {
530             this.emailNotification = emailNotification;
531             this.notifyPrimaryDelegation = notifyPrimaryDelegation;
532             this.notifySecondaryDelegation = notifySecondaryDelegation;
533             this.openNewWindow = openNewWindow;
534             this.showActionRequested = showActionRequested;
535             this.showDateCreated = showDateCreated;
536             this.showDocumentStatus = showDocumentStatus;
537             this.showAppDocStatus = showAppDocStatus;
538             this.showDocType = showDocType;
539             this.showInitiator = showInitiator;
540             this.showDocTitle = showDocTitle;
541             this.showWorkgroupRequest = showWorkgroupRequest;
542             this.showDelegator = showDelegator;
543             this.showClearFyi = showClearFyi;
544             this.pageSize = pageSize;
545             this.refreshRate = refreshRate;
546             this.colorSaved = colorSaved;
547             this.colorInitiated = colorInitiated;
548             this.colorDisapproved = colorDisapproved;
549             this.colorEnroute = colorEnroute;
550             this.colorApproved = colorApproved;
551             this.colorFinal = colorFinal;
552             this.colorDissapproveCancel = colorDissapproveCancel;
553             this.colorProcessed = colorProcessed;
554             this.colorException = colorException;
555             this.colorCanceled = colorCanceled;
556             this.delegatorFilter = delegatorFilter;
557             this.useOutbox = useOutbox;
558             this.showDateApproved = showDateApproved;
559             this.showCurrentNode = showCurrentNode;
560             this.primaryDelegateFilter = primaryDelegateFilter;
561             this.requiresSave = requiresSave;
562             this.notifyAcknowledge = notifyAcknowledge;
563             this.notifyApprove = notifyApprove;
564             this.notifyComplete = notifyComplete;
565             this.notifyFYI = notifyFYI;
566             this.documentTypeNotificationPreferences = documentTypeNotificationPreferences;
567         }
568 
569         public Preferences build() {
570             return new Preferences(this);
571         }
572 
573         public static Builder create() {
574             return new Builder();
575         }
576 
577         public static Builder create(String emailNotification, String notifyPrimaryDelegation, String notifySecondaryDelegation,
578                 String openNewWindow, String showActionRequested, String showDateCreated, String showDocumentStatus,
579                 String showAppDocStatus, String showDocType, String showInitiator, String showDocTitle,
580                 String showWorkgroupRequest, String showDelegator, String showClearFyi, String pageSize, String refreshRate,
581                 String colorSaved, String colorInitiated, String colorDisapproved, String colorEnroute,
582                 String colorApproved, String colorFinal, String colorDissapproveCancel, String colorProcessed,
583                 String colorException, String colorCanceled, String delegatorFilter, String useOutbox,
584                 String showDateApproved, String showCurrentNode, String primaryDelegateFilter, String notifyAcknowledge,
585                 String notifyApprove, String notifyComplete, String notifyFYI, Map<String, String> documentTypeNotificationPreferences,
586                 boolean requiresSave) {
587             return new Builder(emailNotification, notifyPrimaryDelegation, notifySecondaryDelegation, openNewWindow, showActionRequested, showDateCreated,
588                     showDocumentStatus, showAppDocStatus, showDocType, showInitiator, showDocTitle, showWorkgroupRequest,  showDelegator, showClearFyi,
589                     pageSize, refreshRate, colorSaved, colorInitiated, colorDisapproved, colorEnroute, colorApproved, colorFinal, colorDissapproveCancel,
590                     colorProcessed, colorException, colorCanceled, delegatorFilter, useOutbox, showDateApproved, showCurrentNode, primaryDelegateFilter,
591                     notifyAcknowledge, notifyApprove, notifyComplete, notifyFYI, documentTypeNotificationPreferences, requiresSave);
592         }
593 
594         public static Builder create(PreferencesContract contract) {
595             if (contract == null) {
596                 throw new IllegalArgumentException("contract was null");
597             }
598             Builder builder = create(contract.getEmailNotification(), contract.getNotifyPrimaryDelegation(), contract.getNotifySecondaryDelegation(), contract.getOpenNewWindow(),
599                     contract.getShowActionRequested(), contract.getShowDateCreated(), contract.getShowDocumentStatus(), contract.getShowAppDocStatus(), contract.getShowDocType(),
600                     contract.getShowInitiator(), contract.getShowDocTitle(), contract.getShowWorkgroupRequest(), contract.getShowDelegator(), contract.getShowClearFyi(),
601                     contract.getPageSize(), contract.getRefreshRate(), contract.getColorSaved(), contract.getColorInitiated(), contract.getColorDisapproved(),
602                     contract.getColorEnroute(), contract.getColorApproved(), contract.getColorFinal(), contract.getColorDisapproveCancel(), contract.getColorProcessed(),
603                     contract.getColorException(), contract.getColorCanceled(), contract.getDelegatorFilter(), contract.getUseOutbox(), contract.getShowDateApproved(),
604                     contract.getShowCurrentNode(), contract.getPrimaryDelegateFilter(), contract.getNotifyAcknowledge(), contract.getNotifyApprove(), contract.getNotifyComplete(),
605                     contract.getNotifyFYI(), contract.getDocumentTypeNotificationPreferences(), contract.isRequiresSave());
606             return builder;
607         }
608 
609         public static Builder create(Map<String, String> map, Map<String, String> documentTypeNotificationPreferences, boolean requiresSave) {
610             Builder builder = create(map.get(KEYS.EMAIL_NOTIFICATION), map.get(KEYS.NOTIFY_PRIMARY_DELEGATION), map.get(KEYS.NOTIFY_SECONDARY_DELEGATION), map.get(KEYS.OPEN_NEW_WINDOW),
611                     map.get(KEYS.SHOW_ACTION_REQUESTED), map.get(KEYS.SHOW_DATE_CREATED), map.get(KEYS.SHOW_DOCUMENT_STATUS), map.get(KEYS.SHOW_APP_DOC_STATUS), map.get(KEYS.SHOW_DOC_TYPE),
612                     map.get(KEYS.SHOW_INITIATOR), map.get(KEYS.SHOW_DOC_TITLE), map.get(KEYS.SHOW_GROUP_REQUEST), map.get(KEYS.SHOW_DELEGATOR), map.get(KEYS.SHOW_CLEAR_FYI),
613                     map.get(KEYS.PAGE_SIZE), map.get(KEYS.REFRESH_RATE), map.get(KEYS.COLOR_SAVED), map.get(KEYS.COLOR_INITIATED), map.get(KEYS.COLOR_DISAPPROVED),
614                     map.get(KEYS.COLOR_ENROUTE), map.get(KEYS.COLOR_APPROVED), map.get(KEYS.COLOR_FINAL), map.get(KEYS.COLOR_DISAPPROVE_CANCEL), map.get(KEYS.COLOR_PROCESSED),
615                     map.get(KEYS.COLOR_EXCEPTION), map.get(KEYS.COLOR_CANCELED), map.get(KEYS.DELEGATOR_FILTER), map.get(KEYS.USE_OUT_BOX), map.get(KEYS.SHOW_DATE_APPROVED),
616                     map.get(KEYS.SHOW_CURRENT_NODE), map.get(KEYS.PRIMARY_DELEGATE_FILTER), map.get(KEYS.NOTIFY_ACKNOWLEDGE), map.get(KEYS.NOTIFY_APPROVE), map.get(KEYS.NOTIFY_COMPLETE),
617                     map.get(KEYS.NOTIFY_FYI), documentTypeNotificationPreferences, requiresSave);
618             return builder;
619         }
620 
621         public synchronized boolean isRequiresSave() {
622             return requiresSave;
623         }
624 
625         public synchronized void setRequiresSave(boolean requiresSave) {
626             this.requiresSave = requiresSave;
627         }
628 
629         public synchronized String getEmailNotification() {
630             return emailNotification;
631         }
632 
633         public synchronized void setEmailNotification(String emailNotification) {
634             this.emailNotification = emailNotification;
635         }
636 
637         public synchronized String getNotifyPrimaryDelegation() {
638             return notifyPrimaryDelegation;
639         }
640 
641         public synchronized void setNotifyPrimaryDelegation(String notifyPrimaryDelegation) {
642             this.notifyPrimaryDelegation = notifyPrimaryDelegation;
643         }
644 
645         public synchronized String getNotifySecondaryDelegation() {
646             return notifySecondaryDelegation;
647         }
648 
649         public synchronized void setNotifySecondaryDelegation(String notifySecondaryDelegation) {
650             this.notifySecondaryDelegation = notifySecondaryDelegation;
651         }
652 
653         public synchronized String getOpenNewWindow() {
654             return openNewWindow;
655         }
656 
657         public synchronized void setOpenNewWindow(String openNewWindow) {
658             this.openNewWindow = openNewWindow;
659         }
660 
661         public synchronized String getShowActionRequested() {
662             return showActionRequested;
663         }
664 
665         public synchronized void setShowActionRequested(String showActionRequested) {
666             this.showActionRequested = showActionRequested;
667         }
668 
669         public synchronized String getShowDateCreated() {
670             return showDateCreated;
671         }
672 
673         public synchronized void setShowDateCreated(String showDateCreated) {
674             this.showDateCreated = showDateCreated;
675         }
676 
677         public synchronized String getShowDocumentStatus() {
678             return showDocumentStatus;
679         }
680 
681         public synchronized void setShowDocumentStatus(String showDocumentStatus) {
682             this.showDocumentStatus = showDocumentStatus;
683         }
684 
685         public synchronized  String getShowAppDocStatus() {
686             return showAppDocStatus;
687         }
688 
689         public synchronized void setShowAppDocStatus(String showAppDocStatus) {
690             this.showAppDocStatus = showAppDocStatus;
691         }
692 
693         public synchronized String getShowDocType() {
694             return showDocType;
695         }
696 
697         public synchronized void setShowDocType(String showDocType) {
698             this.showDocType = showDocType;
699         }
700 
701         public synchronized String getShowInitiator() {
702             return showInitiator;
703         }
704 
705         public synchronized void setShowInitiator(String showInitiator) {
706             this.showInitiator = showInitiator;
707         }
708 
709         public synchronized String getShowDocTitle() {
710             return showDocTitle;
711         }
712 
713         public synchronized void setShowDocTitle(String showDocTitle) {
714             this.showDocTitle = showDocTitle;
715         }
716 
717         public synchronized String getShowWorkgroupRequest() {
718             return showWorkgroupRequest;
719         }
720 
721         public synchronized void setShowWorkgroupRequest(String showWorkgroupRequest) {
722             this.showWorkgroupRequest = showWorkgroupRequest;
723         }
724 
725         public synchronized String getShowDelegator() {
726             return showDelegator;
727         }
728 
729         public synchronized void setShowDelegator(String showDelegator) {
730             this.showDelegator = showDelegator;
731         }
732 
733         public synchronized String getShowClearFyi() {
734             return showClearFyi;
735         }
736 
737         public synchronized void setShowClearFyi(String showClearFyi) {
738             this.showClearFyi = showClearFyi;
739         }
740 
741         public synchronized String getPageSize() {
742             return pageSize;
743         }
744 
745         public synchronized void setPageSize(String pageSize) {
746             this.pageSize = pageSize;
747         }
748 
749         public synchronized String getRefreshRate() {
750             return refreshRate;
751         }
752 
753         public synchronized void setRefreshRate(String refreshRate) {
754             this.refreshRate = refreshRate;
755         }
756 
757         public synchronized String getColorSaved() {
758             return colorSaved;
759         }
760 
761         public synchronized void setColorSaved(String colorSaved) {
762             this.colorSaved = colorSaved;
763         }
764 
765         public synchronized String getColorInitiated() {
766             return colorInitiated;
767         }
768 
769         public synchronized void setColorInitiated(String colorInitiated) {
770             this.colorInitiated = colorInitiated;
771         }
772 
773         public synchronized String getColorDisapproved() {
774             return colorDisapproved;
775         }
776 
777         public synchronized void setColorDisapproved(String colorDisapproved) {
778             this.colorDisapproved = colorDisapproved;
779         }
780 
781         public synchronized String getColorEnroute() {
782             return colorEnroute;
783         }
784 
785         public synchronized void setColorEnroute(String colorEnroute) {
786             this.colorEnroute = colorEnroute;
787         }
788 
789         public synchronized String getColorApproved() {
790             return colorApproved;
791         }
792 
793         public synchronized void setColorApproved(String colorApproved) {
794             this.colorApproved = colorApproved;
795         }
796 
797         public synchronized String getColorFinal() {
798             return colorFinal;
799         }
800 
801         public synchronized void setColorFinal(String colorFinal) {
802             this.colorFinal = colorFinal;
803         }
804 
805         public synchronized String getColorDisapproveCancel() {
806             return colorDissapproveCancel;
807         }
808 
809         public synchronized void setColorDissapproveCancel(String colorDissapproveCancel) {
810             this.colorDissapproveCancel = colorDissapproveCancel;
811         }
812 
813         public synchronized String getColorProcessed() {
814             return colorProcessed;
815         }
816 
817         public synchronized void setColorProcessed(String colorProcessed) {
818             this.colorProcessed = colorProcessed;
819         }
820 
821         public synchronized String getColorException() {
822             return colorException;
823         }
824 
825         public synchronized void setColorException(String colorException) {
826             this.colorException = colorException;
827         }
828 
829         public synchronized String getColorCanceled() {
830             return colorCanceled;
831         }
832 
833         public synchronized void setColorCanceled(String colorCanceled) {
834             this.colorCanceled = colorCanceled;
835         }
836 
837         public synchronized String getDelegatorFilter() {
838             return delegatorFilter;
839         }
840 
841         public synchronized void setDelegatorFilter(String delegatorFilter) {
842             this.delegatorFilter = delegatorFilter;
843         }
844 
845         public synchronized String getUseOutbox() {
846             return useOutbox;
847         }
848 
849         public synchronized void setUseOutbox(String useOutbox) {
850             this.useOutbox = useOutbox;
851         }
852 
853         public synchronized String getShowDateApproved() {
854             return showDateApproved;
855         }
856 
857         public synchronized void setShowDateApproved(String showDateApproved) {
858             this.showDateApproved = showDateApproved;
859         }
860 
861         public synchronized String getShowCurrentNode() {
862             return showCurrentNode;
863         }
864 
865         public synchronized void setShowCurrentNode(String showCurrentNode) {
866             this.showCurrentNode = showCurrentNode;
867         }
868 
869         public synchronized String getPrimaryDelegateFilter() {
870             return primaryDelegateFilter;
871         }
872 
873         public synchronized void setPrimaryDelegateFilter(String primaryDelegateFilter) {
874             this.primaryDelegateFilter = primaryDelegateFilter;
875         }
876 
877         public synchronized String getNotifyAcknowledge() {
878             return this.notifyAcknowledge;
879         }
880 
881         public synchronized void setNotifyAcknowledge(String notifyAcknowledge) {
882             this.notifyAcknowledge = notifyAcknowledge;
883         }
884 
885         public synchronized String getNotifyApprove() {
886             return this.notifyApprove;
887         }
888 
889         public synchronized void setNotifyApprove(String notifyApprove) {
890             this.notifyApprove = notifyApprove;
891         }
892 
893         public synchronized String getNotifyComplete() {
894             return this.notifyComplete;
895         }
896 
897         public synchronized void setNotifyComplete(String notifyComplete) {
898             this.notifyComplete = notifyComplete;
899         }
900 
901         public synchronized String getNotifyFYI() {
902             return this.notifyFYI;
903         }
904 
905         public synchronized void setNotifyFYI(String notifyFYI) {
906             this.notifyFYI = notifyFYI;
907         }
908         
909         public synchronized String getDocumentTypeNotificationPreference(String documentType) {
910             String preferenceName = documentType.replace(KewApiConstants.DOCUMENT_TYPE_NOTIFICATION_DELIMITER, ".");
911             String preferenceValue = this.documentTypeNotificationPreferences.get(preferenceName);
912             if(StringUtils.isNotBlank(preferenceValue)) {
913                 return preferenceValue;
914             }
915             return null;
916         }
917         
918         public synchronized void setDocumentTypeNotificationPreference(String documentType, String preference) {   
919             documentType = documentType.replace(KewApiConstants.DOCUMENT_TYPE_NOTIFICATION_DELIMITER, ".");
920             this.documentTypeNotificationPreferences.put(documentType, preference);
921         }
922 
923         public synchronized Map<String, String> getDocumentTypeNotificationPreferences() {
924             if(this.documentTypeNotificationPreferences == null) {
925                 this.documentTypeNotificationPreferences = new HashMap<String, String>();
926             }
927             return this.documentTypeNotificationPreferences;
928         }
929 
930         public synchronized void setDocumentTypeNotificationPreferences(Map<String, String> documentTypeNotificationPreferences) {
931             this.documentTypeNotificationPreferences = documentTypeNotificationPreferences;
932         }
933         
934         public synchronized void addDocumentTypeNotificationPreference(String documentType, String preference) {
935             this.getDocumentTypeNotificationPreferences().put(documentType, preference);
936         }
937         
938         public synchronized void removeDocumentTypeNotificationPreference(String documentType) {
939             this.getDocumentTypeNotificationPreferences().remove(documentType);
940         }
941     }
942 
943     static class Constants {
944         static final String ROOT_ELEMENT_NAME = "preferences";
945         static final String TYPE_NAME = "PreferencesType";
946         static final String PREFERENCES_YES_VAL = "yes";
947     }
948 
949     /**
950      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
951      *
952      */
953     static class Elements {
954 
955         static final String REQUIRES_SAVE = "requiresSave";
956         static final String EMAIL_NOTIFICATION = "emailNotification";
957         static final String NOTIFY_PRIMARY_DELEGATION = "notifyPrimaryDelegation";
958         static final String NOTIFY_SECONDARY_DELEGATION = "notifySecondaryDelegation";
959         static final String OPEN_NEW_WINDOW = "openNewWindow";
960         static final String SHOW_ACTION_REQUESTED = "showActionRequested";
961         static final String SHOW_DATE_CREATED = "showDateCreated";
962         static final String SHOW_DOCUMENT_STATUS = "showDocumentStatus";
963         static final String SHOW_APP_DOC_STATUS = "showAppDocStatus";
964         static final String SHOW_DOC_TYPE = "showDocType";
965         static final String SHOW_INITIATOR = "showInitiator";
966         static final String SHOW_DOC_TITLE = "showDocTitle";
967         static final String SHOW_WORKGROUP_REQUEST = "showWorkgroupRequest";
968         static final String SHOW_DELEGATOR = "showDelegator";
969         static final String SHOW_CLEAR_FYI = "showClearFyi";
970         static final String PAGE_SIZE = "pageSize";
971         static final String REFRESH_RATE = "refreshRate";
972         static final String COLOR_SAVED = "colorSaved";
973         static final String COLOR_INITIATED = "colorInitiated";
974         static final String COLOR_DISAPPROVED = "colorDisapproved";
975         static final String COLOR_ENROUTE = "colorEnroute";
976         static final String COLOR_APPROVED = "colorApproved";
977         static final String COLOR_FINAL = "colorFinal";
978         static final String COLOR_DISAPPROVE_CANCEL = "colorDisapproveCancel";
979         static final String COLOR_PROCESSED = "colorProcessed";
980         static final String COLOR_EXCEPTION = "colorException";
981         static final String COLOR_CANCELED = "colorCanceled";
982         static final String DELEGATOR_FILTER = "delegatorFilter";
983         static final String USE_OUTBOX = "useOutbox";
984         static final String SHOW_DATE_APPROVED = "showDateApproved";
985         static final String SHOW_CURRENT_NODE = "showCurrentNode";
986         static final String PRIMARY_DELEGATE_FILTER = "primaryDelegateFilter";
987         static final String NOTIFY_ACKNOWLEDGE = "notifyAcknowledge";
988         static final String NOTIFY_APPROVE = "notifyApprove";
989         static final String NOTIFY_COMPLETE = "notifyCompelte";
990         static final String NOTIFY_FYI = "notifyFYI";
991         static final String DOCUMENT_TYPE_NOTIFICATION_PREFERENCES = "documentTypeNotificationPreferences";
992         static final String DOCUMENT_TYPE_NOTIFICATION_PREFERENCE_MAP = "documentTypeNotificationPreferenceMap";
993     }
994 
995     public static class KEYS {
996         public static final String COLOR_DISAPPROVED = "DOCUMENT_STATUS_COLOR_D";
997         public static final String COLOR_DISAPPROVE_CANCEL = "DOCUMENT_STATUS_COLOR_C";
998         public static final String COLOR_APPROVED = "DOCUMENT_STATUS_COLOR_A";
999         public static final String COLOR_CANCELED = "DOCUMENT_STATUS_COLOR_X";
1000         public static final String COLOR_SAVED = "DOCUMENT_STATUS_COLOR_S";
1001         public static final String COLOR_ENROUTE = "DOCUMENT_STATUS_COLOR_R";
1002         public static final String COLOR_PROCESSED = "DOCUMENT_STATUS_COLOR_P";
1003         public static final String COLOR_INITIATED = "DOCUMENT_STATUS_COLOR_I";
1004         public static final String COLOR_FINAL = "DOCUMENT_STATUS_COLOR_F";
1005         public static final String COLOR_EXCEPTION = "DOCUMENT_STATUS_COLOR_E";
1006         public static final String REFRESH_RATE = "REFRESH_RATE";
1007         public static final String OPEN_NEW_WINDOW = "OPEN_ITEMS_NEW_WINDOW";
1008         public static final String SHOW_DOC_TYPE = "DOC_TYPE_COL_SHOW_NEW";
1009         public static final String SHOW_DOC_TITLE = "TITLE_COL_SHOW_NEW";
1010         public static final String SHOW_ACTION_REQUESTED = "ACTION_REQUESTED_COL_SHOW_NEW";
1011         public static final String SHOW_INITIATOR = "INITIATOR_COL_SHOW_NEW";
1012         public static final String SHOW_DELEGATOR = "DELEGATOR_COL_SHOW_NEW";
1013         public static final String SHOW_DATE_CREATED = "DATE_CREATED_COL_SHOW_NEW";
1014         public static final String SHOW_DOCUMENT_STATUS = "DOCUMENT_STATUS_COL_SHOW_NEW";
1015         public static final String SHOW_APP_DOC_STATUS = "APP_DOC_STATUS_COL_SHOW_NEW";
1016         public static final String SHOW_GROUP_REQUEST = "WORKGROUP_REQUEST_COL_SHOW_NEW";
1017         public static final String SHOW_CLEAR_FYI = "CLEAR_FYI_COL_SHOW_NEW";
1018         public static final String PAGE_SIZE = "ACTION_LIST_SIZE_NEW";
1019         public static final String EMAIL_NOTIFICATION = "EMAIL_NOTIFICATION";
1020         public static final String NOTIFY_PRIMARY_DELEGATION = "EMAIL_NOTIFY_PRIMARY";
1021         public static final String NOTIFY_SECONDARY_DELEGATION = "EMAIL_NOTIFY_SECONDARY";
1022         public static final String DEFAULT_COLOR = "white";
1023         public static final String DEFAULT_ACTION_LIST_SIZE = "10";
1024         public static final String DEFAULT_REFRESH_RATE = "15";
1025         public static final String ERR_KEY_REFRESH_RATE_WHOLE_NUM = "preferences.refreshRate";
1026         public static final String ERR_KEY_ACTION_LIST_PAGE_SIZE_WHOLE_NUM = "preferences.pageSize";
1027         public static final String DELEGATOR_FILTER = "DELEGATOR_FILTER";
1028         public static final String PRIMARY_DELEGATE_FILTER = "PRIMARY_DELEGATE_FILTER";
1029         public static final String USE_OUT_BOX = "USE_OUT_BOX";
1030         public static final String SHOW_DATE_APPROVED = "LAST_APPROVED_DATE_COL_SHOW_NEW";
1031         public static final String SHOW_CURRENT_NODE = "CURRENT_NODE_COL_SHOW_NEW";
1032         public static final String NOTIFY_ACKNOWLEDGE = "NOTIFY_ACKNOWLEDGE";
1033         public static final String NOTIFY_APPROVE = "NOTIFY_APPROVE";
1034         public static final String NOTIFY_COMPLETE = "NOTIFY_COMPLETE";
1035         public static final String NOTIFY_FYI = "NOTIFY_FYI";
1036         public static final String DOCUMENT_TYPE_NOTIFICATION_PREFERENCES = "DOCUMENT_TYPE_NOTIFICATION_PREFERENCES";
1037     }
1038 
1039     public static class Cache {
1040         public static final String NAME = KewApiConstants.Namespaces.KEW_NAMESPACE_2_0 + "/" + Preferences.Constants.TYPE_NAME;
1041     }
1042 
1043 }