Skip to content

Commit

Permalink
Merge pull request #241 from clarin-eric/mp-update
Browse files Browse the repository at this point in the history
Support service unique ids
  • Loading branch information
andmor- authored Oct 18, 2021
2 parents 684b05e + 1119042 commit 6fb7434
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,17 @@ static List<Tool> read(Path registryDir) throws IOException, BadToolException {

private static void checkTools(List<Tool> tools) throws BadToolException {
Set<String> names = new HashSet<>();
for (Tool t : tools) {
Set<Integer> ids = new HashSet<>();
for (Tool t : tools) {
if (t.getId() == null) {
// switch to throwing BadToolException when all the production tools have an id
LOGGER.warn("tools with null id found: " + t.getName());
} else if (ids.contains(t.getId())) {
throw new BadToolException("tools with duplicate ids found: id=" + t.getId() + "; name=" + t.getName());
} else {
ids.add(t.getId());
}

if (names.contains(t.getName())) {
throw new BadToolException("tools with same name found: " + t.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ public Response getTools(@QueryParam("onlyProductionTools") String onlyProductio
return Response.ok(tools).build();
}

@GET
@Path("tools/{id}")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public Response getToolByID(@PathParam("id") Integer id) {
Predicate<Tool> filter = tool-> tool.getId() != null && tool.getId().equals(id);
List<Tool> tools = toolRegistry.filterTools(filter);
if (tools == null || tools.isEmpty()) {
return Response.status(Response.Status.NOT_FOUND).build();
}
return Response.ok(tools.get(0)).build();
}

@POST
@Path("tools/match")
@Consumes(MediaType.APPLICATION_JSON)
Expand Down
21 changes: 11 additions & 10 deletions backend/src/main/java/eu/clarin/switchboard/tool/Tool.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Tool {
public static final String ANY_LANGUAGE_KEYWORD = "generic";

String formatVersion;
Integer id;
String task;
String deployment;
String integrationType;
Expand All @@ -31,7 +32,6 @@ public class Tool {

List<Input> inputs;
BatchProcessing batchProcessing;
List<String> output;

WebApplication webApplication;
StandaloneApplication standaloneApplication;
Expand All @@ -45,6 +45,14 @@ public void setFormatVersion(String formatVersion) {
this.formatVersion = formatVersion;
}

public Integer getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}
Expand Down Expand Up @@ -165,14 +173,6 @@ public void setBatchProcessing(BatchProcessing batchProcessing) {
this.batchProcessing = batchProcessing;
}

public List<String> getOutput() {
return output;
}

public void setOutput(List<String> output) {
this.output = output;
}

public WebApplication getWebApplication() {
return webApplication;
}
Expand Down Expand Up @@ -224,6 +224,7 @@ public void augment(Map<String, Object> v1map) throws BadToolException {
for (String mediatype: mediatypes) {
if (mediatype.startsWith("text/")) {
input.id = "text";
break;
}
}
List<String> languages = (List<String>) v1map.get("languages");
Expand Down Expand Up @@ -311,6 +312,7 @@ public boolean doesInputRequireContent(int inputIndex) {
public String toString() {
return MoreObjects.toStringHelper(this)
.add("\nformatVersion", formatVersion)
.add("\nid", id)
.add("\ntask", task)
.add("\ndeployment", deployment)
.add("\nintegrationType", integrationType)
Expand All @@ -326,7 +328,6 @@ public String toString() {
.add("\nauthentication", authentication)
.add("\ninputs", inputs)
.add("\nbatchProcessing", batchProcessing)
.add("\noutput", output)
.add("\nwebApplication", webApplication)
.add("\nstandaloneApplication", standaloneApplication)
.add("\nusageRestrictions", usageRestrictions)
Expand Down

0 comments on commit 6fb7434

Please sign in to comment.