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.io.Serializable; 019 import java.util.Collection; 020 021 import javax.xml.bind.annotation.XmlAccessType; 022 import javax.xml.bind.annotation.XmlAccessorType; 023 import javax.xml.bind.annotation.XmlAnyElement; 024 import javax.xml.bind.annotation.XmlElement; 025 import javax.xml.bind.annotation.XmlRootElement; 026 import javax.xml.bind.annotation.XmlType; 027 028 import org.apache.commons.lang.StringUtils; 029 import org.kuali.rice.core.api.CoreConstants; 030 import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 031 import org.kuali.rice.core.api.mo.ModelBuilder; 032 import org.kuali.rice.kew.api.document.DocumentContentUpdate; 033 import org.kuali.rice.kew.api.document.DocumentUpdate; 034 import org.w3c.dom.Element; 035 036 @XmlRootElement(name = DocumentActionParameters.Constants.ROOT_ELEMENT_NAME) 037 @XmlAccessorType(XmlAccessType.NONE) 038 @XmlType(name = DocumentActionParameters.Constants.TYPE_NAME, propOrder = { 039 DocumentActionParameters.Elements.DOCUMENT_ID, 040 DocumentActionParameters.Elements.PRINCIPAL_ID, 041 DocumentActionParameters.Elements.ANNOTATION, 042 DocumentActionParameters.Elements.DOCUMENT_UPDATE, 043 DocumentActionParameters.Elements.DOCUMENT_CONTENT_UPDATE, 044 CoreConstants.CommonElements.FUTURE_ELEMENTS 045 }) 046 public final class DocumentActionParameters extends AbstractDataTransferObject { 047 048 private static final long serialVersionUID = -7589214734683758734L; 049 050 @XmlElement(name = Elements.DOCUMENT_ID, required = true) 051 private final String documentId; 052 053 @XmlElement(name = Elements.PRINCIPAL_ID, required = true) 054 private final String principalId; 055 056 @XmlElement(name = Elements.ANNOTATION, required = false) 057 private final String annotation; 058 059 @XmlElement(name = Elements.DOCUMENT_UPDATE, required = false) 060 private final DocumentUpdate documentUpdate; 061 062 @XmlElement(name = Elements.DOCUMENT_CONTENT_UPDATE, required = false) 063 private final DocumentContentUpdate documentContentUpdate; 064 065 @SuppressWarnings("unused") 066 @XmlAnyElement 067 private final Collection<Element> _futureElements = null; 068 069 private DocumentActionParameters() { 070 this.documentId = null; 071 this.principalId = null; 072 this.annotation = null; 073 this.documentUpdate = null; 074 this.documentContentUpdate = null; 075 } 076 077 private DocumentActionParameters(Builder builder) { 078 this.documentId = builder.getDocumentId(); 079 this.principalId = builder.getPrincipalId(); 080 this.annotation = builder.getAnnotation(); 081 this.documentUpdate = builder.getDocumentUpdate(); 082 this.documentContentUpdate = builder.getDocumentContentUpdate(); 083 } 084 085 public static DocumentActionParameters create(String documentId, String principalId) { 086 return create(documentId, principalId, ""); 087 } 088 089 public static DocumentActionParameters create(String documentId, String principalId, String annotation) { 090 Builder builder = Builder.create(documentId, principalId); 091 builder.setAnnotation(annotation); 092 return builder.build(); 093 } 094 095 public String getDocumentId() { 096 return documentId; 097 } 098 099 public String getPrincipalId() { 100 return principalId; 101 } 102 103 public String getAnnotation() { 104 return annotation; 105 } 106 107 public DocumentUpdate getDocumentUpdate() { 108 return documentUpdate; 109 } 110 111 public DocumentContentUpdate getDocumentContentUpdate() { 112 return documentContentUpdate; 113 } 114 115 /** 116 * A builder which can be used to construct {@link DocumentActionParameters} instances. 117 * 118 */ 119 public final static class Builder implements Serializable, ModelBuilder { 120 121 private static final long serialVersionUID = -9209748637365086000L; 122 123 private String documentId; 124 private String principalId; 125 private String annotation; 126 private DocumentUpdate documentUpdate; 127 private DocumentContentUpdate documentContentUpdate; 128 129 private Builder(String documentId, String principalId) { 130 setDocumentId(documentId); 131 setPrincipalId(principalId); 132 } 133 134 public static Builder create(String documentId, String principalId) { 135 return new Builder(documentId, principalId); 136 } 137 138 public DocumentActionParameters build() { 139 return new DocumentActionParameters(this); 140 } 141 142 public String getDocumentId() { 143 return documentId; 144 } 145 146 public void setDocumentId(String documentId) { 147 if (StringUtils.isBlank(documentId)) { 148 throw new IllegalArgumentException("documentId was null or blank"); 149 } 150 this.documentId = documentId; 151 } 152 153 public String getPrincipalId() { 154 return principalId; 155 } 156 157 public void setPrincipalId(String principalId) { 158 if (StringUtils.isBlank(principalId)) { 159 throw new IllegalArgumentException("principalId was null or blank"); 160 } 161 this.principalId = principalId; 162 } 163 164 public String getAnnotation() { 165 return annotation; 166 } 167 168 public void setAnnotation(String annotation) { 169 this.annotation = annotation; 170 } 171 172 public DocumentUpdate getDocumentUpdate() { 173 return documentUpdate; 174 } 175 176 public void setDocumentUpdate(DocumentUpdate documentUpdate) { 177 this.documentUpdate = documentUpdate; 178 } 179 180 public DocumentContentUpdate getDocumentContentUpdate() { 181 return documentContentUpdate; 182 } 183 184 public void setDocumentContentUpdate(DocumentContentUpdate documentContentUpdate) { 185 this.documentContentUpdate = documentContentUpdate; 186 } 187 188 } 189 190 /** 191 * Defines some internal constants used on this class. 192 */ 193 static class Constants { 194 final static String ROOT_ELEMENT_NAME = "documentActionParameters"; 195 final static String TYPE_NAME = "DocumentActionParametersType"; 196 } 197 198 /** 199 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML. 200 */ 201 static class Elements { 202 final static String DOCUMENT_ID = "documentId"; 203 final static String PRINCIPAL_ID = "principalId"; 204 final static String ANNOTATION = "annotation"; 205 final static String DOCUMENT_UPDATE = "documentUpdate"; 206 final static String DOCUMENT_CONTENT_UPDATE = "documentContentUpdate"; 207 } 208 209 }