Turn Flow into an interface and inject all its fields

This concludes your flow flattening experience. Please
fill out a flow flattening satisfaction survey before
exiting.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=137903095
This commit is contained in:
cgoldfeder 2016-11-01 19:50:31 -07:00 committed by Ben McIlwain
parent 82b0bff9b5
commit 053538b1b5
49 changed files with 630 additions and 569 deletions

View file

@ -14,90 +14,24 @@
package google.registry.flows;
import com.google.common.collect.ImmutableList;
import google.registry.model.eppcommon.Trid;
import google.registry.model.eppinput.EppInput;
import google.registry.model.eppoutput.EppOutput;
import google.registry.model.eppoutput.EppResponse;
import google.registry.model.eppoutput.EppResponse.ResponseData;
import google.registry.model.eppoutput.EppResponse.ResponseExtension;
import google.registry.model.eppoutput.Result;
import google.registry.model.poll.MessageQueueInfo;
import javax.annotation.Nullable;
import org.joda.time.DateTime;
import google.registry.model.eppoutput.EppOutput.ResponseOrGreeting;
/**
* An abstract EPP flow.
* An Extensible Provisioning Protocol flow.
*
* <p>This class also contains static methods for loading an appropriate flow based on model
* classes.
* <p>A "flow" is our word for a "command", since we've overloaded the word "command" to mean the
* command objects and also the CLI operation classes.
*/
public abstract class Flow {
protected EppInput eppInput;
protected SessionMetadata sessionMetadata;
protected TransportCredentials credentials;
protected Trid trid;
protected DateTime now;
/** Whether this flow is being run in a superuser mode that can skip some checks. */
protected boolean isSuperuser;
/** Flows can override this for custom initialization. */
@SuppressWarnings("unused")
protected void initFlow() throws EppException {}
/** Execute the business logic for this flow. */
protected abstract EppOutput run() throws EppException;
protected EppOutput createOutput(Result.Code code) {
return createOutput(code, null);
}
protected EppOutput createOutput(Result.Code code, ResponseData responseData) {
return createOutput(code, responseData, null);
}
protected EppOutput createOutput(
Result.Code code,
@Nullable ResponseData responseData,
@Nullable ImmutableList<? extends ResponseExtension> extensions) {
return createOutput(
code, responseData == null ? null : ImmutableList.of(responseData), extensions, null);
}
protected EppOutput createOutput(
Result.Code code,
@Nullable ImmutableList<ResponseData> responseData,
@Nullable ImmutableList<? extends ResponseExtension> responseExtensions,
@Nullable MessageQueueInfo messageQueueInfo) {
return EppOutput.create(new EppResponse.Builder()
.setTrid(trid)
.setResult(Result.create(code))
.setMessageQueueInfo(messageQueueInfo)
.setResData(responseData)
.setExtensions(responseExtensions)
.build());
}
public interface Flow {
/**
* Using an init function instead of a constructor avoids duplicating constructors across the
* entire hierarchy of flow classes
* Executes an EPP "flow" and returns a response object (or in the specific case of the "hello"
* flow a greeting object) that can be converted to XML and returned to the caller.
*
* <p>Flows should have {@link #run} called once per instance. If a flow needs to be retried, a
* new instance should be created.
*
* <p>Flows should get all of their parameters via injection off of {@link FlowComponent}.
*/
public final Flow init(
EppInput eppInput,
Trid trid,
SessionMetadata sessionMetadata,
TransportCredentials credentials,
boolean isSuperuser,
DateTime now) throws EppException {
this.eppInput = eppInput;
this.trid = trid;
this.sessionMetadata = sessionMetadata;
this.credentials = credentials;
this.now = now;
this.isSuperuser = isSuperuser;
initFlow();
return this;
}
ResponseOrGreeting run() throws EppException;
}