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