-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented new getAvailableMethods and cache endpoints.
- Loading branch information
Showing
5 changed files
with
139 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
dicoogle/src/main/java/pt/ua/dicoogle/server/web/servlets/mlprovider/CacheServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package pt.ua.dicoogle.server.web.servlets.mlprovider; | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.apache.commons.io.IOUtils; | ||
import org.restlet.data.Status; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import pt.ua.dicoogle.plugins.PluginController; | ||
import pt.ua.dicoogle.sdk.mlprovider.MLDicomDataset; | ||
import pt.ua.dicoogle.server.web.utils.ResponseUtil; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
public class CacheServlet extends HttpServlet { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(DatastoreServlet.class); | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
|
||
String dataString = IOUtils.toString(req.getReader()); | ||
if (dataString == null) { | ||
resp.sendError(404, "Empty POST body"); | ||
return; | ||
} | ||
|
||
String provider = req.getParameter("provider"); | ||
|
||
if(provider == null || provider.isEmpty()){ | ||
ResponseUtil.sendError(resp, Status.CLIENT_ERROR_BAD_REQUEST.getCode(), "Provider provided was invalid"); | ||
return; | ||
} | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); | ||
MLDicomDataset dataset; | ||
try { | ||
dataset = mapper.readValue(dataString, MLDicomDataset.class); | ||
PluginController.getInstance().cache(provider, dataset); | ||
} catch (Exception e) { | ||
log.error("Error parsing json string", e); | ||
ResponseUtil.sendError(resp, Status.CLIENT_ERROR_BAD_REQUEST.getCode(), "Malformed request"); | ||
} | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...rc/main/java/pt/ua/dicoogle/server/web/servlets/mlprovider/ImplementedMethodsServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package pt.ua.dicoogle.server.web.servlets.mlprovider; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import pt.ua.dicoogle.plugins.PluginController; | ||
import pt.ua.dicoogle.sdk.mlprovider.MLMethod; | ||
import pt.ua.dicoogle.sdk.mlprovider.MLProviderInterface; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.Set; | ||
|
||
public class ImplementedMethodsServlet extends HttpServlet { | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
|
||
String provider = request.getParameter("provider"); | ||
|
||
if(provider == null || provider.isEmpty()){ | ||
response.sendError(404, "Provider provided was invalid"); | ||
return; | ||
|
||
} | ||
|
||
MLProviderInterface mlPlugin = PluginController.getInstance().getMachineLearningProviderByName(provider, true); | ||
Set<MLMethod> implementedMethods = mlPlugin.getImplementedMethods(); | ||
response.setContentType("application/json"); | ||
PrintWriter out = response.getWriter(); | ||
mapper.writeValue(out, implementedMethods); | ||
out.close(); | ||
out.flush(); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
sdk/src/main/java/pt/ua/dicoogle/sdk/mlprovider/MLMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package pt.ua.dicoogle.sdk.mlprovider; | ||
|
||
/** | ||
* This enum lists the available methods of the MLProvider interface. | ||
* This is used when requesting the available methods of a provider. | ||
* It is a ENUM instead for example of a String to restrict the possible values. | ||
*/ | ||
public enum MLMethod { | ||
INFER, | ||
BULK_INFER, | ||
DATASTORE, | ||
CACHE, | ||
LIST_MODELS, | ||
CREATE_MODEL, | ||
MODEL_INFO, | ||
TRAIN_MODEL, | ||
STOP_TRAINING, | ||
DELETE_MODEL, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters