Skip to content

Commit

Permalink
Merge pull request #59 from nicolasmoreau/dev
Browse files Browse the repository at this point in the history
Improve query store result display
  • Loading branch information
nicolasmoreau authored Apr 4, 2017
2 parents 19f2923 + 429c370 commit 25fbdb3
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 81 deletions.
14 changes: 14 additions & 0 deletions notes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
03/04/2017:
Problème avec le clic sur les liens vers les fichiers xsams pour declencher l'association des requêtes dans le querystore.
Le javascript rafraichissant la page ne fonctionnait pas sous firefox. Les liens ont été remplacés par des boutons.


13/02/2017:
SEAM retourne des erreurs d'exécution lorsqu'il est lancé avec java8 :
Could not instantiate Seam component: registration

Le fichier ~/.mavenrc a été édité pour que JAVA_HOME pointe sur java7
JAVA_HOME est défini dans deploy.sh pour que jboss utilise java7

Utilise JSF en version 1.x

6 changes: 6 additions & 0 deletions portal.ejb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.HashMap;
import java.util.Map;

import org.apache.http.Header;
import org.apache.http.HttpException;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
Expand All @@ -20,6 +21,7 @@
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.async.Asynchronous;
import org.jboss.seam.log.Log;
import org.jboss.seam.web.ServletContexts;
import org.vamdc.portal.Settings;
Expand All @@ -39,108 +41,73 @@ public class QueryStore {
/**
* number of requests sent to querystore
*/
private Integer retry = 3;
private Integer retry = 10;

/**
* time between two request to the querystore, in milliseconds
*/
private Integer retryInterval = 2000;
private Integer retryInterval = 3000;

@In
private UserInfo auth;

@Logger
transient private Log log;

private String processing = "";

public String getProcessing() {
return processing;
}

public void setProcessing(String processing) {
this.processing = processing;
}

/**
* return result of querystore for a request
*
* @return
*/
**/
public QueryStoreResponse getNodeUuid(String node) {
// not requested yet
if (this.uuids.containsKey(node) == false)
return new QueryStoreResponse(QueryStoreResponse.STATUS_UNKNOWN,
"", "");

return this.uuids.get(node);
}
}

