code commented removed in GWTdbManagerServiceImpl (methods mainly modified are LoadTables,initVariables,submitQuery,sample,smartSample,randomSample,loadSubmitResult), GxtBorderLayoutPanel classes.

Test class added to test the Uri Resolver.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@101839 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Loredana Liccardo 2014-12-02 16:23:02 +00:00
parent 4102e20eea
commit 7ed18bcc2d
3 changed files with 62 additions and 204 deletions

View File

@ -1153,7 +1153,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// Dialog submitResult = new Dialog();
// submitResult.setLayout(new FitLayout());
//
// //TODO TO MODIFY
// TO MODIFY
// submitResult.setHeading("Result");
// submitResult.setSize(600, 400);
//

View File

@ -81,7 +81,6 @@ import com.extjs.gxt.ui.client.data.PagingLoadResult;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.thoughtworks.xstream.XStream;
import org.apache.bcel.generic.NEWARRAY;
import org.apache.log4j.Logger;
public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
@ -184,14 +183,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
smComputationQuerySamplingNumber = 0;
cacheQuerySamplingHitsNumber = 0;
} catch (Exception e) {
logger.error("dbmanager-> ", e);
throw new ServletException(
"Error while starting the servlet. Exception: " + e);
}
}
public void createCache(String cachePath) throws Exception {
@ -220,9 +217,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// size.maxDepthExceededBehavior(MaxDepthExceededBehavior.ABORT);
// config.sizeOfPolicy(size);
DBCache = new Cache(config);
} catch (Exception e) {
// logger.error("dbmanager-> Error while starting the servlet. Failed to create the cache",
// e);
@ -270,51 +264,21 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
}
cacheManager.shutdown();
} else {
logger.error("dbmanager-> Error while destroying the servlet. Failed to get the cacheManager. cacheManager null");
throw new Exception(
"Error while destroying the servlet. Failed to get the cacheManager. cacheManager null");
}
} catch (Exception e) {
logger.error(
"dbmanager-> Error while destroying the servlet. Exception:",
e);
// e.printStackTrace();
}
// }
}
private void initVariables(ASLSession session) {
// the result generated in the LoadTables method
// List<Result> result = new ArrayList<Result>();
// session.setAttribute("TablesResult", result);
// // map that contains the submit query result and the related uid
// HashMap<String, List<Result>> submitQueryResult = new HashMap<String,
// List<Result>>();
// session.setAttribute("submitQueryResult", submitQueryResult);
// // map that contains the submit query result parsed and the related
// // uid
// HashMap<String, List<Row>> submitQueryResultParsed = new
// HashMap<String, List<Row>>();
// session.setAttribute("submitQueryResultParsed",
// submitQueryResultParsed);
// information about a database
// String currentDB = "";
// session.setAttribute("currentDB", currentDB);
// String previousDB = "";
// session.setAttribute("previousDB", previousDB);
// information about a schema
// String currentSchema = "";
// session.setAttribute("currentSchema", currentSchema);
// String previousSchema = "";
// session.setAttribute("previousSchema", previousSchema);
// Hashmap that contains computationId with a uid key
HashMap<String, String> computationIDMap = new HashMap<String, String>();
session.setAttribute("ComputationIDList", computationIDMap);
@ -381,13 +345,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// initialize variables with application startup
initVariables(session);
return recoverResources(scope);
} catch (Exception e) {
logger.error("dbmanager-> ", e);
throw e;
}
}
// to get information about databases of a resource
@ -410,7 +371,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
logger.error("dbmanager-> ", e);
throw e;
}
}
// to get schema for a database
@ -433,7 +393,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
logger.error("dbmanager-> ", e);
throw e;
}
}
// to get tables
@ -451,7 +410,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
logger.error("dbmanager-> ", e);
throw e;
}
}
// to load tables
@ -460,40 +418,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
LinkedHashMap<String, String> dataInput, String elementType,
boolean SearchTable, String keyword) throws Exception {
// tables' list stored for a user session
// ASLSession session =
// WsUtil.getAslSession(this.getThreadLocalRequest()
// .getSession());
// List<Result> result = (List<Result>) session
// .getAttribute("TablesResult");
// // check on a database
// String currentDB = "";
// currentDB = dataInput.get("DatabaseName");
// String previousDB = (String) session.getAttribute("previousDB");
//
// if (!currentDB.equals(previousDB)) {
// // result = null;
// result = new ArrayList<Result>();
// System.gc();
// }
//
// previousDB = currentDB;
// session.setAttribute("previousDB", previousDB);
//
// // check on a schema
// String currentSchema = "";
// currentSchema = dataInput.get("SchemaName");
// String previousSchema = (String)
// session.getAttribute("previousSchema");
// if (!currentSchema.equals(previousSchema)) {
// // result = null;
// result = new ArrayList<Result>();
// System.gc();
// }
//
// previousSchema = currentSchema;
// session.setAttribute("previousSchema", previousSchema);
// session check
if (isSessionExpired())
throw new SessionExpiredException();
@ -601,7 +525,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// data input
List<Parameter> inputParameters = new ArrayList<Parameter>();
// data output
// List<Result> output = new ArrayList<Result>();
List<Result> output = null;
SubmitQueryResultWithFileFromServlet result = null;
@ -769,29 +692,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
"Error in server while loading data.");
}
// store the result of the submit query operation
// updateSubmitQueryResultMap(UID, output);
// remove job with the specified uid
removeJob(UID);
//TODO ** COMMENTED
// generate the file csv output
// String name = "SubmitQuery";
// String fileName = storeResultIntoCSVFile(output, name);
// get the web application path
// HttpServletRequest request = this
// .getThreadLocalRequest();
// String applicationPath = request.getContextPath();
// // logger.info("dbmanager-> Application Path: " +
// // applicationPath);
// String partialPathFile = applicationPath
// + "/computationResult/" + fileName;
String urlFile=outputData.getUrlFile();
// result = new SubmitQueryResultWithFileFromServlet(
// listAttributes, convertedQuery, partialPathFile, urlFile);
result = new SubmitQueryResultWithFileFromServlet(
listAttributes, convertedQuery, urlFile);
@ -806,8 +712,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
net.sf.ehcache.Element submitQueryResultToCache = new net.sf.ehcache.Element(
keySubmitQueryResult, output);
//TODO **TO DECOMMENT
// updateListSubmitQueryResult(UID, output);
insertDataIntoCache(submitQueryResultToCache);
}
@ -821,7 +726,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} catch (Exception e) {
// e.printStackTrace();
logger.error("dbmanager-> ", e);
// TODO Exception Statistical management to remove a
// Exception Statistical management to remove a
// computation
if (e.getMessage()
.contains(
@ -865,7 +770,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
List<Parameter> inputParameters = new ArrayList<Parameter>();
// output sample result
List<Result> output = new ArrayList<Result>();
// List<Result> outputForFile = new ArrayList<Result>();
SamplingResultWithFileFromServlet result;
String algorithmId = ConstantsPortlet.ALGID_SAMPLEONTABLE;
@ -977,25 +881,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
mapValues.get(String.valueOf(i)));
output.add(row);
//TODO ** COMMENTED
//row truncated
// Result rowForFile = new Result(mapKeys.get(String.valueOf(i)),
// mapValues.get(String.valueOf(i)));
// outputForFile.add(rowForFile);
}
//TODO ** COMMENTED
// String name = "Sampling" + "_" + tab;
// String fileName = storeResultIntoCSVFile(outputForFile, name);
//
// HttpServletRequest request = this.getThreadLocalRequest();
// String applicationPath = request.getContextPath();
// // logger.info("dbmanager-> Application Path: " +
// // applicationPath);
// String partialPathFile = applicationPath
// + "/computationResult/" + fileName;
// result = new SamplingResultWithFileFromServlet(output,
// partialPathFile);
String urlFile=outputData.getUrlFile();
result = new SamplingResultWithFileFromServlet(output, urlFile);
@ -1147,19 +1033,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
output.add(row);
}
//TODO ***COMMENTED
// String name = "SmartSampling" + "_" + tab;
// String fileName = storeResultIntoCSVFile(output, name);
//
// HttpServletRequest request = this.getThreadLocalRequest();
// String applicationPath = request.getContextPath();
// // logger.info("dbmanager-> Application Path: " +
// // applicationPath);
// String partialPathFile = applicationPath
// + "/computationResult/" + fileName;
// result = new SamplingResultWithFileFromServlet(output,
// partialPathFile);
String urlFile=outputData.getUrlFile();
result = new SamplingResultWithFileFromServlet(output, urlFile);
@ -1285,18 +1158,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
output.add(row);
}
//TODO ***COMMENTED
// String name = "RandomSampling" + "_" + tab;
// String fileName = storeResultIntoCSVFile(output, name);
//
// HttpServletRequest request = this.getThreadLocalRequest();
// String applicationPath = request.getContextPath();
// // logger.info("dbmanager-> Application Path: " + applicationPath);
// String partialPathFile = applicationPath + "/computationResult/"
// + fileName;
// SamplingResultWithFileFromServlet obj = new SamplingResultWithFileFromServlet(
// output, partialPathFile);
String urlFile=outputData.getUrlFile();
SamplingResultWithFileFromServlet obj = new SamplingResultWithFileFromServlet(output, urlFile);
@ -1435,31 +1296,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
logger.trace("dbmanager-> Data recovered from cache");
updateListSubmitQueryResult(UID, result);
// data = parseCVSString(result, listAttributes);
//
// int start = config.getOffset();
// int limit = data.size();
//
// if (config.getLimit() > 0) {
// limit = Math.min(start + config.getLimit(), limit);
// }
//
// 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 {
//get the result bound to session
result = getSubmitQueryResult(UID);
logger.trace("dbmanager-> Data recovered from ASL session");
// logger.error("dbmanager-> Error in server while loading data. variable value null");
// throw new Exception("Error in server while loading data.");
}
@ -1836,7 +1677,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
String computationId = factory.executeComputation(request);
float percentage = 0;
// String scope = getScope();
String scope = scopeValue;
String username = getUsername();
@ -1911,12 +1751,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
ComputationOutput outputData, String scope, String FileName) throws Exception {
if (smResType.equals(SMResourceType.OBJECT)) {
// switch (smResType) {
// case FILE:
// SMFile fileRes = (SMFile) smResource;
// System.out.println("Output is a file");
// break;
// case OBJECT:
SMObject objRes = (SMObject) smResource;
if (objRes.name().contentEquals(PrimitiveTypes.MAP.toString())) {
logger.info("dbmanager-> Output is a map");
@ -1926,9 +1761,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
PrimitiveTypes.IMAGES.toString())) {
// logger.info("Output are images");
}
// else
// System.out.println("Output is other");
// rootLogger.log(Level.SEVERE, "Output is other");
}
// StatisticalManager EXCEPTION MANAGEMENT
@ -1972,7 +1805,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
.fromXML(is));
is.close();
// logger.info("**getStorageInputStream - finished");
// logger.info("**build the resultMap - started");
int i = 0;
@ -1987,9 +1819,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// 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());
//TODO *** TO REMOVE
//uriResolver to generate an url http
ScopeProvider.instance.set(scope);
UriResolverManager resolver = new UriResolverManager("SMP");
Map<String, String> params = new HashMap<String, String>();
@ -2196,7 +2027,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} else{
return null;
}
// return data;
}
//method that checks if data retrieved from cache are not corrupted.This fixes an ehcache bug if a big object is moved in the heap.
@ -2216,7 +2046,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// System.out.println("status variable safe: " + safe);
}
}catch (NullPointerException e) {
// TODO: handle exception
logger.error("dbmanager-> ", e);
safe=false;
logger.trace("dbmanager-> data not safe");
@ -2237,7 +2066,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
if(attributes.get(i)==null){
safe=false;
logger.trace("dbmanager-> attributes data not safe");
// System.out.println("status variable safe: " + safe);
//System.out.println("status variable safe: " + safe);
break checkAttributes;
}
}
@ -2248,12 +2077,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
if(elem.getConvertedQuery()==null){
safe=false;
logger.trace("dbmanager-> converted query not safe");
// System.out.println("status variable safe: " + safe);
//System.out.println("status variable safe: " + safe);
}else if(elem.getUrlFile()==null){
//check url file
safe=false;
logger.trace("dbmanager-> file url not safe");
// System.out.println("status variable safe: " + safe);
//System.out.println("status variable safe: " + safe);
}
}
// }
@ -2266,10 +2095,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
if((elem.getProperties()!=null)&&(elem.getProperties().size()==0)){
safe=false;
logger.trace("dbmanager-> data not safe");
// System.out.println("status variable safe: " + safe);
//System.out.println("status variable safe: " + safe);
}
}catch (NullPointerException e) {
// TODO: handle exception
logger.error("dbmanager-> ", e);
safe=false;
logger.trace("dbmanager-> data not safe");
@ -2286,15 +2114,14 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
if((output.get(i).getProperties()!=null)&&(output.get(i).getProperties().size()==0)){
safe=false;
logger.trace("dbmanager-> output not safe");
// System.out.println("status variable safe: " + safe);
//System.out.println("status variable safe: " + safe);
break checkOutput;
}
}catch (NullPointerException e) {
// TODO: handle exception
logger.error("dbmanager-> ", e);
safe=false;
logger.trace("dbmanager-> output not safe");
// System.out.println("status variable safe: " + safe);
//System.out.println("status variable safe: " + safe);
break checkOutput;
}
@ -2306,7 +2133,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
if(elem.getUrlFile()==null){
safe=false;
logger.trace("dbmanager-> file name not safe");
// System.out.println("status variable safe: " + safe);
//System.out.println("status variable safe: " + safe);
}
}
// }
@ -2316,21 +2143,20 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
List<Result> list = new ArrayList<Result>();
list = (ArrayList<Result>)obj;
// System.out.println("size: " + list.size());
//System.out.println("size: " + list.size());
checkResult: for (int i = 0; i < list.size(); i++) {
try{
if ((list.get(i).getProperties()!=null)&&(list.get(i).getProperties().size()==0)){
safe = false;
logger.trace("dbmanager-> data not safe");
// System.out.println("status variable safe: " + safe);
//System.out.println("status variable safe: " + safe);
break checkResult;
};
}catch (NullPointerException e1) {
// TODO: handle exception
logger.error("dbmanager-> ", e1);
safe = false;
logger.trace("dbmanager-> data not safe");
// System.out.println("status variable safe: " + safe);
//System.out.println("status variable safe: " + safe);
break checkResult;
}
@ -2339,21 +2165,20 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
}catch (java.lang.ClassCastException e) {
List<FileModel> list = new ArrayList<FileModel>();
list = (ArrayList<FileModel>)obj;
// System.out.println("size: " + list.size());
//System.out.println("size: " + list.size());
checkFileModel: for (int i = 0; i < list.size(); i++) {
try{
if ((list.get(i).getProperties()!=null)&&(list.get(i).getProperties().size()==0)){
safe = false;
logger.trace("dbmanager-> data not safe");
// System.out.println("status variable safe: " + safe);
//System.out.println("status variable safe: " + safe);
break checkFileModel;
};
}catch (NullPointerException excp) {
// TODO: handle exception
logger.error("dbmanager-> ", excp);
safe = false;
logger.trace("dbmanager-> data not safe");
// System.out.println("status variable safe: " + safe);
//System.out.println("status variable safe: " + safe);
break checkFileModel;
}
@ -2365,7 +2190,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
logger.info("dbmanager-> object is a LinkedHashMap");
LinkedHashMap<String, FileModel> map = new LinkedHashMap<String, FileModel>();
map = (LinkedHashMap<String, FileModel>)obj;
// System.out.println("size: " + map.size());
//System.out.println("size: " + map.size());
Set<String> keys = map.keySet();
Object[] array = keys.toArray();
@ -2374,20 +2199,18 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
if((map.get(array[i].toString()).getProperties()!=null)&&(map.get(array[i].toString()).getProperties().size()==0)){
safe = false;
logger.trace("dbmanager-> data not safe");
// System.out.println("status variable safe: " + safe);
//System.out.println("status variable safe: " + safe);
break checkHashMap;
}
}catch (NullPointerException e) {
// TODO: handle exception
logger.error("dbmanager-> ", e);
logger.error("dbmanager-> ", e);
safe = false;
logger.trace("dbmanager-> data not safe");
// System.out.println("status variable safe: " + safe);
//System.out.println("status variable safe: " + safe);
break checkHashMap;
}
}
}
logger.info("dbmanager-> Safe procedure finished.");
return safe;
}
@ -2410,7 +2233,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// get scope
String scope = session.getScope();
// // call the method related to the element selected
// call the method related to the element selected
String resourceName = "";
String databaseName = "";
@ -3062,7 +2885,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// logger.trace("dbmanager-> element added in cache with key: " + key);
}
}
//TODO ****TO REMOVE
//TODO **TO REMOVE
if (outputParameters!=null){
// logger.info("dbmanager-> ***print output ");
Set<String> keys = outputParameters.keySet();

View File

@ -0,0 +1,35 @@
package org.gcube.portlets.user.databasesmanager.client;
import java.util.HashMap;
import java.util.Map;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
public class Test {
public static void main(String[] args) {
testSMP();
}
public static void testSMP() {
try {
ScopeProvider.instance.set("/gcube/devsec/devVRE");
UriResolverManager resolver = new UriResolverManager("SMP");
Map<String, String> params = new HashMap<String, String>();
params.put("smp-uri","smp://Home/database.manager/Workspace/.applications/StatisticalManager/File14 11 2014 10_41_36?5ezvFfBOLqb3YESyI/kesN4T+ZD0mtmc/4sZ0vGMrl0lgx7k85j8o2Q1vF0ezJi/TEYl7d+F4sKR7EwqeONAlQygGb2MgXevBuU5BA4ahZl9CHdGNt1RznRRA9MqSKeNkz0ze4VoCR7VJeXtBAc6lUJs/lgJNczCGmbP5+HKCzc=");
params.put("fileName", "wikipediaLogo");
params.put("contentType", "text/plain");
// params.put("contentType", "image/jpeg"); //true, link is shorted otherwise none
String shortLink = resolver.getLink(params, true);
System.out.println(shortLink);
} catch (UriResolverMapException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
}
}