Coverage Report - org.kuali.rice.kew.api.document.DocumentUpdate
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentUpdate
0%
0/23
0%
0/2
1.391
DocumentUpdate$1
N/A
N/A
1.391
DocumentUpdate$Builder
0%
0/38
0%
0/10
1.391
DocumentUpdate$Constants
0%
0/2
N/A
1.391
DocumentUpdate$Elements
0%
0/1
N/A
1.391
 
 1  
 /*
 2  
  * Copyright 2011 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/ecl1.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.document;
 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.apache.commons.lang.builder.EqualsBuilder;
 34  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 35  
 import org.apache.commons.lang.builder.ToStringBuilder;
 36  
 import org.kuali.rice.core.api.CoreConstants;
 37  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 38  
 import org.kuali.rice.core.util.jaxb.MapStringStringAdapter;
 39  
 import org.kuali.rice.kew.api.KewApiConstants;
 40  
 import org.w3c.dom.Element;
 41  
 
 42  
 /**
 43  
  * Defines an update to document content on a particular workflow document.
 44  
  * Contains general application content as well as a list of attribute
 45  
  * definitions and searchable definitions.  When passed to the appropriate
 46  
  * workflow services to perform an update on document content, if any of the
 47  
  * internal content or definitions on this object have not been set then they
 48  
  * will not be updated.  This allows for this data structure to be used to only
 49  
  * update the portion of the document content that is desired to be updated.
 50  
  * 
 51  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 52  
  * 
 53  
  */
 54  
 @XmlRootElement(name = DocumentUpdate.Constants.ROOT_ELEMENT_NAME)
 55  
 @XmlAccessorType(XmlAccessType.NONE)
 56  
 @XmlType(name = DocumentUpdate.Constants.TYPE_NAME, propOrder = {
 57  
         DocumentUpdate.Elements.TITLE,
 58  
     DocumentUpdate.Elements.APPLICATION_DOCUMENT_ID,
 59  
     DocumentUpdate.Elements.APPLICATION_DOCUMENT_STATUS,
 60  
     DocumentUpdate.Elements.VARIABLES,
 61  
     CoreConstants.CommonElements.FUTURE_ELEMENTS
 62  
 })
 63  0
 public final class DocumentUpdate implements Serializable {
 64  
 
 65  
         private static final long serialVersionUID = 608839901744771499L;
 66  
 
 67  
         @XmlElement(name = Elements.TITLE, required = false)
 68  
         private final String title;
 69  
 
 70  
         @XmlElement(name = Elements.APPLICATION_DOCUMENT_ID, required = false)
 71  
         private final String applicationDocumentId;
 72  
                 
 73  
         @XmlElement(name = Elements.APPLICATION_DOCUMENT_STATUS, required = false)
 74  
         private final String applicationDocumentStatus;
 75  
         
 76  
         @XmlElement(name = Elements.VARIABLES, required = false)
 77  
         @XmlJavaTypeAdapter(MapStringStringAdapter.class)
 78  
         private final Map<String, String> variables;
 79  
     
 80  0
         @SuppressWarnings("unused")
 81  
     @XmlAnyElement
 82  
     private final Collection<Element> _futureElements = null;
 83  
     
 84  0
         private DocumentUpdate() {
 85  0
                 this.title = null;
 86  0
                 this.applicationDocumentId = null;
 87  0
                 this.applicationDocumentStatus = null;
 88  0
                 this.variables = null;
 89  0
         }
 90  
         
 91  0
     private DocumentUpdate(Builder builder) {
 92  0
             this.title = builder.getTitle();
 93  0
             this.applicationDocumentId = builder.getApplicationDocumentId();
 94  0
             this.applicationDocumentStatus = builder.getApplicationDocumentStatus();
 95  0
             this.variables = builder.getVariables();
 96  0
     }
 97  
 
 98  
         public String getTitle() {
 99  0
                 return title;
 100  
         }
 101  
 
 102  
         public String getApplicationDocumentId() {
 103  0
                 return applicationDocumentId;
 104  
         }
 105  
         
 106  
         public String getApplicationDocumentStatus() {
 107  0
                 return applicationDocumentStatus;
 108  
         }
 109  
         
 110  
         public Map<String, String> getVariables() {
 111  0
                 if (variables == null) {
 112  0
                         return Collections.emptyMap();
 113  
                 }
 114  0
                 return Collections.unmodifiableMap(variables);
 115  
         }
 116  
         
 117  
         @Override
 118  
     public int hashCode() {
 119  0
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 120  
     }
 121  
 
 122  
     @Override
 123  
     public boolean equals(Object object) {
 124  0
         return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 125  
     }
 126  
 
 127  
     @Override
 128  
     public String toString() {
 129  0
         return ToStringBuilder.reflectionToString(this);
 130  
     }
 131  
                 
 132  
         /**
 133  
          * A builder which can be used to construct {@link DocumentUpdate} instances.
 134  
          */
 135  0
         public final static class Builder implements Serializable, ModelBuilder {
 136  
 
 137  
                 private static final long serialVersionUID = 2220000561051177421L;
 138  
 
 139  
                 private String title;
 140  
                 private String applicationDocumentId;
 141  
                 private String applicationDocumentStatus;
 142  
                 private Map<String, String> variables;
 143  
 
 144  
 
 145  0
                 private Builder() {
 146  0
                         this.title = "";
 147  0
                         this.variables = new HashMap<String, String>();
 148  0
                 }
 149  
 
 150  
                 public static Builder create() {
 151  0
                         return new Builder();
 152  
                 }
 153  
 
 154  
                 public static Builder create(Document document) {
 155  0
                         if (document == null) {
 156  0
                                 throw new IllegalArgumentException("document was null");
 157  
                         }
 158  0
                         Builder builder = create();
 159  0
                         builder.setTitle(document.getTitle());
 160  0
                         builder.setApplicationDocumentId(document.getApplicationDocumentId());
 161  0
                         builder.setApplicationDocumentStatus(document.getApplicationDocumentStatus());
 162  0
                         builder.setVariables(document.getVariables());
 163  0
                         return builder;
 164  
                 }
 165  
 
 166  
                 public DocumentUpdate build() {
 167  0
                         return new DocumentUpdate(this);
 168  
                 }
 169  
 
 170  
                 public String getTitle() {
 171  0
                         return title;
 172  
                 }
 173  
 
 174  
                 /**
 175  
                  * TODO: document the fact that this will auto-truncate the title...
 176  
                  */
 177  
                 public void setTitle(String title) {
 178  0
                         if (title == null) {
 179  0
                                 title = "";
 180  
                         }
 181  0
                 if (title.length() > KewApiConstants.TITLE_MAX_LENGTH) {
 182  0
                     title = title.substring(0, KewApiConstants.TITLE_MAX_LENGTH);
 183  
                 }
 184  0
                         this.title = title;
 185  0
                 }
 186  
 
 187  
                 public String getApplicationDocumentId() {
 188  0
                         return applicationDocumentId;
 189  
                 }
 190  
 
 191  
                 public void setApplicationDocumentId(String applicationDocumentId) {
 192  0
                         this.applicationDocumentId = applicationDocumentId;
 193  0
                 }
 194  
 
 195  
                 public String getApplicationDocumentStatus() {
 196  0
                         return applicationDocumentStatus;
 197  
                 }
 198  
 
 199  
                 public void setApplicationDocumentStatus(String applicationDocumentStatus) {
 200  0
                         this.applicationDocumentStatus = applicationDocumentStatus;
 201  0
                 }
 202  
 
 203  
                 public void setVariables(Map<String, String> variables) {
 204  0
                         if (variables == null) {
 205  0
                                 this.variables = new HashMap<String, String>();
 206  
                         } else {
 207  0
                                 this.variables = new HashMap<String, String>(variables);
 208  
                         }
 209  0
                 }
 210  
                 
 211  
                 public Map<String, String> getVariables() {
 212  0
                         return variables;
 213  
                 }
 214  
                 
 215  
                 public String getVariableValue(String name) {
 216  0
                         return variables.get(name);
 217  
             }
 218  
 
 219  
             public void setVariable(String name, String value) {
 220  0
                 if (StringUtils.isBlank(name)) {
 221  0
                         throw new IllegalArgumentException("name was null or blank");
 222  
                 }
 223  0
                 variables.put(name, value);
 224  0
             }
 225  
             
 226  
         }
 227  
         
 228  
     /**
 229  
      * Defines some internal constants used on this class.
 230  
      */
 231  0
     static class Constants {
 232  
         final static String ROOT_ELEMENT_NAME = "documentUpdate";
 233  
         final static String TYPE_NAME = "DocumentUpdateType";
 234  0
         final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] { CoreConstants.CommonElements.FUTURE_ELEMENTS };
 235  
     }
 236  
 
 237  
     /**
 238  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 239  
      */
 240  0
     static class Elements {
 241  
             final static String TITLE = "title";
 242  
         final static String APPLICATION_DOCUMENT_ID = "applicationDocumentId";
 243  
         final static String APPLICATION_DOCUMENT_STATUS = "applicationDocumentStatus";
 244  
         final static String VARIABLES = "variables";
 245  
     }
 246  
 
 247  
 }