Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RDAP RIR Search - Basic Searches Features #1379

Merged
merged 5 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
import static net.ripe.db.whois.common.rpsl.AttributeType.ROLE;
import static net.ripe.db.whois.common.rpsl.AttributeType.TECH_C;
import static net.ripe.db.whois.common.rpsl.AttributeType.ZONE_C;
import static net.ripe.db.whois.common.rpsl.ObjectType.DOMAIN;
import static net.ripe.db.whois.common.rpsl.ObjectType.INET6NUM;

@Component
Expand Down Expand Up @@ -152,14 +151,27 @@ public Object map(final String requestUrl,
public Object mapSearch(final String requestUrl, final List<RpslObject> objects, final int maxResultSize) {
final SearchResult searchResult = new SearchResult();
for (final RpslObject object : objects) {
if (object.getType() == DOMAIN) {
final Domain domain = (Domain) getRdapObject(requestUrl, object, null);
mapRedactions(domain);
searchResult.addDomainSearchResult(domain);
} else {
final Entity entity = (Entity) getRdapObject(requestUrl, object, null);
mapRedactions(entity);
searchResult.addEntitySearchResult(entity);
switch (object.getType()){
case DOMAIN -> {
final Domain domain = (Domain) getRdapObject(requestUrl, object, null);
mapRedactions(domain);
searchResult.addDomainSearchResult(domain);
}
case INET6NUM, INETNUM -> {
final Ip ip = (Ip) getRdapObject(requestUrl, object, null);
mapRedactions(ip);
searchResult.addIpSearchResult(ip);
}
case AUT_NUM -> {
final Autnum autnum = (Autnum) getRdapObject(requestUrl, object, null);
mapRedactions(autnum);
searchResult.addAutnumSearchResult(autnum);
}
default -> {
final Entity entity = (Entity) getRdapObject(requestUrl, object, null);
mapRedactions(entity);
searchResult.addEntitySearchResult(entity);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,45 @@ public Response searchEntities(
return handleSearch(new String[]{"organisation", "nic-hdl"}, handle, request);
}

throw new RdapException("400 Bad Request", "The server is not able to process the request", HttpStatus.BAD_REQUEST_400);
throw new RdapException("400 Bad Request", "Either fn or handle is a required parameter, but never both", HttpStatus.BAD_REQUEST_400);
}

@GET
@Produces({MediaType.APPLICATION_JSON, CONTENT_TYPE_RDAP_JSON})
@Path("/ips")
public Response searchIps(
@Context final HttpServletRequest request,
@QueryParam("name") final String name,
@QueryParam("handle") final String handle) {

LOGGER.debug("Request: {}", RestServiceHelper.getRequestURI(request));

if (name != null && handle == null || name == null && handle != null) {
MiguelAHM marked this conversation as resolved.
Show resolved Hide resolved
return handleSearch(new String[]{"netname"}, name != null ? name : handle, request);
}

throw new RdapException("400 Bad Request", "Either name or handle is a required parameter, but never both", HttpStatus.BAD_REQUEST_400);
}

@GET
@Produces({MediaType.APPLICATION_JSON, CONTENT_TYPE_RDAP_JSON})
@Path("/autnums")
public Response searchAutnums(
@Context final HttpServletRequest request,
@QueryParam("name") final String name,
@QueryParam("handle") final String handle) {

LOGGER.debug("Request: {}", RestServiceHelper.getRequestURI(request));

if (name != null && handle == null) {
return handleSearch(new String[]{"as-name"}, name, request);
}

if (name == null && handle != null) {
return handleSearch(new String[]{"aut-num"}, handle, request);
}

throw new RdapException("400 Bad Request", "Either name or handle is a required parameter, but never both", HttpStatus.BAD_REQUEST_400);
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import com.google.common.collect.Lists;

import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlType;

import java.io.Serializable;
import java.util.List;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "entity", propOrder = {
"entityResults",
"domainResults"
"domainResults",
"ipSearchResults",
"autnumSearchResults"
})
@XmlRootElement
@JsonInclude(JsonInclude.Include.NON_EMPTY)
Expand All @@ -26,6 +28,12 @@ public class SearchResult extends RdapObject implements Serializable {
@XmlElement(name = "domainSearchResults")
protected List<Domain> domainResults;

@XmlElement(name = "ipSearchResults")
protected List<Ip> ipResults;

@XmlElement(name = "autnumSearchResults")
protected List<Autnum> autnumResults;

public List<Entity> getEntitySearchResults() {
return entityResults;
}
Expand All @@ -34,6 +42,14 @@ public List<Domain> getDomainSearchResults() {
return domainResults;
}

public List<Ip> getIpSearchResults() {
return ipResults;
}

public List<Autnum> getAutnumSearchResults() {
return autnumResults;
}

public void addEntitySearchResult(final Entity entity) {
if (entityResults == null) {
entityResults = Lists.newArrayList();
Expand All @@ -47,4 +63,18 @@ public void addDomainSearchResult(final Domain domain) {
}
domainResults.add(domain);
}

public void addIpSearchResult(final Ip ip) {
if (ipResults == null) {
ipResults = Lists.newArrayList();
}
ipResults.add(ip);
}

public void addAutnumSearchResult(final Autnum autnum) {
if (autnumResults == null) {
autnumResults = Lists.newArrayList();
}
autnumResults.add(autnum);
}
}
Loading