1
0
mirror of https://github.com/google/nomulus synced 2026-04-25 02:30:45 +00:00

Add method to show readable key info (#1431)

* Resolve conflict

* Apply new printing method to existing command
This commit is contained in:
Rachel Guan
2021-12-01 10:46:27 -05:00
committed by GitHub
parent 40b7a23d88
commit f054bb2694
5 changed files with 60 additions and 7 deletions

View File

@@ -311,4 +311,29 @@ public class VKey<T> extends ImmutableObject implements Serializable {
}
return key;
}
/**
* Constructs the readable string representation of a {@link VKey}.
*
* <p>This readable string representation of a vkey contains its type and its sql key or ofy key,
* or both.
*/
@Override
public String toString() {
if (maybeGetOfyKey().isPresent() && maybeGetSqlKey().isPresent()) {
return String.format(
"VKey<%s>(%s:%s,%s:%s)",
getKind().getSimpleName(), SQL_LOOKUP_KEY, sqlKey, OFY_LOOKUP_KEY, ofyKeyToString());
} else if (maybeGetSqlKey().isPresent()) {
return String.format("VKey<%s>(%s:%s)", getKind().getSimpleName(), SQL_LOOKUP_KEY, sqlKey);
} else if (maybeGetOfyKey().isPresent()) {
return String.format("VKey<%s>(%s:%s)", ofyKey.getKind(), OFY_LOOKUP_KEY, ofyKeyToString());
} else {
throw new IllegalStateException("VKey should contain at least one form of key");
}
}
private String ofyKeyToString() {
return ofyKey.getName() == null ? String.valueOf(ofyKey.getId()) : ofyKey.getName();
}
}

View File

@@ -48,7 +48,7 @@ final class GetResourceByKeyCommand implements CommandWithRemoteApi {
EppResource resource =
checkNotNull(
auditedOfy().load().key(resourceKey.getOfyKey()).now(),
"Could not load resource for key: " + resourceKey.getOfyKey());
"Could not load resource for key: " + resourceKey);
System.out.println(expand ? resource.toHydratedString() : resource.toString());
}
}