- for the submitQuery the file result management has been modified. The file is retrieved from the statistical. GWTdbManagerServiceImpl, GxtBorderLayoutPanel, ComputationOutput, SubmitQueryResultWithFileFromServlet modified.

- pom file version changed in 1.3.0
- check added on data object in loadSubmitQuery method
- UriResolver used to generate an http link from smp url. Dependency added in the pom file.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@101654 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Loredana Liccardo 2014-11-19 15:00:35 +00:00
parent c5d19b629c
commit aec88a2b18
5 changed files with 145 additions and 50 deletions

View File

@ -19,7 +19,7 @@
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>databases-manager-portlet</artifactId> <artifactId>databases-manager-portlet</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<version>1.2.0-SNAPSHOT</version> <version>1.3.0-SNAPSHOT</version>
<name>DatabasesResourceManagerPortlet</name> <name>DatabasesResourceManagerPortlet</name>
<description>Databases Resource Manager Portlet</description> <description>Databases Resource Manager Portlet</description>
@ -168,6 +168,12 @@
<version>2.8.0</version> <version>2.8.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>uri-resolver-manager</artifactId>
<version>[1.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>
<!-- <dependency> --> <!-- <dependency> -->
<!-- <groupId>jcs</groupId> --> <!-- <groupId>jcs</groupId> -->

View File

@ -6,10 +6,12 @@ public class ComputationOutput {
private LinkedHashMap<String, String> mapValues; private LinkedHashMap<String, String> mapValues;
private LinkedHashMap<String, String> mapKeys; private LinkedHashMap<String, String> mapKeys;
private String urlFile;
public ComputationOutput() { public ComputationOutput() {
mapKeys = new LinkedHashMap<String, String>(); mapKeys = new LinkedHashMap<String, String>();
mapValues = new LinkedHashMap<String, String>(); mapValues = new LinkedHashMap<String, String>();
urlFile="";
} }
public void setMapValues(LinkedHashMap<String, String> mapValues) { public void setMapValues(LinkedHashMap<String, String> mapValues) {
@ -27,4 +29,12 @@ public class ComputationOutput {
public LinkedHashMap<String, String> getmapKeys() { public LinkedHashMap<String, String> getmapKeys() {
return mapKeys; return mapKeys;
} }
public void setUrlFile(String url){
this.urlFile=url;
}
public String getUrlFile(){
return this.urlFile;
}
} }

View File

@ -12,16 +12,27 @@ public class SubmitQueryResultWithFileFromServlet extends BaseModelData
private List<String> attributes; private List<String> attributes;
private String convertedQuery; private String convertedQuery;
private String fileName; private String fileName;
private String urlFile;
public SubmitQueryResultWithFileFromServlet() { public SubmitQueryResultWithFileFromServlet() {
} }
// public SubmitQueryResultWithFileFromServlet(List<String> attributes,
// String query, String fileName, String urlFile) {
// set("attributes", attributes);
// set("convertedQuery", query);
// set("fileName", fileName);
// set("urlFile", urlFile);
//
// }
public SubmitQueryResultWithFileFromServlet(List<String> attributes, public SubmitQueryResultWithFileFromServlet(List<String> attributes,
String query, String fileName) { String query, String urlFile) {
set("attributes", attributes); set("attributes", attributes);
set("convertedQuery", query); set("convertedQuery", query);
set("fileName", fileName); // set("fileName", fileName);
set("urlFile", urlFile);
} }
@ -29,12 +40,16 @@ public class SubmitQueryResultWithFileFromServlet extends BaseModelData
return get("attributes"); return get("attributes");
} }
public String getFileName() { // public String getFileName() {
return get("fileName"); // return get("fileName");
} // }
public String getConvertedQuery() { public String getConvertedQuery() {
return get("convertedQuery"); return get("convertedQuery");
} }
public String getUrlFile(){
return get("urlFile");
}
} }

View File

