001 /** 002 * Copyright 2005-2012 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 */ 016 package org.kuali.rice.kew.documentlink; 017 018 import java.io.Serializable; 019 020 import javax.persistence.Column; 021 import javax.persistence.Entity; 022 import javax.persistence.GeneratedValue; 023 import javax.persistence.Id; 024 import javax.persistence.Table; 025 026 import org.hibernate.annotations.GenericGenerator; 027 import org.hibernate.annotations.Parameter; 028 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; 029 import org.kuali.rice.kew.api.document.DocumentLinkContract; 030 import org.kuali.rice.kew.service.KEWServiceLocator; 031 032 /** 033 * Server side bean for DocumentLinkDAO 034 * 035 * @author Kuali Rice Team (kuali-rice@googlegroups.com) 036 * 037 */ 038 039 @Entity 040 @Table(name="KREW_DOC_LNK_T") 041 //@Sequence(name="KREW_DOC_LNK_S",property="docLinkId") 042 public class DocumentLink implements Serializable, DocumentLinkContract { 043 044 private static final long serialVersionUID = 551926904795633010L; 045 046 @Id 047 @GeneratedValue(generator="KREW_DOC_LNK_S") 048 @GenericGenerator(name="KREW_DOC_LNK_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={ 049 @Parameter(name="sequence_name",value="KREW_DOC_LNK_S"), 050 @Parameter(name="value_column",value="id") 051 }) 052 @Column(name="DOC_LNK_ID") 053 private String docLinkId; 054 @Column(name="ORGN_DOC_ID") 055 private String orgnDocId; 056 @Column(name="DEST_DOC_ID") 057 private String destDocId; 058 059 /** 060 * @return the docLinkId 061 */ 062 public String getDocLinkId() { 063 return this.docLinkId; 064 } 065 066 /** 067 * @param docLinkId the docLinkId to set 068 */ 069 public void setDocLinkId(String docLinkId) { 070 this.docLinkId = docLinkId; 071 } 072 073 /** 074 * @return the orgnDocId 075 */ 076 public String getOrgnDocId() { 077 return this.orgnDocId; 078 } 079 080 /** 081 * @param orgnDocId the orgnDocId to set 082 */ 083 public void setOrgnDocId(String orgnDocId) { 084 this.orgnDocId = orgnDocId; 085 } 086 087 /** 088 * @return the destDocId 089 */ 090 public String getDestDocId() { 091 return this.destDocId; 092 } 093 094 /** 095 * @param destDocId the destDocId to set 096 */ 097 public void setDestDocId(String destDocId) { 098 this.destDocId = destDocId; 099 } 100 101 //@PrePersist 102 public void beforeInsert(){ 103 OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager()); 104 } 105 106 // new contract methods for Rice 2.0 107 108 @Override 109 public String getId() { 110 if (getDocLinkId() == null) { 111 return null; 112 } 113 return getDocLinkId().toString(); 114 } 115 116 @Override 117 public String getOriginatingDocumentId() { 118 return getOrgnDocId(); 119 } 120 121 @Override 122 public String getDestinationDocumentId() { 123 return getDestDocId(); 124 } 125 126 public static org.kuali.rice.kew.api.document.DocumentLink to(DocumentLink documentLinkBo) { 127 if (documentLinkBo == null) { 128 return null; 129 } 130 return org.kuali.rice.kew.api.document.DocumentLink.Builder.create(documentLinkBo).build(); 131 } 132 133 public static DocumentLink from(org.kuali.rice.kew.api.document.DocumentLink documentLink) { 134 if (documentLink == null) { 135 return null; 136 } 137 DocumentLink documentLinkBo = new DocumentLink(); 138 if (documentLink.getId() != null) { 139 documentLinkBo.setDocLinkId(documentLink.getId()); 140 } 141 documentLinkBo.setOrgnDocId(documentLink.getOriginatingDocumentId()); 142 documentLinkBo.setDestDocId(documentLink.getDestinationDocumentId()); 143 return documentLinkBo; 144 } 145 146 }