Fixed storage access

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@85511 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2013-11-14 18:21:17 +00:00
parent c13ac377cd
commit c213f62ada
6 changed files with 160 additions and 43 deletions

View File

@ -58,7 +58,7 @@ public interface TDGWTService extends RemoteService {
* @param tr
* @throws TDGWTServiceException
*/
public void setTabResource(TabResource tr) throws TDGWTServiceException;
public void setTabResource(TabResource tabResource) throws TDGWTServiceException;
/**
* Creates a TabResource on Service
@ -86,7 +86,7 @@ public interface TDGWTService extends RemoteService {
* @param s
* @throws TDGWTServiceException
*/
public void setTDOpenSession(TDOpenSession s) throws TDGWTServiceException;
public void setTDOpenSession(TDOpenSession tdOpenSession) throws TDGWTServiceException;
// Import SDMX
@ -120,7 +120,7 @@ public interface TDGWTService extends RemoteService {
* @param s
* @throws TDGWTServiceException
*/
public void setSDMXSession(SDMXImportSession s)
public void setSDMXSession(SDMXImportSession sdmxImportSession)
throws TDGWTServiceException;
@ -131,7 +131,7 @@ public interface TDGWTService extends RemoteService {
* @param s
* @throws TDGWTServiceException
*/
public void startSDMXImport(SDMXImportSession s)
public void startSDMXImport(SDMXImportSession sdmxImportSession)
throws TDGWTServiceException;
@ -159,8 +159,17 @@ public interface TDGWTService extends RemoteService {
* @param s
* @throws TDGWTServiceException
*/
public void setCSVSession(CSVImportSession s) throws TDGWTServiceException;
public void setCSVSession(CSVImportSession csvImportSession) throws TDGWTServiceException;
/**
*
* @param s
* @throws TDGWTServiceException
*/
public void getFileFromWorkspace(CSVImportSession csvImportSession) throws TDGWTServiceException;
/**
*
* @return
@ -197,7 +206,7 @@ public interface TDGWTService extends RemoteService {
* @param s
* @throws TDGWTServiceException
*/
public void startCSVImport(CSVImportSession s) throws TDGWTServiceException;
public void startCSVImport(CSVImportSession csvImportSession) throws TDGWTServiceException;
/**
* Get Operation Monitor during the CSV Import operation

View File

@ -44,7 +44,7 @@ public interface TDGWTServiceAsync {
void getTabularResources(AsyncCallback<List<TabResource>> callback);
//Open
void setTDOpenSession(TDOpenSession s, AsyncCallback<Void> callback);
void setTDOpenSession(TDOpenSession tdOpenSession, AsyncCallback<Void> callback);
//Import SDMX
void getCodelists(AsyncCallback<ArrayList<Codelist>> callback);
@ -53,27 +53,28 @@ public interface TDGWTServiceAsync {
void getAgencies(AsyncCallback<ArrayList<Agencies>> callback);
void setSDMXSession(SDMXImportSession s, AsyncCallback<Void> callback);
void setSDMXSession(SDMXImportSession sdmxImportSession, AsyncCallback<Void> callback);
void getSDMXImportMonitor(AsyncCallback<SDMXImportMonitor> callback);
void startSDMXImport(SDMXImportSession s,AsyncCallback<Void> callback);
void startSDMXImport(SDMXImportSession sdmxImportSession,AsyncCallback<Void> callback);
//Import CSV
void getFileUploadMonitor(AsyncCallback<FileUploadMonitor> callback);
void getCSVImportMonitor(AsyncCallback<CSVImportMonitor> callback);
void setCSVSession(CSVImportSession s, AsyncCallback<Void> callback);
void setCSVSession(CSVImportSession csvImportSession, AsyncCallback<Void> callback);
void getFileFromWorkspace(CSVImportSession csvImportSession, AsyncCallback<Void> callback);
void getAvailableCharset(AsyncCallback<AvailableCharsetList> callback);
void configureCSVParser(String encoding, HeaderPresence headerPresence, char delimiter, char comment, AsyncCallback<ArrayList<String>> callback);
void checkCSV(long errorsLimit, AsyncCallback<ArrayList<CSVRowError> > callback);
void startCSVImport(CSVImportSession s, AsyncCallback<Void> callback);
void startCSVImport(CSVImportSession csvImportSession, AsyncCallback<Void> callback);
}

View File

@ -3,6 +3,7 @@
*/
package org.gcube.portlets.user.td.gwtservice.server;
import java.io.File;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -15,6 +16,12 @@ import java.util.Map;
import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.common.homelibrary.home.Home;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.HomeManager;
import org.gcube.common.homelibrary.home.HomeManagerFactory;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.data.analysis.tabulardata.metadata.NoSuchMetadataException;
import org.gcube.data.analysis.tabulardata.model.table.Table;
import org.gcube.data.analysis.tabulardata.model.table.TableId;
@ -556,18 +563,18 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
throw new TDGWTServiceException(
"Error in importSDMX Status null");
} else {
logger.debug("Service Task.getStatus(): "+task.getStatus());
logger.debug("Service Task.getStatus(): "
+ task.getStatus());
importMonitor.setStatus(task.getStatus().ordinal());
switch (importMonitor.getStatus()) {
case SUCCEDED:
importMonitor.setProgress(task.getProgress());
logger.debug("Task Result: "+task.getResult());
trId.setTableId(String.valueOf(task
.getResult().getOutput().getId()
.getValue()));
logger.debug("Task Result: " + task.getResult());
trId.setTableId(String.valueOf(task.getResult()
.getOutput().getId().getValue()));
sdmxImportTabResource.setTrId(trId);
SessionUtil.setSDMXImportTabResource(
session, sdmxImportTabResource);
SessionUtil.setSDMXImportTabResource(session,
sdmxImportTabResource);
SessionUtil.setTabResource(session,
sdmxImportTabResource);
@ -575,9 +582,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
break;
case FAILED:
if (task.getResult() != null) {
logger.debug("Task exception:"+task.getResult().getException());
importMonitor.setError(new Throwable(task.getResult()
.getException().toString()));
logger.debug("Task exception:"
+ task.getResult().getException());
importMonitor
.setError(new Throwable(task
.getResult().getException()
.toString()));
} else {
logger.debug("Task exception: Error In Import");
importMonitor.setError(new Throwable(
@ -911,14 +921,17 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
throw new TDGWTServiceException(
"Error in importCSV Status null");
} else {
logger.debug("Status: "+task.getStatus());
logger.debug("Status: " + task.getStatus());
importMonitor.setStatus(task.getStatus().ordinal());
switch (importMonitor.getStatus()) {
case FAILED:
if (task.getResult() != null) {
logger.debug("Task exception:"+task.getResult().getException());
importMonitor.setError(new Throwable(task.getResult()
.getException().toString()));
logger.debug("Task exception:"
+ task.getResult().getException());
importMonitor
.setError(new Throwable(task
.getResult().getException()
.toString()));
} else {
logger.debug("Task exception: Error In Import");
importMonitor.setError(new Throwable(
@ -927,10 +940,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
importMonitor.setProgress(task.getProgress());
break;
case SUCCEDED:
logger.debug("Task Result:"+task.getResult());
logger.debug("Task Result:" + task.getResult());
importMonitor.setProgress(task.getProgress());
Table table = task.getResult().getOutput();
logger.debug("Table retrived: " + table.toString());
trId.setTableId(String.valueOf(table.getId()
.getValue()));
@ -971,4 +984,43 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
@Override
public void getFileFromWorkspace(CSVImportSession csvImportSession)
throws TDGWTServiceException {
// TODO Auto-generated method stub
session = this.getThreadLocalRequest().getSession();
aslSession = SessionUtil.getAslSession(session);
try {
HomeManagerFactory factory = HomeLibrary.getHomeManagerFactory();
HomeManager manager = factory.getHomeManager();
Home home = manager.getHome(aslSession.getUsername());
Workspace w=home.getWorkspace();
WorkspaceItem wi=w.getItem(csvImportSession.getItemId());
if(wi==null){
logger.error("error retrieving the item"+csvImportSession.getItemId());
throw new TDGWTServiceException(
"error retrieving the item"+csvImportSession.getItemId());
}
File file=new File("ciao");
FilesStorage filesStorage=new FilesStorage();
filesStorage.retriveFile(aslSession.getUsername(), wi.getRemotePath(), file);
} catch (Exception e) {
e.printStackTrace();
throw new TDGWTServiceException(
"Error in importCSV getFileFromWorkspace: "
+ e.getLocalizedMessage(),e);
}
return;
}
}

View File

@ -1,20 +1,67 @@
package org.gcube.portlets.user.td.gwtservice.server.storage;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.gcube.portlets.user.td.gwtservice.shared.TDGWTServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FilesStorage {
public String storageCSVTempFile(String user, File file) {
public static final Logger logger = LoggerFactory
.getLogger(FilesStorage.class);
public String storageCSVTempFile(String user, File file) {
IClient client = new StorageClient(user, AccessType.PUBLIC,
MemoryType.VOLATILE).getClient();
String remotePath = "/CSVimport/" + file.getName();
client.put(true).LFile(file.getAbsolutePath()).RFile(remotePath);
String url=client.getUrl().RFile(remotePath);
String url = client.getUrl().RFile(remotePath);
return url;
}
public void retriveFile(String user, String remotePath, File file) throws TDGWTServiceException {
IClient client = new StorageClient(user, AccessType.PUBLIC,
MemoryType.VOLATILE).getClient();
InputStream is = null;
try {
is = client.get().RFileAsInputStream(remotePath);
} catch (Exception e) {
logger.error("No payload found in Storage for remotePath: "
+ remotePath,e);
throw new TDGWTServiceException("No payload found in Storage for remotePath: "
+ remotePath,e);
}
try {
BufferedInputStream bis = new BufferedInputStream(is);
FileOutputStream os = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(os);
byte[] buffer = new byte[1024];
int readCount;
while ((readCount = bis.read(buffer)) > 0) {
bos.write(buffer, 0, readCount);
}
bos.close();
} catch (IOException e) {
logger.error("Error trasferring file from storage: "
+ e.getLocalizedMessage(),e);
throw new TDGWTServiceException("Error trasferring file from storage: "
+ e.getLocalizedMessage(),e);
}
}
}

View File

@ -4,7 +4,9 @@
package org.gcube.portlets.user.td.gwtservice.shared;
/**
* @author "Federico De Faveri defaveri@isti.cnr.it"
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class TDGWTServiceException extends Exception {
@ -26,5 +28,9 @@ public class TDGWTServiceException extends Exception {
}
public TDGWTServiceException(String message,Throwable t) {
super(message,t);
}
}

View File

@ -34,7 +34,7 @@ public class CSVImportSession implements Serializable {
protected boolean[] columnToImportMask;
protected String localFileName;
protected String workspaceItemPath;
protected String itemId;
/*protected long fileLenght;
protected String serverlFileName;
@ -46,6 +46,7 @@ public class CSVImportSession implements Serializable {
*/
public String getId() {
return id;
}
@ -88,7 +89,12 @@ public class CSVImportSession implements Serializable {
public void setLocalFileName(String localFileName) {
this.localFileName = localFileName;
}
public String getItemId() {
return itemId;
}
public void setItemId(String itemId) {
this.itemId = itemId;
}
/*
public long getFileLenght() {
return fileLenght;
@ -127,23 +133,19 @@ public class CSVImportSession implements Serializable {
this.csvRights = csvRights;
}
*/
public String getWorkspaceItemPath() {
return workspaceItemPath;
}
public void setWorkspaceItemPath(String workspaceItemPath) {
this.workspaceItemPath = workspaceItemPath;
}
@Override
public String toString() {
return "CSVImportSession [id=" + id + ", source=" + source
+ ", tabResource=" + tabResource + ", headers=" + headers
+ ", skipInvalidLines=" + skipInvalidLines
+ ", columnToImportMask=" + Arrays.toString(columnToImportMask)
+ ", localFileName=" + localFileName + ", workspaceItemPath="
+ workspaceItemPath + "]";
+ ", localFileName=" + localFileName + ", itemId=" + itemId
+ "]";
}
}