001/** 002 * Copyright 2005-2017 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.core.api.mo.common.Versioned; 019import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator; 020import org.kuali.rice.krms.api.repository.category.CategoryDefinition; 021import org.kuali.rice.krms.api.repository.category.CategoryDefinitionContract; 022 023import javax.persistence.Column; 024import javax.persistence.Entity; 025import javax.persistence.GeneratedValue; 026import javax.persistence.Id; 027import javax.persistence.Table; 028import javax.persistence.Version; 029import java.io.Serializable; 030import java.util.ArrayList; 031import java.util.Collections; 032import java.util.List; 033 034@Entity 035@Table(name = "KRMS_CTGRY_T") 036public class CategoryBo implements CategoryDefinitionContract, Versioned, Serializable { 037 038 private static final long serialVersionUID = 1l; 039 040 @PortableSequenceGenerator(name = "KRMS_CTGRY_S") 041 @GeneratedValue(generator = "KRMS_CTGRY_S") 042 @Id 043 @Column(name = "CTGRY_ID") 044 private String id; 045 046 @Column(name = "NM") 047 private String name; 048 049 @Column(name = "NMSPC_CD") 050 private String namespace; 051 052 @Version 053 @Column(name="VER_NBR", length=8) 054 protected Long versionNumber; 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 CategoryDefinition to(CategoryBo bo) { 063 if (bo == null) { 064 return null; 065 } 066 067 return CategoryDefinition.Builder.create(bo).build(); 068 } 069 070 /** 071 * Converts a list of mutable bos to it's immutable counterpart 072 * 073 * @param bos the list of mutable business objects 074 * @return and immutable list containing the immutable objects 075 */ 076 public static List<CategoryDefinition> to(List<CategoryBo> bos) { 077 if (bos == null) { 078 return null; 079 } 080 081 List<CategoryDefinition> categories = new ArrayList<CategoryDefinition>(); 082 083 for (CategoryBo p : bos) { 084 categories.add(CategoryDefinition.Builder.create(p).build()); 085 } 086 087 return Collections.unmodifiableList(categories); 088 } 089 090 /** 091 * Converts a immutable object to it's mutable bo counterpart 092 * 093 * @param im immutable object 094 * @return the mutable bo 095 */ 096 public static CategoryBo from(CategoryDefinition im) { 097 if (im == null) { 098 return null; 099 } 100 101 CategoryBo bo = new CategoryBo(); 102 bo.id = im.getId(); 103 bo.name = im.getName(); 104 bo.namespace = im.getNamespace(); 105 bo.setVersionNumber(im.getVersionNumber()); 106 107 return bo; 108 } 109 110 public static List<CategoryBo> from(List<CategoryDefinition> ims) { 111 if (ims == null) { 112 return null; 113 } 114 115 List<CategoryBo> bos = new ArrayList<CategoryBo>(); 116 117 for (CategoryDefinition im : ims) { 118 CategoryBo bo = CategoryBo.from(im); 119 ((ArrayList<CategoryBo>) bos).add(bo); 120 } 121 122 return Collections.unmodifiableList(bos); 123 } 124 125 public String getId() { 126 return id; 127 } 128 129 public void setId(String id) { 130 this.id = id; 131 } 132 133 public String getName() { 134 return name; 135 } 136 137 public void setName(String name) { 138 this.name = name; 139 } 140 141 public String getNamespace() { 142 return namespace; 143 } 144 145 public void setNamespace(String namespace) { 146 this.namespace = namespace; 147 } 148 149 public Long getVersionNumber() { 150 return versionNumber; 151 } 152 153 public void setVersionNumber(Long versionNumber) { 154 this.versionNumber = versionNumber; 155 } 156}