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

@ -17,7 +17,6 @@ package google.registry.flows.poll;
import static com.google.common.base.Preconditions.checkState;
import static google.registry.flows.FlowUtils.validateClientIsLoggedIn;
import static google.registry.flows.poll.PollFlowUtils.getPollMessagesQuery;
import static google.registry.model.eppoutput.Result.Code.SUCCESS;
import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_NO_MESSAGES;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.DateTimeUtils.isBeforeOrAt;
@ -30,11 +29,10 @@ import google.registry.flows.EppException.ObjectDoesNotExistException;
import google.registry.flows.EppException.ParameterValueSyntaxErrorException;
import google.registry.flows.EppException.RequiredParameterMissingException;
import google.registry.flows.ExtensionManager;
import google.registry.flows.Flow;
import google.registry.flows.FlowModule.ClientId;
import google.registry.flows.FlowModule.PollMessageId;
import google.registry.flows.TransactionalFlow;
import google.registry.model.eppoutput.EppOutput;
import google.registry.model.eppoutput.EppResponse;
import google.registry.model.poll.MessageQueueInfo;
import google.registry.model.poll.PollMessage;
import google.registry.model.poll.PollMessageExternalKeyConverter;
@ -55,15 +53,16 @@ import org.joda.time.DateTime;
* @error {@link PollAckFlow.MissingMessageIdException}
* @error {@link PollAckFlow.NotAuthorizedToAckMessageException}
*/
public class PollAckFlow extends Flow implements TransactionalFlow {
public class PollAckFlow implements TransactionalFlow {
@Inject ExtensionManager extensionManager;
@Inject @ClientId String clientId;
@Inject @PollMessageId String messageId;
@Inject EppResponse.Builder responseBuilder;
@Inject PollAckFlow() {}
@Override
public final EppOutput run() throws EppException {
public final EppResponse run() throws EppException {
extensionManager.validate(); // There are no legal extensions for this flow.
validateClientIsLoggedIn(clientId);
if (messageId.isEmpty()) {
@ -78,6 +77,8 @@ public class PollAckFlow extends Flow implements TransactionalFlow {
throw new InvalidMessageIdException(messageId);
}
final DateTime now = ofy().getTransactionTime();
// Load the message to be acked. If a message is queued to be delivered in the future, we treat
// it as if it doesn't exist yet.
PollMessage pollMessage = ofy().load().key(pollMessageKey).now();
@ -128,17 +129,14 @@ public class PollAckFlow extends Flow implements TransactionalFlow {
messageCount--;
}
if (messageCount <= 0) {
return createOutput(SUCCESS_WITH_NO_MESSAGES);
return responseBuilder.setResultFromCode(SUCCESS_WITH_NO_MESSAGES).build();
}
return createOutput(
SUCCESS,
null, // responseData
null, // responseExtensions
MessageQueueInfo.create(
null, // eventTime
null, // msg
messageCount,
messageId));
return responseBuilder
.setMessageQueueInfo(new MessageQueueInfo.Builder()
.setQueueLength(messageCount)
.setMessageId(messageId)
.build())
.build();
}
/** Registrar is not authorized to ack this message. */