Search in sources :

Example 1 with ExternalTool

use of edu.harvard.iq.dataverse.externaltools.ExternalTool in project dataverse by IQSS.

the class ExternalTools method addExternalTool.

@POST
public Response addExternalTool(String manifest) {
    try {
        ExternalTool externalTool = ExternalToolServiceBean.parseAddExternalToolManifest(manifest);
        ExternalTool saved = externalToolService.save(externalTool);
        Long toolId = saved.getId();
        actionLogSvc.log(new ActionLogRecord(ActionLogRecord.ActionType.ExternalTool, "addExternalTool").setInfo("External tool added with id " + toolId + "."));
        return ok(saved.toJson());
    } catch (Exception ex) {
        return error(BAD_REQUEST, ex.getMessage());
    }
}
Also used : ActionLogRecord(edu.harvard.iq.dataverse.actionlogging.ActionLogRecord) ExternalTool(edu.harvard.iq.dataverse.externaltools.ExternalTool) POST(javax.ws.rs.POST)

Example 2 with ExternalTool

use of edu.harvard.iq.dataverse.externaltools.ExternalTool in project dataverse by IQSS.

the class ExternalTools method getExternalToolsByFile.

@GET
@Path("file/{id}")
public Response getExternalToolsByFile(@PathParam("id") Long fileIdFromUser) {
    DataFile dataFile = fileSvc.find(fileIdFromUser);
    if (dataFile == null) {
        return error(BAD_REQUEST, "Could not find datafile with id " + fileIdFromUser);
    }
    JsonArrayBuilder tools = Json.createArrayBuilder();
    List<ExternalTool> allExternalTools = externalToolService.findAll();
    List<ExternalTool> toolsByFile = ExternalToolServiceBean.findExternalToolsByFile(allExternalTools, dataFile);
    for (ExternalTool tool : toolsByFile) {
        tools.add(tool.toJson());
    }
    return ok(tools);
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) JsonArrayBuilder(javax.json.JsonArrayBuilder) ExternalTool(edu.harvard.iq.dataverse.externaltools.ExternalTool) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

ExternalTool (edu.harvard.iq.dataverse.externaltools.ExternalTool)2 DataFile (edu.harvard.iq.dataverse.DataFile)1 ActionLogRecord (edu.harvard.iq.dataverse.actionlogging.ActionLogRecord)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1