001 /** 002 * Copyright 2005-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.kim.api.role; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.apache.commons.lang.builder.EqualsBuilder; 020 import org.apache.commons.lang.builder.HashCodeBuilder; 021 import org.apache.commons.lang.builder.ToStringBuilder; 022 import org.kuali.rice.core.api.CoreConstants; 023 import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 024 import org.kuali.rice.core.api.mo.ModelBuilder; 025 import org.kuali.rice.core.api.mo.ModelObjectComplete; 026 import org.kuali.rice.kim.api.KimConstants; 027 import org.w3c.dom.Element; 028 029 import javax.xml.bind.annotation.XmlAccessType; 030 import javax.xml.bind.annotation.XmlAccessorType; 031 import javax.xml.bind.annotation.XmlAnyElement; 032 import javax.xml.bind.annotation.XmlElement; 033 import javax.xml.bind.annotation.XmlRootElement; 034 import javax.xml.bind.annotation.XmlType; 035 import java.util.Collection; 036 037 /** 038 * An lightweight association of a Responsibility and a Role represented by references to the identifiers of a 039 * Role and a Responsibility that are related to each other. 040 * 041 * @author Kuali Rice Team (rice.collab@kuali.org) 042 */ 043 @XmlRootElement(name = RoleResponsibility.Constants.ROOT_ELEMENT_NAME) 044 @XmlAccessorType(XmlAccessType.NONE) 045 @XmlType(name = RoleResponsibility.Constants.TYPE_NAME, propOrder = { 046 RoleResponsibility.Elements.ROLE_RESPONSIBILITY_ID, 047 RoleResponsibility.Elements.ROLE_ID, 048 RoleResponsibility.Elements.RESPONSIBILITY_ID, 049 CoreConstants.CommonElements.ACTIVE, 050 CoreConstants.CommonElements.VERSION_NUMBER, 051 CoreConstants.CommonElements.FUTURE_ELEMENTS 052 }) 053 final public class RoleResponsibility extends AbstractDataTransferObject implements RoleResponsibilityContract { 054 private static final long serialVersionUID = 1L; 055 056 @XmlElement(name = RoleResponsibility.Elements.ROLE_RESPONSIBILITY_ID, required = true) 057 private final String roleResponsibilityId; 058 059 @XmlElement(name = RoleResponsibility.Elements.ROLE_ID) 060 private final String roleId; 061 062 @XmlElement(name = RoleResponsibility.Elements.RESPONSIBILITY_ID) 063 private final String responsibilityId; 064 065 @XmlElement(name = CoreConstants.CommonElements.ACTIVE) 066 private final boolean active; 067 068 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER) 069 private final Long versionNumber; 070 071 @SuppressWarnings("unused") 072 @XmlAnyElement 073 private final Collection<Element> _futureElements = null; 074 075 076 /** 077 * This constructor should never be called except during JAXB unmarshalling. 078 */ 079 @SuppressWarnings("unused") 080 private RoleResponsibility() { 081 this.roleResponsibilityId = null; 082 this.roleId = null; 083 this.responsibilityId = null; 084 this.versionNumber = null; 085 this.active = false; 086 } 087 088 private RoleResponsibility(Builder b) { 089 this.roleResponsibilityId = b.getRoleResponsibilityId(); 090 this.responsibilityId = b.getResponsibilityId(); 091 this.roleId = b.getRoleId(); 092 this.active = b.isActive(); 093 this.versionNumber = b.getVersionNumber(); 094 } 095 096 @Override 097 public String getResponsibilityId() { 098 return this.responsibilityId; 099 } 100 101 @Override 102 public String getRoleId() { 103 return this.roleId; 104 } 105 106 @Override 107 public String getRoleResponsibilityId() { 108 return this.roleResponsibilityId; 109 } 110 111 @Override 112 public boolean isActive() { 113 return this.active; 114 } 115 116 @Override 117 public Long getVersionNumber() { 118 return this.versionNumber; 119 } 120 121 public static class Builder implements RoleResponsibilityContract, ModelBuilder, ModelObjectComplete { 122 private String roleResponsibilityId; 123 private String roleId; 124 private String responsibilityId; 125 private boolean active = true; 126 private Long versionNumber; 127 128 129 private Builder() { 130 } 131 132 public static Builder create() { 133 return new Builder(); 134 } 135 136 public static Builder create(String roleResponsibilityId, String roleId, String responsibilityId) { 137 Builder b = create(); 138 b.setRoleResponsibilityId(roleResponsibilityId); 139 b.setRoleId(roleId); 140 b.setResponsibilityId(responsibilityId); 141 return b; 142 } 143 144 public static Builder create(RoleResponsibilityContract rrContract) { 145 Builder b = create(); 146 b.setRoleResponsibilityId(rrContract.getRoleResponsibilityId()); 147 b.setResponsibilityId(rrContract.getResponsibilityId()); 148 b.setRoleId(rrContract.getRoleId()); 149 b.setActive(rrContract.isActive()); 150 b.setVersionNumber(rrContract.getVersionNumber()); 151 return b; 152 } 153 154 @Override 155 public RoleResponsibility build() { 156 if (versionNumber == null || roleResponsibilityId == null) { 157 throw new IllegalStateException( 158 "versionNumber and roleResponsibilityId must be non-null for a RoleResponsibility object"); 159 } 160 return new RoleResponsibility(this); 161 } 162 163 @Override 164 public String getRoleResponsibilityId() { 165 return roleResponsibilityId; 166 } 167 168 public void setRoleResponsibilityId(String roleResponsibilityId) { 169 if (StringUtils.isBlank(roleResponsibilityId)) { 170 throw new IllegalArgumentException("roleResponsibilityId cannot be blank or null"); 171 } 172 this.roleResponsibilityId = roleResponsibilityId; 173 } 174 175 @Override 176 public String getRoleId() { 177 return roleId; 178 } 179 180 public void setRoleId(String roleId) { 181 this.roleId = roleId; 182 } 183 184 @Override 185 public String getResponsibilityId() { 186 return responsibilityId; 187 } 188 189 public void setResponsibilityId(String responsibilityId) { 190 this.responsibilityId = responsibilityId; 191 } 192 193 194 @Override 195 public boolean isActive() { 196 return active; 197 } 198 199 public void setActive(boolean active) { 200 this.active = active; 201 } 202 203 @Override 204 public Long getVersionNumber() { 205 return versionNumber; 206 } 207 208 public void setVersionNumber(Long versionNumber) { 209 if (versionNumber == null) { 210 throw new IllegalArgumentException("versionNumber must be non-null"); 211 } 212 this.versionNumber = versionNumber; 213 } 214 215 @Override 216 public int hashCode() { 217 return HashCodeBuilder.reflectionHashCode(this); 218 } 219 220 @Override 221 public boolean equals(Object obj) { 222 return EqualsBuilder.reflectionEquals(obj, this); 223 } 224 225 @Override 226 public String toString() { 227 return ToStringBuilder.reflectionToString(this); 228 } 229 } 230 231 /** 232 * A private class which exposes constants which define the XML element names to use 233 * when this object is marshalled to XML. 234 */ 235 static class Elements { 236 final static String ROLE_RESPONSIBILITY_ID = "roleResponsibilityId"; 237 final static String ROLE_ID = "roleId"; 238 final static String RESPONSIBILITY_ID = "responsibilityId"; 239 } 240 241 /** 242 * Defines some internal constants used on this class. 243 */ 244 static class Constants { 245 final static String ROOT_ELEMENT_NAME = "roleResponsibility"; 246 final static String TYPE_NAME = "RoleResponsibilityType"; 247 } 248 249 public static class Cache { 250 public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + RoleResponsibility.Constants.TYPE_NAME; 251 } 252 }