001/** 002 * Copyright 2005-2016 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.krms.impl.repository; 017 018import org.kuali.rice.krad.bo.PersistableBusinessObjectBase; 019import org.kuali.rice.krad.service.KRADServiceLocator; 020import org.kuali.rice.krad.service.SequenceAccessorService; 021import org.kuali.rice.krms.api.repository.typerelation.RelationshipType; 022import org.kuali.rice.krms.api.repository.typerelation.TypeTypeRelation; 023import org.kuali.rice.krms.api.repository.typerelation.TypeTypeRelationContract; 024 025/** 026 * The mutable implementation of the @{link TypeTypeRelationContract} interface, the counterpart to the immutable implementation {@link TypeTypeRelation}. 027 * @author Kuali Rice Team (rice.collab@kuali.org) 028 * 029 */ 030public class TypeTypeRelationBo 031 extends PersistableBusinessObjectBase 032 implements TypeTypeRelationContract 033{ 034 035 private String fromTypeId; 036 private String toTypeId; 037 private RelationshipType relationshipType; 038 private Integer sequenceNumber; 039 private String id; 040 private boolean active; 041 private Long versionNumber; 042 private SequenceAccessorService sequenceAccessorService; 043 044 private KrmsTypeBo fromType; 045 private KrmsTypeBo toType; 046 047 048 049 /** 050 * Default Constructor 051 * 052 */ 053 public TypeTypeRelationBo() { 054 } 055 056 @Override 057 public String getFromTypeId() { 058 return this.fromTypeId; 059 } 060 061 @Override 062 public String getToTypeId() { 063 return this.toTypeId; 064 } 065 066 @Override 067 public RelationshipType getRelationshipType() { 068 return this.relationshipType; 069 } 070 071 @Override 072 public Integer getSequenceNumber() { 073 return this.sequenceNumber; 074 } 075 076 @Override 077 public String getId() { 078 return this.id; 079 } 080 081 @Override 082 public boolean isActive() { 083 return this.active; 084 } 085 086 @Override 087 public Long getVersionNumber() { 088 return this.versionNumber; 089 } 090 091 /** 092 * Sets the value of fromTypeId on this builder to the given value. 093 * 094 * @param fromTypeId the fromTypeId value to set. 095 * 096 */ 097 public void setFromTypeId(String fromTypeId) { 098 this.fromTypeId = fromTypeId; 099 } 100 101 /** 102 * Sets the value of toTypeId on this builder to the given value. 103 * 104 * @param toTypeId the toTypeId value to set. 105 * 106 */ 107 public void setToTypeId(String toTypeId) { 108 this.toTypeId = toTypeId; 109 } 110 111 /** 112 * Sets the value of relationshipType on this builder to the given value. 113 * 114 * @param relationshipType the relationshipType value to set. 115 * 116 */ 117 public void setRelationshipType(RelationshipType relationshipType) { 118 this.relationshipType = relationshipType; 119 } 120 121 /** 122 * Sets the value of sequenceNumber on this builder to the given value. 123 * 124 * @param sequenceNumber the sequenceNumber value to set. 125 * 126 */ 127 public void setSequenceNumber(Integer sequenceNumber) { 128 this.sequenceNumber = sequenceNumber; 129 } 130 131 /** 132 * Sets the value of id on this builder to the given value. 133 * 134 * @param id the id value to set. 135 * 136 */ 137 public void setId(String id) { 138 this.id = id; 139 } 140 141 /** 142 * Sets the value of active on this builder to the given value. 143 * 144 * @param active the active value to set. 145 * 146 */ 147 public void setActive(boolean active) { 148 this.active = active; 149 } 150 151 /** 152 * Sets the value of versionNumber on this builder to the given value. 153 * 154 * @param versionNumber the versionNumber value to set. 155 * 156 */ 157 public void setVersionNumber(Long versionNumber) { 158 this.versionNumber = versionNumber; 159 } 160 161 /** 162 * Converts a mutable {@link TypeTypeRelationBo} to its immutable counterpart, {@link TypeTypeRelation}. 163 * @param typeTypeRelationBo the mutable business object. 164 * @return a {@link TypeTypeRelation} the immutable object. 165 * 166 */ 167 public static TypeTypeRelation to(TypeTypeRelationBo typeTypeRelationBo) { 168 if (typeTypeRelationBo == null) { return null; } 169 return TypeTypeRelation.Builder.create(typeTypeRelationBo).build(); 170 } 171 172 /** 173 * Converts a immutable {@link TypeTypeRelation} to its mutable {@link TypeTypeRelationBo} counterpart. 174 * @param typeTypeRelation the immutable object. 175 * @return a {@link TypeTypeRelationBo} the mutable TypeTypeRelationBo. 176 * 177 */ 178 public static org.kuali.rice.krms.impl.repository.TypeTypeRelationBo from(TypeTypeRelation typeTypeRelation) { 179 if (typeTypeRelation == null) return null; 180 TypeTypeRelationBo typeTypeRelationBo = new TypeTypeRelationBo(); 181 typeTypeRelationBo.setFromTypeId(typeTypeRelation.getFromTypeId()); 182 typeTypeRelationBo.setToTypeId(typeTypeRelation.getToTypeId()); 183 typeTypeRelationBo.setRelationshipType(typeTypeRelation.getRelationshipType()); 184 typeTypeRelationBo.setSequenceNumber(typeTypeRelation.getSequenceNumber()); 185 typeTypeRelationBo.setId(typeTypeRelation.getId()); 186 typeTypeRelationBo.setActive(typeTypeRelation.isActive()); 187 typeTypeRelationBo.setVersionNumber(typeTypeRelation.getVersionNumber()); 188 // TODO collections, etc. 189 return typeTypeRelationBo; 190 } 191 192 /** 193 * Returns the next available id for the given table and class. 194 * @return String the next available id for the given table and class. 195 * 196 */ 197 private String getNewId(String table, Class clazz) { 198 if (sequenceAccessorService == null) { 199 sequenceAccessorService = KRADServiceLocator.getSequenceAccessorService(); 200 } 201 Long id = sequenceAccessorService.getNextAvailableSequenceNumber(table, clazz); 202 return id.toString(); 203 } 204 205 /** 206 * Set the SequenceAccessorService, useful for testing. 207 * @param sas SequenceAccessorService to use for getNewId. 208 * 209 */ 210 public void setSequenceAccessorService(SequenceAccessorService sas) { 211 sequenceAccessorService = sas; 212 } 213 214 public SequenceAccessorService getSequenceAccessorService() { 215 return sequenceAccessorService; 216 } 217 218 public KrmsTypeBo getFromType() { 219 return fromType; 220 } 221 222 public void setFromType(KrmsTypeBo fromType) { 223 this.fromType = fromType; 224 } 225 226 public KrmsTypeBo getToType() { 227 return toType; 228 } 229 230 public void setToType(KrmsTypeBo toType) { 231 this.toType = toType; 232 } 233 234}