@ -997,9 +997,10 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// listAttributes, dataQuery.getQuery()); // listAttributes, dataQuery.getQuery());
// get path // get path
String fileName = obj.getFileName(); // String fileName = obj.getFileName();
String urlFile = obj.getUrlFile();
parseSubmitQueryResult(form, dialogID, parseSubmitQueryResult(form, dialogID,
listAttributes, query, fileName, UID); listAttributes, query, urlFile, UID);
} }
@ -1009,7 +1010,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// start the parsing of the submit result in order to obtain a table // start the parsing of the submit result in order to obtain a table
private void parseSubmitQueryResult(Dialog dialog, final int dialogID, private void parseSubmitQueryResult(Dialog dialog, final int dialogID,
final List<String> listAttributes, String query, String fileName, final List<String> listAttributes, String query, final String urlFile,
final String UID) { final String UID) {
final Dialog form = dialog; final Dialog form = dialog;
@ -1278,8 +1279,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
}); });
// add the button to download the result // add the button to download the result
final String urlFile = Window.Location.getProtocol() + "//" // final String urlFile = Window.Location.getProtocol() + "//"
+ Window.Location.getHost() + fileName; // + Window.Location.getHost() + fileName;
Button download = new Button("Download", Button download = new Button("Download",
new SelectionListener<ButtonEvent>() { new SelectionListener<ButtonEvent>() {

View File

@ -72,6 +72,8 @@ import org.gcube.portlets.user.databasesmanager.server.util.SessionUtil;
import org.gcube.portlets.user.databasesmanager.shared.ConstantsPortlet; import org.gcube.portlets.user.databasesmanager.shared.ConstantsPortlet;
import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException; import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException;
import org.gcube.portlets.user.databasesmanager.shared.StatisticalManagerException; import org.gcube.portlets.user.databasesmanager.shared.StatisticalManagerException;
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
import com.extjs.gxt.ui.client.data.BasePagingLoadResult; import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
import com.extjs.gxt.ui.client.data.PagingLoadConfig; import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult; import com.extjs.gxt.ui.client.data.PagingLoadResult;
@ -150,6 +152,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} else { } else {
cacheManager.addCache(DBCache); cacheManager.addCache(DBCache);
logger.info("dbmanager-> cache added to the cacheManager"); logger.info("dbmanager-> cache added to the cacheManager");
logger.info("dbmanager-> ** SIZE OF THE MEMORY STORE: "+ DBCache.calculateInMemorySize());
// logger.trace("dbmanager-> ** SIZE OF THE OFF HEAP"+ DBCache.calculateOffHeapSize());
logger.info("dbmanager-> ** SIZE OF THE DISK STORE SIZE: "+ DBCache.calculateOnDiskSize());
} }
} }
@ -211,6 +217,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// size.maxDepthExceededBehavior(MaxDepthExceededBehavior.ABORT); // size.maxDepthExceededBehavior(MaxDepthExceededBehavior.ABORT);
// config.sizeOfPolicy(size); // config.sizeOfPolicy(size);
DBCache = new Cache(config); DBCache = new Cache(config);
} catch (Exception e) { } catch (Exception e) {
// logger.error("dbmanager-> Error while starting the servlet. Failed to create the cache", // logger.error("dbmanager-> Error while starting the servlet. Failed to create the cache",
// e); // e);
@ -358,6 +367,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
if ((value == null) || (value.booleanValue() == false)) { if ((value == null) || (value.booleanValue() == false)) {
DataExchangedThroughQueue dataqueue = new DataExchangedThroughQueue( DataExchangedThroughQueue dataqueue = new DataExchangedThroughQueue(
scope); scope);
queue.offer(dataqueue); queue.offer(dataqueue);
Thread t = new Thread(dataLoader); Thread t = new Thread(dataLoader);
t.start(); t.start();
@ -700,9 +710,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// create data structure // create data structure
ComputationOutput outputData = new ComputationOutput(); ComputationOutput outputData = new ComputationOutput();
//file name
String FileName = "QueryResult"+"_" + System.currentTimeMillis() + ".csv";
// computation id // computation id
String computationId = startComputation(algorithmId, String computationId = startComputation(algorithmId,
inputParameters, outputData, scope, UID); inputParameters, outputData, scope, UID, FileName);
// get JobID // get JobID
@ -757,25 +770,32 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// updateSubmitQueryResultMap(UID, output); // updateSubmitQueryResultMap(UID, output);
// remove job with the specified uid // remove job with the specified uid
removeJob(UID); removeJob(UID);
//TODO ** COMMENTED
// generate the file csv output // generate the file csv output
String name = "SubmitQuery"; // String name = "SubmitQuery";
String fileName = storeResultIntoCSVFile(output, name);
// String fileName = storeResultIntoCSVFile(output, name);
// get the web application path // get the web application path
HttpServletRequest request = this // HttpServletRequest request = this
.getThreadLocalRequest(); // .getThreadLocalRequest();
String applicationPath = request.getContextPath(); // String applicationPath = request.getContextPath();
// logger.info("dbmanager-> Application Path: " + // // logger.info("dbmanager-> Application Path: " +
// applicationPath); // // applicationPath);
String partialPathFile = applicationPath // String partialPathFile = applicationPath
+ "/computationResult/" + fileName; // + "/computationResult/" + fileName;
String urlFile=outputData.getUrlFile();
// result = new SubmitQueryResultWithFileFromServlet(
// listAttributes, convertedQuery, partialPathFile, urlFile);
result = new SubmitQueryResultWithFileFromServlet( result = new SubmitQueryResultWithFileFromServlet(
listAttributes, convertedQuery, partialPathFile); listAttributes, convertedQuery, urlFile);
// put the two data in cache // put the two data in cache
net.sf.ehcache.Element dataToCache = new net.sf.ehcache.Element( net.sf.ehcache.Element dataToCache = new net.sf.ehcache.Element(
keyData, result); keyData, result);
insertDataIntoCache(dataToCache); insertDataIntoCache(dataToCache);
// remove the header in order to parse only the result // remove the header in order to parse only the result
@ -783,6 +803,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
net.sf.ehcache.Element submitQueryResultToCache = new net.sf.ehcache.Element( net.sf.ehcache.Element submitQueryResultToCache = new net.sf.ehcache.Element(
keySubmitQueryResult, output); keySubmitQueryResult, output);
//TODO **TO DECOMMENT
// updateListSubmitQueryResult(UID, output);
insertDataIntoCache(submitQueryResultToCache); insertDataIntoCache(submitQueryResultToCache);
} }
@ -806,7 +828,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
if (!(e instanceof StatisticalManagerException)) { if (!(e instanceof StatisticalManagerException)) {
// GWT can't serialize all exceptions // GWT can't serialize all exceptions
throw new Exception( throw new Exception(
"Error in server while loading data. Exception: " + e); "Error in server while loading data.");
} }
throw e; throw e;
} finally { } finally {
@ -1381,6 +1403,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} }
if (value != null) { if (value != null) {
result = (List<Result>) value; result = (List<Result>) value;
logger.trace("dbmanager-> ** Data get from cache");
updateListSubmitQueryResult(UID, result); updateListSubmitQueryResult(UID, result);
// data = parseCVSString(result, listAttributes); // data = parseCVSString(result, listAttributes);
@ -1404,6 +1427,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
//get the result bound to session //get the result bound to session
result = getSubmitQueryResult(UID); result = getSubmitQueryResult(UID);
logger.trace("dbmanager-> ** Data get from ASL session");
// logger.error("dbmanager-> Error in server while loading data. variable value null"); // logger.error("dbmanager-> Error in server while loading data. variable value null");
// throw new Exception("Error in server while loading data."); // throw new Exception("Error in server while loading data.");
@ -1411,23 +1435,27 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} }
data = parseCVSString(result, listAttributes); data = parseCVSString(result, listAttributes);
if(data!=null){
int start = config.getOffset();
int limit = data.size();
int start = config.getOffset(); if (config.getLimit() > 0) {
int limit = data.size(); limit = Math.min(start + config.getLimit(), limit);
}
if (config.getLimit() > 0) { int totalNumber = data.size();
limit = Math.min(start + config.getLimit(), limit); sublist = new ArrayList<Row>(data.subList(start, limit));
loadResult = new BasePagingLoadResult<Row>(sublist,
config.getOffset(), totalNumber);
// System.out.println("start: " + start);
// System.out.println("limit: " + limit);
// System.out.println("sublist size: " + sublist.size());
}else{
logger.error("dbmanager-> Error in server while loading data. object data null");
throw new Exception("Error in server while loading data.");
} }
int totalNumber = data.size();
sublist = new ArrayList<Row>(data.subList(start, limit));
loadResult = new BasePagingLoadResult<Row>(sublist,
config.getOffset(), totalNumber);
// System.out.println("start: " + start);
// System.out.println("limit: " + limit);
// System.out.println("sublist size: " + sublist.size());
} else { } else {
logger.error("dbmanager-> Error in server while loading data. key null"); logger.error("dbmanager-> Error in server while loading data. key null");
throw new Exception("Error in server while loading data."); throw new Exception("Error in server while loading data.");
@ -1752,12 +1780,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
List<Parameter> parameters, ComputationOutput outputData, List<Parameter> parameters, ComputationOutput outputData,
String scope) throws Exception { String scope) throws Exception {
return startComputation(algorithmName, parameters, outputData, scope, return startComputation(algorithmName, parameters, outputData, scope,
null); null, null);
} }
private String startComputation(String algorithmName, private String startComputation(String algorithmName,
List<Parameter> parameters, ComputationOutput outputData, List<Parameter> parameters, ComputationOutput outputData,
String scopeValue, String jobID) throws Exception { String scopeValue, String jobID, String FileName) throws Exception {
SMComputationConfig config = new SMComputationConfig(); SMComputationConfig config = new SMComputationConfig();
SMInputEntry[] list = new SMInputEntry[parameters.size()]; SMInputEntry[] list = new SMInputEntry[parameters.size()];
@ -1788,7 +1816,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
logger.info("dbmanager-> startComputation: the computation has started!"); logger.info("dbmanager-> startComputation: the computation has started!");
while (percentage < 100) { while (percentage < 100) {
percentage = checkComputationStatus(scope, computationId, percentage = checkComputationStatus(scope, computationId,
username, outputData); username, outputData, FileName);
Thread.sleep(3000); Thread.sleep(3000);
} }
logger.info("dbmanager-> startComputation: the computation has finished!"); logger.info("dbmanager-> startComputation: the computation has finished!");
@ -1805,7 +1833,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} }
private float checkComputationStatus(String scope, String computationId, private float checkComputationStatus(String scope, String computationId,
String user, ComputationOutput outputData) throws Exception { String user, ComputationOutput outputData, String FileName) throws Exception {
// System.out.println("checkComputation " + computationId); // System.out.println("checkComputation " + computationId);
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
@ -1836,7 +1864,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
int resourceTypeIndex = smResource.resourceType(); int resourceTypeIndex = smResource.resourceType();
SMResourceType smResType = SMResourceType.values()[resourceTypeIndex]; SMResourceType smResType = SMResourceType.values()[resourceTypeIndex];
displayOutput(smResource, smResType, outputData); displayOutput(smResource, smResType, outputData, scope, FileName);
// print check // print check
// logger.info("SM resource Name: " + smResource.name()); // logger.info("SM resource Name: " + smResource.name());
@ -1851,7 +1879,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} }
private void displayOutput(SMResource smResource, SMResourceType smResType, private void displayOutput(SMResource smResource, SMResourceType smResType,
ComputationOutput outputData) throws Exception { ComputationOutput outputData, String scope, String FileName) throws Exception {
if (smResType.equals(SMResourceType.OBJECT)) { if (smResType.equals(SMResourceType.OBJECT)) {
// switch (smResType) { // switch (smResType) {
@ -1863,7 +1891,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
SMObject objRes = (SMObject) smResource; SMObject objRes = (SMObject) smResource;
if (objRes.name().contentEquals(PrimitiveTypes.MAP.toString())) { if (objRes.name().contentEquals(PrimitiveTypes.MAP.toString())) {
logger.info("dbmanager-> Output is a map"); logger.info("dbmanager-> Output is a map");
getMap(objRes, outputData); getMap(objRes, outputData, scope, FileName);
} else if (objRes.name().contentEquals( } else if (objRes.name().contentEquals(
PrimitiveTypes.IMAGES.toString())) { PrimitiveTypes.IMAGES.toString())) {
@ -1885,14 +1913,14 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} }
// get output result // get output result
private void getMap(SMObject objRes, ComputationOutput outputData) private void getMap(SMObject objRes, ComputationOutput outputData, String scope, String FileName)
throws Exception { throws Exception {
// output data values // output data values
LinkedHashMap<String, String> mapValues = new LinkedHashMap<String, String>(); LinkedHashMap<String, String> mapValues = new LinkedHashMap<String, String>();
// output data keys // output data keys
LinkedHashMap<String, String> mapKeys = new LinkedHashMap<String, String>(); LinkedHashMap<String, String> mapKeys = new LinkedHashMap<String, String>();
// logger.info("getStorageInputStream - started"); // logger.info("**getStorageInputStream - started");
InputStream is = getStorageClientInputStream(objRes.url()); InputStream is = getStorageClientInputStream(objRes.url());
// object serializer // object serializer
XStream xstream = new XStream(); XStream xstream = new XStream();
@ -1914,11 +1942,41 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
Map<String, SMResource> smMap = (Map<String, SMResource>) (xstream Map<String, SMResource> smMap = (Map<String, SMResource>) (xstream
.fromXML(is)); .fromXML(is));
is.close(); is.close();
// logger.info("getStorageInputStream - finished"); // logger.info("**getStorageInputStream - finished");
// logger.info("build the resultMap - started"); // logger.info("**build the resultMap - started");
int i = 0; int i = 0;
for (String key : smMap.keySet()) { for (String key : smMap.keySet()) {
if (key.equals("File")){
logger.info("dbmanager-> " + "the map contains file");
SMResource smres = smMap.get("File");
int resourceTypeIndex = smres.resourceType();
SMResourceType smsubResType = SMResourceType.values()[resourceTypeIndex];
// logger.info("dbmanager-> Output is a file");
SMFile fileRes = (SMFile) smres;
// logger.info("dbmanager-> **FILE URL " + fileRes.url());
// logger.info("dbmanager-> **FILE MIMETYPE " + fileRes.mimeType());
ScopeProvider.instance.set(scope);
UriResolverManager resolver = new UriResolverManager("SMP");
Map<String, String> params = new HashMap<String, String>();
params.put("smp-uri", fileRes.url());
params.put("fileName", FileName);
params.put("contentType", "text/plain");
String shortLink = resolver.getLink(params, true);
if ((shortLink!=null)&&(!shortLink.equals(""))){
outputData.setUrlFile(shortLink);
logger.info("dbmanager-> Http link of the generated File: " + shortLink);
}else{
logger.error("dbmanager-> Error in server while generating the file. Http link null");
throw new Exception("Error in server while generating the file.");
}
} else{
// add key value // add key value
mapKeys.put(String.valueOf(i), key); mapKeys.put(String.valueOf(i), key);
SMResource smres = smMap.get(key); SMResource smres = smMap.get(key);
@ -1934,10 +1992,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
mapValues.put(String.valueOf(i), outstring); mapValues.put(String.valueOf(i), outstring);
i++; i++;
} }
}
} }
outputData.setMapValues(mapValues); outputData.setMapValues(mapValues);
outputData.setmapKeys(mapKeys); outputData.setmapKeys(mapKeys);
// logger.info("build the resultMap - finished"); // logger.info("**build the resultMap - finished");
} }
private InputStream getStorageClientInputStream(String url) private InputStream getStorageClientInputStream(String url)
@ -2076,6 +2135,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
if (DBCache.getStatus().toString().equals(Status.STATUS_ALIVE.toString())){ if (DBCache.getStatus().toString().equals(Status.STATUS_ALIVE.toString())){
DBCache.put(data); DBCache.put(data);
logger.trace("dbmanager-> element with key: " + data.getKey().toString()+" added in cache"); logger.trace("dbmanager-> element with key: " + data.getKey().toString()+" added in cache");
logger.info("dbmanager-> ** SIZE OF THE MEMORY STORE: "+ DBCache.calculateInMemorySize());
// logger.trace("dbmanager-> ** SIZE OF THE OFF HEAP"+ DBCache.calculateOffHeapSize());
logger.info("dbmanager-> ** SIZE OF THE DISK STORE SIZE: "+ DBCache.calculateOnDiskSize());
} }
} }
} }
@ -2767,7 +2830,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} }
//TODO ****TO REMOVE //TODO ****TO REMOVE
if (outputParameters!=null){ if (outputParameters!=null){
logger.info("dbmanager-> ***print output "); // logger.info("dbmanager-> ***print output ");
Set<String> keys = outputParameters.keySet(); Set<String> keys = outputParameters.keySet();
Object[] array = keys.toArray(); Object[] array = keys.toArray();