mirror of
https://github.com/google/nomulus.git
synced 2025-05-16 09:27:16 +02:00
Add Ability to return registrar contacts of a certain type
This is required by ICANN Consistent Labeling & Display policy that WHOIS domain query response contains registrar abuse contact's phone number and email address. Add a helper function to load registrar contact of a certain type for a given registrar. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=153606137
This commit is contained in:
parent
d35be27b65
commit
8f05ca466f
2 changed files with 86 additions and 23 deletions
|
@ -188,6 +188,17 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
|
|||
immutableEnumSet(
|
||||
Type.REAL, Type.PDT, Type.OTE, Type.EXTERNAL_MONITORING, Type.MONITORING, Type.INTERNAL);
|
||||
|
||||
/**
|
||||
* Compare two instances of {@link RegistrarContact} by their email addresses lexicographically.
|
||||
*/
|
||||
private static final Comparator<RegistrarContact> CONTACT_EMAIL_COMPARATOR =
|
||||
new Comparator<RegistrarContact>() {
|
||||
@Override
|
||||
public int compare(RegistrarContact rc1, RegistrarContact rc2) {
|
||||
return rc1.getEmailAddress().compareTo(rc2.getEmailAddress());
|
||||
}
|
||||
};
|
||||
|
||||
@Parent
|
||||
Key<EntityGroupRoot> parent = getCrossTldKey();
|
||||
|
||||
|
@ -532,14 +543,30 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
|
|||
* address.
|
||||
*/
|
||||
public ImmutableSortedSet<RegistrarContact> getContacts() {
|
||||
return FluentIterable
|
||||
.from(ofy().load().type(RegistrarContact.class).ancestor(Registrar.this))
|
||||
return FluentIterable.from(getContactsIterable())
|
||||
.filter(notNull())
|
||||
.toSortedSet(new Comparator<RegistrarContact>() {
|
||||
@Override
|
||||
public int compare(RegistrarContact rc1, RegistrarContact rc2) {
|
||||
return rc1.getEmailAddress().compareTo(rc2.getEmailAddress());
|
||||
}});
|
||||
.toSortedSet(CONTACT_EMAIL_COMPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of {@link RegistrarContact} objects of a given type for this registrar sorted by
|
||||
* their email address.
|
||||
*/
|
||||
public ImmutableSortedSet<RegistrarContact> getContactsOfType(final RegistrarContact.Type type) {
|
||||
return FluentIterable.from(getContactsIterable())
|
||||
.filter(notNull())
|
||||
.filter(
|
||||
new Predicate<RegistrarContact>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable RegistrarContact contact) {
|
||||
return contact.getTypes().contains(type);
|
||||
}
|
||||
})
|
||||
.toSortedSet(CONTACT_EMAIL_COMPARATOR);
|
||||
}
|
||||
|
||||
private Iterable<RegistrarContact> getContactsIterable() {
|
||||
return ofy().load().type(RegistrarContact.class).ancestor(Registrar.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue