001    /**
002     * Copyright 2005-2013 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.engine.node;
017    
018    import org.hibernate.annotations.GenericGenerator;
019    import org.hibernate.annotations.Parameter;
020    import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
021    import org.kuali.rice.kew.api.doctype.ProcessDefinitionContract;
022    import org.kuali.rice.kew.doctype.bo.DocumentType;
023    import org.kuali.rice.kew.service.KEWServiceLocator;
024    
025    import javax.persistence.CascadeType;
026    import javax.persistence.Column;
027    import javax.persistence.Entity;
028    import javax.persistence.FetchType;
029    import javax.persistence.GeneratedValue;
030    import javax.persistence.Id;
031    import javax.persistence.JoinColumn;
032    import javax.persistence.ManyToOne;
033    import javax.persistence.OneToOne;
034    import javax.persistence.Table;
035    import javax.persistence.Version;
036    import java.io.Serializable;
037    
038    
039    /**
040     * Represents a route path defined on a {@link DocumentType}.  A ProcessDefinition is a named entity which
041     * simply points to an initial {@link RouteNode} which represents the beginning of the ProcessDefinition.
042     * The path of the process can then be followed using the next nodes defined on the route nodes. 
043     *
044     * @author Kuali Rice Team (rice.collab@kuali.org)
045     */
046    @Entity
047    @Table(name="KREW_DOC_TYP_PROC_T")
048    //@Sequence(name="KREW_RTE_NODE_S",property="processId")
049    public class ProcessDefinitionBo implements Serializable, ProcessDefinitionContract {
050    
051            private static final long serialVersionUID = -6338857095673479752L;
052        
053        @Id
054        @GeneratedValue(generator="KREW_RTE_NODE_S")
055            @GenericGenerator(name="KREW_RTE_NODE_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
056                            @Parameter(name="sequence_name",value="KREW_RTE_NODE_S"),
057                            @Parameter(name="value_column",value="id")
058            })
059            @Column(name="DOC_TYP_PROC_ID")
060            private String processId;
061            @Column(name="NM")
062            private String name;
063            @ManyToOne(fetch=FetchType.EAGER)
064            @JoinColumn(name="DOC_TYP_ID")
065            private DocumentType documentType;
066            @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.MERGE})
067            @JoinColumn(name="INIT_RTE_NODE_ID")
068            private RouteNode initialRouteNode;
069        @Column(name="INIT_IND")
070            private boolean initial = false;
071            @Version
072            @Column(name="VER_NBR")
073            private Integer lockVerNbr;
074            
075            public String getProcessId() {
076                    return processId;
077            }
078            public void setProcessId(String processId) {
079                    this.processId = processId;
080            }
081            public DocumentType getDocumentType() {
082                    return documentType;
083            }
084            public void setDocumentType(DocumentType documentType) {
085                    this.documentType = documentType;
086            }
087            public RouteNode getInitialRouteNode() {
088                    return initialRouteNode;
089            }
090            public void setInitialRouteNode(RouteNode initialRouteNode) {
091                    this.initialRouteNode = initialRouteNode;
092            }
093            public String getName() {
094                    return name;
095            }
096            public void setName(String name) {
097                    this.name = name;
098            }
099            public boolean isInitial() {
100                    return initial;
101            }
102            public void setInitial(boolean initial) {
103                    this.initial = initial;
104            }
105            public Integer getLockVerNbr() {
106                    return lockVerNbr;
107            }
108            public void setLockVerNbr(Integer lockVerNbr) {
109                    this.lockVerNbr = lockVerNbr;
110            }
111    
112            //@PrePersist
113            public void beforeInsert(){
114                    OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
115            }
116    
117            @Override
118        public String getId() {
119            if (processId == null) {
120                return null;
121            }
122            return processId.toString();
123        }
124    
125        @Override
126        public Long getVersionNumber() {
127            if (lockVerNbr == null) {
128                return null;
129            }
130            return new Long(lockVerNbr.longValue());
131        }
132    
133        @Override
134        public String getDocumentTypeId() {
135            if (documentType == null) {
136                return null;
137            }
138            return documentType.getId();
139        }
140    
141    }