/**
* Ask a permanent identifier for the request identified by the token string
*
* @param token
* token of a head request
* @param token token of a head request
*/
//@Asynchronous
public void associateRequest(String token, String node) {
String result = "";
String error = null;
this.processing = "Starting process";
QueryStoreResponse result = null;
Integer count = 0;

try {
String request = this.getRequest(token, this.getUserEmail(),
this.getIpAdress());

// not tried yet or previous try failed
if (uuids.containsKey(node) == false
if (!uuids.containsKey(node)
|| !uuids.get(node).getStatus()
.equals(QueryStoreResponse.STATUS_SUCCESS)) {
while (("").equals(result) && count < this.retry) {

.equals(QueryStoreResponse.STATUS_SUCCESS)) {
while ((result == null || QueryStoreResponse.STATUS_EMPTY.equals(result.getStatus())) && count < this.retry) {
result = this.doRequest(request);
Thread.sleep(this.retryInterval);
count++;
}

this.setUuid(node, result, error);
this.uuids.put(node, result);
}
} catch (ClientProtocolException e) {
error = "ClientProtocolException";
log.debug(e);
count = this.retry;
} catch (IOException e) {
error = "IOException";
} catch (Exception e) {
log.debug(e);
count = this.retry;
} catch (InterruptedException e) {
error = "InterruptedException";
log.debug(e);
count = this.retry;
} catch (HttpException e) {
error = "HttpException";
log.debug(e);
count = this.retry;
}
this.processing = "INFO : A request was sent to the query store to get a citation link. Request status : " + uuids.get(node).getStatus();
}

/**
* add a uuid in the uuid map
*
* @param node
* vamdc node id
* @param result
* uuid found
* @param error
* error message
*/
private void setUuid(String node, String result, String error) {
// no exception in process
if (error == null) {
if (!result.equals("")) {
// found
this.uuids.put(node, new QueryStoreResponse(
QueryStoreResponse.STATUS_SUCCESS, result, ""));
} else {
// not found
this.uuids.put(node, new QueryStoreResponse(
QueryStoreResponse.STATUS_UNKNOWN, result, ""));
}
}
// failed
else {
this.uuids.put(node, new QueryStoreResponse(
QueryStoreResponse.STATUS_ERROR, "", error));
}
}

/**
* Send an HTTP request to the query store to get a UUID corresponding to a
Expand All @@ -157,7 +124,7 @@ private void setUuid(String node, String result, String error) {
* @throws IOException
* @throws HttpException
*/
private String doRequest(String requestString)
private QueryStoreResponse doRequest(String requestString)
throws ClientProtocolException, IOException, HttpException {

RequestConfig requestConfig = RequestConfig.custom()
Expand All @@ -167,7 +134,7 @@ private String doRequest(String requestString)
HttpGet request = new HttpGet(requestString);
request.addHeader("User-Agent", Settings.PORTAL_USER_AGENT.get());
StringBuilder result = new StringBuilder();
HttpResponse response = httpClient.execute(request);
HttpResponse response = httpClient.execute(request);

if (response.getStatusLine().getStatusCode() == 200) {
BufferedReader rd = new BufferedReader(new InputStreamReader(
Expand All @@ -178,10 +145,11 @@ private String doRequest(String requestString)
result.append(uuid);
}
rd.close();

} else {
// empty response
if (response.getStatusLine().getStatusCode() == 204) {
return "";
return new QueryStoreResponse(QueryStoreResponse.STATUS_EMPTY, "", "");
}
// server error
else if (response.getStatusLine().getStatusCode() >= 500) {
Expand All @@ -195,8 +163,9 @@ else if (response.getStatusLine().getStatusCode() >= 400
+ response.getStatusLine().getStatusCode());
}
}

return result.toString();

// extract uuid from json response
return QueryStoreResponseReader.parseResponse(result.toString());
}

/**
Expand All @@ -210,12 +179,9 @@ else if (response.getStatusLine().getStatusCode() >= 400
*/
private String getRequest(String token, String email, String userIp) throws UnsupportedEncodingException {
String result = Settings.QUERYSTORE_ASSOCIATION_URL.get();


result = result + "queryToken=" + token + "&email=" + email
+ "&userIp=" + userIp + "&usedClient=" + URLEncoder.encode(
Settings.PORTAL_USER_AGENT.get() + "-"
+ Settings.PORTAL_VERSION.get(), "UTF-8");
Settings.PORTAL_USER_AGENT.get()+"-"+Settings.PORTAL_VERSION.get(), "UTF-8");
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class QueryStoreResponse {
public final static String STATUS_ERROR = "error";
public final static String STATUS_SUCCESS = "success";
public final static String STATUS_UNKNOWN = "unknown";
public final static String STATUS_EMPTY = "empty";

public QueryStoreResponse(String status, String uuid, String errorMessage){
this.status = status;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.vamdc.portal.session.queryLog;

import org.json.JSONException;
import org.json.JSONObject;

public class QueryStoreResponseReader {

public final static String SUCCESSFULL_REQUEST = "UUIDCorrectlyAssociated";
public final static String HEAD_ASSOCIATION_FAILED = "UUIDInErrorOnHeadQuery";
public final static String GET_ASSOCIATION_FAILED = "UUIDInErrorOnGetQuery";

public final static QueryStoreResponse parseResponse(String json) throws JSONException{
JSONObject jsonObject = new JSONObject(json);

if(jsonObject.keySet().contains(SUCCESSFULL_REQUEST))
return new QueryStoreResponse(QueryStoreResponse.STATUS_SUCCESS, jsonObject.getString(SUCCESSFULL_REQUEST), "");
else if(jsonObject.keySet().contains(HEAD_ASSOCIATION_FAILED))
return new QueryStoreResponse(QueryStoreResponse.STATUS_ERROR, jsonObject.getString(SUCCESSFULL_REQUEST), "Head association failed");
else if(jsonObject.keySet().contains(GET_ASSOCIATION_FAILED))
return new QueryStoreResponse(QueryStoreResponse.STATUS_ERROR, jsonObject.getString(SUCCESSFULL_REQUEST), "Get association failed");

else
throw new JSONException("Unknown field in JSON object");

}

}
34 changes: 22 additions & 12 deletions portal.war/src/main/webapp/xhtml/preview/table.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j">

xmlns:p="http://primefaces.org/ui"
xmlns:a4j="http://richfaces.org/a4j">


<h:panelGroup layout="block" >
<h:outputText id="logRequestStatus" />
</h:panelGroup>

<h:panelGroup layout="block" id="nodeResults">

<h:outputText id="logRequestResult" value="#{querystore.processing}" />

<rich:panel styleClass="resultTable">
<f:facet name="header">
<!-- titlePrefix defined in file including this one -->
Expand Down Expand Up @@ -122,24 +128,27 @@
</h:column>

<h:column>
<h:panelGroup>
<h:outputLink value="#{node.fullQueryURL}"
rendered="#{node.isOk()}">
<h:outputText value="XSAMS" />
<a4j:support action="#{querystore.associateRequest(node.requestToken, node.ivoaID)}"
event="onmousedown" reRender="nodeResults" eventsQueue="portalQueue"/>

</h:outputLink>
<h:panelGroup >
<a4j:commandButton value="XSAMS file" reRender="nodeResults"
onclick="window.open('#{node.fullQueryURL}');document.getElementById('j_id23:logRequestResult').innerHTML = ''; \
document.getElementById('j_id23:logRequestStatus').innerHTML = 'Association process for #{registryFacade.getResourceTitle(node.ivoaID)} started';"
action="#{querystore.associateRequest(node.requestToken, node.ivoaID)}"
id="button" eventsQueue="portalQueue" rendered="#{node.isOk()}" disabled="#{!preview.done }">
</a4j:commandButton>
</h:panelGroup>
<br/>
<h:outputText value="" />
<h:panelGroup rendered="#{querystore.getNodeUuid(node.ivoaID).status eq 'success' }">
<h:outputLink value="http://cite.vamdc.eu/references.html?uuid=#{querystore.getNodeUuid(node.ivoaID).uuid}" target="_blank">
<h:outputText value="Citation link" />
</h:outputLink>
</h:panelGroup >
<h:panelGroup rendered="#{querystore.getNodeUuid(node.ivoaID).status eq 'error' }">
<h:outputText value="No citation link : #{querystore.getNodeUuid(node.ivoaID).errorMessage }" />
</h:panelGroup >
</h:panelGroup >
<h:panelGroup rendered="#{querystore.getNodeUuid(node.ivoaID).status eq 'empty' }">
<h:outputText value="No citation link : query not found in querystore" />
</h:panelGroup >
</h:column>

<h:column>
Expand All @@ -164,3 +173,4 @@
</rich:panel>
</h:panelGroup>
</ui:composition>

0 comments on commit 25fbdb3

Please sign in to comment.