Skip to content

Commit

Permalink
be loosy with entryTypes names
Browse files Browse the repository at this point in the history
  • Loading branch information
redmitry committed Apr 30, 2024
1 parent a2a851d commit 06cf210
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import jakarta.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
* @author Dmitry Repchevsky
Expand All @@ -28,8 +30,8 @@ public Map<String, Map.Entry<String, String>> match(HttpServletRequest request)

final StringBuffer url = request.getRequestURL();

final String endpointType = getEndpointType(url.toString());
if (endpointType == null) {
final Set<String> endpointTypes = getEndpointTypes(url.toString());
if (endpointTypes.isEmpty()) {
return Collections.EMPTY_MAP;
}

Expand All @@ -41,7 +43,7 @@ public Map<String, Map.Entry<String, String>> match(HttpServletRequest request)
for (Map.Entry<String, Map<String, String>> entry : all_endpoints.entrySet()) {
final Map<String, String> urls = entry.getValue();
for (Map.Entry<String, String> urlEntry : urls.entrySet()) {
if (endpointType.equals(urlEntry.getKey()) &&
if (endpointTypes.contains(urlEntry.getKey()) &&
match(path, urlEntry.getValue())) {
matched_endpoints.put(entry.getKey(), urlEntry);
}
Expand All @@ -56,10 +58,12 @@ public Map<String, Map.Entry<String, String>> match(HttpServletRequest request)
*
* @param path current request URL path
*
* @return typed endpoint (e.g. 'genomicVariant',
* @return a set of typed endpoints (e.g. 'genomicVariant',
* 'genomicVariant:genomicVariant', 'genomicVariant:analysis') or null
*/
private String getEndpointType(String path) {
private Set<String> getEndpointTypes(String path) {
final Set<String> types = new HashSet();

final BeaconMap map = map_response.maps().getResponse();
if (map != null) {
final Map<String, Endpoint> endpoints = map.getEndpointSets();
Expand All @@ -72,10 +76,12 @@ private String getEndpointType(String path) {
}

if (match(path, endpoint.getRootUrl())) {
return entryType;
types.add(entryType);
continue;
}
if (match(path, endpoint.getSingleEntryUrl())) {
return entryType + ":" + entryType;
types.add(entryType + ":" + entryType);
continue;
}

final Map<String, RelatedEndpoint> related_endpont = endpoint.getEndpoints();
Expand All @@ -87,14 +93,16 @@ private String getEndpointType(String path) {
if (relEntryType == null) {
relEntryType = rel_entry.getKey();
}
return entryType + ":" + relEntryType;
types.add(entryType + ":" + relEntryType);
break;
}
}
}
}
}
}
return null;

return types;
}

/**
Expand Down

0 comments on commit 06cf210

Please sign in to comment.