Fixed CSVMonitor

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@84784 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2013-10-31 16:22:17 +00:00
parent cee14f4964
commit ccf47b6e04
3 changed files with 171 additions and 99 deletions

View File

@ -55,7 +55,8 @@ public class SessionUtil {
protected static final String CSV_IMPORT_SESSION = "CSV_IMPORT";
protected static final String CSV_IMPORT_FILE_UPLOAD_SESSION = "CSV_IMPORT_FILE_UPLOAD";
protected static final String CSV_IMPORT_TASK="CSV_IMPORT_TASK";
protected static final String CSV_IMPORT_TABULAR_RESOURCE = "CSV_IMPORT_TABULAR_RESOURCE";
protected static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
protected static ASLSession getAslSession(HttpSession httpSession) {
@ -175,6 +176,31 @@ public class SessionUtil {
ASLSession aslSession = getAslSession(httpSession);
ScopeProvider.instance.set(aslSession.getScope().toString());
}
////
public static TabResource getCSVImportTabResource(HttpSession httpSession) {
TabResource tabResource = (TabResource) httpSession
.getAttribute(CSV_IMPORT_TABULAR_RESOURCE);
if (tabResource == null) {
Log.error("CSV_IMPORT_TABULAR_RESOURCE was not acquired");
}
return tabResource;
}
public static void setCSVImportTabResource(HttpSession httpSession,
TabResource tabResource) {
TabResource t = (TabResource) httpSession
.getAttribute(CSV_IMPORT_TABULAR_RESOURCE);
if (t != null)
httpSession.removeAttribute(CSV_IMPORT_TABULAR_RESOURCE);
httpSession.setAttribute(CSV_IMPORT_TABULAR_RESOURCE, tabResource);
ASLSession aslSession = getAslSession(httpSession);
ScopeProvider.instance.set(aslSession.getScope().toString());
}
////
public static void setSDMXImportSession(HttpSession httpSession,
SDMXImportSession s) {

View File

@ -196,10 +196,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
tr.setMetadata(new NameMetadata(tabResource.getName()));
tr.setMetadata(new DescriptionMetadata(tabResource.getDescription()));
tr.setMetadata(new CreationDateMetadata(date));
tr.setMetadata(new AgencyMetadata(tabResource.getAgency()));
if (tabResource.getAgency() != null
&& !tabResource.getAgency().isEmpty()) {
tr.setMetadata(new AgencyMetadata(tabResource.getAgency()));
}
tr.setMetadata(new RightsMetadata(tabResource.getRight()));
}
protected void retriveTRMetadataFromService(TabularResource tr)
@ -267,8 +269,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
try {
session = this.getThreadLocalRequest().getSession();
aslSession = SessionUtil.getAslSession(session);
service = TabularDataServiceFactory.getService(aslSession.getUsername());
service = TabularDataServiceFactory.getService(aslSession
.getUsername());
List<TabularResource> trs = service.getTabularResources();
SessionUtil.setTabularResources(session, trs);
@ -311,7 +314,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
throw new TDGWTServiceException(
"Error removing TabularResource no parameters set");
}
service = TabularDataServiceFactory.getService(aslSession.getUsername());
service = TabularDataServiceFactory.getService(aslSession
.getUsername());
TabularResourceId id = new TabularResourceId(
Long.valueOf(tabResource.getTrId().getId()));
service.removeTabularResource(id);
@ -325,8 +329,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
}
@Override
public TabResource createTabularResource(TabResource tabResource)
throws TDGWTServiceException {
@ -339,7 +341,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
throw new TDGWTServiceException(
"Error creating new TabularResource no parameters set");
}
service = TabularDataServiceFactory.getService(aslSession.getUsername());
service = TabularDataServiceFactory.getService(aslSession
.getUsername());
TabularResource serviceTR = service.createTabularResource();
Table table = service.getLastTable(serviceTR.getId());
syncTRMetaData(serviceTR, tabResource);
@ -433,8 +436,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
session = this.getThreadLocalRequest().getSession();
SessionUtil.setSDMXImportSession(session, sdmxImportSession);
aslSession = SessionUtil.getAslSession(session);
service = TabularDataServiceFactory.getService(aslSession.getUsername());
service = TabularDataServiceFactory.getService(aslSession
.getUsername());
OperationInterface oService = service;
TabularResourceInterface trService = service;
@ -626,24 +630,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
return fileUploadSession.getFileUploadMonitor();
}
@Override
public CSVImportMonitor getCSVImportMonitor() throws TDGWTServiceException {
session = this.getThreadLocalRequest().getSession();
if (session == null) {
throw new TDGWTServiceException(
"Error retrieving the session: null");
}
logger.info("Session:" + session.getId());
FileUploadSession importSession = SessionUtil
.getFileUploadSession(session);
if (importSession == null) {
throw new TDGWTServiceException(
"Error retrieving the fileUploadSession: null");
}
return importSession.getCsvImportMonitor();
}
@Override
public AvailableCharsetList getAvailableCharset()
throws TDGWTServiceException {
@ -766,7 +752,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
final String HASHEADER = "hasHeader";
final String SEPARATOR = "separator";
final String URL = "url";
Map<String, Object> parameterInstances = new HashMap<String, Object>();
parameterInstances.put(URL, fileUrlOnStorage);
parameterInstances.put(SEPARATOR, fileUploadSession
@ -782,8 +768,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
protected void importCSVFileOnService(String user,
FileUploadSession fileUploadSession, CSVImportSession csvImportSession)
throws TDGWTServiceException {
FileUploadSession fileUploadSession,
CSVImportSession csvImportSession) throws TDGWTServiceException {
FilesStorage filesStorage = new FilesStorage();
String fileUrlOnStorage = filesStorage.storageCSVTempFile(user,
@ -792,7 +778,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
Map<String, Object> parameterInstance = csvImportFileParameter(
fileUrlOnStorage, fileUploadSession, csvImportSession);
service = TabularDataServiceFactory.getService(aslSession.getUsername());
service = TabularDataServiceFactory
.getService(aslSession.getUsername());
List<EligibleOperation> capabilities = service.getCapabilities();
// Import CSV file
@ -802,7 +789,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
OperationInvocation oi = importCSVFileOperation
.createOperationInvocation(parameterInstance);
TabularResource tabularResource = service.createTabularResource();
TabResource csvImportTabResource = csvImportSession.getTabResource();
syncTRMetaData(tabularResource, csvImportTabResource);
TRId trId = new TRId(String.valueOf(tabularResource.getId().getValue()));
csvImportTabResource.setTrId(trId);
SessionUtil.setCSVImportTabResource(session, csvImportTabResource);
Task trTask;
try {
trTask = service.execute(oi, tabularResource.getId());
@ -816,4 +807,83 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
SessionUtil.setCSVImportFileTask(session, trTask);
}
@Override
public CSVImportMonitor getCSVImportMonitor() throws TDGWTServiceException {
try {
session = this.getThreadLocalRequest().getSession();
aslSession = SessionUtil.getAslSession(session);
Task task = SessionUtil.getCSVImportFileTask(session);
TabResource csvImportTabResource = SessionUtil
.getCSVImportTabResource(session);
TRId trId = csvImportTabResource.getTrId();
CSVImportMonitor importMonitor = new CSVImportMonitor();
if (trId == null) {
throw new TDGWTServiceException(
"Error in importCSV TabularResource Id null");
} else {
if (task == null) {
throw new TDGWTServiceException(
"Error in importCSV task null");
} else {
ActivityStatus status = task.getStatus();
if (status == null) {
throw new TDGWTServiceException(
"Error in importCSV Status null");
} else {
importMonitor.setStatus(task.getStatus().ordinal());
importMonitor.setProgress(task.getProgress());
JobResult result = task.getResult();
if (result == null) {
logger.info("Task Result: " + task.getResult());
} else {
importMonitor.setError(task.getResult()
.getException());
if (task.getResult().getOutput() == null) {
logger.info("Task Result Output: "
+ task.getResult().getOutput());
} else {
if (task.getResult().getOutput().getId() == null) {
logger.info("Task Result Output Id: "
+ task.getResult().getOutput()
.getId());
} else {
logger.info("Task TableId: "
+ task.getResult().getOutput()
.getId().getValue());
trId.setTableId(String.valueOf(task
.getResult().getOutput().getId()
.getValue()));
csvImportTabResource.setTrId(trId);
SessionUtil.setCSVImportTabResource(
session, csvImportTabResource);
SessionUtil.setTabResource(session,
csvImportTabResource);
SessionUtil.setTRId(session, trId);
}
}
}
}
SessionUtil.setCSVImportFileTask(session, task);
}
importMonitor.setTrId(trId);
}
logger.info("getImportMonitor(): " + importMonitor);
return importMonitor;
} catch (Exception e) {
e.printStackTrace();
throw new TDGWTServiceException(
"Error in importSDMX ImportMonitor: "
+ e.getLocalizedMessage());
}
}
}

View File

@ -5,6 +5,9 @@ package org.gcube.portlets.user.td.gwtservice.shared.csv;
import java.io.Serializable;
import org.gcube.portlets.user.td.gwtservice.shared.TRId;
import org.gcube.portlets.user.td.gwtservice.shared.sdmx.State;
/**
*
* @author "Giancarlo Panichi"
@ -13,93 +16,66 @@ import java.io.Serializable;
*/
public class CSVImportMonitor implements Serializable {
private static final long serialVersionUID = -1150111422206443617L;
private static final long serialVersionUID = -5998841163159590481L;
protected long totalLenght;
protected long elaboratedLenght;
protected CSVImportState state;
protected String failureReason;
protected String failureDetails;
protected float progress;
protected State status;
protected String statusDescription;
protected Throwable error;
protected TRId trId;
public CSVImportMonitor(){
state = CSVImportState.STARTED;
}
public float getProgress(){
return progress;
};
public CSVImportMonitor(long totalLenght, long elaboratedLenght, CSVImportState state, String failureReason) {
this.totalLenght = totalLenght;
this.elaboratedLenght = elaboratedLenght;
this.state = state;
this.failureReason = failureReason;
}
/**
* @return the totalLenght
*/
public long getTotalLenght() {
return totalLenght;
public State getStatus(){
return status;
}
/**
* @return the elaboratedLenght
*/
public long getElaboratedLenght() {
return elaboratedLenght;
public String getStatusDescription(){
return statusDescription;
}
public void setProgress(float progress) {
this.progress = progress;
}
public void setStatus(State status) {
this.status = status;
}
public CSVImportState getState(){
return state;
public void setStatus(int status) {
this.status = State.values()[status];
}
/**
* @return the failureDetails
*/
public String getFailureDetails() {
return failureDetails;
public void setStatusDescription(String statusDescription) {
this.statusDescription = statusDescription;
}
public void setState(CSVImportState state)
{
this.state = state;
public Throwable getError() {
return error;
}
/**
* @return the reason
*/
public String getFailureReason() {
return failureReason;
public void setError(Throwable error) {
this.error = error;
}
/**
* @param totalLenght the totalLenght to set
*/
public void setTotalLenght(long totalLenght) {
this.totalLenght = totalLenght;
public TRId getTrId() {
return trId;
}
/**
* @param elaboratedLenght the elaboratedLenght to set
*/
public void setElaboratedLenght(long elaboratedLenght) {
this.elaboratedLenght = elaboratedLenght;
}
/**
* @param failed the failed to set
*/
public void setFailed(String failureReason, String failureDetails) {
this.state = CSVImportState.FAILED;
this.failureReason = failureReason;
this.failureDetails = failureDetails;
public void setTrId(TRId trId) {
this.trId = trId;
}
@Override
public String toString() {
return "CSVImportMonitor [totalLenght=" + totalLenght
+ ", elaboratedLenght=" + elaboratedLenght + ", state=" + state
+ ", failureReason=" + failureReason + ", failureDetails="
+ failureDetails + "]";
return "SDMXImportMonitor [progress=" + progress + ", status=" + status
+ ", statusDescription=" + statusDescription + ", error="
+ error + ", trId=" + trId + "]";
}
}