Skip to content

Commit

Permalink
Add the ability to replace header in configured links
Browse files Browse the repository at this point in the history
Fix an issue that cause configured link in help were displayed twice.
  • Loading branch information
dhfelix committed Sep 19, 2019
1 parent 8ff375d commit cf996f9
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 86 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>mx.nic.labs.reddog</groupId>
<artifactId>rdap-server</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
<packaging>war</packaging>

<name>mx.nic.labs.reddog:rdap-server</name>
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/mx/nic/rdap/server/notices/NoticesUpdaterTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import java.util.TimerTask;
import java.util.logging.Level;
Expand Down Expand Up @@ -42,9 +43,18 @@ public void run() {
private void checkForUpdate(String fileName, ResultType type) {
Path updated = Paths.get(userPath, fileName + RequestNotices.UPDATED_EXTENSION);

List<Remark> updatedNotices;
List<Remark> parsedNotices;
List<Remark> updatedNotices = new ArrayList<Remark>();
List<Remark> updatedHostNotices = new ArrayList<Remark>();
try {
updatedNotices = NoticesReader.parseNoticesXML(updated.toString());
parsedNotices = NoticesReader.parseNoticesXML(updated.toString());

UserNotices.splitHostLinks(parsedNotices, updatedNotices, updatedHostNotices);

if (updatedHostNotices.isEmpty()) {
updatedHostNotices = null;
}

} catch (NoSuchFileException | FileNotFoundException e) {
return;
} catch (SAXException | ParserConfigurationException | IOException e) {
Expand All @@ -67,7 +77,7 @@ private void checkForUpdate(String fileName, ResultType type) {
return;
}

RequestNotices.updateNotices(type, updatedNotices);
RequestNotices.updateNotices(type, updatedNotices, updatedHostNotices);
}

}
121 changes: 104 additions & 17 deletions src/main/java/mx/nic/rdap/server/notices/RequestNotices.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,32 @@ public class RequestNotices {
private static List<Remark> autnumNotices;
private static List<Remark> ipNotices;

private static List<Remark> domainHostNotices;
private static List<Remark> entityHostNotices;
private static List<Remark> nsHostNotices;
private static List<Remark> autnumHostNotices;
private static List<Remark> ipHostNotices;

private static ReadWriteLock lock;

public static List<Remark> getDomainNotices() {
return getNotices(ResultType.DOMAIN);
public static List<Remark> getDomainNotices(String header) {
return getNotices(ResultType.DOMAIN, header);
}

public static List<Remark> getEntityNotices() {
return getNotices(ResultType.ENTITY);
public static List<Remark> getEntityNotices(String header) {
return getNotices(ResultType.ENTITY, header);
}

public static List<Remark> getAutnumNotices() {
return getNotices(ResultType.AUTNUM);
public static List<Remark> getAutnumNotices(String header) {
return getNotices(ResultType.AUTNUM, header);
}

public static List<Remark> getNsNotices() {
return getNotices(ResultType.NAMESERVER);
public static List<Remark> getNsNotices(String header) {
return getNotices(ResultType.NAMESERVER, header);
}

public static List<Remark> getIpNotices() {
return getNotices(ResultType.IP);
public static List<Remark> getIpNotices(String header) {
return getNotices(ResultType.IP, header);
}

/**
Expand All @@ -71,6 +77,18 @@ static void init(String userPath) throws SAXException, IOException, ParserConfig

try {
domainNotices = NoticesReader.parseNoticesXML(Paths.get(userPath, DOMAIN_FILE_NAME).toString());

List<Remark> normalList = new ArrayList<Remark>();
List<Remark> hostList = new ArrayList<Remark>();

UserNotices.splitHostLinks(domainNotices, normalList, hostList);

if (hostList.isEmpty()) {
hostList = null;
}

domainNotices = normalList;
domainHostNotices = hostList;
} catch (FileNotFoundException | NoSuchFileException e) {
// Nothing happens, continue
logger.log(Level.INFO,
Expand All @@ -79,41 +97,92 @@ static void init(String userPath) throws SAXException, IOException, ParserConfig

try {
entityNotices = NoticesReader.parseNoticesXML(Paths.get(userPath, ENTITY_FILE_NAME).toString());

List<Remark> normalList = new ArrayList<Remark>();
List<Remark> hostList = new ArrayList<Remark>();

UserNotices.splitHostLinks(entityNotices, normalList, hostList);

if (hostList.isEmpty()) {
hostList = null;
}

entityNotices = normalList;
entityHostNotices = hostList;

} catch (FileNotFoundException | NoSuchFileException e) {
// Nothing happens, continue
logger.log(Level.INFO, "Optional File '" + ENTITY_FILE_NAME + "' not found, continue. \n\t" + e);
}

try {
nsNotices = NoticesReader.parseNoticesXML(Paths.get(userPath, NS_FILE_NAME).toString());

List<Remark> normalList = new ArrayList<Remark>();
List<Remark> hostList = new ArrayList<Remark>();

UserNotices.splitHostLinks(nsNotices, normalList, hostList);

if (hostList.isEmpty()) {
hostList = null;
}

nsNotices = normalList;
nsHostNotices = hostList;

} catch (FileNotFoundException | NoSuchFileException e) {
// Nothing happens, continue
logger.log(Level.INFO, "Optional File '" + NS_FILE_NAME + "' not found, continue. \n\t" + e);
}

try {
autnumNotices = NoticesReader.parseNoticesXML(Paths.get(userPath, AUTNUM_FILE_NAME).toString());

List<Remark> normalList = new ArrayList<Remark>();
List<Remark> hostList = new ArrayList<Remark>();

UserNotices.splitHostLinks(autnumNotices, normalList, hostList);

if (hostList.isEmpty()) {
hostList = null;
}

autnumNotices = normalList;
autnumHostNotices = hostList;
} catch (FileNotFoundException | NoSuchFileException e) {
// Nothing happens, continue
logger.log(Level.INFO, "Optional File '" + AUTNUM_FILE_NAME + "' not found, continue. \n\t" + e);
}

try {
ipNotices = NoticesReader.parseNoticesXML(Paths.get(userPath, IP_NETWORK_FILE_NAME).toString());

List<Remark> normalList = new ArrayList<Remark>();
List<Remark> hostList = new ArrayList<Remark>();

UserNotices.splitHostLinks(ipNotices, normalList, hostList);

if (hostList.isEmpty()) {
hostList = null;
}

ipNotices = normalList;
ipHostNotices = hostList;
} catch (FileNotFoundException | NoSuchFileException e) {
// Nothing happens, continue
logger.log(Level.INFO,
"Optional File '" + IP_NETWORK_FILE_NAME + "' not found, continue. \n\t" + e);
}

if (RdapConfiguration.getNoticesUpdateTime() > 0) {
if (RdapConfiguration.getNoticesUpdateTime() >= UserNotices.MIN_TIMER_TIME) {
lock = new ReentrantReadWriteLock();
}
}

private static List<Remark> getNotices(ResultType type) {
private static List<Remark> getNotices(ResultType type, String header) {

List<Remark> notices = null;
List<Remark> hostNotices = null;
List<Remark> result = null;
if (lock != null) {
lock.readLock().lock();
Expand All @@ -123,57 +192,75 @@ private static List<Remark> getNotices(ResultType type) {
switch (type) {
case DOMAIN :
notices = domainNotices;
hostNotices = domainHostNotices;
break;
case ENTITY :
notices = entityNotices;
hostNotices = entityHostNotices;
break;
case AUTNUM :
notices = autnumNotices;
hostNotices = autnumHostNotices;
break;
case IP :
notices = ipNotices;
hostNotices = ipHostNotices;
break;
case NAMESERVER :
notices = nsNotices;
hostNotices = nsHostNotices;
break;

default :
notices = null;
}

if (notices != null) {
result = new ArrayList<>(notices);
}
notices = null;
} finally {
if (lock != null) {
lock.readLock().unlock();
}
}

if (notices != null) {
result = new ArrayList<>(notices);
notices = null;
}

if (hostNotices != null) {
if (result == null)
result = new ArrayList<Remark>();

UserNotices.appendRemarkWithPatternHost(result, hostNotices, header);
}

return result;
}

public static void updateNotices(ResultType type, List<Remark> updatedNotices) {
public static void updateNotices(ResultType type, List<Remark> updatedNotices, List<Remark> updatedHostNotices) {
if (lock != null) {
lock.writeLock().lock();
}
try {
switch (type) {
case DOMAIN :
domainNotices = updatedNotices;
domainHostNotices = updatedHostNotices;
break;
case ENTITY :
entityNotices = updatedNotices;
entityHostNotices = updatedHostNotices;
break;
case AUTNUM :
autnumNotices = updatedNotices;
autnumHostNotices = updatedHostNotices;
break;
case IP :
ipNotices = updatedNotices;
ipHostNotices = updatedHostNotices;
break;
case NAMESERVER :
nsNotices = updatedNotices;
nsHostNotices = updatedHostNotices;
break;
default :
break;
Expand Down
Loading

0 comments on commit cf996f9

Please sign in to comment.