Skip to content

Commit

Permalink
Merge pull request #159 from clarin-eric/bugfixes2
Browse files Browse the repository at this point in the history
Bugfixes: missing language selection
  • Loading branch information
andmor- authored Nov 30, 2020
2 parents db071b5 + bd357ec commit e349dfd
Show file tree
Hide file tree
Showing 7 changed files with 20,719 additions and 396 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,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("")
Expand All @@ -20,12 +22,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 @@ -76,8 +92,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 e349dfd

Please sign in to comment.