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