001/** 002 * Copyright 2005-2015 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 */ 016package org.kuali.rice.kim.api.role; 017 018import org.apache.commons.lang.StringUtils; 019import org.apache.commons.lang.builder.EqualsBuilder; 020import org.apache.commons.lang.builder.HashCodeBuilder; 021import org.apache.commons.lang.builder.ToStringBuilder; 022import org.kuali.rice.core.api.CoreConstants; 023import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 024import org.kuali.rice.core.api.mo.ModelBuilder; 025import org.kuali.rice.core.api.mo.ModelObjectComplete; 026import org.kuali.rice.kim.api.KimConstants; 027import org.w3c.dom.Element; 028 029import javax.xml.bind.annotation.XmlAccessType; 030import javax.xml.bind.annotation.XmlAccessorType; 031import javax.xml.bind.annotation.XmlAnyElement; 032import javax.xml.bind.annotation.XmlElement; 033import javax.xml.bind.annotation.XmlRootElement; 034import javax.xml.bind.annotation.XmlType; 035import 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}) 053public final class RoleResponsibility extends AbstractDataTransferObject implements RoleResponsibilityContract { 054 private static final long serialVersionUID = 1L; 055 056 @XmlElement(name = RoleResponsibility.Elements.ROLE_RESPONSIBILITY_ID, required = false) 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 roleId, String responsibilityId) { 137 Builder b = create(); 138 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 return new RoleResponsibility(this); 157 } 158 159 @Override 160 public String getRoleResponsibilityId() { 161 return roleResponsibilityId; 162 } 163 164 public void setRoleResponsibilityId(String roleResponsibilityId) { 165 if (StringUtils.isWhitespace(roleResponsibilityId)) { 166 throw new IllegalArgumentException("roleResponsibilityId cannot be whitespace"); 167 } 168 this.roleResponsibilityId = roleResponsibilityId; 169 } 170 171 @Override 172 public String getRoleId() { 173 return roleId; 174 } 175 176 public void setRoleId(String roleId) { 177 this.roleId = roleId; 178 } 179 180 @Override 181 public String getResponsibilityId() { 182 return responsibilityId; 183 } 184 185 public void setResponsibilityId(String responsibilityId) { 186 this.responsibilityId = responsibilityId; 187 } 188 189 190 @Override 191 public boolean isActive() { 192 return active; 193 } 194 195 public void setActive(boolean active) { 196 this.active = active; 197 } 198 199 @Override 200 public Long getVersionNumber() { 201 return versionNumber; 202 } 203 204 public void setVersionNumber(Long versionNumber) { 205 this.versionNumber = versionNumber; 206 } 207 208 @Override 209 public int hashCode() { 210 return HashCodeBuilder.reflectionHashCode(this); 211 } 212 213 @Override 214 public boolean equals(Object obj) { 215 return EqualsBuilder.reflectionEquals(obj, this); 216 } 217 218 @Override 219 public String toString() { 220 return ToStringBuilder.reflectionToString(this); 221 } 222 } 223 224 /** 225 * A private class which exposes constants which define the XML element names to use 226 * when this object is marshalled to XML. 227 */ 228 static class Elements { 229 final static String ROLE_RESPONSIBILITY_ID = "roleResponsibilityId"; 230 final static String ROLE_ID = "roleId"; 231 final static String RESPONSIBILITY_ID = "responsibilityId"; 232 } 233 234 /** 235 * Defines some internal constants used on this class. 236 */ 237 static class Constants { 238 final static String ROOT_ELEMENT_NAME = "roleResponsibility"; 239 final static String TYPE_NAME = "RoleResponsibilityType"; 240 } 241 242 public static class Cache { 243 public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + RoleResponsibility.Constants.TYPE_NAME; 244 } 245}