mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +02:00
Change to FlowModule to support the new flat flows
This factors out a huge chunk of boilerplate that would otherwise be in every single flow. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=133014837
This commit is contained in:
parent
04fd14995e
commit
efd3424849
1 changed files with 43 additions and 0 deletions
|
@ -18,9 +18,14 @@ import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
|
import google.registry.flows.exceptions.OnlyToolCanPassMetadataException;
|
||||||
import google.registry.flows.picker.FlowPicker;
|
import google.registry.flows.picker.FlowPicker;
|
||||||
|
import google.registry.model.domain.metadata.MetadataExtension;
|
||||||
import google.registry.model.eppcommon.Trid;
|
import google.registry.model.eppcommon.Trid;
|
||||||
import google.registry.model.eppinput.EppInput;
|
import google.registry.model.eppinput.EppInput;
|
||||||
|
import google.registry.model.eppinput.EppInput.ResourceCommandWrapper;
|
||||||
|
import google.registry.model.eppinput.ResourceCommand;
|
||||||
|
import google.registry.model.reporting.HistoryEntry;
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Qualifier;
|
import javax.inject.Qualifier;
|
||||||
|
@ -164,6 +169,44 @@ public class FlowModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@FlowScope
|
||||||
|
static ResourceCommand provideResourceCommand(EppInput eppInput) {
|
||||||
|
return ((ResourceCommandWrapper) eppInput.getCommandWrapper().getCommand())
|
||||||
|
.getResourceCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a partially filled in {@link HistoryEntry} builder.
|
||||||
|
*
|
||||||
|
* <p>This is not marked with {@link FlowScope} so that each retry gets a fresh one. Otherwise,
|
||||||
|
* the fact that the builder is one-use would cause NPEs.
|
||||||
|
*/
|
||||||
|
@Provides
|
||||||
|
static HistoryEntry.Builder provideHistoryEntryBuilder(
|
||||||
|
Trid trid,
|
||||||
|
@InputXml byte[] inputXmlBytes,
|
||||||
|
@Superuser boolean isSuperuser,
|
||||||
|
@ClientId @Nullable String clientId,
|
||||||
|
EppRequestSource eppRequestSource,
|
||||||
|
EppInput eppInput) {
|
||||||
|
HistoryEntry.Builder historyBuilder = new HistoryEntry.Builder()
|
||||||
|
.setTrid(trid)
|
||||||
|
.setXmlBytes(inputXmlBytes)
|
||||||
|
.setBySuperuser(isSuperuser)
|
||||||
|
.setClientId(clientId);
|
||||||
|
MetadataExtension metadataExtension = eppInput.getSingleExtension(MetadataExtension.class);
|
||||||
|
if (metadataExtension != null) {
|
||||||
|
if (!eppRequestSource.equals(EppRequestSource.TOOL)) {
|
||||||
|
throw new EppExceptionInProviderException(new OnlyToolCanPassMetadataException());
|
||||||
|
}
|
||||||
|
historyBuilder
|
||||||
|
.setReason(metadataExtension.getReason())
|
||||||
|
.setRequestedByRegistrar(metadataExtension.getRequestedByRegistrar());
|
||||||
|
}
|
||||||
|
return historyBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
/** Wrapper class to carry an {@link EppException} to the calling code. */
|
/** Wrapper class to carry an {@link EppException} to the calling code. */
|
||||||
static class EppExceptionInProviderException extends RuntimeException {
|
static class EppExceptionInProviderException extends RuntimeException {
|
||||||
EppExceptionInProviderException(EppException exception) {
|
EppExceptionInProviderException(EppException exception) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue