View Javadoc

1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.documentlink;
17  
18  import java.io.Serializable;
19  
20  import javax.persistence.Column;
21  import javax.persistence.Entity;
22  import javax.persistence.GeneratedValue;
23  import javax.persistence.Id;
24  import javax.persistence.Table;
25  
26  import org.hibernate.annotations.GenericGenerator;
27  import org.hibernate.annotations.Parameter;
28  import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
29  import org.kuali.rice.kew.api.document.DocumentLinkContract;
30  import org.kuali.rice.kew.service.KEWServiceLocator;
31  
32  /**
33   * Server side bean for DocumentLinkDAO 
34   * 
35   * @author Kuali Rice Team (kuali-rice@googlegroups.com)
36   *
37   */
38  
39  @Entity
40  @Table(name="KREW_DOC_LNK_T")
41  //@Sequence(name="KREW_DOC_LNK_S",property="docLinkId")
42  public class DocumentLink implements Serializable, DocumentLinkContract {
43  
44  	private static final long serialVersionUID = 551926904795633010L;
45  	
46  	@Id
47  	@GeneratedValue(generator="KREW_DOC_LNK_S")
48  	@GenericGenerator(name="KREW_DOC_LNK_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
49  			@Parameter(name="sequence_name",value="KREW_DOC_LNK_S"),
50  			@Parameter(name="value_column",value="id")
51  	})
52  	@Column(name="DOC_LNK_ID")
53  	private String docLinkId;
54      @Column(name="ORGN_DOC_ID")
55  	private String orgnDocId;
56      @Column(name="DEST_DOC_ID")
57  	private String destDocId;
58      
59  	/**
60  	 * @return the docLinkId
61  	 */
62  	public String getDocLinkId() {
63  		return this.docLinkId;
64  	}
65  
66  	/**
67  	 * @param docLinkId the docLinkId to set
68  	 */
69  	public void setDocLinkId(String docLinkId) {
70  		this.docLinkId = docLinkId;
71  	}
72  
73  	/**
74  	 * @return the orgnDocId
75  	 */
76  	public String getOrgnDocId() {
77  		return this.orgnDocId;
78  	}
79  
80  	/**
81  	 * @param orgnDocId the orgnDocId to set
82  	 */
83  	public void setOrgnDocId(String orgnDocId) {
84  		this.orgnDocId = orgnDocId;
85  	}
86  
87  	/**
88  	 * @return the destDocId
89  	 */
90  	public String getDestDocId() {
91  		return this.destDocId;
92  	}
93  
94  	/**
95  	 * @param destDocId the destDocId to set
96  	 */
97  	public void setDestDocId(String destDocId) {
98  		this.destDocId = destDocId;
99  	}
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 }