mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 08:57:12 +02:00
Fix nits on flows:
Rename existingResource flows variable to be specific to EPP resource type and replace some explicit checks with helper methods. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=133774229
This commit is contained in:
parent
df70da48a2
commit
aed3c0f0d0
14 changed files with 125 additions and 156 deletions
|
@ -96,7 +96,7 @@ public class HostCreateFlow extends LoggedInFlow implements TransactionalFlow {
|
|||
}
|
||||
Builder builder = new Builder();
|
||||
command.applyTo(builder);
|
||||
HostResource newResource = builder
|
||||
HostResource newHost = builder
|
||||
.setCreationClientId(clientId)
|
||||
.setCurrentSponsorClientId(clientId)
|
||||
.setRepoId(createContactHostRoid(ObjectifyService.allocateId()))
|
||||
|
@ -106,12 +106,12 @@ public class HostCreateFlow extends LoggedInFlow implements TransactionalFlow {
|
|||
historyBuilder
|
||||
.setType(HistoryEntry.Type.HOST_CREATE)
|
||||
.setModificationTime(now)
|
||||
.setParent(Key.create(newResource));
|
||||
.setParent(Key.create(newHost));
|
||||
ImmutableSet<ImmutableObject> entitiesToSave = ImmutableSet.of(
|
||||
newResource,
|
||||
newHost,
|
||||
historyBuilder.build(),
|
||||
ForeignKeyIndex.create(newResource, newResource.getDeletionTime()),
|
||||
EppResourceIndex.create(Key.create(newResource)));
|
||||
ForeignKeyIndex.create(newHost, newHost.getDeletionTime()),
|
||||
EppResourceIndex.create(Key.create(newHost)));
|
||||
if (superordinateDomain.isPresent()) {
|
||||
entitiesToSave = union(
|
||||
entitiesToSave,
|
||||
|
|
|
@ -79,20 +79,20 @@ public class HostDeleteFlow extends LoggedInFlow implements TransactionalFlow {
|
|||
@Override
|
||||
public final EppOutput run() throws EppException {
|
||||
failfastForAsyncDelete(targetId, now, HostResource.class, GET_NAMESERVERS);
|
||||
HostResource existingResource = loadResourceToMutate(HostResource.class, targetId, now);
|
||||
verifyNoDisallowedStatuses(existingResource, DISALLOWED_STATUSES);
|
||||
verifyOptionalAuthInfoForResource(authInfo, existingResource);
|
||||
HostResource existingHost = loadResourceToMutate(HostResource.class, targetId, now);
|
||||
verifyNoDisallowedStatuses(existingHost, DISALLOWED_STATUSES);
|
||||
verifyOptionalAuthInfoForResource(authInfo, existingHost);
|
||||
if (!isSuperuser) {
|
||||
verifyResourceOwnership(clientId, existingResource);
|
||||
verifyResourceOwnership(clientId, existingHost);
|
||||
}
|
||||
asyncFlowEnqueuer.enqueueAsyncDelete(existingResource, clientId, isSuperuser);
|
||||
HostResource newResource =
|
||||
existingResource.asBuilder().addStatusValue(StatusValue.PENDING_DELETE).build();
|
||||
asyncFlowEnqueuer.enqueueAsyncDelete(existingHost, clientId, isSuperuser);
|
||||
HostResource newHost =
|
||||
existingHost.asBuilder().addStatusValue(StatusValue.PENDING_DELETE).build();
|
||||
historyBuilder
|
||||
.setType(HistoryEntry.Type.HOST_PENDING_DELETE)
|
||||
.setModificationTime(now)
|
||||
.setParent(Key.create(existingResource));
|
||||
ofy().save().<Object>entities(newResource, historyBuilder.build());
|
||||
.setParent(Key.create(existingHost));
|
||||
ofy().save().<Object>entities(newHost, historyBuilder.build());
|
||||
return createOutput(SUCCESS_WITH_ACTION_PENDING);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,8 +41,8 @@ public class HostInfoFlow extends LoggedInFlow {
|
|||
|
||||
@Override
|
||||
public EppOutput run() throws EppException {
|
||||
HostResource existingResource = loadResourceForQuery(HostResource.class, targetId, now);
|
||||
verifyOptionalAuthInfoForResource(authInfo, existingResource);
|
||||
return createOutput(SUCCESS, cloneResourceWithLinkedStatus(existingResource, now));
|
||||
HostResource host = loadResourceForQuery(HostResource.class, targetId, now);
|
||||
verifyOptionalAuthInfoForResource(authInfo, host);
|
||||
return createOutput(SUCCESS, cloneResourceWithLinkedStatus(host, now));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,17 +106,17 @@ public class HostUpdateFlow extends LoggedInFlow implements TransactionalFlow {
|
|||
public final EppOutput run() throws EppException {
|
||||
Update command = (Update) resourceCommand;
|
||||
String suppliedNewHostName = command.getInnerChange().getFullyQualifiedHostName();
|
||||
HostResource existingResource = loadResourceToMutate(HostResource.class, targetId, now);
|
||||
HostResource existingHost = loadResourceToMutate(HostResource.class, targetId, now);
|
||||
boolean isHostRename = suppliedNewHostName != null;
|
||||
String oldHostName = targetId;
|
||||
String newHostName = firstNonNull(suppliedNewHostName, oldHostName);
|
||||
Optional<DomainResource> superordinateDomain =
|
||||
Optional.fromNullable(lookupSuperordinateDomain(validateHostName(newHostName), now));
|
||||
verifyUpdateAllowed(command, existingResource, superordinateDomain.orNull());
|
||||
verifyUpdateAllowed(command, existingHost, superordinateDomain.orNull());
|
||||
if (isHostRename && loadAndGetKey(HostResource.class, newHostName, now) != null) {
|
||||
throw new HostAlreadyExistsException(newHostName);
|
||||
}
|
||||
Builder builder = existingResource.asBuilder();
|
||||
Builder builder = existingHost.asBuilder();
|
||||
try {
|
||||
command.applyTo(builder);
|
||||
} catch (AddRemoveSameValueException e) {
|
||||
|
@ -132,23 +132,23 @@ public class HostUpdateFlow extends LoggedInFlow implements TransactionalFlow {
|
|||
superordinateDomain.isPresent() ? Key.create(superordinateDomain.get()) : null)
|
||||
.setLastSuperordinateChange(superordinateDomain == null ? null : now);
|
||||
// Rely on the host's cloneProjectedAtTime() method to handle setting of transfer data.
|
||||
HostResource newResource = builder.build().cloneProjectedAtTime(now);
|
||||
verifyHasIpsIffIsExternal(command, existingResource, newResource);
|
||||
HostResource newHost = builder.build().cloneProjectedAtTime(now);
|
||||
verifyHasIpsIffIsExternal(command, existingHost, newHost);
|
||||
ImmutableSet.Builder<ImmutableObject> entitiesToSave = new ImmutableSet.Builder<>();
|
||||
entitiesToSave.add(newResource);
|
||||
entitiesToSave.add(newHost);
|
||||
// Keep the {@link ForeignKeyIndex} for this host up to date.
|
||||
if (isHostRename) {
|
||||
// Update the foreign key for the old host name and save one for the new host name.
|
||||
entitiesToSave.add(
|
||||
ForeignKeyIndex.create(existingResource, now),
|
||||
ForeignKeyIndex.create(newResource, newResource.getDeletionTime()));
|
||||
updateSuperordinateDomains(existingResource, newResource);
|
||||
ForeignKeyIndex.create(existingHost, now),
|
||||
ForeignKeyIndex.create(newHost, newHost.getDeletionTime()));
|
||||
updateSuperordinateDomains(existingHost, newHost);
|
||||
}
|
||||
enqueueTasks(existingResource, newResource);
|
||||
enqueueTasks(existingHost, newHost);
|
||||
entitiesToSave.add(historyBuilder
|
||||
.setType(HistoryEntry.Type.HOST_UPDATE)
|
||||
.setModificationTime(now)
|
||||
.setParent(Key.create(existingResource))
|
||||
.setParent(Key.create(existingHost))
|
||||
.build());
|
||||
ofy().save().entities(entitiesToSave.build());
|
||||
return createOutput(SUCCESS);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue