Added Generic File to ResourceType

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@112240 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-02-23 17:25:17 +00:00
parent ff146461b9
commit 110596da88
5 changed files with 175 additions and 120 deletions

View File

@ -145,7 +145,7 @@ import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Time
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Union; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Union;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecutionDirector; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecutionDirector;
import org.gcube.portlets.user.td.gwtservice.server.resource.ResourceTDCreator; import org.gcube.portlets.user.td.gwtservice.server.resource.ResourceTDCreator;
import org.gcube.portlets.user.td.gwtservice.server.resource.ResourceTDTypeMap; import org.gcube.portlets.user.td.gwtservice.server.resource.ResourceTypeMap;
import org.gcube.portlets.user.td.gwtservice.server.storage.FilesStorage; import org.gcube.portlets.user.td.gwtservice.server.storage.FilesStorage;
import org.gcube.portlets.user.td.gwtservice.server.trservice.ColumnDataTypeMap; import org.gcube.portlets.user.td.gwtservice.server.trservice.ColumnDataTypeMap;
import org.gcube.portlets.user.td.gwtservice.server.trservice.ExtractReferences; import org.gcube.portlets.user.td.gwtservice.server.trservice.ExtractReferences;
@ -247,10 +247,14 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoad
import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.Direction; import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.Direction;
import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.OrderInfo; import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.OrderInfo;
import org.gcube.portlets.user.td.gwtservice.shared.tr.replacebyexternal.ReplaceByExternalSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.replacebyexternal.ReplaceByExternalSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.InternalURITD;
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.RemoveResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.RemoveResourceSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTD;
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDDescriptor; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDDescriptor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDType; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDType;
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.SaveResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.SaveResourceSession;
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.gwtservice.shared.tr.rows.DeleteRowsSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DeleteRowsSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DuplicatesSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DuplicatesSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.EditRowSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.EditRowSession;
@ -271,6 +275,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession;
import org.gcube.portlets.user.td.gwtservice.shared.uriresolver.UriResolverSession; import org.gcube.portlets.user.td.gwtservice.shared.uriresolver.UriResolverSession;
import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo; import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.gcube.portlets.user.td.widgetcommonevent.shared.mime.MimeTypeSupport;
import org.gcube.portlets.user.td.widgetcommonevent.shared.operations.OperationsId; import org.gcube.portlets.user.td.widgetcommonevent.shared.operations.OperationsId;
import org.gcube.portlets.user.td.widgetcommonevent.shared.operations.UIOperationsId; import org.gcube.portlets.user.td.widgetcommonevent.shared.operations.UIOperationsId;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType; import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType;
@ -8248,9 +8253,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
HashMap<String, TaskWrapper> taskInBackgroundMap = SessionUtil HashMap<String, TaskWrapper> taskInBackgroundMap = SessionUtil
.getTaskInBackgroundMap(session); .getTaskInBackgroundMap(session);
if (taskInBackgroundMap != null && taskInBackgroundMap.size() > 0) { if (taskInBackgroundMap != null && taskInBackgroundMap.size() > 0) {
logger.debug("Tasks In Background : "+taskInBackgroundMap.size()); logger.debug("Tasks In Background : "
+ taskInBackgroundMap.size());
OperationMonitorSession operationMonitorSession; OperationMonitorSession operationMonitorSession;
for (Map.Entry<String, TaskWrapper> taskInBackground : taskInBackgroundMap for (Map.Entry<String, TaskWrapper> taskInBackground : taskInBackgroundMap
.entrySet()) { .entrySet()) {
@ -8388,7 +8393,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
checkTabularResourceLocked(tabularResource); checkTabularResourceLocked(tabularResource);
ResourceType resourceType = ResourceTDTypeMap ResourceType resourceType = ResourceTypeMap
.getResourceType(resourceTDType); .getResourceType(resourceTDType);
List<ResourceDescriptor> resources = service.getResourcesByType( List<ResourceDescriptor> resources = service.getResourcesByType(
@ -8564,8 +8569,20 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
link = resolver.getLink(params, true); // true, link is shorted link = resolver.getLink(params, true); // true, link is shorted
// otherwise none // otherwise none
break; break;
case SMP:
resolver = new UriResolverManager(uriResolverSession
.getApplicationType().toString());
params.put("smp-uri", uriResolverSession.getUuid());
logger.debug("Uri Resolver params: " + params);
link = resolver.getLink(params, true); // true, link is shorted
// otherwise none
break;
default: default:
break; logger.debug("No resolver enable on this application type");
throw new TDGWTServiceException(
"Error retrieving uri from resolver:"
+ " No resolver enable on this application type");
} }
@ -8659,22 +8676,57 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.setSaveResourceSession(session, saveResourceSession); SessionUtil.setSaveResourceSession(session, saveResourceSession);
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getAslSession(session);
logger.debug("SaveResource(): "+saveResourceSession);
FilesStorage storage = new FilesStorage(); FilesStorage storage = new FilesStorage();
logger.debug("Create Item On Workspace: [ uri: "
+ saveResourceSession.getUri() + " ,user: " String mimeType;
+ aslSession.getUsername() + " ,fileName: " MimeTypeSupport mimeTypeSupport = saveResourceSession.getMime();
if (mimeTypeSupport.compareTo(MimeTypeSupport._unknow) == 0) {
mimeType = null;
} else {
mimeType = mimeTypeSupport.getMimeName();
}
ResourceTD resource = saveResourceSession.getResourceTDDescriptor()
.getResourceTD();
String uri=null;
if (resource instanceof StringResourceTD) {
StringResourceTD stringResourceTD=(StringResourceTD)resource;
uri=stringResourceTD.getStringValue();
} else {
if (resource instanceof InternalURITD) {
InternalURITD internalURITD = (InternalURITD) resource;
uri = internalURITD.getUri();
} else {
if (resource instanceof TableResourceTD) {
throw new TDGWTServiceException(
"Save is not supported for this resource!");
} else {
throw new TDGWTServiceException(
"Save is not supported for this resource!");
}
}
}
if (uri == null || uri.isEmpty()) {
throw new TDGWTServiceException(
"This resource does not have valid uri: "+uri);
}
logger.debug("Create Item On Workspace: [uri="
+ uri
+ " ,user: " + aslSession.getUsername() + " ,fileName: "
+ saveResourceSession.getFileName() + " ,fileDescription: " + saveResourceSession.getFileName() + " ,fileDescription: "
+ saveResourceSession.getFileDescription() + " ,mimetype:" + saveResourceSession.getFileDescription() + " ,mimetype:"
+ saveResourceSession.getMimeType() + " ,folder: " + mimeType + " ,folder: "
+ saveResourceSession.getItemId() + "]"); + saveResourceSession.getItemId() + "]");
storage.createItemOnWorkspace(saveResourceSession.getUri(),
aslSession.getUsername(), storage.createItemOnWorkspace(uri, aslSession.getUsername(),
saveResourceSession.getFileName(), saveResourceSession.getFileName(), saveResourceSession.getFileDescription(),
saveResourceSession.getFileDescription(), mimeType, saveResourceSession.getItemId());
saveResourceSession.getMimeType(),
saveResourceSession.getItemId());
return; return;
@ -8806,7 +8858,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
OpExecutionDirector director = new OpExecutionDirector(); OpExecutionDirector director = new OpExecutionDirector();
director.setOperationExecutionBuilder(opEx); director.setOperationExecutionBuilder(opEx);
director.constructOperationExecution(); director.constructOperationExecution();
ArrayList<OperationExecution> invocation = director ArrayList<OperationExecution> invocation = director
.getListOperationExecution(); .getListOperationExecution();

View File

@ -20,22 +20,19 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.TableResourceTD
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* *
* @author giancarlo * @author giancarlo email: <a
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a> * href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* *
*/ */
public class ResourceTDCreator { public class ResourceTDCreator {
protected static Logger logger = LoggerFactory protected static Logger logger = LoggerFactory
.getLogger(ResourceTDCreator.class); .getLogger(ResourceTDCreator.class);
protected static SimpleDateFormat sdf = new SimpleDateFormat( protected static SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd HH:mm"); "yyyy-MM-dd HH:mm");
/** /**
* *
* @param resources * @param resources
@ -48,42 +45,47 @@ public class ResourceTDCreator {
for (ResourceDescriptor resourceDescriptor : resources) { for (ResourceDescriptor resourceDescriptor : resources) {
ResourceTDDescriptor resourceTDDescriptor = null; ResourceTDDescriptor resourceTDDescriptor = null;
long id=resourceDescriptor.getId(); long id = resourceDescriptor.getId();
String name=resourceDescriptor.getName(); String name = resourceDescriptor.getName();
String description=resourceDescriptor.getDescription(); String description = resourceDescriptor.getDescription();
long creatorId=resourceDescriptor.getCreatorId(); long creatorId = resourceDescriptor.getCreatorId();
Resource resource = resourceDescriptor.getResource(); Resource resource = resourceDescriptor.getResource();
if (resource != null) { if (resource != null) {
ResourceTD resourceTD = createResourceTD(resource); ResourceTD resourceTD = createResourceTD(resource);
ResourceType resourceType = resourceDescriptor ResourceType resourceType = resourceDescriptor
.getResourceType(); .getResourceType();
ResourceTDType resourceTDType = ResourceTDTypeMap ResourceTDType resourceTDType = ResourceTypeMap
.getResourceTDType(resourceType); .getResourceTDType(resourceType);
String creationDate=null; String creationDate = null;
try{ try {
creationDate=sdf.format(resourceDescriptor.getCreationDate().getTime()); creationDate = sdf.format(resourceDescriptor
} catch(Throwable e){ .getCreationDate().getTime());
logger.error("ResourceDescription[id="+id+", name="+name+", description="+description+", creatorId="+creatorId+"] has invalid creation date!"); } catch (Throwable e) {
logger.error("ResourceDescription[id=" + id + ", name="
+ name + ", description=" + description
+ ", creatorId=" + creatorId
+ "] has invalid creation date!");
} }
resourceTDDescriptor = new ResourceTDDescriptor(id, name, resourceTDDescriptor = new ResourceTDDescriptor(id, name,
description, creationDate, creatorId, resourceTDType, description, creationDate, creatorId, resourceTDType,
resourceTD); resourceTD);
resourcesTD.add(resourceTDDescriptor); resourcesTD.add(resourceTDDescriptor);
} else { } else {
logger.error("ResourceDescription[id="+id+", name="+name+", description="+description+", creatorId="+creatorId+"] has resource null!"); logger.error("ResourceDescription[id=" + id + ", name=" + name
+ ", description=" + description + ", creatorId="
+ creatorId + "] has resource null!");
} }
} }
logger.debug("Resources retrieved: "+resourcesTD); logger.debug("Resources retrieved: " + resourcesTD);
return resourcesTD; return resourcesTD;
} }
/** /**
* *
* @param resource * @param resource
@ -95,15 +97,15 @@ public class ResourceTDCreator {
Class<? extends Resource> resourceClass = resource.getResourceType(); Class<? extends Resource> resourceClass = resource.getResourceType();
if (resourceClass == InternalURI.class) { if (resourceClass == InternalURI.class) {
InternalURI internalURI = (InternalURI) resource; InternalURI internalURI = (InternalURI) resource;
String uri= internalURI.getUri().toString(); String uri = internalURI.getUri().toString();
return new InternalURITD(internalURI.getFileId(),uri); return new InternalURITD(internalURI.getFileId(), uri);
} else { } else {
if (resourceClass == StringResource.class) { if (resourceClass == StringResource.class) {
StringResource stringResource = (StringResource) resource; StringResource stringResource = (StringResource) resource;
return new StringResourceTD(stringResource.getStringValue()); return new StringResourceTD(stringResource.getStringValue());
} else { } else {
if (resourceClass == TableResource.class) { if (resourceClass == TableResource.class) {
TableResource tableResource = (TableResource) resource; TableResource tableResource = (TableResource) resource;
return new TableResourceTD(tableResource.getTableId() return new TableResourceTD(tableResource.getTableId()
.getValue(), tableResource.getStringValue()); .getValue(), tableResource.getStringValue());
} else { } else {
@ -115,8 +117,5 @@ public class ResourceTDCreator {
return resourceTD; return resourceTD;
} }
} }

View File

@ -2,35 +2,19 @@ package org.gcube.portlets.user.td.gwtservice.server.resource;
import org.gcube.data.analysis.tabulardata.model.resources.ResourceType; import org.gcube.data.analysis.tabulardata.model.resources.ResourceType;
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDType; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ResourceTDTypeMap { /**
*
public static ResourceTDType getResourceTDType(ResourceType resourceType) { * @author "Giancarlo Panichi" email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
switch (resourceType) { *
case CHART: */
return ResourceTDType.CHART; public class ResourceTypeMap {
case CODELIST: protected static Logger logger = LoggerFactory.getLogger(ResourceTypeMap.class);
return ResourceTDType.CODELIST;
case CSV: public static ResourceType getResourceType(ResourceTDType resourceTDType){
return ResourceTDType.CSV;
case GUESSER:
return ResourceTDType.GUESSER;
case JSON:
return ResourceTDType.JSON;
case MAP:
return ResourceTDType.MAP;
case SDMX:
return ResourceTDType.SDMX;
default:
return null;
}
}
public static ResourceType getResourceType(ResourceTDType resourceTDType) {
switch (resourceTDType) { switch (resourceTDType) {
case CHART: case CHART:
return ResourceType.CHART; return ResourceType.CHART;
@ -46,6 +30,35 @@ public class ResourceTDTypeMap {
return ResourceType.MAP; return ResourceType.MAP;
case SDMX: case SDMX:
return ResourceType.SDMX; return ResourceType.SDMX;
case GENERIC_FILE:
return ResourceType.GENERIC_FILE;
case GENERIC_TABLE:
return ResourceType.GENERIC_TABLE;
default:
return null;
}
}
public static ResourceTDType getResourceTDType(ResourceType resourceType){
switch (resourceType) {
case CHART:
return ResourceTDType.CHART;
case CODELIST:
return ResourceTDType.CODELIST;
case CSV:
return ResourceTDType.CSV;
case GUESSER:
return ResourceTDType.GUESSER;
case JSON:
return ResourceTDType.JSON;
case MAP:
return ResourceTDType.MAP;
case SDMX:
return ResourceTDType.SDMX;
case GENERIC_FILE:
return ResourceTDType.GENERIC_FILE;
case GENERIC_TABLE:
return ResourceTDType.GENERIC_TABLE;
default: default:
return null; return null;
@ -53,4 +66,6 @@ public class ResourceTDTypeMap {
} }
} }

View File

@ -1,9 +1,17 @@
package org.gcube.portlets.user.td.gwtservice.shared.tr.resources; package org.gcube.portlets.user.td.gwtservice.shared.tr.resources;
/**
*
* @author giancarlo
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public enum ResourceTDType { public enum ResourceTDType {
CHART("Chart"), GUESSER("Guesser"), MAP("Map"), CODELIST("Codelist"), CSV( CHART("Chart"), GUESSER("Guesser"), MAP("Map"), CODELIST("Codelist"), CSV(
"CSV"), SDMX("SDMX"), JSON("JSON"); "CSV"), SDMX("SDMX"), JSON("JSON"), GENERIC_FILE("Generic File"), GENERIC_TABLE(
"Generic Table");
/** /**
* @param text * @param text
@ -18,5 +26,8 @@ public enum ResourceTDType {
public String toString() { public String toString() {
return id; return id;
} }
} }

View File

@ -3,6 +3,7 @@ package org.gcube.portlets.user.td.gwtservice.shared.tr.resources;
import java.io.Serializable; import java.io.Serializable;
import org.gcube.portlets.user.td.gwtservice.shared.destination.Destination; import org.gcube.portlets.user.td.gwtservice.shared.destination.Destination;
import org.gcube.portlets.user.td.widgetcommonevent.shared.mime.MimeTypeSupport;
/** /**
* *
@ -14,9 +15,8 @@ public class SaveResourceSession implements Serializable {
private static final long serialVersionUID = 2282498402676932983L; private static final long serialVersionUID = 2282498402676932983L;
private String uri; private ResourceTDDescriptor resourceTDDescriptor;
private String mimeType; private MimeTypeSupport mime;
private String extension;
private Destination destination; private Destination destination;
private String itemId; private String itemId;
private String fileName; private String fileName;
@ -26,54 +26,34 @@ public class SaveResourceSession implements Serializable {
super(); super();
} }
/** public SaveResourceSession(ResourceTDDescriptor resourceTDDescriptor,
* MimeTypeSupport mime, Destination destination, String itemId,
* @param uri String fileName, String fileDescription) {
* @param mimeType
* @param extension
* @param destination
* @param itemId
* @param fileName
* @param fileDescription
*/
public SaveResourceSession(String uri, String mimeType, String extension,
Destination destination, String itemId, String fileName,
String fileDescription) {
super(); super();
this.uri = uri; this.resourceTDDescriptor = resourceTDDescriptor;
this.mimeType = mimeType; this.mime = mime;
this.extension = extension;
this.destination = destination; this.destination = destination;
this.itemId = itemId; this.itemId = itemId;
this.fileName = fileName; this.fileName = fileName;
this.fileDescription = fileDescription; this.fileDescription = fileDescription;
} }
public ResourceTDDescriptor getResourceTDDescriptor() {
return resourceTDDescriptor;
public String getUri() {
return uri;
} }
public void setUri(String uri) { public void setResourceTDDescriptor(
this.uri = uri; ResourceTDDescriptor resourceTDDescriptor) {
this.resourceTDDescriptor = resourceTDDescriptor;
} }
public String getMimeType() { public MimeTypeSupport getMime() {
return mimeType; return mime;
} }
public void setMimeType(String mimeType) { public void setMime(MimeTypeSupport mime) {
this.mimeType = mimeType; this.mime = mime;
}
public String getExtension() {
return extension;
}
public void setExtension(String extension) {
this.extension = extension;
} }
public Destination getDestination() { public Destination getDestination() {
@ -110,12 +90,10 @@ public class SaveResourceSession implements Serializable {
@Override @Override
public String toString() { public String toString() {
return "SaveResourceSession [uri=" + uri + ", mimeType=" + mimeType return "SaveResourceSession [resourceTDDescriptor="
+ ", extension=" + extension + ", destination=" + destination + resourceTDDescriptor + ", mime=" + mime + ", destination="
+ ", itemId=" + itemId + ", fileName=" + fileName + destination + ", itemId=" + itemId + ", fileName=" + fileName
+ ", fileDescription=" + fileDescription + "]"; + ", fileDescription=" + fileDescription + "]";
} }
} }