001/* 002 * Copyright 2020 Global Biodiversity Information Facility (GBIF) 003 * 004 * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0 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.gbif.api.model.pipelines; 017 018import java.util.HashSet; 019import java.util.Objects; 020import java.util.Set; 021 022/** 023 * Encapsulates the possible response of the request of re-execute a pipeline of dataset and 024 * attempt. 025 */ 026@SuppressWarnings("unused") 027public class RunPipelineResponse { 028 029 /** Possible response statuses. */ 030 public enum ResponseStatus { 031 OK, 032 PIPELINE_IN_SUBMITTED, 033 UNSUPPORTED_STEP, 034 ERROR 035 } 036 037 private ResponseStatus responseStatus; 038 039 private Set<StepType> steps; 040 041 private Set<StepType> stepsFailed; 042 043 private String message; 044 045 public RunPipelineResponse() { 046 } 047 048 public RunPipelineResponse( 049 ResponseStatus responseStatus, 050 Set<StepType> steps, 051 Set<StepType> stepsFailed, 052 String message) { 053 this.responseStatus = responseStatus; 054 this.steps = steps; 055 this.message = message; 056 this.stepsFailed = stepsFailed; 057 } 058 059 /** @return the response status of execution request */ 060 public ResponseStatus getResponseStatus() { 061 return responseStatus; 062 } 063 064 /** @return steps requested to be executed */ 065 public Set<StepType> getSteps() { 066 return steps; 067 } 068 069 public String getMessage() { 070 return message; 071 } 072 073 public Set<StepType> getStepsFailed() { 074 return stepsFailed; 075 } 076 077 @Override 078 public boolean equals(Object o) { 079 if (this == o) return true; 080 if (o == null || getClass() != o.getClass()) return false; 081 RunPipelineResponse that = (RunPipelineResponse) o; 082 return responseStatus == that.responseStatus 083 && steps.equals(that.steps) 084 && stepsFailed.equals(that.stepsFailed) 085 && message.equals(that.message); 086 } 087 088 @Override 089 public int hashCode() { 090 return Objects.hash(responseStatus, steps, stepsFailed, message); 091 } 092 093 /** @return a new Builder instance. */ 094 public static Builder builder() { 095 return new Builder(); 096 } 097 098 /** @return a new Builder instance. */ 099 public static Builder builder(RunPipelineResponse runPipelineResponse) { 100 Builder builder = new Builder(); 101 return builder 102 .setSteps(runPipelineResponse.steps) 103 .setResponseStatus(runPipelineResponse.responseStatus); 104 } 105 106 /** Builder for {@link RunPipelineResponse}. */ 107 public static class Builder { 108 109 private ResponseStatus responseStatus; 110 private Set<StepType> steps; 111 private Set<StepType> stepsFailed; 112 private String message; 113 114 public Builder setResponseStatus(ResponseStatus responseStatus) { 115 this.responseStatus = responseStatus; 116 return this; 117 } 118 119 public Builder setSteps(Set<StepType> steps) { 120 this.steps = steps; 121 return this; 122 } 123 124 public Builder addStep(StepType step) { 125 if (this.steps == null) { 126 this.steps = new HashSet<>(); 127 } 128 this.steps.add(step); 129 return this; 130 } 131 132 public Builder setStepsFailed(Set<StepType> stepsFailed) { 133 this.stepsFailed = stepsFailed; 134 return this; 135 } 136 137 public Builder addStepFailed(StepType stepFailed) { 138 if (this.stepsFailed == null) { 139 this.stepsFailed = new HashSet<>(); 140 } 141 this.stepsFailed.add(stepFailed); 142 return this; 143 } 144 145 public Builder setMessage(String message) { 146 this.message = message; 147 return this; 148 } 149 150 public RunPipelineResponse build() { 151 return new RunPipelineResponse(responseStatus, steps, stepsFailed, message); 152 } 153 } 154}