001 /**
002 * Copyright 2005-2013 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 */
016 package org.kuali.rice.kew.api.action;
017
018 import java.util.Collection;
019 import java.util.Collections;
020 import java.util.EnumSet;
021 import java.util.Set;
022
023 import javax.xml.bind.annotation.XmlAccessType;
024 import javax.xml.bind.annotation.XmlAccessorType;
025 import javax.xml.bind.annotation.XmlAnyElement;
026 import javax.xml.bind.annotation.XmlElement;
027 import javax.xml.bind.annotation.XmlRootElement;
028 import javax.xml.bind.annotation.XmlType;
029
030 import org.kuali.rice.core.api.CoreConstants;
031 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
032 import org.w3c.dom.Element;
033
034 @XmlRootElement(name = RequestedActions.Constants.ROOT_ELEMENT_NAME)
035 @XmlAccessorType(XmlAccessType.NONE)
036 @XmlType(name = RequestedActions.Constants.TYPE_NAME, propOrder = {
037 RequestedActions.Elements.COMPLETE_REQUESTED,
038 RequestedActions.Elements.APPROVE_REQUESTED,
039 RequestedActions.Elements.ACKNOWLEDGE_REQUESTED,
040 RequestedActions.Elements.FYI_REQUESTED,
041 CoreConstants.CommonElements.FUTURE_ELEMENTS
042 })
043 public final class RequestedActions extends AbstractDataTransferObject {
044
045 private static final long serialVersionUID = -6600754341497697330L;
046
047 @XmlElement(name = Elements.COMPLETE_REQUESTED, required = true)
048 private final boolean completeRequested;
049
050 @XmlElement(name = Elements.APPROVE_REQUESTED, required = true)
051 private final boolean approveRequested;
052
053 @XmlElement(name = Elements.ACKNOWLEDGE_REQUESTED, required = true)
054 private final boolean acknowledgeRequested;
055
056 @XmlElement(name = Elements.FYI_REQUESTED, required = true)
057 private final boolean fyiRequested;
058
059 @SuppressWarnings("unused")
060 @XmlAnyElement
061 private final Collection<Element> _futureElements = null;
062
063 private RequestedActions() {
064 this.completeRequested = false;
065 this.approveRequested = false;
066 this.acknowledgeRequested = false;
067 this.fyiRequested = false;
068 }
069
070 private RequestedActions(boolean completeRequested, boolean approveRequested, boolean acknowledgeRequested, boolean fyiRequested) {
071 this.completeRequested = completeRequested;
072 this.approveRequested = approveRequested;
073 this.acknowledgeRequested = acknowledgeRequested;
074 this.fyiRequested = fyiRequested;
075 }
076
077 public static RequestedActions create(boolean completeRequested, boolean approveRequested, boolean acknowledgeRequested, boolean fyiRequested) {
078 return new RequestedActions(completeRequested, approveRequested, acknowledgeRequested, fyiRequested);
079 }
080
081 public boolean isCompleteRequested() {
082 return completeRequested;
083 }
084
085 public boolean isApproveRequested() {
086 return approveRequested;
087 }
088
089 public boolean isAcknowledgeRequested() {
090 return acknowledgeRequested;
091 }
092
093 public boolean isFyiRequested() {
094 return fyiRequested;
095 }
096
097 /**
098 * Returns a Set of {@link ActionRequestType}s which indicate the actions which have been requested. This will
099 * essentially contain request types for any of the request-related methods on this class which return "true". If
100 * no actions are requested, the empty set will be returned (this method will never return null).
101 *
102 * @return an unmodifiable Set of action request types which have been requested, or an empty set if no actions are
103 * requested
104 */
105 public Set<ActionRequestType> getRequestedActions() {
106 EnumSet<ActionRequestType> requestedActions = EnumSet.noneOf(ActionRequestType.class);
107 if (isCompleteRequested()) {
108 requestedActions.add(ActionRequestType.COMPLETE);
109 }
110 if (isApproveRequested()) {
111 requestedActions.add(ActionRequestType.APPROVE);
112 }
113 if (isAcknowledgeRequested()) {
114 requestedActions.add(ActionRequestType.ACKNOWLEDGE);
115 }
116 if (isFyiRequested()) {
117 requestedActions.add(ActionRequestType.FYI);
118 }
119 return Collections.unmodifiableSet(requestedActions);
120 }
121
122 /**
123 * Returns true if this set of requested actions contains the given action request type.
124 *
125 * @param actionRequestType the {@link ActionRequestType} to check for, can't be null
126 *
127 * @return true if the action is requested, false otherwise
128 *
129 * @throws IllegalArgumentException if actionRequestType is null
130 */
131 public boolean contains(ActionRequestType actionRequestType) {
132 if (actionRequestType == null) {
133 throw new IllegalArgumentException("actionRequestType was null");
134 }
135 return getRequestedActions().contains(actionRequestType);
136 }
137
138 /**
139 * Defines some internal constants used on this class.
140 */
141 static class Constants {
142 final static String ROOT_ELEMENT_NAME = "requestedActions";
143 final static String TYPE_NAME = "RequestedActionsType";
144 }
145
146 /**
147 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
148 */
149 static class Elements {
150 final static String COMPLETE_REQUESTED = "completeRequested";
151 final static String APPROVE_REQUESTED = "approveRequested";
152 final static String ACKNOWLEDGE_REQUESTED = "acknowledgeRequested";
153 final static String FYI_REQUESTED = "fyiRequested";
154 }
155
156 }