Skip to content

Commit

Permalink
Fix #94 and #93
Browse files Browse the repository at this point in the history
  • Loading branch information
dhfelix committed May 27, 2019
1 parent d008d59 commit dd6248e
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 33 deletions.
11 changes: 8 additions & 3 deletions src/main/java/mx/nic/rdap/server/notices/UserEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,29 @@ public static List<Event> getEvents() {
return result;
}

public static void setCurrentTimestamp(List<Event> events) {
public static void setCurrentTimestamp(List<Event> 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());
events.add(lastUpdateRdapDatabase);
}
}

public static void setCurrentTimestamp(List<Event> events) {
setCurrentTimestamp(events, true);
}

public static void updateEvents(List<Event> updatedEvents) {
try {
checkForDuplicateEvents(updatedEvents);
Expand Down
110 changes: 80 additions & 30 deletions src/main/java/mx/nic/rdap/server/servlet/RdapServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -346,19 +372,27 @@ private void handleCountryProperty(RdapObject rdapObj) {
private List<Event> mergeEvents(List<Event> userEvents, List<Event> objectEvents) {
int userEventsSize = userEvents.size();
boolean equals = false;
List<Event> 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
Expand All @@ -370,27 +404,35 @@ private void addToRequestEventsAndNotices(RequestResponse<? extends RdapObject>
List<Remark> requestNotices) {
RdapObject rdapObject = response.getRdapObject();
List<Event> events = UserEvents.getEvents();
if (events != null && !events.isEmpty()) {
if (rdapObject.getEvents() == null) {
rdapObject.setEvents(events);
} else {
List<Event> 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<Event> 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) {
response.setNotices(new ArrayList<>());
}
response.getNotices().addAll(requestNotices);
}

}

/**
Expand All @@ -402,24 +444,32 @@ private void addToRequestEventsAndNotices(RequestResponse<? extends RdapObject>
private void addToSearchEventsAndNotices(SearchResponse<? extends RdapObject> searchResponse,
List<Remark> requestNotices) {
List<? extends RdapObject> rdapObjects = searchResponse.getRdapObjects();
List<Event> events = UserEvents.getEvents();
if (events != null && !events.isEmpty() && !rdapObjects.isEmpty()) {
for (RdapObject rdapObject : rdapObjects) {
if (rdapObject.getEvents() == null) {
rdapObject.setEvents(events);
} else {
List<Event> mergedEvents = mergeEvents(events, rdapObject.getEvents());
rdapObject.setEvents(mergedEvents);
List<Event> 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<Event> 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()) {
Expand Down

0 comments on commit dd6248e

Please sign in to comment.