diff --git a/portal/src/main/java/edu/isi/wings/portal/controllers/RunController.java b/portal/src/main/java/edu/isi/wings/portal/controllers/RunController.java index 73d8ea26..5e0ce89b 100644 --- a/portal/src/main/java/edu/isi/wings/portal/controllers/RunController.java +++ b/portal/src/main/java/edu/isi/wings/portal/controllers/RunController.java @@ -47,6 +47,7 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; +import org.apache.jena.base.Sys; import edu.isi.kcap.wings.opmm.WorkflowExecutionExport; import edu.isi.kcap.wings.opmm.WorkflowTemplateExport; @@ -534,13 +535,15 @@ private String urlToString(URL url) { /** * @param runid * @return + * @throws Exception */ - public String publishRun(String runid) { + public HashMap publishRun(String runid) throws Exception { HashMap retmap = new HashMap(); ExecutionMonitorAPI monitor = config.getDomainExecutionMonitor(); RuntimePlan plan = monitor.getRunDetails(runid); + HashMap response = null; if (plan.getRuntimeInfo().getStatus() != Status.SUCCESS) { - retmap.put("error", "Can only publish successfully completed runs"); + throw new Exception("Can only publish successfully completed runs"); } else try { // Mapper opmm = new Mapper(); @@ -649,30 +652,29 @@ public String publishRun(String runid) { String executionFilePath = run_exportdir + File.separator + "execution"; String expandedTemplateFilePath = run_exportdir + File.separator + "expandedTemplate"; String abstractFilePath = run_exportdir + File.separator + "abstract"; - // OPMW MAPPER CODE - // domain - // exportName - // catalogRepositoryDirectory - // componentLibraryFile - // String serialization = "turtle"; File file = new File("tmp/" + serialization); if (!file.exists()) { file.mkdir(); } try { - HashMap response = Mapper.main(domain, exportPrefix, exportUrl, catalogRepositoryDirectory, + response = Mapper.main(domain, exportPrefix, exportUrl, catalogRepositoryDirectory, componentLibraryFilePath.getAbsolutePath(), planFilePath.getAbsolutePath(), endpointQueryURI, endpointPostURI, executionFilePath, expandedTemplateFilePath, abstractFilePath, filePublisher, serialization); - return json.toJson(response); + System.out.println(executionFilePath); + System.out.println(expandedTemplateFilePath); + System.out.println(abstractFilePath); + + System.out.println("Response: " + response); + System.out.println("Published ended"); } catch (Exception e) { - e.printStackTrace(); + throw new Exception("Error publishing run: " + e.getMessage()); } } catch (Exception e) { - e.printStackTrace(); + throw new Exception("Error publishing run: " + e.getMessage()); } - return json.toJson(retmap); + return response; } /* diff --git a/portal/src/main/java/edu/isi/wings/portal/resources/RunResource.java b/portal/src/main/java/edu/isi/wings/portal/resources/RunResource.java index afb3c2c8..95874f62 100644 --- a/portal/src/main/java/edu/isi/wings/portal/resources/RunResource.java +++ b/portal/src/main/java/edu/isi/wings/portal/resources/RunResource.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; @@ -15,7 +16,9 @@ import javax.ws.rs.core.Response; import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.gson.Gson; +import edu.isi.kcap.wings.opmm.DataTypes.Links; import edu.isi.wings.portal.classes.util.TemplateBindings; import edu.isi.wings.portal.controllers.RunController; @@ -26,102 +29,97 @@ public class RunResource extends WingsResource { @PostConstruct public void init() { super.init(); - if(this.hasPermissions() && !this.isPage("intro")) + if (this.hasPermissions() && !this.isPage("intro")) this.rc = new RunController(config); } - + @PreDestroy public void destroy() { - if(this.rc != null) { + if (this.rc != null) { this.rc.end(); } } - + @GET @Produces(MediaType.TEXT_HTML) public String getHTML( @QueryParam("run_id") final String run_id) { - if(this.rc != null) { + if (this.rc != null) { request.setAttribute("controller", this.rc); request.setAttribute("run_id", run_id); return this.callViewer("RunViewer"); } return null; } - + @GET @Path("intro") public void getIntroduction() { this.loadIntroduction("ManageRuns"); } - + @GET @Path("getRunList") @Produces(MediaType.APPLICATION_JSON) public String getRunList( - @QueryParam("pattern") final String pattern, - @QueryParam("status") final String status, - @QueryParam("start") int start, - @QueryParam("limit") int limit - ) { - if(this.rc != null) + @QueryParam("pattern") final String pattern, + @QueryParam("status") final String status, + @QueryParam("start") int start, + @QueryParam("limit") int limit) { + if (this.rc != null) return this.rc.getRunListJSON(pattern, status, start, limit); return null; } - @GET @Path("getRunListSimple") @Produces(MediaType.APPLICATION_JSON) public String getRunListSimple( - @QueryParam("pattern") final String pattern, - @QueryParam("status") final String status, - @QueryParam("start") int start, - @QueryParam("limit") int limit, - @QueryParam("started_after") final long started_after - ) { - if(this.rc != null) { + @QueryParam("pattern") final String pattern, + @QueryParam("status") final String status, + @QueryParam("start") int start, + @QueryParam("limit") int limit, + @QueryParam("started_after") final long started_after) { + if (this.rc != null) { Date startdate = null; - if(started_after != 0) - startdate = new Date(started_after*1000); + if (started_after != 0) + startdate = new Date(started_after * 1000); return this.rc.getRunListSimpleJSON(pattern, status, start, limit, startdate); } return null; } - @POST @Path("getRunDetails") @Produces(MediaType.APPLICATION_JSON) public String getRunDetails( @FormParam("run_id") String run_id) { - if(this.rc != null) + if (this.rc != null) return this.rc.getRunJSON(run_id); return null; } - + @POST @Path("getRunPlan") @Produces(MediaType.APPLICATION_JSON) public String getRunPlan( @FormParam("run_id") String run_id) { - if(this.rc != null) + if (this.rc != null) return this.rc.getRunPlanJSON(run_id); return null; } - + @POST @Path("expandAndRunWorkflow") @Produces(MediaType.APPLICATION_JSON) public ArrayList expandAndRunWorkflow( @JsonProperty("template_bindings") final TemplateBindings tbindings) { - if(this.rc != null) { + if (this.rc != null) { return rc.expandAndRunTemplate(tbindings, this.context); } return null; } - @POST @Path("runWorkflow") @Produces(MediaType.TEXT_PLAIN) @@ -131,61 +129,71 @@ public String runWorkflow( @FormParam("constraints_json") String constraints_json, @FormParam("seed_json") String seed_json, @FormParam("seed_constraints_json") String seed_constraints_json) { - if(this.rc != null) + if (this.rc != null) return rc.runExpandedTemplate(template_id, json, constraints_json, seed_json, seed_constraints_json, null, this.context); return null; } - + @POST @Path("reRunWorkflow") @Produces("application/json") public Response reRunWorkflow( - @FormParam("run_id") String run_id) { - if(this.rc != null){ - return rc.reRunPlan(run_id, this.context); + @FormParam("run_id") String run_id) { + if (this.rc != null) { + return rc.reRunPlan(run_id, this.context); } return null; } - + @POST @Path("deleteRun") @Produces(MediaType.TEXT_PLAIN) public String deleteRun(@FormParam("json") String json) { - if(this.rc != null) + if (this.rc != null) return rc.deleteRun(json, context); return null; } - + @POST @Path("deleteRuns") @Produces(MediaType.TEXT_PLAIN) public String deleteRuns(@FormParam("json") String json) { - if(this.rc != null) + if (this.rc != null) return rc.deleteRuns(json, context); return null; } - + @POST @Path("stopRun") @Produces(MediaType.TEXT_PLAIN) public String stopRun( @FormParam("run_id") String run_id) { - if(this.rc != null) + if (this.rc != null) return this.rc.stopRun(run_id, context) + ""; return "false"; } - + @POST @Path("publishRun") @Produces(MediaType.TEXT_PLAIN) public String publishRun( - @FormParam("run_id") String run_id) { - if(this.rc != null) - return this.rc.publishRun(run_id); + @FormParam("run_id") String run_id) { + if (this.rc != null) { + try { + HashMap responseQuery = this.rc.publishRun(run_id); + Gson gson = new Gson(); + String json = gson.toJson(responseQuery); + Links catalog = responseQuery.get("catalog"); + System.out.println(json); + return json; + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } return null; } - - } \ No newline at end of file