Skip to content

Commit

Permalink
Merge pull request #158 from clarin-eric/bugfixes
Browse files Browse the repository at this point in the history
Bug fixes (languages in UI, errors while downloading resources)
  • Loading branch information
andmor- authored Nov 30, 2020
2 parents f6389ae + aad978c commit 19f69c9
Show file tree
Hide file tree
Showing 7 changed files with 7,906 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public static LinkInfo getLinkData(CloseableHttpClient client, String originalUr
throw new LinkException(LinkException.Kind.DATA_STREAM_ERROR, "" + linkInfo.downloadLink, xc);
}

int status = response.getStatusLine().getStatusCode();
if (status >= 400) {
throw new LinkException(LinkException.Kind.STATUS_ERROR, "" + linkInfo.downloadLink, status);
}

switch (context.getCacheResponseStatus()) {
case CACHE_HIT:
LOGGER.debug("A response was generated from the cache with no requests sent upstream");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.*;

@Path("/api")
Expand All @@ -21,12 +23,26 @@ public class InfoResource {
long maxAllowedDataSize;
String contactEmail;
ToolRegistry toolRegistry;
Map<String, String> languageCodeToName;

public InfoResource(ToolRegistry toolRegistry, Map<String, String> gitProps, long maxAllowedDataSize, String contactEmail) {
public InfoResource(ToolRegistry toolRegistry, Map<String, String> gitProps, long maxAllowedDataSize, String contactEmail) throws IOException {
this.toolRegistry = toolRegistry;
this.gitProps = gitProps == null ? new HashMap<>() : gitProps;
this.maxAllowedDataSize = maxAllowedDataSize;
this.contactEmail = contactEmail;

this.languageCodeToName = new HashMap<>();
try (InputStream is = getClass().getResourceAsStream("/iso639-3.tsv");
Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8);
BufferedReader buffered = new BufferedReader(reader)) {
buffered.lines().forEach(line -> {
int i = line.indexOf('\t');
assert i > 0;
languageCodeToName.put(
line.substring(0, i),
line.substring(i+1, line.length()).trim());
});
}
}

@GET
Expand Down Expand Up @@ -77,8 +93,13 @@ public Response getMimetypes() {
@Path("/languages")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public Response getLanguages() {
List<String> list = new ArrayList<>(toolRegistry.getAllLanguages());
list.sort(String::compareTo);
List<String[]> list = new ArrayList<>();
for (String code : toolRegistry.getAllLanguages()) {
String name = languageCodeToName.get(code);
if (name != null) {
list.add(new String[]{code, name});
}
}
return Response.ok(list).build();
}
}
Loading

0 comments on commit 19f69c9

Please sign in to comment.