Coverage Report - org.directdemocracyportal.democracy.model.core.Agent
 
Classes in this File Line Coverage Branch Coverage Complexity
Agent
53%
22/41
50%
11/22
2.5
 
 1  
 /*
 2  
 Copyright 2010 James Pether Sörling Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 
 3  
         $Id
 4  
 */
 5  
 package org.directdemocracyportal.democracy.model.core;
 6  
 
 7  
 import java.util.HashSet;
 8  
 import java.util.Set;
 9  
 
 10  
 import javax.persistence.CascadeType;
 11  
 import javax.persistence.Entity;
 12  
 import javax.persistence.FetchType;
 13  
 import javax.persistence.GeneratedValue;
 14  
 import javax.persistence.GenerationType;
 15  
 import javax.persistence.Id;
 16  
 import javax.persistence.Inheritance;
 17  
 import javax.persistence.InheritanceType;
 18  
 import javax.persistence.ManyToMany;
 19  
 import javax.persistence.OneToMany;
 20  
 
 21  
 import org.hibernate.annotations.Cache;
 22  
 import org.hibernate.annotations.CacheConcurrencyStrategy;
 23  
 
 24  
 /*
 25  
  * Agent
 26  
  */
 27  
 /**
 28  
  * The Class Agent.
 29  
  */
 30  
 @Entity
 31  
 @Inheritance(strategy = InheritanceType.JOINED)
 32  
 @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
 33  
 public abstract class Agent extends BaseEntity
 34  
 {
 35  
 
 36  
     /** The id. */
 37  
     private Long id;
 38  
 
 39  
     /** The name. */
 40  
     private String name;
 41  
 
 42  
     /** The roles. */
 43  19
     private Set<Role> roles = new HashSet<Role>();
 44  
 
 45  
     /** The resources. */
 46  19
     private Set<Resource> resources = new HashSet<Resource>();
 47  
 
 48  
     /**
 49  
      * Instantiates a new agent.
 50  
      */
 51  19
     public Agent() {
 52  19
     }
 53  
 
 54  
     /**
 55  
      * Instantiates a new agent.
 56  
      *
 57  
      * @param name the name
 58  
      */
 59  0
     public Agent(String name) {
 60  0
         this.name = name;
 61  0
     }
 62  
 
 63  
     /*
 64  
      * (non-Javadoc)
 65  
      *
 66  
      * @see org.directdemocracyportal.democracy.model.core.BaseEntity#getId()
 67  
      */
 68  
     @Override
 69  
     @Id
 70  
     @GeneratedValue(strategy = GenerationType.AUTO)
 71  
     public Long getId() {
 72  9
         return id;
 73  
     }
 74  
 
 75  
     /**
 76  
      * Sets the id.
 77  
      *
 78  
      * @param id the new id
 79  
      */
 80  
     public void setId(Long id) {
 81  5
         this.id = id;
 82  5
     }
 83  
 
 84  
     /**
 85  
      * Gets the name.
 86  
      *
 87  
      * @return the name
 88  
      */
 89  
     public String getName() {
 90  0
         return name;
 91  
     }
 92  
 
 93  
     /**
 94  
      * Sets the name.
 95  
      *
 96  
      * @param name the new name
 97  
      */
 98  
     public void setName(String name) {
 99  0
         this.name = name;
 100  0
     }
 101  
 
 102  
     /**
 103  
      * Gets the roles.
 104  
      *
 105  
      * @return the roles
 106  
      */
 107  
     @ManyToMany(fetch = FetchType.LAZY)
 108  
     public Set<Role> getRoles() {
 109  0
         return roles;
 110  
     }
 111  
 
 112  
     /**
 113  
      * Sets the roles.
 114  
      *
 115  
      * @param roles the new roles
 116  
      */
 117  
     public void setRoles(Set<Role> roles) {
 118  0
         this.roles = roles;
 119  0
     }
 120  
 
 121  
     /*
 122  
      * (non-Javadoc)
 123  
      *
 124  
      * @see java.lang.Object#hashCode()
 125  
      */
 126  
     @Override
 127  
     public int hashCode() {
 128  
         final int prime = 31;
 129  4
         int result = 1;
 130  4
         result = prime * result + ((id == null) ? 0 : id.hashCode());
 131  4
         result = prime * result + ((name == null) ? 0 : name.hashCode());
 132  4
         return result;
 133  
     }
 134  
 
 135  
     /*
 136  
      * (non-Javadoc)
 137  
      *
 138  
      * @see java.lang.Object#equals(java.lang.Object)
 139  
      */
 140  
     @Override
 141  
     public boolean equals(Object obj) {
 142  3
         if (this == obj)
 143  1
             return true;
 144  2
         if (obj == null)
 145  0
             return false;
 146  2
         if (getClass() != obj.getClass())
 147  0
             return false;
 148  2
         final Agent other = (Agent) obj;
 149  2
         if (id == null) {
 150  0
             if (other.id != null)
 151  0
                 return false;
 152  2
         } else if (!id.equals(other.id))
 153  1
             return false;
 154  1
         if (name == null) {
 155  1
             if (other.name != null)
 156  0
                 return false;
 157  0
         } else if (!name.equals(other.name))
 158  0
             return false;
 159  1
         return true;
 160  
     }
 161  
 
 162  
     /**
 163  
      * Gets the resources.
 164  
      *
 165  
      * @return the resources
 166  
      */
 167  
     @OneToMany(mappedBy = "owner", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
 168  
     public Set<Resource> getResources() {
 169  0
         return resources;
 170  
     }
 171  
 
 172  
     /**
 173  
      * Sets the resources.
 174  
      *
 175  
      * @param resources the new resources
 176  
      */
 177  
     public void setResources(Set<Resource> resources) {
 178  0
         this.resources = resources;
 179  0
     }
 180  
 }