diff --git a/src/main/java/de/uni_hamburg/corpora/server/CorpusChecker.java b/src/main/java/de/uni_hamburg/corpora/server/CorpusChecker.java index 4d9cca3959ff3675e13cb93dba2c252c97bd3fbe..02ef6a2f6480abe2dd416df276679580425c2e1e 100644 --- a/src/main/java/de/uni_hamburg/corpora/server/CorpusChecker.java +++ b/src/main/java/de/uni_hamburg/corpora/server/CorpusChecker.java @@ -41,15 +41,18 @@ class CorpusThread extends Thread { String inFile ; String functionNames; String outFile; + Properties props; // The properties for the function calls String token; // Identifier to be sent back to the server to identify and authorize task String callbackUrl; // URL to be called when the task is done, giving an empty string means skipping the callback - CorpusThread(String infile, String outfile, String functions, String token, String callbackUrl) { + CorpusThread(String infile, String outfile, String functions, Properties properties, String token, + String callbackUrl) { if (infile.equals("tmp")) this.inFile = System.getProperty("java.io.tmpdir") + "/corpus-files"; else this.inFile = infile; this.functionNames = functions ; + this.props = properties; if (outfile.equals("tmp")) this.outFile = this.inFile + "/report.html"; else @@ -77,7 +80,7 @@ class CorpusThread extends Thread { // Create an object from canonical name. calls the constructor with thr constructor setting hasfixingoption to false try { // functions.add((CorpusFunction) Class.forName(canonical).getDeclaredConstructor(boolean.class).newInstance(false)); - functions.add((CorpusFunction) Class.forName(canonical).getDeclaredConstructor().newInstance()); + functions.add((CorpusFunction) Class.forName(canonical).getDeclaredConstructor(Properties.class).newInstance()); found = true ; } catch (IllegalArgumentException | NoSuchMethodException | InstantiationException | InvocationTargetException | IllegalAccessException e) { @@ -181,6 +184,7 @@ public class CorpusChecker { public Response checkCorpus(@QueryParam("input") String input, @QueryParam("output") String output, @QueryParam("functions") String functions, + @QueryParam("params") String paramStr, @QueryParam("token") String token, @QueryParam("callback") String callbackUrl) { boolean error = false ; @@ -215,7 +219,12 @@ public class CorpusChecker { logger.error(errorMsg); return Response.status(400).entity("400 - " + errorMsg).build(); } - CorpusThread ct = new CorpusThread(input,output,functions,token,callbackUrl); + Properties params = new Properties(); + if (paramStr != null) { + ObjectMapper mapper = new ObjectMapper(); + params.putAll(mapper.convertValue(paramStr,Map.class)); + } + CorpusThread ct = new CorpusThread(input,output,functions,params,token,callbackUrl); ct.start(); Main.addThread(ct); return Response.ok().entity("Executing " + functions + " on " + input + diff --git a/src/main/java/de/uni_hamburg/corpora/server/ListCorpusFunctions.java b/src/main/java/de/uni_hamburg/corpora/server/ListCorpusFunctions.java index 7c39a2f174f267de1b84dd269e6aa17c3329199d..bdc61d3e565beefa96bb13aa6df0a4616e3bc675 100644 --- a/src/main/java/de/uni_hamburg/corpora/server/ListCorpusFunctions.java +++ b/src/main/java/de/uni_hamburg/corpora/server/ListCorpusFunctions.java @@ -16,7 +16,7 @@ import java.util.stream.Collectors; /** * @author bba1792 Dr. Herbert Lange - * @version 20211004 + * @version 20220405 * Resource to list corpus functions defined in the corpus services * Scope: any */ @@ -30,12 +30,15 @@ public class ListCorpusFunctions { String description; boolean available ; Set<String> usableFor; + Map<String,String> params; - public CorpusFunctionInfo(String name, String description, boolean available, Set<String> usableFor) { + public CorpusFunctionInfo(String name, String description, boolean available, Set<String> usableFor, + Map<String,String> params) { this.name = name; this.description = description; this.available = available; this.usableFor = usableFor; + this.params = params ; } public String getName() { @@ -53,6 +56,15 @@ public class ListCorpusFunctions { public Set<String> getUsableFor() { return usableFor; } + + public String getUsableForString() { return String.join(", ", usableFor); } + + public Map<String,String> getParams() { return params; } + + public String getParamsString() { + return params.keySet().stream().map((k) -> k + ": " + params.get(k)) + .collect(Collectors.joining("<br>\n")); + } } /** * Method handling HTTP GET requests. The returned object will be sent @@ -88,12 +100,15 @@ public class ListCorpusFunctions { for (String s : CorpusServices.getCorpusFunctions()) { String function, description; Set<String> usableClasses = new HashSet<>(); + Map<String,String> params = new HashMap<>(); boolean available; try { // Create the corpus function object using reflections and get its information - CorpusFunction cf = (CorpusFunction) Class.forName(s).getDeclaredConstructor().newInstance(); + CorpusFunction cf = + (CorpusFunction) Class.forName(s).getDeclaredConstructor(Properties.class).newInstance(new Properties()); function = cf.getFunction(); usableClasses.addAll(cf.getIsUsableFor().stream().map(Class::getSimpleName).collect(Collectors.toSet())); + params.putAll(cf.getParameters()); try { description = cf.getDescription(); available = true; @@ -107,7 +122,8 @@ public class ListCorpusFunctions { available = false; } // Create new info object and add it to the list - CorpusFunctionInfo functionInfo = new CorpusFunctionInfo(function, description, available, usableClasses); + CorpusFunctionInfo functionInfo = new CorpusFunctionInfo(function, description, available, usableClasses, + params); functionList.add(functionInfo); } // Sort the list by name