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