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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user