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

View File

@ -52,7 +52,7 @@ public class OpExecution4CSVImport extends OpExecutionBuilder {
String user = aslSession.getUsername(); String user = aslSession.getUsername();
logger.debug("Session User:" + user); logger.debug("Session User:" + user);
String fileUrlOnStorage = loadCSVFileOnStorage(user, String fileIdOnStorage = loadCSVFileOnStorage(user,
fileUploadSession, csvImportSession); fileUploadSession, csvImportSession);
fileUploadSession.getCsvFile().delete(); fileUploadSession.getCsvFile().delete();
@ -61,7 +61,7 @@ public class OpExecution4CSVImport extends OpExecutionBuilder {
.map(OperationsId.CSVImport.toString(), service); .map(OperationsId.CSVImport.toString(), service);
Map<String, Object> map = new HashMap<String, Object>(); 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 map.put(Constants.PARAMETER_SEPARATOR, String
.valueOf(fileUploadSession.getParserConfiguration() .valueOf(fileUploadSession.getParserConfiguration()
.getDelimiter()));// ',' .getDelimiter()));// ','
@ -97,7 +97,7 @@ public class OpExecution4CSVImport extends OpExecutionBuilder {
private String loadCSVFileOnStorage(String user, private String loadCSVFileOnStorage(String user,
CSVFileUploadSession fileUploadSession, CSVFileUploadSession fileUploadSession,
CSVImportSession csvImportSession) throws TDGWTServiceException { CSVImportSession csvImportSession) throws TDGWTServiceException {
String fileUrlOnStorage = null; String fileIdOnStorage = null;
logger.debug("File Storage Access"); logger.debug("File Storage Access");
@ -106,16 +106,16 @@ public class OpExecution4CSVImport extends OpExecutionBuilder {
FilesStorage filesStorage = new FilesStorage(); FilesStorage filesStorage = new FilesStorage();
fileUrlOnStorage = filesStorage.storageCSVTempFile(user, fileIdOnStorage = filesStorage.storageCSVTempFile(user,
fileUploadSession.getCsvFile()); 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( throw new TDGWTServiceException(
"Tabular Data Service error loading file on storage"); "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 TabularDataService service;
private CodelistMappingSession codelistMappingSession; private CodelistMappingSession codelistMappingSession;
private String importUrl; private String storageId;
public OpExecution4CodelistMapping( public OpExecution4CodelistMapping(
TabularDataService service, TabularDataService service,
CodelistMappingSession codelistMappingSession, String importUrl) { CodelistMappingSession codelistMappingSession, String storageId) {
this.service = service; this.service = service;
this.codelistMappingSession = codelistMappingSession; this.codelistMappingSession = codelistMappingSession;
this.importUrl=importUrl; this.storageId=storageId;
} }
@Override @Override
@ -51,7 +51,7 @@ public class OpExecution4CodelistMapping extends OpExecutionBuilder {
operationDefinition = OperationDefinitionMap.map( operationDefinition = OperationDefinitionMap.map(
OperationsId.CodelistMappingImport.toString(), service); OperationsId.CodelistMappingImport.toString(), service);
map.put(Constants.PARAMETER_URL, importUrl); map.put(Constants.PARAMETER_ID, storageId);
ColumnData columnData=codelistMappingSession.getConnectedColumn(); ColumnData columnData=codelistMappingSession.getConnectedColumn();
long tabId; long tabId;

View File

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

View File

@ -6,6 +6,7 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import org.gcube.common.homelibrary.home.HomeLibrary; import org.gcube.common.homelibrary.home.HomeLibrary;
@ -33,16 +34,18 @@ public class FilesStorage {
public static final Logger logger = LoggerFactory public static final Logger logger = LoggerFactory
.getLogger(FilesStorage.class); .getLogger(FilesStorage.class);
public String storageCSVTempFile(String user, File file) { public String storageCSVTempFile(String user, File file) {
String url = null;
try { try {
IClient client = new StorageClient(user, AccessType.PUBLIC, IClient client = new StorageClient(user, AccessType.PUBLIC,
MemoryType.VOLATILE).getClient(); MemoryType.VOLATILE).getClient();
String remotePath = "/CSVimport/" + file.getName(); String remotePath = "/CSVimport/" + file.getName();
logger.debug("remotePath: " + remotePath); logger.debug("remotePath: " + remotePath);
client.put(true).LFile(file.getAbsolutePath()).RFile(remotePath); String id = client.put(true).LFile(file.getAbsolutePath())
url = client.getUrl().RFile(remotePath); .RFile(remotePath);
// url = client.getUrl().RFile(remotePath);
return id;
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error no csv file loaded on storage" logger.error("Error no csv file loaded on storage"
+ e.getLocalizedMessage()); + e.getLocalizedMessage());
@ -50,25 +53,57 @@ public class FilesStorage {
throw e; throw e;
} }
return url;
} }
public String storageCodelistMappingTempFile(String user, File file) { public String storageCodelistMappingTempFile(String user, File file) {
String url = null;
try { try {
// String url = null;
IClient client = new StorageClient(user, AccessType.PUBLIC, IClient client = new StorageClient(user, AccessType.PUBLIC,
MemoryType.VOLATILE).getClient(); MemoryType.VOLATILE).getClient();
String remotePath = "/CodelistMappingImport/" + file.getName(); String remotePath = "/CodelistMappingImport/" + file.getName();
logger.debug("remotePath: " + remotePath); logger.debug("remotePath: " + remotePath);
client.put(true).LFile(file.getAbsolutePath()).RFile(remotePath); String id = client.put(true).LFile(file.getAbsolutePath())
url = client.getUrl().RFile(remotePath); .RFile(remotePath);
// url = client.getUrl().RFile(remotePath);
return id;
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error no codelist mapping file loaded on storage" logger.error("Error no codelist mapping file loaded on storage"
+ e.getLocalizedMessage()); + e.getLocalizedMessage());
e.printStackTrace(); 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 { try {
org.gcube.common.homelibrary.home.workspace.folder.items.File gcubeItem = ((org.gcube.common.homelibrary.home.workspace.folder.items.File) wi); 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(); * Handler.activateProtocol(); URL smsHome = null; smsHome = new
URL smsHome = null; * URL(gcubeItem.getPublicLink());
smsHome = new URL(gcubeItem.getPublicLink());*/ */
logger.debug("smsHome: [host:" + smsHome.getHost() + " path:" logger.debug("smsHome: [host:" + smsHome.getHost() + " path:"
+ smsHome.getPath() + " ref:" + smsHome.getRef() + smsHome.getPath() + " ref:" + smsHome.getRef()
+ " userinfo:" + smsHome.getUserInfo() + " ]"); + " userinfo:" + smsHome.getUserInfo() + " ]");
@ -145,22 +180,17 @@ public class FilesStorage {
try { try {
org.gcube.common.homelibrary.home.workspace.folder.items.File gcubeItem = ((org.gcube.common.homelibrary.home.workspace.folder.items.File) wi); 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(); * Handler.activateProtocol(); URL smsHome = null; smsHome = new
URL smsHome = null; * URL(null, gcubeItem.getPublicLink(), new URLStreamHandler() {
smsHome = new URL(null, gcubeItem.getPublicLink(), *
new URLStreamHandler() { * @Override protected URLConnection openConnection(URL u) throws
* IOException { return new SMPURLConnection(u); }
@Override *
protected URLConnection openConnection(URL u) * });
throws IOException { */
return new SMPURLConnection(u);
}
});
*/
logger.debug("smsHome: [host:" + smsHome.getHost() + " path:" logger.debug("smsHome: [host:" + smsHome.getHost() + " path:"
+ smsHome.getPath() + " ref:" + smsHome.getRef() + smsHome.getPath() + " ref:" + smsHome.getRef()
+ " userinfo:" + smsHome.getUserInfo() + " ]"); + " userinfo:" + smsHome.getUserInfo() + " ]");
@ -193,20 +223,17 @@ public class FilesStorage {
throws TDGWTServiceException { throws TDGWTServiceException {
InputStream is = null; InputStream is = null;
try { try {
SMPUrl smsHome= new SMPUrl(uri); SMPUrl smsHome = new SMPUrl(uri);
/* /*
Handler.activateProtocol(); * Handler.activateProtocol(); URL smsHome = null; smsHome = new
URL smsHome = null; * URL(null, uri, new URLStreamHandler() {
smsHome = new URL(null, uri, new URLStreamHandler() { *
* @Override protected URLConnection openConnection(URL u) throws
@Override * IOException { return new SMPURLConnection(u); }
protected URLConnection openConnection(URL u) *
throws IOException { * });
return new SMPURLConnection(u); */
}
});*/
logger.debug("smsHome: [host:" + smsHome.getHost() + " path:" logger.debug("smsHome: [host:" + smsHome.getHost() + " path:"
+ smsHome.getPath() + " ref:" + smsHome.getRef() + smsHome.getPath() + " ref:" + smsHome.getRef()
@ -242,24 +269,22 @@ public class FilesStorage {
InputStream is = null; InputStream is = null;
try { try {
SMPUrl smsHome= new SMPUrl(uri); SMPUrl smsHome = new SMPUrl(uri);
/* /*
URL smsHome = new SMPUrl(); * URL smsHome = new SMPUrl(); smsHome = new URL(null, uri, new
smsHome = new URL(null, uri, new URLStreamHandler() { * URLStreamHandler() {
*
@Override * @Override protected URLConnection openConnection(URL u) throws
protected URLConnection openConnection(URL u) * IOException { return new SMPURLConnection(u); }
throws IOException { *
return new SMPURLConnection(u); * });
} */
});*/
logger.debug("smsHome: [host:" + smsHome.getHost() + " path:" logger.debug("smsHome: [host:" + smsHome.getHost() + " path:"
+ smsHome.getPath() + " ref:" + smsHome.getRef() + smsHome.getPath() + " ref:" + smsHome.getRef()
+ " userinfo:" + smsHome.getUserInfo() + " ]"); + " userinfo:" + smsHome.getUserInfo() + " ]");
URLConnection uc = null; URLConnection uc = null;
uc = (URLConnection) smsHome.openConnection(); uc = (URLConnection) smsHome.openConnection();
is = uc.getInputStream(); 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_VIEW_COLUMNS ="useView";
public static final String PARAMETER_COLUMNS = "columns"; public static final String PARAMETER_COLUMNS = "columns";
public static final String PARAMETER_URL = "url"; 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_REGISTRYBASEURL = "registryBaseUrl";
public static final String PARAMETER_AGENCY = "agency"; 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_VERSION = "version";
public static final String PARAMETER_DATA_TYPE = "dataType"; 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 { public class InternalURITD extends ResourceTD {
private static final long serialVersionUID = -3230438212164027113L; private static final long serialVersionUID = -3230438212164027113L;
private String url; private String id;
private String mimeType; private String mimeType;
@ -24,27 +24,26 @@ public class InternalURITD extends ResourceTD {
/** /**
* *
* @param fileId * @param fileId
* @param url * @param id
*/ */
public InternalURITD(String url, public InternalURITD(String id, String mimeType, ThumbnailTD thumbnailTD) {
String mimeType, ThumbnailTD thumbnailTD) { super(id);
super(url); this.id = id;
this.url = url; this.mimeType = mimeType;
this.mimeType=mimeType; this.thumbnailTD = thumbnailTD;
this.thumbnailTD=thumbnailTD;
} }
@Override @Override
public String getStringValue() { public String getStringValue() {
return url; return id;
} }
public String getUrl() { public String getId() {
return url; return id;
} }
public void setUrl(String url) { public void setId(String id) {
this.url = url; this.id = id;
} }
public String getMimeType() { public String getMimeType() {
@ -65,12 +64,8 @@ public class InternalURITD extends ResourceTD {
@Override @Override
public String toString() { public String toString() {
return "InternalURITD [url=" + url + ", mimeType=" + mimeType return "InternalURITD [id=" + id + ", mimeType=" + mimeType
+ ", thumbnailTD=" + thumbnailTD + "]"; + ", thumbnailTD=" + thumbnailTD + "]";
} }
} }