WorkflowTransition.java
/*
* Copyright 2024 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gringlobal.model.workflow;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import org.gringlobal.api.exception.InvalidApiUsageException;
import org.gringlobal.compatibility.SysTableInfo;
/**
* A directional link between two workflow steps.
*/
@Entity
@Table(name = "workflow_transition")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
@SysTableInfo(ignore = true, area = "")
public class WorkflowTransition implements Serializable {
private static final long serialVersionUID = 1091882527302443206L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "workflow_transition_id")
private Long id;
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(updatable = false, name = "workflow_id")
private Workflow workflow;
/** Source step in workflow */
@ManyToOne(fetch = FetchType.LAZY, optional = false, cascade = {})
@JoinColumn(updatable = false, name = "origin_step_id")
private WorkflowStep origin;
/** Target step in the same workflow */
@ManyToOne(fetch = FetchType.LAZY, optional = false, cascade = {})
@JoinColumn(updatable = false, name = "target_step_id")
private WorkflowStep target;
@Size(max = 200)
@Column(length = 200)
private String condition;
public WorkflowTransition(Long id) {
this.id = id;
}
@PrePersist
protected void prePersist() {
if (target instanceof WorkflowStartStep) {
throw new InvalidApiUsageException("WorkflowStartStep must only be as origin");
}
if (origin instanceof WorkflowEndStep) {
throw new InvalidApiUsageException("WorkflowEndStep must be target only");
}
}
}