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
This commit is contained in:
Giancarlo Panichi 2019-03-12 18:20:22 +00:00
parent 90711b50bb
commit 2eb9091e33
6 changed files with 50 additions and 57 deletions

View File

@ -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;
}

View File

@ -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();

View File

@ -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);

View File

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

View File

@ -33,20 +33,19 @@ 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";
if (dataMiner == null || dataMiner.isEmpty()) {
try {
DMDiscover discoverDataMinerService=new DMDiscover();
dataMiner=discoverDataMinerService.retrieveServiceUrl(token);
DMDiscover discoverDataMinerService = new DMDiscover();
dataMiner = discoverDataMinerService.retrieveServiceUrl(token);
} catch (Exception e) {
logger.error("Error retrieving DataMiner service:" + e.getMessage(),e);
logger.error("Error retrieving DataMiner service:" + e.getMessage(), e);
throw new Exception("Error retrieving DataMiner service:" + e.getMessage());
}
}
// else
// this.dataMiner = "http://" + dataMiner;
@ -69,23 +68,19 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
super.setMethod(httpMethod);
}
/*public NlpAsyncNerRunner(String baseUrl, String method) {
super(baseUrl, method, null);
}*/
/*
* public NlpAsyncNerRunner(String baseUrl, String method) { super(baseUrl,
* method, null); }
*/
/*
public String getIdentifier() {
return identifier;
}
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");

View File

@ -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%>';