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.OpExecutionDirector;
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.trservice.ColumnDataTypeMap;
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.OrderInfo;
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.ResourceTD;
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.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.DuplicatesSession;
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.user.UserInfo;
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.UIOperationsId;
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
.getTaskInBackgroundMap(session);
if (taskInBackgroundMap != null && taskInBackgroundMap.size() > 0) {
logger.debug("Tasks In Background : "+taskInBackgroundMap.size());
logger.debug("Tasks In Background : "
+ taskInBackgroundMap.size());
OperationMonitorSession operationMonitorSession;
for (Map.Entry<String, TaskWrapper> taskInBackground : taskInBackgroundMap
.entrySet()) {
@ -8388,7 +8393,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
checkTabularResourceLocked(tabularResource);
ResourceType resourceType = ResourceTDTypeMap
ResourceType resourceType = ResourceTypeMap
.getResourceType(resourceTDType);
List<ResourceDescriptor> resources = service.getResourcesByType(
@ -8564,8 +8569,20 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
link = resolver.getLink(params, true); // true, link is shorted
// otherwise none
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:
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();
SessionUtil.setSaveResourceSession(session, saveResourceSession);
ASLSession aslSession = SessionUtil.getAslSession(session);
logger.debug("SaveResource(): "+saveResourceSession);
FilesStorage storage = new FilesStorage();
logger.debug("Create Item On Workspace: [ uri: "
+ saveResourceSession.getUri() + " ,user: "
+ aslSession.getUsername() + " ,fileName: "
String mimeType;
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.getFileDescription() + " ,mimetype:"
+ saveResourceSession.getMimeType() + " ,folder: "
+ mimeType + " ,folder: "
+ saveResourceSession.getItemId() + "]");
storage.createItemOnWorkspace(saveResourceSession.getUri(),
aslSession.getUsername(),
saveResourceSession.getFileName(),
saveResourceSession.getFileDescription(),
saveResourceSession.getMimeType(),
saveResourceSession.getItemId());
storage.createItemOnWorkspace(uri, aslSession.getUsername(),
saveResourceSession.getFileName(), saveResourceSession.getFileDescription(),
mimeType, saveResourceSession.getItemId());
return;
@ -8806,7 +8858,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
OpExecutionDirector director = new OpExecutionDirector();
director.setOperationExecutionBuilder(opEx);
director.constructOperationExecution();
ArrayList<OperationExecution> invocation = director
.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.LoggerFactory;
/**
*
* @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 ResourceTDCreator {
protected static Logger logger = LoggerFactory
.getLogger(ResourceTDCreator.class);
protected static SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd HH:mm");
/**
*
* @param resources
@ -48,42 +45,47 @@ public class ResourceTDCreator {
for (ResourceDescriptor resourceDescriptor : resources) {
ResourceTDDescriptor resourceTDDescriptor = null;
long id=resourceDescriptor.getId();
String name=resourceDescriptor.getName();
String description=resourceDescriptor.getDescription();
long creatorId=resourceDescriptor.getCreatorId();
long id = resourceDescriptor.getId();
String name = resourceDescriptor.getName();
String description = resourceDescriptor.getDescription();
long creatorId = resourceDescriptor.getCreatorId();
Resource resource = resourceDescriptor.getResource();
if (resource != null) {
ResourceTD resourceTD = createResourceTD(resource);
ResourceType resourceType = resourceDescriptor
.getResourceType();
ResourceTDType resourceTDType = ResourceTDTypeMap
ResourceTDType resourceTDType = ResourceTypeMap
.getResourceTDType(resourceType);
String creationDate=null;
try{
creationDate=sdf.format(resourceDescriptor.getCreationDate().getTime());
} catch(Throwable e){
logger.error("ResourceDescription[id="+id+", name="+name+", description="+description+", creatorId="+creatorId+"] has invalid creation date!");
String creationDate = null;
try {
creationDate = sdf.format(resourceDescriptor
.getCreationDate().getTime());
} catch (Throwable e) {
logger.error("ResourceDescription[id=" + id + ", name="
+ name + ", description=" + description
+ ", creatorId=" + creatorId
+ "] has invalid creation date!");
}
resourceTDDescriptor = new ResourceTDDescriptor(id, name,
description, creationDate, creatorId, resourceTDType,
resourceTD);
resourcesTD.add(resourceTDDescriptor);
} 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;
}
/**
*
* @param resource
@ -95,15 +97,15 @@ public class ResourceTDCreator {
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 uri = internalURI.getUri().toString();
return new InternalURITD(internalURI.getFileId(), uri);
} else {
if (resourceClass == StringResource.class) {
StringResource stringResource = (StringResource) resource;
return new StringResourceTD(stringResource.getStringValue());
} else {
if (resourceClass == TableResource.class) {
TableResource tableResource = (TableResource) resource;
TableResource tableResource = (TableResource) resource;
return new TableResourceTD(tableResource.getTableId()
.getValue(), tableResource.getStringValue());
} else {
@ -115,8 +117,5 @@ public class ResourceTDCreator {
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.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) {
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;
default:
return null;
}
}
public static ResourceType getResourceType(ResourceTDType resourceTDType) {
/**
*
* @author "Giancarlo Panichi" email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ResourceTypeMap {
protected static Logger logger = LoggerFactory.getLogger(ResourceTypeMap.class);
public static ResourceType getResourceType(ResourceTDType resourceTDType){
switch (resourceTDType) {
case CHART:
return ResourceType.CHART;
@ -46,6 +30,35 @@ public class ResourceTDTypeMap {
return ResourceType.MAP;
case 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:
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;
/**
*
* @author giancarlo
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public enum ResourceTDType {
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
@ -18,5 +26,8 @@ public enum ResourceTDType {
public String toString() {
return id;
}
}

View File

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