From dd6248efe9db9abb961734312deb1a17bb845748 Mon Sep 17 00:00:00 2001 From: dhfelix Date: Mon, 27 May 2019 15:36:08 -0500 Subject: [PATCH] Fix #94 and #93 --- .../nic/rdap/server/notices/UserEvents.java | 11 +- .../nic/rdap/server/servlet/RdapServlet.java | 110 +++++++++++++----- 2 files changed, 88 insertions(+), 33 deletions(-) diff --git a/src/main/java/mx/nic/rdap/server/notices/UserEvents.java b/src/main/java/mx/nic/rdap/server/notices/UserEvents.java index cf50345..6f2caca 100644 --- a/src/main/java/mx/nic/rdap/server/notices/UserEvents.java +++ b/src/main/java/mx/nic/rdap/server/notices/UserEvents.java @@ -99,17 +99,18 @@ public static List getEvents() { return result; } - public static void setCurrentTimestamp(List events) { + public static void setCurrentTimestamp(List events, boolean addLastUpdate) { boolean lastUpdateFound = false; for (Event e : events) { - if (e.getEventAction().equals(EventAction.LAST_UPDATE_OF_RDAP_DATABASE)) { + EventAction eventAction = e.getEventAction(); + if (eventAction != null && eventAction.equals(EventAction.LAST_UPDATE_OF_RDAP_DATABASE)) { Date newDate = new Date(); e.setEventDate(newDate); lastUpdateFound = true; } } - if (!lastUpdateFound) { + if (!lastUpdateFound && addLastUpdate) { Event lastUpdateRdapDatabase = new Event(); lastUpdateRdapDatabase.setEventAction(EventAction.LAST_UPDATE_OF_RDAP_DATABASE); lastUpdateRdapDatabase.setEventDate(new Date()); @@ -117,6 +118,10 @@ public static void setCurrentTimestamp(List events) { } } + public static void setCurrentTimestamp(List events) { + setCurrentTimestamp(events, true); + } + public static void updateEvents(List updatedEvents) { try { checkForDuplicateEvents(updatedEvents); diff --git a/src/main/java/mx/nic/rdap/server/servlet/RdapServlet.java b/src/main/java/mx/nic/rdap/server/servlet/RdapServlet.java index d23cc44..a24b0d4 100644 --- a/src/main/java/mx/nic/rdap/server/servlet/RdapServlet.java +++ b/src/main/java/mx/nic/rdap/server/servlet/RdapServlet.java @@ -318,11 +318,37 @@ private void handleCountryProperty(RdapObject rdapObj) { } } + if (rdapObj instanceof Domain) { + Domain d = (Domain) rdapObj; + if (d.getNameServers() != null) { + for (Nameserver ns : d.getNameServers()) { + handleCountryProperty(ns); + } + } + + if (d.getIpNetwork() != null) { + handleCountryProperty(d.getIpNetwork()); + } + } + if (!(rdapObj instanceof Entity)) { return; } Entity e = (Entity) rdapObj; + + if (e.getIpNetworks() != null) { + for (IpNetwork ip : e.getIpNetworks()) { + handleCountryProperty(ip); + } + } + + if (e.getAutnums() != null) { + for (Autnum a : e.getAutnums()) { + handleCountryProperty(a); + } + } + if (e.getVCardList() == null || e.getVCardList().isEmpty()) { /* nothing to do */ return; @@ -346,19 +372,27 @@ private void handleCountryProperty(RdapObject rdapObj) { private List mergeEvents(List userEvents, List objectEvents) { int userEventsSize = userEvents.size(); boolean equals = false; + List mergedEvents = new ArrayList<>(userEvents); for (Event oe : objectEvents) { + /* The Event action could be hidden in privacy filter. */ + if (oe.getEventAction() == null) { + mergedEvents.add(oe); + continue; + } + for (int i = 0 ; i < userEventsSize ; i++) { Event ue = userEvents.get(i); equals = ue.getEventAction().equals(oe.getEventAction()); - if (equals) + if (equals) { break; + } } if (!equals) - userEvents.add(oe); + mergedEvents.add(oe); } - return userEvents; + return mergedEvents; } /** * Function to add to a single request response the events and notices configured in the application @@ -370,19 +404,28 @@ private void addToRequestEventsAndNotices(RequestResponse List requestNotices) { RdapObject rdapObject = response.getRdapObject(); List events = UserEvents.getEvents(); - if (events != null && !events.isEmpty()) { - if (rdapObject.getEvents() == null) { - rdapObject.setEvents(events); - } else { - List mergedEvents = mergeEvents(events, rdapObject.getEvents()); - rdapObject.setEvents(mergedEvents); + + if (rdapObject != null) { + if (events != null && !events.isEmpty()) { + if (rdapObject.getEvents() == null) { + rdapObject.setEvents(events); + } else { + List mergedEvents = mergeEvents(events, rdapObject.getEvents()); + rdapObject.setEvents(mergedEvents); + } + } + + /* + * Set the current timestamp on "last update of RDAP database" event if + * configured. + */ + if (RdapConfiguration.isDbDataLive()) { + if (rdapObject.getEvents() == null) { + rdapObject.setEvents(new ArrayList<>()); + } + UserEvents.setCurrentTimestamp(rdapObject.getEvents()); } } - - /* Set the current timestamp on "last update of RDAP database" event if configured. */ - if (RdapConfiguration.isDbDataLive()) { - UserEvents.setCurrentTimestamp(rdapObject.getEvents()); - } if (requestNotices != null && !requestNotices.isEmpty()) { if (response.getNotices() == null) { @@ -390,7 +433,6 @@ private void addToRequestEventsAndNotices(RequestResponse } response.getNotices().addAll(requestNotices); } - } /** @@ -402,24 +444,32 @@ private void addToRequestEventsAndNotices(RequestResponse private void addToSearchEventsAndNotices(SearchResponse searchResponse, List requestNotices) { List rdapObjects = searchResponse.getRdapObjects(); - List events = UserEvents.getEvents(); - if (events != null && !events.isEmpty() && !rdapObjects.isEmpty()) { - for (RdapObject rdapObject : rdapObjects) { - if (rdapObject.getEvents() == null) { - rdapObject.setEvents(events); - } else { - List mergedEvents = mergeEvents(events, rdapObject.getEvents()); - rdapObject.setEvents(mergedEvents); + List userEvents = UserEvents.getEvents(); + + if (rdapObjects != null) { + if (userEvents != null && !userEvents.isEmpty()) { + for (RdapObject rdapObject : rdapObjects) { + if (rdapObject.getEvents() == null) { + rdapObject.setEvents(new ArrayList<>(userEvents)); + } else { + List mergedEvents = mergeEvents(userEvents, rdapObject.getEvents()); + rdapObject.setEvents(mergedEvents); + } } + } - /* - * Set the current timestamp on "last update of RDAP database" event if - * configured. - */ - if (RdapConfiguration.isDbDataLive()) + /* + * Set the current timestamp on "last update of RDAP database" event if + * configured. + */ + if (RdapConfiguration.isDbDataLive()) { + for (RdapObject rdapObject : rdapObjects) { + if (rdapObject.getEvents() == null) { + rdapObject.setEvents(new ArrayList<>()); + } UserEvents.setCurrentTimestamp(rdapObject.getEvents()); - } - + } + } } if (requestNotices != null && !requestNotices.isEmpty()) {