Updated Resource
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@113635 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
40aff27b87
commit
7bd02e8ba1
11
pom.xml
11
pom.xml
|
@ -73,7 +73,7 @@
|
|||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
|
@ -187,7 +187,7 @@
|
|||
<artifactId>uri-resolver-manager</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- R-Connector-Client -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.data.analysis</groupId>
|
||||
|
@ -203,6 +203,13 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Tika -->
|
||||
<dependency>
|
||||
<groupId>org.apache.tika</groupId>
|
||||
<artifactId>tika-core</artifactId>
|
||||
<version>1.7</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<!-- LOGGING -->
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.td.gwtservice.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.tika.config.TikaConfig;
|
||||
import org.apache.tika.metadata.Metadata;
|
||||
import org.apache.tika.mime.MediaType;
|
||||
import org.gcube.portlets.user.td.gwtservice.server.storage.FilesStorage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Returns a file from storage and discover mime type
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class RetrieveFileAndDiscoverMimeTypeServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = -1649268678733476057L;
|
||||
|
||||
private static Logger logger = LoggerFactory
|
||||
.getLogger(RetrieveFileAndDiscoverMimeTypeServlet.class);
|
||||
|
||||
private static final String ATTRIBUTE_STORAGE_URI = "storageURI";
|
||||
private static final int BUFSIZE = 4096;
|
||||
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
handleRequest(req, resp);
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
handleRequest(req, resp);
|
||||
}
|
||||
|
||||
protected void handleRequest(HttpServletRequest request,
|
||||
HttpServletResponse response) throws ServletException, IOException {
|
||||
try {
|
||||
logger.info("RetrieveFileAndDiscoverMimeTypeServlet");
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
HttpSession session = request.getSession();
|
||||
|
||||
if (session == null) {
|
||||
logger.error("Error getting the session, no session valid found: "
|
||||
+ session);
|
||||
response.sendError(
|
||||
HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
|
||||
"ERROR-Error getting the user session, no session found "
|
||||
+ session);
|
||||
return;
|
||||
}
|
||||
logger.debug("RetrieveFileAndDiscoverMimeTypeServlet session id: "
|
||||
+ session.getId());
|
||||
|
||||
SessionUtil.getAslSession(session);
|
||||
String uri = (String) request.getParameter(ATTRIBUTE_STORAGE_URI);
|
||||
logger.debug("Request storage uri: " + uri);
|
||||
|
||||
if (uri == null || uri.isEmpty()) {
|
||||
logger.error("Error getting request uri: " + uri);
|
||||
response.sendError(
|
||||
HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
|
||||
"ERROR-Error getting request uri: " + session);
|
||||
return;
|
||||
}
|
||||
|
||||
FilesStorage storage = new FilesStorage();
|
||||
InputStream inMime = storage.retrieveImputStream(uri);
|
||||
|
||||
TikaConfig tika = new TikaConfig();
|
||||
|
||||
|
||||
MediaType mimeType=null;
|
||||
try {
|
||||
mimeType = tika.getDetector().detect(
|
||||
inMime, new Metadata());
|
||||
|
||||
} catch(Throwable e){
|
||||
logger.error("RetrieveFileAndDiscoverMimeTypeServlet parse: "+e.getLocalizedMessage());
|
||||
} finally {
|
||||
inMime.close();
|
||||
}
|
||||
|
||||
|
||||
if (mimeType == null) {
|
||||
response.setContentType("unknown");
|
||||
logger.debug("Discover Mime Type: unknown");
|
||||
} else {
|
||||
response.setContentType(mimeType.toString());
|
||||
logger.debug("Discover Mime Type: "+mimeType.toString());
|
||||
|
||||
}
|
||||
|
||||
InputStream in = storage.retrieveImputStream(uri);
|
||||
|
||||
OutputStream out = response.getOutputStream();
|
||||
|
||||
byte[] byteBuffer = new byte[BUFSIZE];
|
||||
|
||||
|
||||
int length = 0;
|
||||
while ((in != null) && ((length = in.read(byteBuffer)) != -1)) {
|
||||
out.write(byteBuffer, 0, length);
|
||||
}
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
in.close();
|
||||
out.close();
|
||||
|
||||
logger.trace("Response in "
|
||||
+ (System.currentTimeMillis() - startTime));
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error("Error retrieving file from storage: "
|
||||
+ e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
response.sendError(
|
||||
HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
|
||||
"Error retrieving file from storage: "
|
||||
+ e.getLocalizedMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,8 +22,10 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
|
@ -321,6 +323,24 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|||
private static SimpleDateFormat sdfPerformance = new SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss.SSS");
|
||||
|
||||
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
super.init();
|
||||
//Handler.activateProtocol();
|
||||
//logger.debug("Activated SMP Handler");
|
||||
/*
|
||||
ConfigurableStreamHandlerFactory confStreamHandlerFactory = new ConfigurableStreamHandlerFactory(
|
||||
"smp", new Handler());
|
||||
|
||||
URL.setURLStreamHandlerFactory(confStreamHandlerFactory);
|
||||
logger.debug("Activated SMP Handler");
|
||||
*/
|
||||
Properties props=System.getProperties();
|
||||
logger.debug("System Properties: "+props);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* {@inheritDoc}
|
||||
|
@ -600,7 +620,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|||
public TRId restoreUISession(TRId startTRId) throws TDGWTServiceException {
|
||||
try {
|
||||
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||
ASLSession aslSession=SessionUtil.getAslSession(session);
|
||||
ASLSession aslSession = SessionUtil.getAslSession(session);
|
||||
if (startTRId == null || startTRId.getId() == null
|
||||
|| startTRId.getId().isEmpty()) {
|
||||
|
||||
|
@ -620,14 +640,14 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|||
}
|
||||
return trId;
|
||||
} else {
|
||||
logger.debug("Restore UI Session() request TabularResource:" + startTRId);
|
||||
SessionUtil
|
||||
.removeAllFromCurrentTabularResourcesOpen(session);
|
||||
|
||||
logger.debug("Restore UI Session() request TabularResource:"
|
||||
+ startTRId);
|
||||
SessionUtil.removeAllFromCurrentTabularResourcesOpen(session);
|
||||
|
||||
AuthorizationProvider.instance.set(new AuthorizationToken(
|
||||
aslSession.getUsername(), aslSession.getScope()));
|
||||
TabularDataService service = TabularDataServiceFactory.getService();
|
||||
|
||||
TabularDataService service = TabularDataServiceFactory
|
||||
.getService();
|
||||
|
||||
TabularResourceId tabularResourceId = new TabularResourceId(
|
||||
Long.valueOf(startTRId.getId()));
|
||||
|
@ -635,16 +655,18 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|||
.getTabularResource(tabularResourceId);
|
||||
|
||||
checkTabularResourceLocked(tabularResource);
|
||||
|
||||
TabResource tabResource=retrieveTRMetadataFromServiceAndLastTable(service, tabularResource, 1);
|
||||
|
||||
if(tabResource.getTrId()==null|| tabResource.getTrId().getId()==null||
|
||||
tabResource.getTrId().getId().isEmpty()){
|
||||
|
||||
TabResource tabResource = retrieveTRMetadataFromServiceAndLastTable(
|
||||
service, tabularResource, 1);
|
||||
|
||||
if (tabResource.getTrId() == null
|
||||
|| tabResource.getTrId().getId() == null
|
||||
|| tabResource.getTrId().getId().isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
setCurrentTabResource(tabResource, session);
|
||||
}
|
||||
|
||||
|
||||
return tabResource.getTrId();
|
||||
}
|
||||
|
||||
|
@ -693,8 +715,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|||
TDGWTSessionExpiredException {
|
||||
if (tabResource == null) {
|
||||
logger.error("Error setting TabResource: null");
|
||||
throw new TDGWTServiceException(
|
||||
"Error setting TabResource: null");
|
||||
throw new TDGWTServiceException("Error setting TabResource: null");
|
||||
}
|
||||
|
||||
SessionUtil.setTabResource(session, tabResource);
|
||||
|
@ -4335,7 +4356,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|||
ArrayList<Validations> vList = new ArrayList<Validations>();
|
||||
int i = 0;
|
||||
for (Validation v : vals) {
|
||||
valid = new Validations(String.valueOf(i),"",
|
||||
valid = new Validations(String.valueOf(i), "",
|
||||
v.getDescription(), v.isValid(), null, null);
|
||||
vList.add(valid);
|
||||
i++;
|
||||
|
@ -6865,12 +6886,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|||
ArrayList<Validations> validations = new ArrayList<Validations>();
|
||||
for (ValidationDescriptor val : job.getValidations()) {
|
||||
Validations validation = new Validations(
|
||||
String.valueOf(i),val.getTitle(), val.getDescription(),
|
||||
val.isValid(),
|
||||
String.valueOf(i), val.getTitle(),
|
||||
val.getDescription(), val.isValid(),
|
||||
ConditionCodeMap.mapConditionCode(val
|
||||
.getConditionCode()),
|
||||
val.getValidationColumn());
|
||||
|
||||
|
||||
validations.add(validation);
|
||||
i++;
|
||||
}
|
||||
|
@ -6899,12 +6920,13 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|||
operationExecution.getOperationId(), mapSent,
|
||||
task.getId().getValue(), refColumn);
|
||||
}
|
||||
|
||||
JobSClassifier jobClassifier=JobClassifierMap.map(job.getJobClassifier());
|
||||
|
||||
|
||||
JobSClassifier jobClassifier = JobClassifierMap.map(job
|
||||
.getJobClassifier());
|
||||
|
||||
JobS jobS = new JobS(String.valueOf(j), job.getProgress(),
|
||||
job.getHumaReadableStatus(), jobClassifier, job.getDescription(),
|
||||
validations, invocationS);
|
||||
job.getHumaReadableStatus(), jobClassifier,
|
||||
job.getDescription(), validations, invocationS);
|
||||
jobSList.add(jobS);
|
||||
j++;
|
||||
|
||||
|
@ -8795,7 +8817,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|||
} else {
|
||||
if (resource instanceof InternalURITD) {
|
||||
InternalURITD internalURITD = (InternalURITD) resource;
|
||||
uri = internalURITD.getUri();
|
||||
uri = internalURITD.getUrl();
|
||||
} else {
|
||||
if (resource instanceof TableResourceTD) {
|
||||
throw new TDGWTServiceException(
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.gcube.data.analysis.tabulardata.model.resources.Resource;
|
|||
import org.gcube.data.analysis.tabulardata.model.resources.ResourceType;
|
||||
import org.gcube.data.analysis.tabulardata.model.resources.StringResource;
|
||||
import org.gcube.data.analysis.tabulardata.model.resources.TableResource;
|
||||
import org.gcube.data.analysis.tabulardata.model.resources.Thumbnail;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.InternalURITD;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTD;
|
||||
|
@ -17,6 +18,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDDescr
|
|||
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDType;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.StringResourceTD;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.TableResourceTD;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.mime.MimeTypeSupport;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.thumbnail.ThumbnailTD;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -93,12 +96,23 @@ public class ResourceTDCreator {
|
|||
*/
|
||||
protected ResourceTD createResourceTD(Resource resource) {
|
||||
ResourceTD resourceTD = null;
|
||||
|
||||
|
||||
Class<? extends Resource> resourceClass = resource.getResourceType();
|
||||
if (resourceClass == InternalURI.class) {
|
||||
|
||||
InternalURI internalURI = (InternalURI) resource;
|
||||
String uri = internalURI.getUri().toString();
|
||||
return new InternalURITD(internalURI.getFileId(), uri);
|
||||
String url = internalURI.getUrl().toString();
|
||||
MimeTypeSupport mimeTypeSupport = MimeTypeSupport
|
||||
.getMimeTypeSupportFromMimeName(internalURI.getMimeType()
|
||||
.getValue());
|
||||
Thumbnail thumbnail = internalURI.getThumbnail();
|
||||
MimeTypeSupport mimeTypeThumbnail = MimeTypeSupport
|
||||
.getMimeTypeSupportFromMimeName(thumbnail.getMimeType()
|
||||
.getValue());
|
||||
ThumbnailTD thumbnailTD = new ThumbnailTD(thumbnail.getUrl()
|
||||
.toString(), mimeTypeThumbnail);
|
||||
return new InternalURITD(internalURI.getFileId(), url,
|
||||
mimeTypeSupport, thumbnailTD);
|
||||
} else {
|
||||
if (resourceClass == StringResource.class) {
|
||||
StringResource stringResource = (StringResource) resource;
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package org.gcube.portlets.user.td.gwtservice.shared.tr.resources;
|
||||
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.mime.MimeTypeSupport;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.thumbnail.ThumbnailTD;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author giancarlo
|
||||
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
* @author giancarlo email: <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class InternalURITD extends ResourceTD {
|
||||
|
@ -12,28 +14,35 @@ public class InternalURITD extends ResourceTD {
|
|||
|
||||
private String fileId;
|
||||
|
||||
private String uri;
|
||||
private String url;
|
||||
|
||||
private MimeTypeSupport mimeTypeSupport;
|
||||
|
||||
private ThumbnailTD thumbnailTD;
|
||||
|
||||
public InternalURITD() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fileId
|
||||
* @param uri
|
||||
* @param url
|
||||
*/
|
||||
public InternalURITD(String fileId, String uri) {
|
||||
super(uri);
|
||||
public InternalURITD(String fileId, String url,
|
||||
MimeTypeSupport mimeTypeSupport, ThumbnailTD thumbnailTD) {
|
||||
super(url);
|
||||
this.fileId = fileId;
|
||||
this.uri = uri;
|
||||
this.url = url;
|
||||
this.mimeTypeSupport=mimeTypeSupport;
|
||||
this.thumbnailTD=thumbnailTD;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getStringValue() {
|
||||
return uri;
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
public String getFileId() {
|
||||
return fileId;
|
||||
}
|
||||
|
@ -42,21 +51,38 @@ public class InternalURITD extends ResourceTD {
|
|||
this.fileId = fileId;
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return uri;
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setUri(String uri) {
|
||||
this.uri = uri;
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public MimeTypeSupport getMimeTypeSupport() {
|
||||
return mimeTypeSupport;
|
||||
}
|
||||
|
||||
public void setMimeTypeSupport(MimeTypeSupport mimeTypeSupport) {
|
||||
this.mimeTypeSupport = mimeTypeSupport;
|
||||
}
|
||||
|
||||
public ThumbnailTD getThumbnailTD() {
|
||||
return thumbnailTD;
|
||||
}
|
||||
|
||||
public void setThumbnailTD(ThumbnailTD thumbnailTD) {
|
||||
this.thumbnailTD = thumbnailTD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "InternalURITD [fileId=" + fileId + ", uri=" + uri + "]";
|
||||
return "InternalURITD [fileId=" + fileId + ", url=" + url
|
||||
+ ", mimeTypeSupport=" + mimeTypeSupport + ", thumbnailTD="
|
||||
+ thumbnailTD + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,10 @@
|
|||
<servlet-class>org.gcube.portlets.user.td.gwtservice.server.RetrieveChartFileServlet</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>RetrieveFileAndDiscoverMimeTypeServlet</servlet-name>
|
||||
<servlet-class>org.gcube.portlets.user.td.gwtservice.server.RetrieveFileAndDiscoverMimeTypeServlet</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>TDRStudioServlet</servlet-name>
|
||||
|
@ -76,6 +80,11 @@
|
|||
<url-pattern>/tdgwtservice/RetrieveChartFileServlet</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>RetrieveFileAndDiscoverMimeTypeServlet</servlet-name>
|
||||
<url-pattern>/tdgwtservice/RetrieveFileAndDiscoverMimeTypeServlet</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>TDRStudioServlet</servlet-name>
|
||||
<url-pattern>/tdgwtservice/TDRStudioServlet</url-pattern>
|
||||
|
|
Loading…
Reference in New Issue