Add --reason flag to UpdateSmdCommand

Just an old patch that I had lying around and never mailed out.  Seemed like it could be worth having checked in.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=124853504
This commit is contained in:
Nick Felt 2016-06-14 10:27:09 -07:00 committed by Justine Tunney
parent cc01035fe8
commit 9a2b88ee28
2 changed files with 13 additions and 4 deletions

View file

@ -57,6 +57,11 @@ final class UpdateSmdCommand implements RemoteApiCommand {
required = true) required = true)
private Path smdFile; private Path smdFile;
@Parameter(
names = "--reason",
description = "Special reason for the SMD update to record in the history entry.")
private String reason;
@Override @Override
public void run() throws Exception { public void run() throws Exception {
final EncodedSignedMark encodedSignedMark = final EncodedSignedMark encodedSignedMark =
@ -66,14 +71,15 @@ final class UpdateSmdCommand implements RemoteApiCommand {
@Override @Override
public void vrun() { public void vrun() {
try { try {
updateSmd(id, encodedSignedMark); updateSmd(id, encodedSignedMark, reason);
} catch (EppException e) { } catch (EppException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}}); }});
} }
private void updateSmd(String applicationId, EncodedSignedMark encodedSignedMark) private static void updateSmd(
String applicationId, EncodedSignedMark encodedSignedMark, String reason)
throws EppException { throws EppException {
ofy().assertInTransaction(); ofy().assertInTransaction();
DateTime now = ofy().getTransactionTime(); DateTime now = ofy().getTransactionTime();
@ -105,6 +111,7 @@ final class UpdateSmdCommand implements RemoteApiCommand {
.setModificationTime(now) .setModificationTime(now)
.setClientId(domainApplication.getCurrentSponsorClientId()) .setClientId(domainApplication.getCurrentSponsorClientId())
.setBySuperuser(true) .setBySuperuser(true)
.setReason("UpdateSmdCommand" + (reason != null ? ": " + reason : ""))
.build(); .build();
// Save entities to datastore. // Save entities to datastore.

View file

@ -77,7 +77,7 @@ public class UpdateSmdCommandTest extends CommandTestCase<UpdateSmdCommand> {
public void testSuccess() throws Exception { public void testSuccess() throws Exception {
DateTime before = new DateTime(UTC); DateTime before = new DateTime(UTC);
String smdFile = writeToTmpFile(ACTIVE_SMD); String smdFile = writeToTmpFile(ACTIVE_SMD);
runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile); runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile, "--reason=testing");
EncodedSignedMark encodedSignedMark = TmchData.readEncodedSignedMark(ACTIVE_SMD); EncodedSignedMark encodedSignedMark = TmchData.readEncodedSignedMark(ACTIVE_SMD);
assertAboutApplications().that(reloadDomainApplication()) assertAboutApplications().that(reloadDomainApplication())
@ -86,7 +86,9 @@ public class UpdateSmdCommandTest extends CommandTestCase<UpdateSmdCommand> {
.hasLastEppUpdateClientId("TheRegistrar").and() .hasLastEppUpdateClientId("TheRegistrar").and()
.hasOnlyOneHistoryEntryWhich() .hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.DOMAIN_APPLICATION_UPDATE).and() .hasType(HistoryEntry.Type.DOMAIN_APPLICATION_UPDATE).and()
.hasClientId("TheRegistrar"); .hasClientId("TheRegistrar").and()
.hasMetadataReason("UpdateSmdCommand: testing").and()
.hasNoXml();
} }
@Test @Test