Updated SDMX Codelist Import Op

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@100967 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-10-24 13:06:16 +00:00
parent d56d7044ee
commit cafeb0d1b7
3 changed files with 161 additions and 53 deletions

View File

@ -41,6 +41,7 @@ import org.gcube.common.resources.gcore.utils.Group;
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationProvider;
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationToken;
import org.gcube.data.analysis.tabulardata.commons.utils.Licence;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.TabularResourceType;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.TemplateDescription;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationDefinition;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution;
@ -100,9 +101,6 @@ import org.gcube.data.analysis.tabulardata.service.tabular.metadata.TabularResou
import org.gcube.data.analysis.tabulardata.service.tabular.metadata.ValidSinceMetadata;
import org.gcube.data.analysis.tabulardata.service.tabular.metadata.ValidUntilMetadata;
import org.gcube.data.analysis.tabulardata.service.template.TemplateId;
import org.gcube.datapublishing.sdmx.api.model.SDMXRegistryDescriptor;
import org.gcube.datapublishing.sdmx.api.model.SDMXRegistryInterfaceType;
import org.gcube.datapublishing.sdmx.impl.model.GCubeSDMXRegistryDescriptor;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTService;
import org.gcube.portlets.user.td.gwtservice.server.file.CSVFileUploadSession;
import org.gcube.portlets.user.td.gwtservice.server.file.CodelistMappingFileUploadSession;
@ -129,6 +127,7 @@ import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Norm
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ReplaceBatch;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ReplaceColumn;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ReplaceColumnByExpression;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4SDMXCodelistImport;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4SplitColumn;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4StatisticalOperation;
import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Union;
@ -154,6 +153,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVParserConfiguration;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CheckCSVSession;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsFinalException;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsFlowException;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.extract.ExtractCodelistSession;
@ -2619,17 +2619,16 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
TabularResourceId id = new TabularResourceId(Long.valueOf(trId
checkTRId(trId);
TabularResourceId tabResourceId = new TabularResourceId(Long.valueOf(trId
.getId()));
TabularResource tr = service.getTabularResource(id);
if (tr.isLocked()) {
throw new TDGWTServiceException("Tabular Resource Is Locked");
}
String owner = tr.getOwner();
TabularResource tabularResource = service.getTabularResource(tabResourceId);
checkTabularResourceLocked(tabularResource);
String owner = tabularResource.getOwner();
if (owner != null && owner.compareTo(aslSession.getUsername()) == 0) {
service.removeTabularResource(id);
service.removeTabularResource(tabResourceId);
} else {
throw new TDGWTServiceException(
"You are not the owner of this tabular resource (owner: "
@ -2755,32 +2754,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
/**
*
* @param sdmxImportSession
* @return
*/
protected Map<String, Object> retrieveOperationParameters(
SDMXImportSession sdmxImportSession) {
Map<String, Object> map = new HashMap<String, Object>();
Codelist codelist = sdmxImportSession.getSelectedCodelist();
map.put(Constants.PARAMETER_AGENCY, codelist.getAgencyId());
map.put(Constants.PARAMETER_ID, codelist.getId());
map.put(Constants.PARAMETER_VERSION, codelist.getVersion());
// TODO-GP: Get registry url from client
SDMXRegistryDescriptor descriptor = new GCubeSDMXRegistryDescriptor();
map.put(Constants.PARAMETER_REGISTRYBASEURL,
descriptor.getUrl(SDMXRegistryInterfaceType.RESTV2_1));
return map;
}
/**
* {@inheritDoc}
*/
@ -2797,15 +2771,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService();
// Import SDMX Codelist takes id 200
OperationDefinition importSDMXCodelistOperation = OperationDefinitionMap
.map(OperationsId.SDMXCodelistImport.toString(), service);
TabularResource serviceTR = service.createTabularResource();
TabResource sdmxImportTabResource = sdmxImportSession
.getTabResource();
TabularResource serviceTR = service.createTabularResource();
syncTRMetaData(serviceTR, sdmxImportTabResource);
TRId trId = new TRId(String.valueOf(serviceTR.getId().getValue()));
@ -2814,17 +2784,23 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
SessionUtil
.setSDMXImportTabResource(session, sdmxImportTabResource);
OpExecution4SDMXCodelistImport opEx = new OpExecution4SDMXCodelistImport(service,
sdmxImportSession);
OpExecutionDirector director = new OpExecutionDirector();
director.setOperationExecutionBuilder(opEx);
director.constructOperationExecution();
OperationExecution invocation = director.getOperationExecution();
Map<String, Object> parameterInstance = retrieveOperationParameters(sdmxImportSession);
OperationExecution invocation = new OperationExecution(
importSDMXCodelistOperation.getOperationId(),
parameterInstance);
if (invocation == null) {
throw new TDGWTServiceException(
"Error SDMX Codelist Import: Operation not supported!");
}
logger.debug("OperationInvocation: \n" + invocation.toString());
Task trTask = service.execute(invocation, serviceTR.getId());
logger.debug("Start Task on service: TaskId " + trTask.getId());
TaskWrapper taskWrapper = new TaskWrapper(trTask,
UIOperationsId.SDMXImport, trId);
SessionUtil.setStartedTask(session, taskWrapper);
@ -2838,7 +2814,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
"Security exception, you haven't rights!");
} catch (Throwable e) {
e.printStackTrace();
throw new TDGWTServiceException("Error in Client Library Request: "
throw new TDGWTServiceException("Error in SDMX Import: "
+ e.getLocalizedMessage());
}
}
@ -3954,6 +3930,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
throw new TDGWTServiceException(e.getLocalizedMessage());
}
}
/**
*
@ -3979,6 +3956,32 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
throw new TDGWTServiceException(e.getLocalizedMessage());
}
}
/**
*
* @param service
* @param trId
* @throws TDGWTServiceException
*/
protected void checkTabularResourceIsFlow(TabularResource tabularResource)
throws TDGWTServiceException {
try {
if (tabularResource.getTabularResourceType().compareTo(TabularResourceType.FLOW)==0) {
logger.error("Operation not allowed on a tabular resource of type flow");
throw new TDGWTIsFlowException("Operation not allowed on a tabular resource of type flow");
}
} catch (TDGWTServiceException e) {
throw e;
} catch (SecurityException e) {
throw e;
} catch (Throwable e) {
e.printStackTrace();
throw new TDGWTServiceException(e.getLocalizedMessage());
}
}
/**
*

View File

@ -0,0 +1,68 @@
package org.gcube.portlets.user.td.gwtservice.server.opexecution;
import java.util.HashMap;
import java.util.Map;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationDefinition;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution;
import org.gcube.data.analysis.tabulardata.service.TabularDataService;
import org.gcube.datapublishing.sdmx.api.model.SDMXRegistryDescriptor;
import org.gcube.datapublishing.sdmx.api.model.SDMXRegistryInterfaceType;
import org.gcube.datapublishing.sdmx.impl.model.GCubeSDMXRegistryDescriptor;
import org.gcube.portlets.user.td.gwtservice.server.trservice.OperationDefinitionMap;
import org.gcube.portlets.user.td.gwtservice.shared.Constants;
import org.gcube.portlets.user.td.gwtservice.shared.OperationsId;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXImportSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Operation Execution for sdmx codelist import
*
* @author "Giancarlo Panichi" email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class OpExecution4SDMXCodelistImport extends OpExecutionBuilder {
protected static Logger logger = LoggerFactory
.getLogger(OpExecution4SDMXCodelistImport.class);
private TabularDataService service;
private SDMXImportSession sdmxImportSession;
public OpExecution4SDMXCodelistImport(TabularDataService service,
SDMXImportSession sdmxImportSession) {
this.service = service;
this.sdmxImportSession = sdmxImportSession;
}
@Override
public void buildOpEx() throws TDGWTServiceException {
logger.debug(sdmxImportSession.toString());
OperationDefinition operationDefinition= OperationDefinitionMap
.map(OperationsId.SDMXCodelistImport.toString(), service);
Map<String, Object> map = new HashMap<String, Object>();
Codelist codelist = sdmxImportSession.getSelectedCodelist();
map.put(Constants.PARAMETER_AGENCY, codelist.getAgencyId());
map.put(Constants.PARAMETER_ID, codelist.getId());
map.put(Constants.PARAMETER_VERSION, codelist.getVersion());
// TODO: Get registry url from client
SDMXRegistryDescriptor descriptor = new GCubeSDMXRegistryDescriptor();
map.put(Constants.PARAMETER_REGISTRYBASEURL,
descriptor.getUrl(SDMXRegistryInterfaceType.RESTV2_1));
OperationExecution invocation = new OperationExecution(
operationDefinition.getOperationId(), map);
operationExecutionSpec.setOp(invocation);
}
}

View File

@ -0,0 +1,37 @@
package org.gcube.portlets.user.td.gwtservice.shared.exception;
/**
* ASL Session Expired Exception
*
* @author "Giancarlo Panichi"
*
*/
public class TDGWTIsFlowException extends TDGWTServiceException {
private static final long serialVersionUID = 4306091799912937920L;
/**
*
*/
public TDGWTIsFlowException() {
super();
}
/**
* @param message
*/
public TDGWTIsFlowException(String message) {
super(message);
}
/**
*
* @param message
* @param t
*/
public TDGWTIsFlowException(String message,Throwable t) {
super(message,t);
}
}