001/* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014package org.gbif.api.model.pipelines; 015 016import org.gbif.api.jackson.LocalDateTimeSerDe; 017 018import java.io.Serializable; 019import java.time.LocalDateTime; 020import java.util.HashSet; 021import java.util.Objects; 022import java.util.Set; 023import java.util.StringJoiner; 024import java.util.TreeSet; 025 026import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 027import com.fasterxml.jackson.databind.annotation.JsonSerialize; 028 029import static org.gbif.api.model.pipelines.PipelineStep.STEPS_BY_FINISHED_ASC; 030 031 032/** 033 * Models an execution of a pipeline that can include one or more steps. 034 */ 035public class PipelineExecution implements Serializable { 036 037 private long key; 038 private Set<StepType> stepsToRun = new HashSet<>(); 039 private String rerunReason; 040 private String remarks; 041 042 @JsonSerialize(using = LocalDateTimeSerDe.LocalDateTimeSerializer.class) 043 @JsonDeserialize(using = LocalDateTimeSerDe.LocalDateTimeDeserializer.class) 044 private LocalDateTime created; 045 046 private String createdBy; 047 private Set<PipelineStep> steps = new TreeSet<>(STEPS_BY_FINISHED_ASC); 048 private boolean finished; 049 050 public long getKey() { 051 return key; 052 } 053 054 public PipelineExecution setKey(long key) { 055 this.key = key; 056 return this; 057 } 058 059 public Set<StepType> getStepsToRun() { 060 return stepsToRun; 061 } 062 063 public PipelineExecution setStepsToRun(Set<StepType> stepsToRun) { 064 this.stepsToRun = stepsToRun; 065 return this; 066 } 067 068 public String getRerunReason() { 069 return rerunReason; 070 } 071 072 public PipelineExecution setRerunReason(String rerunReason) { 073 this.rerunReason = rerunReason; 074 return this; 075 } 076 077 public String getRemarks() { 078 return remarks; 079 } 080 081 public PipelineExecution setRemarks(String remarks) { 082 this.remarks = remarks; 083 return this; 084 } 085 086 public LocalDateTime getCreated() { 087 return created; 088 } 089 090 public PipelineExecution setCreated(LocalDateTime created) { 091 this.created = created; 092 return this; 093 } 094 095 public String getCreatedBy() { 096 return createdBy; 097 } 098 099 public PipelineExecution setCreatedBy(String createdBy) { 100 this.createdBy = createdBy; 101 return this; 102 } 103 104 public Set<PipelineStep> getSteps() { 105 return steps; 106 } 107 108 public PipelineExecution setSteps(Set<PipelineStep> steps) { 109 this.steps.clear(); 110 this.steps.addAll(steps); 111 return this; 112 } 113 114 public PipelineExecution addStep(PipelineStep step) { 115 steps.add(step); 116 return this; 117 } 118 119 public boolean isFinished() { 120 return finished; 121 } 122 123 public PipelineExecution setFinished(boolean finished) { 124 this.finished = finished; 125 return this; 126 } 127 128 @Override 129 public boolean equals(Object o) { 130 if (this == o) return true; 131 if (o == null || getClass() != o.getClass()) return false; 132 PipelineExecution that = (PipelineExecution) o; 133 return key == that.key 134 && Objects.equals(stepsToRun, that.stepsToRun) 135 && Objects.equals(rerunReason, that.rerunReason) 136 && Objects.equals(remarks, that.remarks) 137 && Objects.equals(created, that.created) 138 && Objects.equals(createdBy, that.createdBy) 139 && Objects.equals(steps, that.steps) 140 && Objects.equals(finished, that.finished); 141 } 142 143 @Override 144 public int hashCode() { 145 return Objects.hash(key, stepsToRun, rerunReason, remarks, created, createdBy, finished); 146 } 147 148 @Override 149 public String toString() { 150 return new StringJoiner(", ", PipelineExecution.class.getSimpleName() + "[", "]") 151 .add("key=" + key) 152 .add("stepsToRun=" + stepsToRun) 153 .add("rerunReason='" + rerunReason + "'") 154 .add("remarks='" + remarks + "'") 155 .add("created=" + created) 156 .add("createdBy='" + createdBy + "'") 157 .add("steps='" + steps + "'") 158 .add("finished='" + finished + "'") 159 .toString(); 160 } 161}