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.apache.commons.lang.StringUtils; 019import org.kuali.rice.core.api.mo.common.Versioned; 020import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator; 021import org.kuali.rice.krms.api.repository.term.TermResolverDefinition; 022 023import javax.persistence.Column; 024import javax.persistence.Entity; 025import javax.persistence.GeneratedValue; 026import javax.persistence.Id; 027import javax.persistence.JoinColumn; 028import javax.persistence.ManyToOne; 029import javax.persistence.Table; 030import javax.persistence.Version; 031import java.io.Serializable; 032 033@Entity 034@Table(name = "KRMS_TERM_RSLVR_PARM_SPEC_T") 035public class TermResolverParameterSpecificationBo implements Versioned, Serializable { 036 037 private static final long serialVersionUID = 1l; 038 039 @PortableSequenceGenerator(name = "KRMS_TERM_RSLVR_PARM_SPEC_S") 040 @GeneratedValue(generator = "KRMS_TERM_RSLVR_PARM_SPEC_S") 041 @Id 042 @Column(name = "TERM_RSLVR_PARM_SPEC_ID") 043 private String id; 044 045 @Column(name = "NM") 046 private String name; 047 048 @Version 049 @Column(name="VER_NBR", length=8) 050 protected Long versionNumber; 051 052 @ManyToOne() 053 @JoinColumn(name = "TERM_RSLVR_ID", referencedColumnName = "TERM_RSLVR_ID") 054 private TermResolverBo termResolver; 055 056 /** 057 * Converts a mutable bo to it's immutable counterpart 058 * 059 * @param bo the mutable business object 060 * @return the immutable object 061 */ 062 public static String to(TermResolverParameterSpecificationBo bo) { 063 if (bo == null) { 064 return null; 065 } 066 067 return bo.name; 068 } 069 070 /** 071 * Converts a immutable object to it's mutable bo counterpart 072 * 073 * @param resolver immutable object 074 * @param name 075 * @return the mutable bo 076 */ 077 public static TermResolverParameterSpecificationBo from(TermResolverDefinition resolver, String name) { 078 if (resolver == null) { 079 return null; 080 } 081 082 if (StringUtils.isBlank(name)) { 083 return null; 084 } 085 086 TermResolverParameterSpecificationBo bo = new TermResolverParameterSpecificationBo(); 087 088 // we won't set termResolver here, it gets set in TermResolver.from 089 090 bo.name = name; 091 092 return bo; 093 } 094 095 public String getId() { 096 return id; 097 } 098 099 public void setId(String id) { 100 this.id = id; 101 } 102 103 public String getTermResolverId() { 104 if (termResolver != null) { 105 return termResolver.getId(); 106 } 107 108 return null; 109 } 110 111 public String getName() { 112 return name; 113 } 114 115 public void setName(String name) { 116 this.name = name; 117 } 118 119 public Long getVersionNumber() { 120 return versionNumber; 121 } 122 123 public void setVersionNumber(Long versionNumber) { 124 this.versionNumber = versionNumber; 125 } 126 127 public TermResolverBo getTermResolver() { 128 return termResolver; 129 } 130 131 public void setTermResolver(TermResolverBo termResolver) { 132 this.termResolver = termResolver; 133 } 134}