Coverage Report - org.kuali.rice.kim.api.responsibility.Responsibility
 
Classes in this File Line Coverage Branch Coverage Complexity
Responsibility
94%
35/37
100%
2/2
1.306
Responsibility$1
N/A
N/A
1.306
Responsibility$Builder
94%
50/53
66%
8/12
1.306
Responsibility$Constants
50%
1/2
N/A
1.306
Responsibility$Elements
0%
0/1
N/A
1.306
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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.kim.api.responsibility;
 17  
 
 18  
 import com.google.common.collect.Maps;
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.apache.commons.lang.builder.EqualsBuilder;
 21  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 22  
 import org.apache.commons.lang.builder.ToStringBuilder;
 23  
 import org.kuali.rice.core.api.CoreConstants;
 24  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 25  
 import org.kuali.rice.core.api.mo.ModelObjectComplete;
 26  
 import org.kuali.rice.core.util.jaxb.MapStringStringAdapter;
 27  
 import org.kuali.rice.kim.api.common.template.Template;
 28  
 import org.w3c.dom.Element;
 29  
 
 30  
 import javax.xml.bind.annotation.XmlAccessType;
 31  
 import javax.xml.bind.annotation.XmlAccessorType;
 32  
 import javax.xml.bind.annotation.XmlAnyElement;
 33  
 import javax.xml.bind.annotation.XmlElement;
 34  
 import javax.xml.bind.annotation.XmlRootElement;
 35  
 import javax.xml.bind.annotation.XmlType;
 36  
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 37  
 import java.io.Serializable;
 38  
 import java.util.Collection;
 39  
 import java.util.Collections;
 40  
 import java.util.Map;
 41  
 
 42  
 /**
 43  
  * An immutable representation of a {@link ResponsibilityContract}.
 44  
  *
 45  
  * <p>To construct an instance of a Permission, use the {@link org.kuali.rice.kim.api.responsibility.Responsibility.Builder} class.<p/>
 46  
  *
 47  
  * @see ResponsibilityContract
 48  
  */
 49  1
 @XmlRootElement(name = Responsibility.Constants.ROOT_ELEMENT_NAME)
 50  
 @XmlAccessorType(XmlAccessType.NONE)
 51  
 @XmlType(name = Responsibility.Constants.TYPE_NAME, propOrder = {
 52  
                 Responsibility.Elements.ID,
 53  
                 Responsibility.Elements.NAMESPACE_CODE,
 54  
                 Responsibility.Elements.NAME,
 55  
                 Responsibility.Elements.DESCRIPTION,
 56  
                 Responsibility.Elements.TEMPLATE,
 57  
         Responsibility.Elements.ACTIVE,
 58  
         Responsibility.Elements.ATTRIBUTES,
 59  
         CoreConstants.CommonElements.VERSION_NUMBER,
 60  
         CoreConstants.CommonElements.OBJECT_ID,
 61  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 62  
 })
 63  4
 public final class Responsibility implements ResponsibilityContract, ModelObjectComplete{
 64  
 
 65  
         private static final long serialVersionUID = 1L;
 66  
 
 67  
     @XmlElement(name = Responsibility.Elements.ID, required = false)
 68  
     private final String id;
 69  
 
 70  
     @XmlElement(name = Responsibility.Elements.NAMESPACE_CODE, required = true)
 71  
     private final String namespaceCode;
 72  
 
 73  
     @XmlElement(name = Responsibility.Elements.NAME, required = true)
 74  
     private final String name;
 75  
 
 76  
     @XmlElement(name = Responsibility.Elements.DESCRIPTION, required = false)
 77  
     private final String description;
 78  
 
 79  
     @XmlElement(name = Responsibility.Elements.TEMPLATE, required = true)
 80  
     private final Template template;
 81  
 
 82  
     @XmlElement(name = Responsibility.Elements.ATTRIBUTES, required = false)
 83  
     @XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
 84  
     private final Map<String, String> attributes;
 85  
 
 86  
     @XmlElement(name = Responsibility.Elements.ACTIVE, required = false)
 87  
     private boolean active;
 88  
 
 89  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 90  
     private final Long versionNumber;
 91  
 
 92  
     @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
 93  
     private final String objectId;
 94  
 
 95  6
     @SuppressWarnings("unused")
 96  
     @XmlAnyElement
 97  
     private final Collection<Element> _futureElements = null;
 98  
 
 99  
     /**
 100  
          *  A constructor to be used only by JAXB unmarshalling.
 101  
          *
 102  
          */
 103  2
         private Responsibility() {
 104  2
                 this.id = null;
 105  2
         this.namespaceCode = null;
 106  2
         this.name = null;
 107  2
         this.description = null;
 108  2
         this.template = null;
 109  2
         this.attributes = null;
 110  2
         this.active = false;
 111  2
         this.versionNumber = Long.valueOf(1L);
 112  2
         this.objectId = null;
 113  2
         }
 114  
 
 115  
     /**
 116  
          * A constructor using the Builder.
 117  
          *
 118  
          * @param builder
 119  
          */
 120  4
         private Responsibility(Builder builder) {
 121  4
                 this.id = builder.getId();
 122  4
         this.namespaceCode = builder.getNamespaceCode();
 123  4
         this.name = builder.getName();
 124  4
         this.description = builder.getDescription();
 125  4
         this.template = builder.getTemplate().build();
 126  4
         this.attributes = builder.getAttributes() != null ? builder.getAttributes() : Collections.<String, String>emptyMap();
 127  4
         this.active = builder.isActive();
 128  4
         this.versionNumber = builder.getVersionNumber();
 129  4
         this.objectId = builder.getObjectId();
 130  4
         }
 131  
 
 132  
         /**
 133  
          * @see ResponsibilityContract#getId()
 134  
          */
 135  
         @Override
 136  
         public String getId() {
 137  1
                 return id;
 138  
         }
 139  
 
 140  
         /**
 141  
          * @see ResponsibilityContract#getNamespaceCode()
 142  
          */
 143  
         @Override
 144  
         public String getNamespaceCode() {
 145  1
                 return namespaceCode;
 146  
         }
 147  
 
 148  
         /**
 149  
          * @see ResponsibilityContract#getName()
 150  
          */
 151  
         @Override
 152  
         public String getName() {
 153  1
                 return name;
 154  
         }
 155  
 
 156  
         /**
 157  
          * @see ResponsibilityContract#getDescription()
 158  
          */
 159  
         @Override
 160  
         public String getDescription() {
 161  1
                 return description;
 162  
         }
 163  
 
 164  
         /**
 165  
          * @see ResponsibilityContract#getTemplate()
 166  
          */
 167  
         @Override
 168  
         public Template getTemplate() {
 169  1
                 return template;
 170  
         }
 171  
 
 172  
         /**
 173  
          * @see org.kuali.rice.core.api.mo.common.active.Inactivatable#isActive()
 174  
          */
 175  
         @Override
 176  
         public boolean isActive() {
 177  1
                 return active;
 178  
         }
 179  
 
 180  
         /**
 181  
          *
 182  
          * @see ResponsibilityContract#getAttributes()
 183  
          */
 184  
         @Override
 185  
         public Map<String, String> getAttributes() {
 186  2
                 return this.attributes;
 187  
         }
 188  
 
 189  
         /**
 190  
          * @see org.kuali.rice.core.api.mo.common.Versioned#getVersionNumber()
 191  
          */
 192  
         @Override
 193  
         public Long getVersionNumber() {
 194  1
                 return versionNumber;
 195  
         }
 196  
 
 197  
         /**
 198  
          * @see org.kuali.rice.core.api.mo.common.GloballyUnique#getObjectId()
 199  
          */
 200  
         @Override
 201  
         public String getObjectId() {
 202  1
                 return objectId;
 203  
         }
 204  
 
 205  
     @Override
 206  
     public int hashCode() {
 207  0
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 208  
     }
 209  
 
 210  
     @Override
 211  
     public boolean equals(Object obj) {
 212  2
         return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 213  
     }
 214  
 
 215  
     @Override
 216  
     public String toString() {
 217  0
         return ToStringBuilder.reflectionToString(this);
 218  
     }
 219  
 
 220  
     /**
 221  
      * This builder constructs a Responsibility enforcing the constraints of the {@link ResponsibilityContract}.
 222  
      */
 223  4
     public static final class Builder implements ResponsibilityContract, ModelBuilder, Serializable {
 224  
         private String id;
 225  
         private String namespaceCode;
 226  
         private String name;
 227  
         private String description;
 228  
         private Template.Builder template;
 229  
         private Map<String, String> attributes;
 230  6
         private Long versionNumber = 1L;
 231  
         private String objectId;
 232  
         private boolean active;
 233  
 
 234  6
         private Builder(String namespaceCode, String name, Template.Builder template) {
 235  6
             setNamespaceCode(namespaceCode);
 236  6
             setName(name);
 237  6
             setTemplate(template);
 238  6
         }
 239  
 
 240  
         /**
 241  
          * Creates a Responsibility with the required fields.
 242  
          */
 243  
         public static Builder create(String namespaceCode, String name, Template.Builder template) {
 244  4
             return new Builder(namespaceCode, name, template);
 245  
         }
 246  
 
 247  
         /**
 248  
          * Creates a Responsibility from an existing {@link ResponsibilityContract}.
 249  
          */
 250  
         public static Builder create(ResponsibilityContract contract) {
 251  2
             Builder builder = new Builder(contract.getNamespaceCode(), contract.getName(), Template.Builder.create(contract.getTemplate()));
 252  2
             builder.setId(contract.getId());
 253  2
             builder.setDescription(contract.getDescription());
 254  2
             if (contract.getAttributes() != null) {
 255  2
                 builder.setAttributes(contract.getAttributes());
 256  
             }
 257  2
             builder.setActive(contract.isActive());
 258  2
             builder.setVersionNumber(contract.getVersionNumber());
 259  2
             builder.setObjectId(contract.getObjectId());
 260  
 
 261  2
             return builder;
 262  
         }
 263  
 
 264  
         @Override
 265  
         public String getId() {
 266  4
             return id;
 267  
         }
 268  
 
 269  
         public void setId(final String id) {
 270  2
                 this.id = id;
 271  2
         }
 272  
         
 273  
         @Override
 274  
         public String getNamespaceCode() {
 275  4
             return namespaceCode;
 276  
         }
 277  
 
 278  
         public void setNamespaceCode(final String namespaceCode) {
 279  6
                 if (StringUtils.isBlank(namespaceCode)) {
 280  0
                 throw new IllegalArgumentException("namespaceCode is blank");
 281  
             }
 282  6
                 this.namespaceCode = namespaceCode;
 283  6
         }
 284  
 
 285  
         @Override
 286  
         public String getName() {
 287  4
             return name;
 288  
         }
 289  
 
 290  
         public void setName(final String name) {
 291  6
                 if (StringUtils.isBlank(name)) {
 292  0
                 throw new IllegalArgumentException("name is blank");
 293  
             }
 294  6
                 this.name = name;
 295  6
         }
 296  
 
 297  
                 @Override
 298  
                 public String getDescription() {
 299  4
                         return description;
 300  
                 }
 301  
                 
 302  
                 public void setDescription(final String description) {
 303  3
                         this.description = description;
 304  3
                 }
 305  
 
 306  
                 @Override
 307  
                 public Template.Builder getTemplate() {
 308  4
                         return template;
 309  
                 }
 310  
                 
 311  
                 public void setTemplate(final Template.Builder template) {
 312  6
                         if (template == null) {
 313  0
                 throw new IllegalArgumentException("template is null");
 314  
             }
 315  6
                         this.template = template;
 316  6
                 }
 317  
                 
 318  
                 @Override
 319  
                 public boolean isActive() {
 320  4
                         return active;
 321  
                 }
 322  
                 
 323  
                 public void setActive(final boolean active) {
 324  2
             this.active = active;
 325  2
         }
 326  
 
 327  
                 @Override
 328  
                 public Long getVersionNumber() {
 329  4
                         return versionNumber;
 330  
                 }
 331  
 
 332  
                 public void setVersionNumber(final Long versionNumber) {
 333  4
                         if (versionNumber == null || versionNumber <= 0) {
 334  2
                     throw new IllegalArgumentException("versionNumber is invalid");
 335  
                 }
 336  2
                         this.versionNumber = versionNumber;
 337  2
             }
 338  
                  
 339  
                 @Override
 340  
                 public String getObjectId() {
 341  4
                         return objectId;
 342  
                 }
 343  
 
 344  
         public void setObjectId(final String objectId) {
 345  2
             this.objectId = objectId;
 346  2
         }
 347  
 
 348  
                 @Override
 349  
                 public Map<String, String> getAttributes() {
 350  6
                         return attributes;
 351  
                 }
 352  
                 
 353  
                 public void setAttributes(Map<String, String> attributes) {
 354  2
             this.attributes = Collections.unmodifiableMap(Maps.newHashMap(attributes));
 355  2
         }
 356  
                 
 357  
         @Override
 358  
         public Responsibility build() {
 359  4
             return new Responsibility(this);
 360  
         }
 361  
     }
 362  
     
 363  
     /**
 364  
      * Defines some internal constants used on this class.
 365  
      */
 366  0
     static class Constants {
 367  
         static final String ROOT_ELEMENT_NAME = "responsibility";
 368  
         static final String TYPE_NAME = "ResponsibilityType";
 369  1
         static final String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS};
 370  
     }
 371  
 
 372  
     /**
 373  
      * A private class which exposes constants which define the XML element names to use
 374  
      * when this object is marshalled to XML.
 375  
      */
 376  0
     static class Elements {
 377  
         static final String ID = "id";
 378  
         static final String NAMESPACE_CODE = "namespaceCode";
 379  
         static final String NAME = "name";
 380  
         static final String DESCRIPTION = "description";
 381  
         static final String TEMPLATE = "template";
 382  
         static final String ATTRIBUTES = "attributes";
 383  
         static final String ACTIVE = "active";
 384  
     }
 385  
 }