001/** 002 * Copyright 2005-2016 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 */ 016package org.kuali.rice.kew.api.document; 017 018import java.io.Serializable; 019import java.util.ArrayList; 020import java.util.Collection; 021import java.util.List; 022 023import javax.xml.bind.annotation.XmlAccessType; 024import javax.xml.bind.annotation.XmlAccessorType; 025import javax.xml.bind.annotation.XmlAnyElement; 026import javax.xml.bind.annotation.XmlElement; 027import javax.xml.bind.annotation.XmlElementWrapper; 028import javax.xml.bind.annotation.XmlRootElement; 029import javax.xml.bind.annotation.XmlType; 030 031import org.kuali.rice.core.api.CoreConstants; 032import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 033import org.kuali.rice.core.api.mo.ModelBuilder; 034import org.kuali.rice.kew.api.action.ActionRequest; 035import org.kuali.rice.kew.api.action.ActionTaken; 036import org.kuali.rice.kew.api.document.node.RouteNodeInstance; 037import org.w3c.dom.Element; 038 039@XmlRootElement(name = DocumentDetail.Constants.ROOT_ELEMENT_NAME) 040@XmlAccessorType(XmlAccessType.NONE) 041@XmlType(name = DocumentDetail.Constants.TYPE_NAME, propOrder = { 042 DocumentDetail.Elements.DOCUMENT, 043 DocumentDetail.Elements.ACTION_REQUESTS, 044 DocumentDetail.Elements.ACTIONS_TAKEN, 045 DocumentDetail.Elements.ROUTE_NODE_INSTANCES, 046 CoreConstants.CommonElements.FUTURE_ELEMENTS 047}) 048public final class DocumentDetail extends AbstractDataTransferObject implements DocumentDetailContract { 049 050 private static final long serialVersionUID = -8569515693892958719L; 051 052 @XmlElement(name = Elements.DOCUMENT, required = true) 053 private final Document document; 054 055 @XmlElementWrapper(name = Elements.ACTION_REQUESTS, required = true) 056 @XmlElement(name = Elements.ACTION_REQUEST, required = false) 057 private final List<ActionRequest> actionRequests; 058 059 @XmlElementWrapper(name = Elements.ACTIONS_TAKEN, required = true) 060 @XmlElement(name = Elements.ACTION_TAKEN, required = false) 061 private final List<ActionTaken> actionsTaken; 062 063 @XmlElementWrapper(name = Elements.ROUTE_NODE_INSTANCES, required = true) 064 @XmlElement(name = Elements.ROUTE_NODE_INSTANCES, required = true) 065 private final List<RouteNodeInstance> routeNodeInstances; 066 067 @SuppressWarnings("unused") 068 @XmlAnyElement 069 private final Collection<Element> _futureElements = null; 070 071 /** 072 * Private constructor used only by JAXB. 073 */ 074 private DocumentDetail() { 075 this.document = null; 076 this.actionRequests = null; 077 this.actionsTaken = null; 078 this.routeNodeInstances = null; 079 } 080 081 private DocumentDetail(Builder builder) { 082 this.document = builder.getDocument(); 083 this.actionRequests = builder.getActionRequests(); 084 this.actionsTaken = builder.getActionsTaken(); 085 this.routeNodeInstances = builder.getRouteNodeInstances(); 086 } 087 088 @Override 089 public Document getDocument() { 090 return this.document; 091 } 092 093 @Override 094 public List<ActionRequest> getActionRequests() { 095 return this.actionRequests; 096 } 097 098 @Override 099 public List<ActionTaken> getActionsTaken() { 100 return this.actionsTaken; 101 } 102 103 @Override 104 public List<RouteNodeInstance> getRouteNodeInstances() { 105 return this.routeNodeInstances; 106 } 107 108 109 /** 110 * A builder which can be used to construct {@link DocumentDetail} instances. Enforces the constraints of the {@link DocumentDetailContract}. 111 */ 112 public final static class Builder implements Serializable, ModelBuilder, DocumentDetailContract { 113 114 private static final long serialVersionUID = 3108177943363491329L; 115 116 private Document document; 117 private List<ActionRequest> actionRequests; 118 private List<ActionTaken> actionsTaken; 119 private List<RouteNodeInstance> routeNodeInstances; 120 121 private Builder() { 122 // TODO modify this constructor as needed to pass any required values and invoke the appropriate 'setter' methods 123 } 124 125 public static Builder create(Document document) { 126 Builder builder = new Builder(); 127 builder.setDocument(document); 128 builder.setActionRequests(new ArrayList<ActionRequest>()); 129 builder.setActionsTaken(new ArrayList<ActionTaken>()); 130 builder.setRouteNodeInstances(new ArrayList<RouteNodeInstance>()); 131 return builder; 132 } 133 134 public static Builder create(DocumentDetailContract contract) { 135 if (contract == null) { 136 throw new IllegalArgumentException("contract was null"); 137 } 138 Builder builder = create(contract.getDocument()); 139 builder.setActionRequests(contract.getActionRequests()); 140 builder.setActionsTaken(contract.getActionsTaken()); 141 builder.setRouteNodeInstances(contract.getRouteNodeInstances()); 142 return builder; 143 } 144 145 public DocumentDetail build() { 146 return new DocumentDetail(this); 147 } 148 149 @Override 150 public Document getDocument() { 151 return this.document; 152 } 153 154 @Override 155 public List<ActionRequest> getActionRequests() { 156 return this.actionRequests; 157 } 158 159 @Override 160 public List<ActionTaken> getActionsTaken() { 161 return this.actionsTaken; 162 } 163 164 @Override 165 public List<RouteNodeInstance> getRouteNodeInstances() { 166 return this.routeNodeInstances; 167 } 168 169 public void setDocument(Document document) { 170 if (document == null) { 171 throw new IllegalArgumentException("document was null"); 172 } 173 this.document = document; 174 } 175 176 public void setActionRequests(List<ActionRequest> actionRequests) { 177 if (actionRequests == null) { 178 throw new IllegalArgumentException("actionRequests was null"); 179 } 180 this.actionRequests = actionRequests; 181 } 182 183 public void setActionsTaken(List<ActionTaken> actionsTaken) { 184 if (actionsTaken == null) { 185 throw new IllegalArgumentException("actionsTaken was null"); 186 } 187 this.actionsTaken = actionsTaken; 188 } 189 190 public void setRouteNodeInstances(List<RouteNodeInstance> routeNodeInstances) { 191 if (routeNodeInstances == null) { 192 throw new IllegalArgumentException("routeNodeInstances was null"); 193 } 194 this.routeNodeInstances = routeNodeInstances; 195 } 196 197 } 198 199 /** 200 * Defines some internal constants used on this class. 201 */ 202 static class Constants { 203 final static String ROOT_ELEMENT_NAME = "documentDetail"; 204 final static String TYPE_NAME = "DocumentDetailType"; 205 } 206 207 /** 208 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML. 209 */ 210 static class Elements { 211 final static String DOCUMENT = "document"; 212 final static String ACTION_REQUESTS = "actionRequests"; 213 final static String ACTION_REQUEST = "actionRequest"; 214 final static String ACTIONS_TAKEN = "actionsTaken"; 215 final static String ACTION_TAKEN = "actionTaken"; 216 final static String ROUTE_NODE_INSTANCES = "routeNodeInstances"; 217 final static String ROUTE_NODE_INSTANCE = "routeNodeInstance"; 218 } 219 220} 221