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:
parent
cee14f4964
commit
ccf47b6e04
|
@ -55,7 +55,8 @@ public class SessionUtil {
|
||||||
protected static final String CSV_IMPORT_SESSION = "CSV_IMPORT";
|
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_FILE_UPLOAD_SESSION = "CSV_IMPORT_FILE_UPLOAD";
|
||||||
protected static final String CSV_IMPORT_TASK="CSV_IMPORT_TASK";
|
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 Logger logger = LoggerFactory.getLogger(SessionUtil.class);
|
||||||
|
|
||||||
protected static ASLSession getAslSession(HttpSession httpSession) {
|
protected static ASLSession getAslSession(HttpSession httpSession) {
|
||||||
|
@ -175,6 +176,31 @@ public class SessionUtil {
|
||||||
ASLSession aslSession = getAslSession(httpSession);
|
ASLSession aslSession = getAslSession(httpSession);
|
||||||
ScopeProvider.instance.set(aslSession.getScope().toString());
|
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,
|
public static void setSDMXImportSession(HttpSession httpSession,
|
||||||
SDMXImportSession s) {
|
SDMXImportSession s) {
|
||||||
|
|
|
@ -196,10 +196,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
tr.setMetadata(new NameMetadata(tabResource.getName()));
|
tr.setMetadata(new NameMetadata(tabResource.getName()));
|
||||||
tr.setMetadata(new DescriptionMetadata(tabResource.getDescription()));
|
tr.setMetadata(new DescriptionMetadata(tabResource.getDescription()));
|
||||||
tr.setMetadata(new CreationDateMetadata(date));
|
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()));
|
tr.setMetadata(new RightsMetadata(tabResource.getRight()));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void retriveTRMetadataFromService(TabularResource tr)
|
protected void retriveTRMetadataFromService(TabularResource tr)
|
||||||
|
@ -267,8 +269,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
try {
|
try {
|
||||||
session = this.getThreadLocalRequest().getSession();
|
session = this.getThreadLocalRequest().getSession();
|
||||||
aslSession = SessionUtil.getAslSession(session);
|
aslSession = SessionUtil.getAslSession(session);
|
||||||
service = TabularDataServiceFactory.getService(aslSession.getUsername());
|
service = TabularDataServiceFactory.getService(aslSession
|
||||||
|
.getUsername());
|
||||||
|
|
||||||
List<TabularResource> trs = service.getTabularResources();
|
List<TabularResource> trs = service.getTabularResources();
|
||||||
SessionUtil.setTabularResources(session, trs);
|
SessionUtil.setTabularResources(session, trs);
|
||||||
|
|
||||||
|
@ -311,7 +314,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
throw new TDGWTServiceException(
|
throw new TDGWTServiceException(
|
||||||
"Error removing TabularResource no parameters set");
|
"Error removing TabularResource no parameters set");
|
||||||
}
|
}
|
||||||
service = TabularDataServiceFactory.getService(aslSession.getUsername());
|
service = TabularDataServiceFactory.getService(aslSession
|
||||||
|
.getUsername());
|
||||||
TabularResourceId id = new TabularResourceId(
|
TabularResourceId id = new TabularResourceId(
|
||||||
Long.valueOf(tabResource.getTrId().getId()));
|
Long.valueOf(tabResource.getTrId().getId()));
|
||||||
service.removeTabularResource(id);
|
service.removeTabularResource(id);
|
||||||
|
@ -325,8 +329,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TabResource createTabularResource(TabResource tabResource)
|
public TabResource createTabularResource(TabResource tabResource)
|
||||||
throws TDGWTServiceException {
|
throws TDGWTServiceException {
|
||||||
|
@ -339,7 +341,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
throw new TDGWTServiceException(
|
throw new TDGWTServiceException(
|
||||||
"Error creating new TabularResource no parameters set");
|
"Error creating new TabularResource no parameters set");
|
||||||
}
|
}
|
||||||
service = TabularDataServiceFactory.getService(aslSession.getUsername());
|
service = TabularDataServiceFactory.getService(aslSession
|
||||||
|
.getUsername());
|
||||||
TabularResource serviceTR = service.createTabularResource();
|
TabularResource serviceTR = service.createTabularResource();
|
||||||
Table table = service.getLastTable(serviceTR.getId());
|
Table table = service.getLastTable(serviceTR.getId());
|
||||||
syncTRMetaData(serviceTR, tabResource);
|
syncTRMetaData(serviceTR, tabResource);
|
||||||
|
@ -433,8 +436,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
session = this.getThreadLocalRequest().getSession();
|
session = this.getThreadLocalRequest().getSession();
|
||||||
SessionUtil.setSDMXImportSession(session, sdmxImportSession);
|
SessionUtil.setSDMXImportSession(session, sdmxImportSession);
|
||||||
aslSession = SessionUtil.getAslSession(session);
|
aslSession = SessionUtil.getAslSession(session);
|
||||||
|
|
||||||
service = TabularDataServiceFactory.getService(aslSession.getUsername());
|
service = TabularDataServiceFactory.getService(aslSession
|
||||||
|
.getUsername());
|
||||||
OperationInterface oService = service;
|
OperationInterface oService = service;
|
||||||
TabularResourceInterface trService = service;
|
TabularResourceInterface trService = service;
|
||||||
|
|
||||||
|
@ -626,24 +630,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
return fileUploadSession.getFileUploadMonitor();
|
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
|
@Override
|
||||||
public AvailableCharsetList getAvailableCharset()
|
public AvailableCharsetList getAvailableCharset()
|
||||||
throws TDGWTServiceException {
|
throws TDGWTServiceException {
|
||||||
|
@ -766,7 +752,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
final String HASHEADER = "hasHeader";
|
final String HASHEADER = "hasHeader";
|
||||||
final String SEPARATOR = "separator";
|
final String SEPARATOR = "separator";
|
||||||
final String URL = "url";
|
final String URL = "url";
|
||||||
|
|
||||||
Map<String, Object> parameterInstances = new HashMap<String, Object>();
|
Map<String, Object> parameterInstances = new HashMap<String, Object>();
|
||||||
parameterInstances.put(URL, fileUrlOnStorage);
|
parameterInstances.put(URL, fileUrlOnStorage);
|
||||||
parameterInstances.put(SEPARATOR, fileUploadSession
|
parameterInstances.put(SEPARATOR, fileUploadSession
|
||||||
|
@ -782,8 +768,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void importCSVFileOnService(String user,
|
protected void importCSVFileOnService(String user,
|
||||||
FileUploadSession fileUploadSession, CSVImportSession csvImportSession)
|
FileUploadSession fileUploadSession,
|
||||||
throws TDGWTServiceException {
|
CSVImportSession csvImportSession) throws TDGWTServiceException {
|
||||||
FilesStorage filesStorage = new FilesStorage();
|
FilesStorage filesStorage = new FilesStorage();
|
||||||
|
|
||||||
String fileUrlOnStorage = filesStorage.storageCSVTempFile(user,
|
String fileUrlOnStorage = filesStorage.storageCSVTempFile(user,
|
||||||
|
@ -792,7 +778,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
Map<String, Object> parameterInstance = csvImportFileParameter(
|
Map<String, Object> parameterInstance = csvImportFileParameter(
|
||||||
fileUrlOnStorage, fileUploadSession, csvImportSession);
|
fileUrlOnStorage, fileUploadSession, csvImportSession);
|
||||||
|
|
||||||
service = TabularDataServiceFactory.getService(aslSession.getUsername());
|
service = TabularDataServiceFactory
|
||||||
|
.getService(aslSession.getUsername());
|
||||||
List<EligibleOperation> capabilities = service.getCapabilities();
|
List<EligibleOperation> capabilities = service.getCapabilities();
|
||||||
|
|
||||||
// Import CSV file
|
// Import CSV file
|
||||||
|
@ -802,7 +789,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
OperationInvocation oi = importCSVFileOperation
|
OperationInvocation oi = importCSVFileOperation
|
||||||
.createOperationInvocation(parameterInstance);
|
.createOperationInvocation(parameterInstance);
|
||||||
TabularResource tabularResource = service.createTabularResource();
|
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;
|
Task trTask;
|
||||||
try {
|
try {
|
||||||
trTask = service.execute(oi, tabularResource.getId());
|
trTask = service.execute(oi, tabularResource.getId());
|
||||||
|
@ -816,4 +807,83 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
SessionUtil.setCSVImportFileTask(session, trTask);
|
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());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,9 @@ package org.gcube.portlets.user.td.gwtservice.shared.csv;
|
||||||
|
|
||||||
import java.io.Serializable;
|
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"
|
* @author "Giancarlo Panichi"
|
||||||
|
@ -13,93 +16,66 @@ import java.io.Serializable;
|
||||||
*/
|
*/
|
||||||
public class CSVImportMonitor implements Serializable {
|
public class CSVImportMonitor implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -1150111422206443617L;
|
private static final long serialVersionUID = -5998841163159590481L;
|
||||||
|
|
||||||
protected long totalLenght;
|
protected float progress;
|
||||||
protected long elaboratedLenght;
|
protected State status;
|
||||||
protected CSVImportState state;
|
protected String statusDescription;
|
||||||
protected String failureReason;
|
protected Throwable error;
|
||||||
protected String failureDetails;
|
protected TRId trId;
|
||||||
|
|
||||||
public CSVImportMonitor(){
|
public float getProgress(){
|
||||||
state = CSVImportState.STARTED;
|
return progress;
|
||||||
}
|
};
|
||||||
|
|
||||||
public CSVImportMonitor(long totalLenght, long elaboratedLenght, CSVImportState state, String failureReason) {
|
public State getStatus(){
|
||||||
this.totalLenght = totalLenght;
|
return status;
|
||||||
this.elaboratedLenght = elaboratedLenght;
|
|
||||||
this.state = state;
|
|
||||||
this.failureReason = failureReason;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the totalLenght
|
|
||||||
*/
|
|
||||||
public long getTotalLenght() {
|
|
||||||
return totalLenght;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public String getStatusDescription(){
|
||||||
* @return the elaboratedLenght
|
return statusDescription;
|
||||||
*/
|
|
||||||
public long getElaboratedLenght() {
|
|
||||||
return elaboratedLenght;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setProgress(float progress) {
|
||||||
|
this.progress = progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(State status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
public CSVImportState getState(){
|
public void setStatus(int status) {
|
||||||
return state;
|
this.status = State.values()[status];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void setStatusDescription(String statusDescription) {
|
||||||
* @return the failureDetails
|
this.statusDescription = statusDescription;
|
||||||
*/
|
|
||||||
public String getFailureDetails() {
|
|
||||||
return failureDetails;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setState(CSVImportState state)
|
public Throwable getError() {
|
||||||
{
|
return error;
|
||||||
this.state = state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void setError(Throwable error) {
|
||||||
* @return the reason
|
this.error = error;
|
||||||
*/
|
|
||||||
public String getFailureReason() {
|
|
||||||
return failureReason;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public TRId getTrId() {
|
||||||
* @param totalLenght the totalLenght to set
|
return trId;
|
||||||
*/
|
|
||||||
public void setTotalLenght(long totalLenght) {
|
|
||||||
this.totalLenght = totalLenght;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void setTrId(TRId trId) {
|
||||||
* @param elaboratedLenght the elaboratedLenght to set
|
this.trId = trId;
|
||||||
*/
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "CSVImportMonitor [totalLenght=" + totalLenght
|
return "SDMXImportMonitor [progress=" + progress + ", status=" + status
|
||||||
+ ", elaboratedLenght=" + elaboratedLenght + ", state=" + state
|
+ ", statusDescription=" + statusDescription + ", error="
|
||||||
+ ", failureReason=" + failureReason + ", failureDetails="
|
+ error + ", trId=" + trId + "]";
|
||||||
+ failureDetails + "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue