Fixed Get Algorithm Info
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/nlphub@179627 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e9ffe7de57
commit
1164662df3
|
@ -4,7 +4,7 @@
|
||||||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||||
<property name="context-root" value="nlphub"/>
|
|
||||||
<property name="java-output-path" value="/nlphub/target/classes"/>
|
<property name="java-output-path" value="/nlphub/target/classes"/>
|
||||||
|
<property name="context-root" value="nlphub"/>
|
||||||
</wb-module>
|
</wb-module>
|
||||||
</project-modules>
|
</project-modules>
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -12,7 +12,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.gcube.data.analysis</groupId>
|
<groupId>org.gcube.data.analysis</groupId>
|
||||||
<artifactId>nlphub</artifactId>
|
<artifactId>nlphub</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.1-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
package org.gcube.data.analysis.nlphub;
|
package org.gcube.data.analysis.nlphub;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
@ -13,18 +9,12 @@ import javax.servlet.annotation.WebServlet;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
|
|
||||||
import org.gcube.data.analysis.nlphub.legacy.JsonManager;
|
import org.gcube.data.analysis.nlphub.legacy.JsonManager;
|
||||||
import org.gcube.data.analysis.nlphub.nlp.NlpAsyncNerRunner;
|
|
||||||
import org.gcube.data.analysis.nlphub.nlp.RunnerCommander;
|
import org.gcube.data.analysis.nlphub.nlp.RunnerCommander;
|
||||||
import org.gcube.data.analysis.nlphub.session.SessionUtils;
|
import org.gcube.data.analysis.nlphub.session.SessionUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Servlet implementation class NLPHub
|
* Servlet implementation class NLPHub
|
||||||
|
@ -73,61 +63,29 @@ public class NLPHub extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getAlgorithmInfo(HttpServletRequest request, HttpServletResponse response, String token)
|
private void getAlgorithmInfo(HttpServletRequest request, HttpServletResponse response, String token)
|
||||||
throws ServletException, IOException {
|
throws ServletException {
|
||||||
|
PrintWriter writer = null;
|
||||||
try {
|
try {
|
||||||
|
logger.info("GetAlgorithmInfo");
|
||||||
|
|
||||||
String dataMiner = request.getParameter("dataminer");
|
String dataMiner = request.getParameter("dataminer");
|
||||||
//dataMiner=java.net.URLDecoder.decode(dataMiner,"UTF-8");
|
|
||||||
|
|
||||||
String algId = request.getParameter("algId");
|
String algId = request.getParameter("algId");
|
||||||
logger.debug("NLPHub getAlgorithmInfo: [DataMiner="+dataMiner+", algorithmID="+algId+"]");
|
logger.debug("NLPHub getAlgorithmInfo: [DataMiner=" + dataMiner + ", algorithmID=" + algId + "]");
|
||||||
HttpURLConnection connection = null;
|
|
||||||
BufferedReader r = null;
|
String algoLink = "https://services.d4science.org/group/rprototypinglab/data-miner?OperatorId=";
|
||||||
String algAbsrtact = "";
|
algoLink=algoLink+algId;
|
||||||
PrintWriter writer = response.getWriter();
|
logger.debug("Algorithm link: "+algoLink);
|
||||||
|
writer = response.getWriter();
|
||||||
response.setContentType("application/json;charset=UTF-8");
|
response.setContentType("application/json;charset=UTF-8");
|
||||||
try {
|
writer.println(new JsonManager().getSuccessJsonResponse(algoLink));
|
||||||
String finalUrl = "https://" + dataMiner + NlpAsyncNerRunner.WPS_DESCRIBE_PROCESS_URL+"&lang=en-US&Identifier=" + algId;
|
|
||||||
logger.debug("Request url: "+finalUrl);
|
|
||||||
finalUrl+="&gcube-token="
|
|
||||||
+ token;
|
|
||||||
URL url = new URL(finalUrl);
|
|
||||||
connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setDoInput(true);
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
connection.setUseCaches(false);
|
|
||||||
connection.setRequestMethod("GET");
|
|
||||||
r = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
||||||
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(r));
|
|
||||||
doc.getDocumentElement().normalize();
|
|
||||||
|
|
||||||
NodeList nListInput = doc.getElementsByTagName("ows:Abstract");
|
|
||||||
if (nListInput.getLength() <= 0) {
|
|
||||||
algAbsrtact = "No description.";
|
|
||||||
writer.println(new JsonManager().getErrorJsonResponse(algAbsrtact));
|
|
||||||
} else {
|
|
||||||
Node nodeAbstract = nListInput.item(0);
|
|
||||||
algAbsrtact = nodeAbstract.getTextContent();
|
|
||||||
writer.println(new JsonManager().getSuccessJsonResponse("" + algAbsrtact));
|
|
||||||
}
|
|
||||||
writer.close();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("NLPHub error in GET algorithmInfo: "+e.getLocalizedMessage(),e);
|
|
||||||
writer.println(new JsonManager().getErrorJsonResponse("" + e.getLocalizedMessage()));
|
|
||||||
writer.close();
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (r != null)
|
|
||||||
r.close();
|
|
||||||
if (connection != null)
|
|
||||||
connection.disconnect();
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("NLPHub error in GET algorithmInfo: "+e.getLocalizedMessage(),e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("NLPHub error in GET algorithmInfo: "+e.getLocalizedMessage(),e);
|
logger.error("NLPHub error in GET AlgorithmInfo: " + e.getLocalizedMessage(), e);
|
||||||
|
throw new ServletException("Error retrieving algorithm info!",e);
|
||||||
|
} finally{
|
||||||
|
if(writer!=null){
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,33 +93,31 @@ public class NLPHub extends HttpServlet {
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
try {
|
try {
|
||||||
String dataMiner = request.getParameter("dataminer");
|
String dataMiner = request.getParameter("dataminer");
|
||||||
//dataMiner=java.net.URLDecoder.decode(dataMiner,"UTF-8");
|
// dataMiner=java.net.URLDecoder.decode(dataMiner,"UTF-8");
|
||||||
|
|
||||||
String[] algs = request.getParameter("algs").split(",");
|
String[] algs = request.getParameter("algs").split(",");
|
||||||
String plink=request.getParameter("plink");
|
String plink = request.getParameter("plink");
|
||||||
String annotations=request.getParameter("annotations");
|
String annotations = request.getParameter("annotations");
|
||||||
logger.debug("NLPHub getAlgorithmInfo: [DataMiner="+dataMiner+", plink="+plink+
|
logger.debug("NLPHub getAlgorithmInfo: [DataMiner=" + dataMiner + ", plink=" + plink + ", annotations="
|
||||||
", annotations="+annotations+", algorithms="+Arrays.toString(algs)+"]");
|
+ annotations + ", algorithms=" + Arrays.toString(algs) + "]");
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < algs.length; i++) {
|
for (int i = 0; i < algs.length; i++) {
|
||||||
algs[i] = algs[i].trim();
|
algs[i] = algs[i].trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
String maxWaitingTime= getServletConfig().getInitParameter("MaxWaitingTime");
|
String maxWaitingTime = getServletConfig().getInitParameter("MaxWaitingTime");
|
||||||
String sleepTime= getServletConfig().getInitParameter("SleepTime");
|
String sleepTime = getServletConfig().getInitParameter("SleepTime");
|
||||||
logger.debug("NLPHub: [maxWaitingTime="+maxWaitingTime+", sleepTime="+sleepTime+"]");
|
logger.debug("NLPHub: [maxWaitingTime=" + maxWaitingTime + ", sleepTime=" + sleepTime + "]");
|
||||||
|
|
||||||
long maxWaitingTimeL=Long.parseLong(maxWaitingTime);
|
long maxWaitingTimeL = Long.parseLong(maxWaitingTime);
|
||||||
long sleepTimeL=Long.parseLong(sleepTime);
|
long sleepTimeL = Long.parseLong(sleepTime);
|
||||||
RunnerCommander commander = new RunnerCommander(dataMiner, algs,plink ,
|
RunnerCommander commander = new RunnerCommander(dataMiner, algs, plink, annotations, token, response);
|
||||||
annotations, token, response);
|
|
||||||
commander.setSleepTime(sleepTimeL);
|
commander.setSleepTime(sleepTimeL);
|
||||||
commander.setMaxWaitingTime(maxWaitingTimeL);
|
commander.setMaxWaitingTime(maxWaitingTimeL);
|
||||||
commander.startProcess();
|
commander.startProcess();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("NLPHub runAlgorithms: "+e.getLocalizedMessage(), e);
|
logger.error("NLPHub runAlgorithms: " + e.getLocalizedMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -890,7 +890,8 @@ getAlgInformation = function(alg) {
|
||||||
async : true,
|
async : true,
|
||||||
success : function(data, stato) {
|
success : function(data, stato) {
|
||||||
// alert(data.message);
|
// alert(data.message);
|
||||||
showPopupText(data.message);
|
let linkMessage="<a target='_blank' rel='noopener noreferrer' href='"+data.message+"'>"+data.message+"</a>";
|
||||||
|
showPopupText(linkMessage);
|
||||||
},
|
},
|
||||||
error : function(richiesta, stato, errori) {
|
error : function(richiesta, stato, errori) {
|
||||||
alert("Unexpected Error. Status: " + richiesta.status);
|
alert("Unexpected Error. Status: " + richiesta.status);
|
||||||
|
|
Loading…
Reference in New Issue