mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 16:07:15 +02:00
Flatten and inject the poll flows
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=133302791
This commit is contained in:
parent
939112318b
commit
4a723576d5
6 changed files with 107 additions and 131 deletions
|
@ -14,18 +14,20 @@
|
|||
|
||||
package google.registry.flows.poll;
|
||||
|
||||
import static google.registry.flows.poll.PollFlowUtils.getPollMessagesQuery;
|
||||
import static google.registry.model.eppoutput.Result.Code.SuccessWithAckMessage;
|
||||
import static google.registry.model.eppoutput.Result.Code.SuccessWithNoMessages;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.util.CollectionUtils.forceEmptyToNull;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.flows.EppException;
|
||||
import google.registry.flows.EppException.ParameterValueSyntaxErrorException;
|
||||
import google.registry.flows.FlowModule.ClientId;
|
||||
import google.registry.flows.FlowModule.PollMessageId;
|
||||
import google.registry.flows.LoggedInFlow;
|
||||
import google.registry.model.eppoutput.EppOutput;
|
||||
import google.registry.model.poll.MessageQueueInfo;
|
||||
import google.registry.model.poll.PollMessage;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
|
@ -33,34 +35,31 @@ import javax.inject.Inject;
|
|||
*
|
||||
* @error {@link PollRequestFlow.UnexpectedMessageIdException}
|
||||
*/
|
||||
public class PollRequestFlow extends PollFlow {
|
||||
public class PollRequestFlow extends LoggedInFlow {
|
||||
|
||||
@Inject @ClientId String clientId;
|
||||
@Inject @PollMessageId String messageId;
|
||||
@Inject PollRequestFlow() {}
|
||||
|
||||
@Override
|
||||
public final EppOutput run() throws EppException {
|
||||
if (command.getMessageId() != null) {
|
||||
if (!messageId.isEmpty()) {
|
||||
throw new UnexpectedMessageIdException();
|
||||
}
|
||||
|
||||
List<Key<PollMessage>> pollMessageKeys = getMessageQueueKeysInOrder();
|
||||
// Retrieve the oldest message from the queue that still exists -- since the query is eventually
|
||||
// consistent, it may return keys to some entities that no longer exist.
|
||||
for (Key<PollMessage> key : pollMessageKeys) {
|
||||
PollMessage pollMessage = ofy().load().key(key).now();
|
||||
if (pollMessage != null) {
|
||||
return createOutput(
|
||||
SuccessWithAckMessage,
|
||||
MessageQueueInfo.create(
|
||||
pollMessage.getEventTime(),
|
||||
pollMessage.getMsg(),
|
||||
pollMessageKeys.size(),
|
||||
PollMessage.EXTERNAL_KEY_CONVERTER.convert(key)),
|
||||
forceEmptyToNull(pollMessage.getResponseData()),
|
||||
forceEmptyToNull(pollMessage.getResponseExtensions()));
|
||||
}
|
||||
// Return the oldest message from the queue.
|
||||
PollMessage pollMessage = getPollMessagesQuery(clientId, now).first().now();
|
||||
if (pollMessage == null) {
|
||||
return createOutput(SuccessWithNoMessages);
|
||||
}
|
||||
return createOutput(SuccessWithNoMessages);
|
||||
return createOutput(
|
||||
SuccessWithAckMessage,
|
||||
forceEmptyToNull(pollMessage.getResponseData()),
|
||||
forceEmptyToNull(pollMessage.getResponseExtensions()),
|
||||
MessageQueueInfo.create(
|
||||
pollMessage.getEventTime(),
|
||||
pollMessage.getMsg(),
|
||||
getPollMessagesQuery(clientId, now).count(),
|
||||
PollMessage.EXTERNAL_KEY_CONVERTER.convert(Key.create(pollMessage))));
|
||||
}
|
||||
|
||||
/** Unexpected message id. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue