180: TDM - Portlets must support Storage Id in communications with service

Task-Url: https://support.d4science.org/issues/180

Updated the comunications with Storage

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@115150 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-05-29 13:54:58 +00:00
parent 5d1603580b
commit df78e9c846
7 changed files with 120 additions and 97 deletions

View File

@ -7926,11 +7926,13 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
ASLSession aslSession, String user,
CodelistMappingSession codelistMappingSession) throws Throwable {
String importUrl = null;
String storageId = null;
if (codelistMappingSession.getSource().getId()
.compareTo(SourceType.URL.toString()) == 0) {
importUrl = codelistMappingSession.getUrl();
FilesStorage filesStorage = new FilesStorage();
storageId = filesStorage
.storageCodelistMappingTempFile(user, codelistMappingSession.getUrl());
} else {
CodelistMappingFileUploadSession codelistMappingFileUploadSession = SessionUtil
.getCodelistMappingFileUploadSession(session);
@ -7940,18 +7942,18 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
logger.debug("File Storage Access");
FilesStorage filesStorage = new FilesStorage();
String fileUrlOnStorage = filesStorage
String fileIdOnStorage = filesStorage
.storageCodelistMappingTempFile(user,
codelistMappingFileUploadSession
.getCodelistMappingFile());
logger.debug("File Url On Storage:" + fileUrlOnStorage);
logger.debug("File Url On Storage:" + fileIdOnStorage);
codelistMappingFileUploadSession.getCodelistMappingFile().delete();
if (fileUrlOnStorage == null || fileUrlOnStorage.isEmpty()) {
if (fileIdOnStorage == null || fileIdOnStorage.isEmpty()) {
throw new TDGWTServiceException(
"Tabular Data Service error loading file on storage");
}
importUrl = fileUrlOnStorage;
storageId = fileIdOnStorage;
}
AuthorizationProvider.instance.set(new AuthorizationToken(aslSession
@ -7970,7 +7972,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
checkTabularResourceIsFinal(tabularResource);
OpExecution4CodelistMapping opEx = new OpExecution4CodelistMapping(
service, codelistMappingSession, importUrl);
service, codelistMappingSession, storageId);
OpExecutionDirector director = new OpExecutionDirector();
director.setOperationExecutionBuilder(opEx);
director.constructOperationExecution();
@ -9035,7 +9037,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
ASLSession aslSession = SessionUtil.getAslSession(session);
logger.debug("SaveResource(): " + saveResourceSession);
FilesStorage storage = new FilesStorage();
String mimeType;
MimeTypeSupport mimeTypeSupport = saveResourceSession.getMime();
@ -9102,7 +9104,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
if (resource instanceof InternalURITD) {
InternalURITD internalURITD = (InternalURITD) resource;
uriResolverSession = new UriResolverSession(
internalURITD.getUrl(), applicationType,
internalURITD.getId(), applicationType,
resourceTDDescriptor.getName(),
internalURITD.getMimeType());
mimeType = internalURITD.getMimeType();
@ -9132,7 +9134,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
+ saveResourceSession.getFileDescription() + " ,mimetype:"
+ mimeType + " ,folder: " + saveResourceSession.getItemId()
+ "]");
FilesStorage storage = new FilesStorage();
storage.createItemOnWorkspace(link, aslSession.getUsername(),
saveResourceSession.getFileName(),
saveResourceSession.getFileDescription(), mimeType,

View File

@ -52,7 +52,7 @@ public class OpExecution4CSVImport extends OpExecutionBuilder {
String user = aslSession.getUsername();
logger.debug("Session User:" + user);
String fileUrlOnStorage = loadCSVFileOnStorage(user,
String fileIdOnStorage = loadCSVFileOnStorage(user,
fileUploadSession, csvImportSession);
fileUploadSession.getCsvFile().delete();
@ -61,7 +61,7 @@ public class OpExecution4CSVImport extends OpExecutionBuilder {
.map(OperationsId.CSVImport.toString(), service);
Map<String, Object> map = new HashMap<String, Object>();
map.put(Constants.PARAMETER_URL, fileUrlOnStorage);
map.put(Constants.PARAMETER_ID, fileIdOnStorage);
map.put(Constants.PARAMETER_SEPARATOR, String
.valueOf(fileUploadSession.getParserConfiguration()
.getDelimiter()));// ','
@ -97,7 +97,7 @@ public class OpExecution4CSVImport extends OpExecutionBuilder {
private String loadCSVFileOnStorage(String user,
CSVFileUploadSession fileUploadSession,
CSVImportSession csvImportSession) throws TDGWTServiceException {
String fileUrlOnStorage = null;
String fileIdOnStorage = null;
logger.debug("File Storage Access");
@ -106,16 +106,16 @@ public class OpExecution4CSVImport extends OpExecutionBuilder {
FilesStorage filesStorage = new FilesStorage();
fileUrlOnStorage = filesStorage.storageCSVTempFile(user,
fileIdOnStorage = filesStorage.storageCSVTempFile(user,
fileUploadSession.getCsvFile());
logger.debug("File Url On Storage:" + fileUrlOnStorage);
logger.debug("File Url On Storage:" + fileIdOnStorage);
if (fileUrlOnStorage == null || fileUrlOnStorage.isEmpty()) {
if (fileIdOnStorage == null || fileIdOnStorage.isEmpty()) {
throw new TDGWTServiceException(
"Tabular Data Service error loading file on storage");
}
return fileUrlOnStorage;
return fileIdOnStorage;
}
}

View File

@ -31,14 +31,14 @@ public class OpExecution4CodelistMapping extends OpExecutionBuilder {
private TabularDataService service;
private CodelistMappingSession codelistMappingSession;
private String importUrl;
private String storageId;
public OpExecution4CodelistMapping(
TabularDataService service,
CodelistMappingSession codelistMappingSession, String importUrl) {
CodelistMappingSession codelistMappingSession, String storageId) {
this.service = service;
this.codelistMappingSession = codelistMappingSession;
this.importUrl=importUrl;
this.storageId=storageId;
}
@Override
@ -51,7 +51,7 @@ public class OpExecution4CodelistMapping extends OpExecutionBuilder {
operationDefinition = OperationDefinitionMap.map(
OperationsId.CodelistMappingImport.toString(), service);
map.put(Constants.PARAMETER_URL, importUrl);
map.put(Constants.PARAMETER_ID, storageId);
ColumnData columnData=codelistMappingSession.getConnectedColumn();
long tabId;

View File

@ -100,7 +100,7 @@ public class ResourceTDCreator {
if (resourceClass == InternalURI.class) {
InternalURI internalURI = (InternalURI) resource;
String url = internalURI.getUri().toString();
String id = internalURI.getUri().toString();
Thumbnail thumbnail = internalURI.getThumbnail();
ThumbnailTD thumbnailTD=null;
@ -110,7 +110,7 @@ public class ResourceTDCreator {
}
return new InternalURITD(url,
return new InternalURITD(id,
internalURI.getMimeType(), thumbnailTD);
} else {
if (resourceClass == StringResource.class) {

View File

@ -6,6 +6,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.gcube.common.homelibrary.home.HomeLibrary;
@ -33,16 +34,18 @@ public class FilesStorage {
public static final Logger logger = LoggerFactory
.getLogger(FilesStorage.class);
public String storageCSVTempFile(String user, File file) {
String url = null;
try {
IClient client = new StorageClient(user, AccessType.PUBLIC,
MemoryType.VOLATILE).getClient();
String remotePath = "/CSVimport/" + file.getName();
logger.debug("remotePath: " + remotePath);
client.put(true).LFile(file.getAbsolutePath()).RFile(remotePath);
url = client.getUrl().RFile(remotePath);
String id = client.put(true).LFile(file.getAbsolutePath())
.RFile(remotePath);
// url = client.getUrl().RFile(remotePath);
return id;
} catch (Throwable e) {
logger.error("Error no csv file loaded on storage"
+ e.getLocalizedMessage());
@ -50,25 +53,57 @@ public class FilesStorage {
throw e;
}
return url;
}
public String storageCodelistMappingTempFile(String user, File file) {
String url = null;
try {
// String url = null;
IClient client = new StorageClient(user, AccessType.PUBLIC,
MemoryType.VOLATILE).getClient();
String remotePath = "/CodelistMappingImport/" + file.getName();
logger.debug("remotePath: " + remotePath);
client.put(true).LFile(file.getAbsolutePath()).RFile(remotePath);
url = client.getUrl().RFile(remotePath);
String id = client.put(true).LFile(file.getAbsolutePath())
.RFile(remotePath);
// url = client.getUrl().RFile(remotePath);
return id;
} catch (Throwable e) {
logger.error("Error no codelist mapping file loaded on storage"
+ e.getLocalizedMessage());
e.printStackTrace();
throw e;
}
}
public String storageCodelistMappingTempFile(String user, String url)
throws TDGWTServiceException {
InputStream is = null;
try {
URL address = new URL(url);
is = address.openStream();
IClient client = new StorageClient(user, AccessType.PUBLIC,
MemoryType.VOLATILE).getClient();
String remotePath = "/CodelistMappingImport/" + address.getFile();
logger.debug("remotePath: " + remotePath);
String id = client.put(true).LFile(is).RFile(remotePath);
is.close();
return id;
} catch (IOException e) {
logger.error("Error no codelist mapping file loaded on storage"
+ e.getLocalizedMessage());
e.printStackTrace();
throw new TDGWTServiceException(
"Error no codelist mapping file loaded on storage"
+ e.getLocalizedMessage());
} catch (Throwable e) {
logger.error("Error no codelist mapping file loaded on storage"
+ e.getLocalizedMessage());
e.printStackTrace();
throw e;
}
return url;
}
/**
@ -88,11 +123,11 @@ public class FilesStorage {
try {
org.gcube.common.homelibrary.home.workspace.folder.items.File gcubeItem = ((org.gcube.common.homelibrary.home.workspace.folder.items.File) wi);
SMPUrl smsHome= new SMPUrl(gcubeItem.getPublicLink());
SMPUrl smsHome = new SMPUrl(gcubeItem.getPublicLink());
/*
Handler.activateProtocol();
URL smsHome = null;
smsHome = new URL(gcubeItem.getPublicLink());*/
* Handler.activateProtocol(); URL smsHome = null; smsHome = new
* URL(gcubeItem.getPublicLink());
*/
logger.debug("smsHome: [host:" + smsHome.getHost() + " path:"
+ smsHome.getPath() + " ref:" + smsHome.getRef()
+ " userinfo:" + smsHome.getUserInfo() + " ]");
@ -145,22 +180,17 @@ public class FilesStorage {
try {
org.gcube.common.homelibrary.home.workspace.folder.items.File gcubeItem = ((org.gcube.common.homelibrary.home.workspace.folder.items.File) wi);
SMPUrl smsHome= new SMPUrl(gcubeItem.getPublicLink());
SMPUrl smsHome = new SMPUrl(gcubeItem.getPublicLink());
/*
Handler.activateProtocol();
URL smsHome = null;
smsHome = new URL(null, gcubeItem.getPublicLink(),
new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL u)
throws IOException {
return new SMPURLConnection(u);
}
});
*/
* Handler.activateProtocol(); URL smsHome = null; smsHome = new
* URL(null, gcubeItem.getPublicLink(), new URLStreamHandler() {
*
* @Override protected URLConnection openConnection(URL u) throws
* IOException { return new SMPURLConnection(u); }
*
* });
*/
logger.debug("smsHome: [host:" + smsHome.getHost() + " path:"
+ smsHome.getPath() + " ref:" + smsHome.getRef()
+ " userinfo:" + smsHome.getUserInfo() + " ]");
@ -193,20 +223,17 @@ public class FilesStorage {
throws TDGWTServiceException {
InputStream is = null;
try {
SMPUrl smsHome= new SMPUrl(uri);
SMPUrl smsHome = new SMPUrl(uri);
/*
Handler.activateProtocol();
URL smsHome = null;
smsHome = new URL(null, uri, new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL u)
throws IOException {
return new SMPURLConnection(u);
}
});*/
* Handler.activateProtocol(); URL smsHome = null; smsHome = new
* URL(null, uri, new URLStreamHandler() {
*
* @Override protected URLConnection openConnection(URL u) throws
* IOException { return new SMPURLConnection(u); }
*
* });
*/
logger.debug("smsHome: [host:" + smsHome.getHost() + " path:"
+ smsHome.getPath() + " ref:" + smsHome.getRef()
@ -242,24 +269,22 @@ public class FilesStorage {
InputStream is = null;
try {
SMPUrl smsHome= new SMPUrl(uri);
SMPUrl smsHome = new SMPUrl(uri);
/*
URL smsHome = new SMPUrl();
smsHome = new URL(null, uri, new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL u)
throws IOException {
return new SMPURLConnection(u);
}
});*/
* URL smsHome = new SMPUrl(); smsHome = new URL(null, uri, new
* URLStreamHandler() {
*
* @Override protected URLConnection openConnection(URL u) throws
* IOException { return new SMPURLConnection(u); }
*
* });
*/
logger.debug("smsHome: [host:" + smsHome.getHost() + " path:"
+ smsHome.getPath() + " ref:" + smsHome.getRef()
+ " userinfo:" + smsHome.getUserInfo() + " ]");
URLConnection uc = null;
uc = (URLConnection) smsHome.openConnection();
is = uc.getInputStream();

View File

@ -27,10 +27,10 @@ public class Constants {
public static final String PARAMETER_VIEW_COLUMNS ="useView";
public static final String PARAMETER_COLUMNS = "columns";
public static final String PARAMETER_URL = "url";
public static final String PARAMETER_ID = "id";
public static final String PARAMETER_REGISTRYBASEURL = "registryBaseUrl";
public static final String PARAMETER_AGENCY = "agency";
public static final String PARAMETER_ID = "id";
public static final String PARAMETER_VERSION = "version";
public static final String PARAMETER_DATA_TYPE = "dataType";

View File

@ -11,7 +11,7 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.thumbnail.ThumbnailTD
public class InternalURITD extends ResourceTD {
private static final long serialVersionUID = -3230438212164027113L;
private String url;
private String id;
private String mimeType;
@ -24,27 +24,26 @@ public class InternalURITD extends ResourceTD {
/**
*
* @param fileId
* @param url
* @param id
*/
public InternalURITD(String url,
String mimeType, ThumbnailTD thumbnailTD) {
super(url);
this.url = url;
this.mimeType=mimeType;
this.thumbnailTD=thumbnailTD;
public InternalURITD(String id, String mimeType, ThumbnailTD thumbnailTD) {
super(id);
this.id = id;
this.mimeType = mimeType;
this.thumbnailTD = thumbnailTD;
}
@Override
public String getStringValue() {
return url;
return id;
}
public String getUrl() {
return url;
public String getId() {
return id;
}
public void setUrl(String url) {
this.url = url;
public void setId(String id) {
this.id = id;
}
public String getMimeType() {
@ -65,12 +64,8 @@ public class InternalURITD extends ResourceTD {
@Override
public String toString() {
return "InternalURITD [url=" + url + ", mimeType=" + mimeType
return "InternalURITD [id=" + id + ", mimeType=" + mimeType
+ ", thumbnailTD=" + thumbnailTD + "]";
}
}