Coverage Report - org.kuali.rice.kew.api.document.search.DocumentSearchResults
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentSearchResults
0%
0/22
N/A
1.286
DocumentSearchResults$1
N/A
N/A
1.286
DocumentSearchResults$Builder
0%
0/37
0%
0/8
1.286
DocumentSearchResults$Constants
0%
0/1
N/A
1.286
DocumentSearchResults$Elements
0%
0/1
N/A
1.286
 
 1  
 /**
 2  
  * Copyright 2005-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/ecl2.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.search;
 17  
 
 18  
 import org.apache.commons.collections.CollectionUtils;
 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.mo.ModelObjectUtils;
 23  
 import org.w3c.dom.Element;
 24  
 
 25  
 import javax.xml.bind.annotation.XmlAccessType;
 26  
 import javax.xml.bind.annotation.XmlAccessorType;
 27  
 import javax.xml.bind.annotation.XmlAnyElement;
 28  
 import javax.xml.bind.annotation.XmlElement;
 29  
 import javax.xml.bind.annotation.XmlElementWrapper;
 30  
 import javax.xml.bind.annotation.XmlRootElement;
 31  
 import javax.xml.bind.annotation.XmlType;
 32  
 import java.io.Serializable;
 33  
 import java.util.ArrayList;
 34  
 import java.util.Collection;
 35  
 import java.util.List;
 36  
 
 37  
 /**
 38  
  * An immutable data transfer object implementation of the {@link DocumentSearchResultsContract}.  Instances of this
 39  
  * class should be constructed using the nested {@link Builder} class.
 40  
  *
 41  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 42  
  */
 43  0
 @XmlRootElement(name = DocumentSearchResults.Constants.ROOT_ELEMENT_NAME)
 44  
 @XmlAccessorType(XmlAccessType.NONE)
 45  
 @XmlType(name = DocumentSearchResults.Constants.TYPE_NAME, propOrder = {
 46  
     DocumentSearchResults.Elements.SEARCH_RESULTS,
 47  
     DocumentSearchResults.Elements.CRITERIA,
 48  
     DocumentSearchResults.Elements.CRITERIA_MODIFIED,
 49  
     DocumentSearchResults.Elements.OVER_THRESHOLD,
 50  
     DocumentSearchResults.Elements.NUMBER_OF_SECURITY_FILTERED_RESULTS,
 51  
     CoreConstants.CommonElements.FUTURE_ELEMENTS
 52  
 })
 53  0
 public final class DocumentSearchResults extends AbstractDataTransferObject implements DocumentSearchResultsContract {
 54  
 
 55  
     @XmlElementWrapper(name = Elements.SEARCH_RESULTS, required = true)
 56  
     @XmlElement(name = Elements.SEARCH_RESULT, required = false)
 57  
     private final List<DocumentSearchResult> searchResults;
 58  
 
 59  
     @XmlElement(name = Elements.CRITERIA, required = true)
 60  
     private final DocumentSearchCriteria criteria;
 61  
 
 62  
     @XmlElement(name = Elements.CRITERIA_MODIFIED, required = true)
 63  
     private final boolean criteriaModified;
 64  
 
 65  
     @XmlElement(name = Elements.OVER_THRESHOLD, required = true)
 66  
     private final boolean overThreshold;
 67  
 
 68  
     @XmlElement(name = Elements.NUMBER_OF_SECURITY_FILTERED_RESULTS, required = true)
 69  
     private final int numberOfSecurityFilteredResults;
 70  
 
 71  0
     @SuppressWarnings("unused")
 72  
     @XmlAnyElement
 73  
     private final Collection<Element> _futureElements = null;
 74  
 
 75  
     /**
 76  
      * Private constructor used only by JAXB.
 77  
      */
 78  
     @SuppressWarnings("unused")
 79  0
     private DocumentSearchResults() {
 80  0
         this.searchResults = null;
 81  0
         this.criteria = null;
 82  0
         this.criteriaModified = false;
 83  0
         this.overThreshold = false;
 84  0
         this.numberOfSecurityFilteredResults = 0;
 85  0
     }
 86  
 
 87  0
     private DocumentSearchResults(Builder builder) {
 88  0
         this.searchResults = ModelObjectUtils.buildImmutableCopy(builder.getSearchResults());
 89  0
         this.criteria = builder.getCriteria().build();
 90  0
         this.criteriaModified = builder.isCriteriaModified();
 91  0
         this.overThreshold = builder.isOverThreshold();
 92  0
         this.numberOfSecurityFilteredResults = builder.getNumberOfSecurityFilteredResults();
 93  0
     }
 94  
 
 95  
     @Override
 96  
     public List<DocumentSearchResult> getSearchResults() {
 97  0
         return this.searchResults;
 98  
     }
 99  
 
 100  
     @Override
 101  
     public DocumentSearchCriteria getCriteria() {
 102  0
         return this.criteria;
 103  
     }
 104  
 
 105  
     @Override
 106  
     public boolean isCriteriaModified() {
 107  0
         return this.criteriaModified;
 108  
     }
 109  
 
 110  
     @Override
 111  
     public boolean isOverThreshold() {
 112  0
         return this.overThreshold;
 113  
     }
 114  
 
 115  
     @Override
 116  
     public int getNumberOfSecurityFilteredResults() {
 117  0
         return this.numberOfSecurityFilteredResults;
 118  
     }
 119  
 
 120  
     /**
 121  
      * A builder which can be used to construct {@link DocumentSearchResults} instances.  Enforces the constraints of
 122  
      * the {@link DocumentSearchResultsContract}.
 123  
      */
 124  0
     public final static class Builder implements Serializable, ModelBuilder, DocumentSearchResultsContract {
 125  
 
 126  
         private List<DocumentSearchResult.Builder> searchResults;
 127  
         private DocumentSearchCriteria.Builder criteria;
 128  
         private boolean criteriaModified;
 129  
         private boolean overThreshold;
 130  
         private int numberOfSecurityFilteredResults;
 131  
 
 132  0
         private Builder(DocumentSearchCriteria.Builder criteria) {
 133  0
             setSearchResults(new ArrayList<DocumentSearchResult.Builder>());
 134  0
             setCriteria(criteria);
 135  0
             setCriteriaModified(false);
 136  0
             setOverThreshold(false);
 137  0
             setNumberOfSecurityFilteredResults(0);
 138  
 
 139  0
         }
 140  
 
 141  
         /**
 142  
          * Create a builder for the document search result and initialize it with the given document search criteria
 143  
          * builder.  Additionally initializes {@code criteriaModified} to "false", {@code overThreshold} to "false",
 144  
          * and {@code numberOfSecurityFilteredResults} to 0.
 145  
          *
 146  
          * @param criteria the document search criteria builder with which to initialize the returned builder instance
 147  
          *
 148  
          * @return a builder instance initialized with the given document search criteria builder
 149  
          *
 150  
          * @throws IllegalArgumentException if the given document search criteria builder is null
 151  
          */
 152  
         public static Builder create(DocumentSearchCriteria.Builder criteria) {
 153  0
             return new Builder(criteria);
 154  
         }
 155  
 
 156  
         /**
 157  
          * Creates a new builder instance initialized with copies of the properties from the given contract.
 158  
          *
 159  
          * @param contract the contract from which to copy properties
 160  
          *
 161  
          * @return a builder instance initialized with properties from the given contract
 162  
          *
 163  
          * @throws IllegalArgumentException if the given contract is null
 164  
          */
 165  
         public static Builder create(DocumentSearchResultsContract contract) {
 166  0
             if (contract == null) {
 167  0
                 throw new IllegalArgumentException("contract was null");
 168  
             }
 169  0
             Builder builder = create(DocumentSearchCriteria.Builder.create(contract.getCriteria()));
 170  0
             if (!CollectionUtils.isEmpty(contract.getSearchResults())) {
 171  0
                 for (DocumentSearchResultContract searchResultContract : contract.getSearchResults()) {
 172  0
                     builder.getSearchResults().add(DocumentSearchResult.Builder.create(searchResultContract));
 173  
                 }
 174  
             }
 175  0
             builder.setCriteriaModified(contract.isCriteriaModified());
 176  0
             builder.setOverThreshold(contract.isOverThreshold());
 177  0
             builder.setNumberOfSecurityFilteredResults(contract.getNumberOfSecurityFilteredResults());
 178  0
             return builder;
 179  
         }
 180  
 
 181  
         public DocumentSearchResults build() {
 182  0
             return new DocumentSearchResults(this);
 183  
         }
 184  
 
 185  
         @Override
 186  
         public List<DocumentSearchResult.Builder> getSearchResults() {
 187  0
             return this.searchResults;
 188  
         }
 189  
 
 190  
         @Override
 191  
         public DocumentSearchCriteria.Builder getCriteria() {
 192  0
             return this.criteria;
 193  
         }
 194  
 
 195  
         @Override
 196  
         public boolean isCriteriaModified() {
 197  0
             return this.criteriaModified;
 198  
         }
 199  
 
 200  
         @Override
 201  
         public boolean isOverThreshold() {
 202  0
             return this.overThreshold;
 203  
         }
 204  
 
 205  
         @Override
 206  
         public int getNumberOfSecurityFilteredResults() {
 207  0
             return this.numberOfSecurityFilteredResults;
 208  
         }
 209  
 
 210  
         public void setSearchResults(List<DocumentSearchResult.Builder> searchResults) {
 211  0
             this.searchResults = searchResults;
 212  0
         }
 213  
 
 214  
         /**
 215  
          * Sets the criteria builder on this builder to the given value.
 216  
          *
 217  
          * @param criteria the criteria builder to set, must not be null
 218  
          *
 219  
          * @throws IllegalArgumentException if criteria is null
 220  
          */
 221  
         public void setCriteria(DocumentSearchCriteria.Builder criteria) {
 222  0
             if (criteria == null) {
 223  0
                 throw new IllegalArgumentException("criteria was null");
 224  
             }
 225  0
             this.criteria = criteria;
 226  0
         }
 227  
 
 228  
         public void setCriteriaModified(boolean criteriaModified) {
 229  0
             this.criteriaModified = criteriaModified;
 230  0
         }
 231  
 
 232  
         public void setOverThreshold(boolean overThreshold) {
 233  0
             this.overThreshold = overThreshold;
 234  0
         }
 235  
 
 236  
         public void setNumberOfSecurityFilteredResults(int numberOfSecurityFilteredResults) {
 237  0
             this.numberOfSecurityFilteredResults = numberOfSecurityFilteredResults;
 238  0
         }
 239  
 
 240  
     }
 241  
 
 242  
     /**
 243  
      * Defines some internal constants used on this class.
 244  
      */
 245  0
     static class Constants {
 246  
         final static String ROOT_ELEMENT_NAME = "documentSearchResults";
 247  
         final static String TYPE_NAME = "DocumentSearchResultsType";
 248  
     }
 249  
 
 250  
     /**
 251  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 252  
      */
 253  0
     static class Elements {
 254  
         final static String SEARCH_RESULTS = "searchResults";
 255  
         final static String SEARCH_RESULT = "searchResult";
 256  
         final static String CRITERIA = "criteria";
 257  
         final static String CRITERIA_MODIFIED = "criteriaModified";
 258  
         final static String OVER_THRESHOLD = "overThreshold";
 259  
         final static String NUMBER_OF_SECURITY_FILTERED_RESULTS = "numberOfSecurityFilteredResults";
 260  
     }
 261  
 
 262  
 }