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