ref 16252: NLP Hub portlet not working when token is passed

https://support.d4science.org/issues/16252

Fixed DataMiner Discover by token

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/nlphub@178557 82a268e6-3cf1-43bd-a215-b396298e98cf
master
Giancarlo Panichi 5 years ago
parent 90711b50bb
commit 2eb9091e33

@ -13,12 +13,16 @@ public class DMDiscover {
private static Logger logger = LoggerFactory.getLogger(DMDiscover.class);
public DMDiscover() {
}
public String retrieveServiceUrl(String token) throws Exception {
logger.debug("Retrieve DataMiner Service by token: " + token);
String scope = retrieveScope(token);
logger.debug("Retrieve DataMiner Service in scope: "+scope);
String url= retrieveServiceInScope(scope);
logger.debug("DataMiner url: "+url);
logger.debug("Retrieve DataMiner Service in scope: " + scope);
String url = retrieveServiceInScope(scope);
logger.debug("DataMiner url: " + url);
return url;
}

@ -14,28 +14,19 @@ public class NerAnnotationData {
private String name;
private ArrayList<NerEntity> nerEntities;
/**
* Class constructor; require the name of the annotation
* @param name
*/
public NerAnnotationData(String name) {
logger.debug("NerAnnotationData: "+name);
this.name = name;
nerEntities = new ArrayList<>();
}
/**
* add a new NerEntity to the collection
* @param entity
*/
public void addNerEntity(NerEntity entity) {
nerEntities.add(entity);
}
/**
* build the proper Json object.
* @return JsonObject
*/
public JsonObject toJson() {
JsonObject json = new JsonObject();
JsonArray entities = new JsonArray();

@ -30,8 +30,8 @@ public class NerEntity {
/**
* Add an additional property (property is a couple {name, value})
* @param name
* @param value
* @param name name
* @param value value
*/
public void addProperty(String name, String value) {
properties.put(name, value);

@ -48,16 +48,19 @@ public class NLpLanguageRecognizer {
public static void run(String dataMiner, String sentence, String token, String publicLink,
HttpServletResponse response) throws NlpHubException {
try {
try {
DMDiscover discoverDataMinerService=new DMDiscover();
dataMiner=discoverDataMinerService.retrieveServiceUrl(token);
} catch (Exception e) {
logger.error("Error retrieving DataMiner service:" + e.getMessage(),e);
throw new Exception("Error retrieving DataMiner service:" + e.getMessage());
if (dataMiner == null || dataMiner.isEmpty()) {
try {
DMDiscover discoverDataMinerService = new DMDiscover();
dataMiner = discoverDataMinerService.retrieveServiceUrl(token);
} catch (Exception e) {
logger.error("Error retrieving DataMiner service:" + e.getMessage(), e);
throw new Exception("Error retrieving DataMiner service:" + e.getMessage());
}
}
//else
// dataMiner = "http://" + dataMiner;
// else
// dataMiner = "http://" + dataMiner;
String urlService = dataMiner + "?request=Execute&service=WPS&Version=1.0.0";
urlService += "&gcube-token=" + token;
urlService += "&lang=en-US";

@ -33,21 +33,20 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
public NlpAsyncNerRunner(String dataMiner, String identifier, String token, String publicLink, String annotations,
String language, RunnerCommander commander) throws Exception {
super();
this.commander=commander;
this.identifier=identifier;
this.commander = commander;
this.identifier = identifier;
String httpMethod = "GET";
try {
DMDiscover discoverDataMinerService=new DMDiscover();
dataMiner=discoverDataMinerService.retrieveServiceUrl(token);
} catch (Exception e) {
logger.error("Error retrieving DataMiner service:" + e.getMessage(),e);
throw new Exception("Error retrieving DataMiner service:" + e.getMessage());
if (dataMiner == null || dataMiner.isEmpty()) {
try {
DMDiscover discoverDataMinerService = new DMDiscover();
dataMiner = discoverDataMinerService.retrieveServiceUrl(token);
} catch (Exception e) {
logger.error("Error retrieving DataMiner service:" + e.getMessage(), e);
throw new Exception("Error retrieving DataMiner service:" + e.getMessage());
}
}
// else
// this.dataMiner = "http://" + dataMiner;
logger.debug("NlpAsyncNerRunner: Create Excution Request");
@ -63,29 +62,25 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
serviceUrl.append("&");
serviceUrl.append(setParams(params));
serviceUrl.append("&gcube-token=" + token);
logger.debug("NlpAsyncNerRunner: [serviceUrl=" + serviceUrl + ", method=" + httpMethod + "]");
super.setBaseUrl(serviceUrl.toString());
super.setMethod(httpMethod);
}
/*public NlpAsyncNerRunner(String baseUrl, String method) {
super(baseUrl, method, null);
}*/
/*
public String getIdentifier() {
return identifier;
}
* public NlpAsyncNerRunner(String baseUrl, String method) { super(baseUrl,
* method, null); }
*/
public String getToken() {
return token;
}
public String getHttpMethod() {
return httpMethod;
}*/
/*
* public String getIdentifier() { return identifier; }
*
*
* public String getToken() { return token; }
*
* public String getHttpMethod() { return httpMethod; }
*/
private String setParams(ArrayList<NlpParameter> parameters) {
logger.debug("Set Params");
@ -116,7 +111,7 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
serviceUrl.append(token);
URL url = new URL(serviceUrl.toString());
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoInput(true);

@ -28,7 +28,7 @@
String requestToken=request.getParameter(Constants.TOKEN_PARAMETER);
if( requestToken == null||requestToken.isEmpty()) {
%>
var gCubeToken = "fea75a5a-d84c-495f-b0ca-09cdd95bacce-843339462";
var gCubeToken = "d35c72d3-f6b5-4363-afbe-8e330ef9a913-843339462";
<% } else { %>
var gCubeToken = '<%=requestToken%>';

Loading…
Cancel
Save