1
0
mirror of https://github.com/google/nomulus synced 2026-06-08 16:02:56 +00:00

Check token type of currentPackageToken (#1825)

* Check currentPackageToken TokenType

* Check TokenType of currentPackageToken

* Check that token already exists
This commit is contained in:
sarahcaseybot
2022-10-25 12:39:33 -04:00
committed by GitHub
parent aaa311ec40
commit 0746d28e0c
3 changed files with 72 additions and 14 deletions

View File

@@ -55,6 +55,7 @@ import google.registry.model.domain.launch.LaunchNotice;
import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.domain.secdns.DomainDsData;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.Host;
import google.registry.model.poll.PollMessage;
@@ -919,6 +920,21 @@ public class DomainBase extends EppResource
}
public B setCurrentPackageToken(@Nullable VKey<AllocationToken> currentPackageToken) {
if (currentPackageToken == null) {
getInstance().currentPackageToken = currentPackageToken;
return thisCastToDerived();
}
AllocationToken token =
tm().transact(() -> tm().loadByKeyIfPresent(currentPackageToken))
.orElseThrow(
() ->
new IllegalArgumentException(
String.format(
"The package token %s does not exist",
currentPackageToken.getSqlKey())));
checkArgument(
token.getTokenType().equals(TokenType.PACKAGE),
"The currentPackageToken must have a PACKAGE TokenType");
getInstance().currentPackageToken = currentPackageToken;
return thisCastToDerived();
}