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