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.kew.doctype; 017 018import org.hibernate.annotations.GenericGenerator; 019import org.hibernate.annotations.Parameter; 020import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; 021import org.kuali.rice.kew.api.KewApiServiceLocator; 022import org.kuali.rice.kew.api.doctype.DocumentTypeAttribute; 023import org.kuali.rice.kew.api.doctype.DocumentTypeAttributeContract; 024import org.kuali.rice.kew.doctype.bo.DocumentType; 025import org.kuali.rice.kew.rule.bo.RuleAttribute; 026import org.kuali.rice.kew.service.KEWServiceLocator; 027 028import javax.persistence.Column; 029import javax.persistence.Entity; 030import javax.persistence.FetchType; 031import javax.persistence.GeneratedValue; 032import javax.persistence.Id; 033import javax.persistence.JoinColumn; 034import javax.persistence.ManyToOne; 035import javax.persistence.Table; 036import javax.persistence.Transient; 037import java.io.Serializable; 038 039 040/** 041 * Data bean representing an attribute associated at the document type level. e.g. NoteAttribute, 042 * EmailAttribute, SearchableAttribute, etc. 043 * 044 * @author Kuali Rice Team (rice.collab@kuali.org) 045 * 046 */ 047@Entity 048//@Sequence(name="KREW_DOC_TYP_ATTR_S", property="id") 049@Table(name="KREW_DOC_TYP_ATTR_T") 050public class DocumentTypeAttributeBo implements DocumentTypeAttributeContract, Comparable, Serializable { 051 052 private static final long serialVersionUID = -4429421648373903566L; 053 054 @Id 055 @GeneratedValue(generator="KREW_DOC_TYP_ATTR_S") 056 @GenericGenerator(name="KREW_DOC_TYP_ATTR_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={ 057 @Parameter(name="sequence_name",value="KREW_DOC_TYP_ATTR_S"), 058 @Parameter(name="value_column",value="id") 059 }) 060 @Column(name="DOC_TYP_ATTRIB_ID") 061 private String id; 062 @Column(name="RULE_ATTR_ID",insertable=false, updatable=false) 063 private String ruleAttributeId; 064 @ManyToOne(fetch=FetchType.EAGER) 065 @JoinColumn(name="RULE_ATTR_ID") 066 private RuleAttribute ruleAttribute; 067 @Column(name="DOC_TYP_ID",insertable=false, updatable=false) 068 private String documentTypeId; 069 @ManyToOne(fetch=FetchType.EAGER) 070 @JoinColumn(name="DOC_TYP_ID") 071 private DocumentType documentType; 072 @Column(name="ORD_INDX") 073 private int orderIndex; 074 @Transient 075 private Integer lockVerNbr; 076 077 //@PrePersist 078 public void beforeInsert(){ 079 OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager()); 080 } 081 082 /** 083 * @param id The id to set. 084 */ 085 public void setId(String id) { 086 this.id = id; 087 } 088 089 /** 090 * @return Returns the id. 091 */ 092 public String getId() { 093 return id; 094 } 095 096 /** 097 * @param documentTypeId The documentTypeId to set. 098 */ 099 public void setDocumentTypeId(String documentTypeId) { 100 this.documentTypeId = documentTypeId; 101 } 102 103 /** 104 * @return Returns the documentTypeId. 105 */ 106 public String getDocumentTypeId() { 107 return documentTypeId; 108 } 109 110 /** 111 * @param ruleAttributeId The ruleAttributeId to set. 112 */ 113 public void setRuleAttributeId(String ruleAttributeId) { 114 this.ruleAttributeId = ruleAttributeId; 115 if (ruleAttributeId == null) { 116 ruleAttribute = null; 117 } else { 118 ruleAttribute = RuleAttribute.from(KewApiServiceLocator.getExtensionRepositoryService().getExtensionById(ruleAttributeId)); 119 //ruleAttribute = getRuleAttributeService().findByRuleAttributeId(ruleAttributeId); 120 } 121 } 122 123 /** 124 * @return Returns the ruleAttributeId. 125 */ 126 public String getRuleAttributeId() { 127 return ruleAttributeId; 128 } 129 130 /** 131 * @param ruleAttribute The ruleAttribute to set. 132 */ 133 public void setRuleAttribute(RuleAttribute ruleAttribute) { 134 this.ruleAttribute = ruleAttribute; 135 } 136 137 /** 138 * @return Returns the ruleAttribute. 139 */ 140 public RuleAttribute getRuleAttribute() { 141 return ruleAttribute; 142 } 143 144 /* (non-Javadoc) 145 * @see java.lang.Comparable#compareTo(java.lang.Object) 146 */ 147 public int compareTo(Object o) { 148 if (o instanceof DocumentTypeAttributeBo) { 149 return this.getRuleAttribute().getName().compareTo(((DocumentTypeAttributeBo) o).getRuleAttribute().getName()); 150 } 151 return 0; 152 } 153 154 public DocumentType getDocumentType() { 155 return documentType; 156 } 157 158 public void setDocumentType(DocumentType documentType) { 159 this.documentType = documentType; 160 } 161 162 public int getOrderIndex() { 163 return orderIndex; 164 } 165 166 public void setOrderIndex(int orderIndex) { 167 this.orderIndex = orderIndex; 168 } 169 170 public Integer getLockVerNbr() { 171 return lockVerNbr; 172 } 173 174 public void setLockVerNbr(Integer lockVerNbr) { 175 this.lockVerNbr = lockVerNbr; 176 } 177 178 public static DocumentTypeAttribute to(DocumentTypeAttributeBo documentTypeAttributeBo) { 179 if (documentTypeAttributeBo == null) { 180 return null; 181 } 182 DocumentTypeAttribute.Builder builder = DocumentTypeAttribute.Builder.create(documentTypeAttributeBo); 183 return builder.build(); 184 } 185 186 public static DocumentTypeAttributeBo from(DocumentTypeAttribute dta) { 187 // DocumentType BO and DTO are not symmetric 188 // set what fields we can 189 DocumentTypeAttributeBo bo = new DocumentTypeAttributeBo(); 190 bo.setDocumentTypeId(dta.getDocumentTypeId()); 191 if (dta.getRuleAttribute() != null) { 192 bo.setRuleAttributeId(dta.getRuleAttribute().getId()); 193 bo.setRuleAttribute(RuleAttribute.from(dta.getRuleAttribute())); 194 } 195 bo.setId(dta.getId()); 196 bo.setOrderIndex(dta.getOrderIndex()); 197 198 return bo; 199 } 200} 201