Updated to service impl 2.0.0

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@86136 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2013-11-26 10:29:04 +00:00
parent 560bf36210
commit 3e6d59a895
4 changed files with 60 additions and 79 deletions

View File

@ -151,7 +151,7 @@
<dependency> <dependency>
<groupId>org.gcube.data.analysis.tabulardata</groupId> <groupId>org.gcube.data.analysis.tabulardata</groupId>
<artifactId>service-client-impl</artifactId> <artifactId>service-client-impl</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version> <version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
</dependency> </dependency>

View File

@ -36,15 +36,17 @@ import org.gcube.data.analysis.tabulardata.model.metadata.table.TableMetadata;
import org.gcube.data.analysis.tabulardata.model.metadata.table.VersionMetadata; import org.gcube.data.analysis.tabulardata.model.metadata.table.VersionMetadata;
import org.gcube.data.analysis.tabulardata.model.table.Table; import org.gcube.data.analysis.tabulardata.model.table.Table;
import org.gcube.data.analysis.tabulardata.model.table.TableId; import org.gcube.data.analysis.tabulardata.model.table.TableId;
import org.gcube.data.analysis.tabulardata.operation.worker.ActivityStatus; import org.gcube.data.analysis.tabulardata.operation.OperationDescriptor;
import org.gcube.data.analysis.tabulardata.operation.worker.EligibleOperation; import org.gcube.data.analysis.tabulardata.operation.invocation.InvocationCreator;
import org.gcube.data.analysis.tabulardata.operation.worker.OperationInvocation; import org.gcube.data.analysis.tabulardata.operation.invocation.OperationInvocation;
import org.gcube.data.analysis.tabulardata.service.TabularDataService; import org.gcube.data.analysis.tabulardata.service.TabularDataService;
import org.gcube.data.analysis.tabulardata.service.exception.InvalidTabularResourceException; import org.gcube.data.analysis.tabulardata.service.exception.InvalidTabularResourceException;
import org.gcube.data.analysis.tabulardata.service.exception.NoSuchTabularResourceException; import org.gcube.data.analysis.tabulardata.service.exception.NoSuchTabularResourceException;
import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactory; import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactory;
import org.gcube.data.analysis.tabulardata.service.operation.OperationInterface; import org.gcube.data.analysis.tabulardata.service.operation.OperationInterface;
import org.gcube.data.analysis.tabulardata.service.operation.Task; import org.gcube.data.analysis.tabulardata.service.operation.Task;
import org.gcube.data.analysis.tabulardata.service.operation.TaskStatus;
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource; import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource;
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceId; import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceId;
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceInterface; import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceInterface;
@ -546,10 +548,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
OperationInterface oService = service; OperationInterface oService = service;
TabularResourceInterface trService = service; TabularResourceInterface trService = service;
List<EligibleOperation> capabilities = service.getCapabilities(); List<OperationDescriptor> capabilities = service.getCapabilities();
// Import SDMX Codelist takes id 200 // Import SDMX Codelist takes id 200
EligibleOperation importSDMXCodelistOperation = getEligibleOperationWithId( OperationDescriptor importSDMXCodelistOperation = getOperationDescriptorWithId(
OperationsId.SDMXCodelistImport.toString(), capabilities); OperationsId.SDMXCodelistImport.toString(), capabilities);
TabResource importSDMXTabResource = sdmxImportSession TabResource importSDMXTabResource = sdmxImportSession
@ -564,10 +566,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
SessionUtil SessionUtil
.setSDMXImportTabResource(session, importSDMXTabResource); .setSDMXImportTabResource(session, importSDMXTabResource);
Map<String, Object> parameterInstances = retrieveOperationParameters(sdmxImportSession); Map<String, Object> parameterInstance = retrieveOperationParameters(sdmxImportSession);
OperationInvocation invocation = importSDMXCodelistOperation InvocationCreator ic=InvocationCreator.getCreator(importSDMXCodelistOperation);
.createOperationInvocation(parameterInstances); OperationInvocation invocation = ic.setParameters(parameterInstance).create();
logger.debug("OperationInvocation: \n" + invocation.toString()); logger.debug("OperationInvocation: \n" + invocation.toString());
Task trTask = oService.execute(invocation, serviceTR.getId()); Task trTask = oService.execute(invocation, serviceTR.getId());
logger.debug("Start Task on service: TaskId " + trTask.getId()); logger.debug("Start Task on service: TaskId " + trTask.getId());
@ -587,17 +590,16 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
* @return * @return
* @throws TDGWTServiceException * @throws TDGWTServiceException
*/ */
protected EligibleOperation getEligibleOperationWithId(String op, protected OperationDescriptor getOperationDescriptorWithId(String op,
List<EligibleOperation> capabilities) throws TDGWTServiceException { List<OperationDescriptor> capabilities) throws TDGWTServiceException {
for (EligibleOperation operation : capabilities) { for (OperationDescriptor operation : capabilities) {
if (Long.valueOf(op) == operation.getOperationDescriptor() if (Long.valueOf(op) == operation.getOperationId().getValue()) {
.getOperationId().getValue()) {
return operation; return operation;
} }
;
} }
throw new TDGWTServiceException("ElegibleOperation not found"); throw new TDGWTServiceException("OperationDescriptor not found");
} }
@ -625,7 +627,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
"Error in importSDMX task null"); "Error in importSDMX task null");
} else { } else {
logger.debug("Service task: " + task.toString()); logger.debug("Service task: " + task.toString());
ActivityStatus status = task.getStatus(); TaskStatus status = task.getStatus();
if (status == null) { if (status == null) {
throw new TDGWTServiceException( throw new TDGWTServiceException(
"Error in importSDMX Status null"); "Error in importSDMX Status null");
@ -637,8 +639,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
case SUCCEDED: case SUCCEDED:
importMonitor.setProgress(task.getProgress()); importMonitor.setProgress(task.getProgress());
logger.debug("Task Result: " + task.getResult()); logger.debug("Task Result: " + task.getResult());
trId.setTableId(String.valueOf(task.getResult() trId.setTableId(String.valueOf(task.getResult().getPrimaryTable().getId().getValue()));
.getOutput().getId().getValue()));
sdmxImportTabResource.setTrId(trId); sdmxImportTabResource.setTrId(trId);
SessionUtil.setSDMXImportTabResource(session, SessionUtil.setSDMXImportTabResource(session,
sdmxImportTabResource); sdmxImportTabResource);
@ -650,11 +651,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
case FAILED: case FAILED:
if (task.getResult() != null) { if (task.getResult() != null) {
logger.debug("Task exception:" logger.debug("Task exception:"
+ task.getResult().getException()); + task.getErrorMessage());
importMonitor importMonitor
.setError(new Throwable(task .setError(new Throwable(task.getErrorMessage()));
.getResult().getException()
.toString()));
} else { } else {
logger.debug("Task exception: Error In Import"); logger.debug("Task exception: Error In Import");
importMonitor.setError(new Throwable( importMonitor.setError(new Throwable(
@ -930,15 +929,17 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
service = TabularDataServiceFactory service = TabularDataServiceFactory
.getService(aslSession.getUsername()); .getService(aslSession.getUsername());
List<EligibleOperation> capabilities = service.getCapabilities(); List<OperationDescriptor> capabilities = service.getCapabilities();
// Import CSV file // Import CSV file
EligibleOperation importCSVFileOperation = getEligibleOperationWithId(
OperationDescriptor importCSVFileOperation = getOperationDescriptorWithId(
OperationsId.CSVImport.toString(), capabilities); OperationsId.CSVImport.toString(), capabilities);
OperationInvocation oi = importCSVFileOperation InvocationCreator ic=InvocationCreator.getCreator(importCSVFileOperation);
.createOperationInvocation(parameterInstance); OperationInvocation invocation = ic.setParameters(parameterInstance).create();
logger.debug("OperationInvocation: \n" + oi.toString());
logger.debug("OperationInvocation: \n" + invocation.toString());
TabularResource tabularResource = service.createTabularResource(); TabularResource tabularResource = service.createTabularResource();
TabResource csvImportTabResource = csvImportSession.getTabResource(); TabResource csvImportTabResource = csvImportSession.getTabResource();
syncTRMetaData(tabularResource, csvImportTabResource); syncTRMetaData(tabularResource, csvImportTabResource);
@ -947,7 +948,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
SessionUtil.setCSVImportTabResource(session, csvImportTabResource); SessionUtil.setCSVImportTabResource(session, csvImportTabResource);
Task trTask; Task trTask;
try { try {
trTask = service.execute(oi, tabularResource.getId()); trTask = service.execute(invocation, tabularResource.getId());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new TDGWTServiceException( throw new TDGWTServiceException(
@ -983,7 +984,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
throw new TDGWTServiceException( throw new TDGWTServiceException(
"Error in importCSV task null"); "Error in importCSV task null");
} else { } else {
ActivityStatus status = task.getStatus(); TaskStatus status = task.getStatus();
if (status == null) { if (status == null) {
throw new TDGWTServiceException( throw new TDGWTServiceException(
"Error in importCSV Status null"); "Error in importCSV Status null");
@ -994,11 +995,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
case FAILED: case FAILED:
if (task.getResult() != null) { if (task.getResult() != null) {
logger.debug("Task exception:" logger.debug("Task exception:"
+ task.getResult().getException()); + task.getErrorMessage());
importMonitor importMonitor
.setError(new Throwable(task .setError(new Throwable(task.getErrorMessage()));
.getResult().getException()
.toString()));
} else { } else {
logger.debug("Task exception: Error In Import"); logger.debug("Task exception: Error In Import");
importMonitor.setError(new Throwable( importMonitor.setError(new Throwable(
@ -1009,7 +1008,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
case SUCCEDED: case SUCCEDED:
logger.debug("Task Result:" + task.getResult()); logger.debug("Task Result:" + task.getResult());
importMonitor.setProgress(task.getProgress()); importMonitor.setProgress(task.getProgress());
Table table = task.getResult().getOutput(); Table table = task.getResult().getPrimaryTable();
logger.debug("Table retrived: " + table.toString()); logger.debug("Table retrived: " + table.toString());
trId.setTableId(String.valueOf(table.getId() trId.setTableId(String.valueOf(table.getId()
@ -1155,7 +1154,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
TRLocalizedText trLocalizedText=new TRLocalizedText(); TRLocalizedText trLocalizedText=new TRLocalizedText();
trLocalizedText.setId(i); trLocalizedText.setId(i);
trLocalizedText.setValue(lt.getValue()); trLocalizedText.setValue(lt.getValue());
trLocalizedText.setLocaleCode(lt.getLocaleCode()); trLocalizedText.setLocaleCode(lt.getLocale());
listTRLocalizedText.add(trLocalizedText); listTRLocalizedText.add(trLocalizedText);
i++; i++;
} }
@ -1172,7 +1171,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
TRLocalizedText trLocalizedText=new TRLocalizedText(); TRLocalizedText trLocalizedText=new TRLocalizedText();
trLocalizedText.setId(i); trLocalizedText.setId(i);
trLocalizedText.setValue(lt.getValue()); trLocalizedText.setValue(lt.getValue());
trLocalizedText.setLocaleCode(lt.getLocaleCode()); trLocalizedText.setLocaleCode(lt.getLocale());
listTRLocalizedText.add(trLocalizedText); listTRLocalizedText.add(trLocalizedText);
i++; i++;
} }

View File

@ -6,13 +6,15 @@ import java.util.Map;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.data.analysis.tabulardata.model.table.Table; import org.gcube.data.analysis.tabulardata.model.table.Table;
import org.gcube.data.analysis.tabulardata.operation.worker.ActivityStatus; import org.gcube.data.analysis.tabulardata.operation.OperationDescriptor;
import org.gcube.data.analysis.tabulardata.operation.worker.EligibleOperation; import org.gcube.data.analysis.tabulardata.operation.invocation.InvocationCreator;
import org.gcube.data.analysis.tabulardata.operation.worker.OperationInvocation; import org.gcube.data.analysis.tabulardata.operation.invocation.OperationInvocation;
import org.gcube.data.analysis.tabulardata.query.parameters.QueryPage; import org.gcube.data.analysis.tabulardata.query.parameters.QueryPage;
import org.gcube.data.analysis.tabulardata.service.TabularDataService; import org.gcube.data.analysis.tabulardata.service.TabularDataService;
import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactory; import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactory;
import org.gcube.data.analysis.tabulardata.service.operation.Task; import org.gcube.data.analysis.tabulardata.service.operation.Task;
import org.gcube.data.analysis.tabulardata.service.operation.TaskStatus;
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource; import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource;
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceId; import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceId;
import org.gcube.data.analysis.tabulardata.service.tabular.metadata.NameMetadata; import org.gcube.data.analysis.tabulardata.service.tabular.metadata.NameMetadata;
@ -49,21 +51,24 @@ public class TestService {
System.out.println("tabular data id: " + resource.getId().getValue()); System.out.println("tabular data id: " + resource.getId().getValue());
TabularResourceId resourceId = resource.getId(); TabularResourceId resourceId = resource.getId();
List<EligibleOperation> ops = service.getCapabilities(); List<OperationDescriptor> ops = service.getCapabilities();
EligibleOperation csvop = null; OperationDescriptor csvop = null;
for (EligibleOperation op : ops) { for (OperationDescriptor op : ops) {
System.out.println(op.getOperationDescriptor().getName()); System.out.println(op.getName());
if (op.getOperationDescriptor().getName().equals("SDMX Codelist import")) if (op.getName().equals("SDMX Codelist import"))
csvop = op; csvop = op;
} }
OperationInvocation opInvocation = csvop InvocationCreator ic=InvocationCreator.getCreator(csvop);
.createOperationInvocation(getParameterInvocation());
OperationInvocation opInvocation = ic.setParameters(getParameterInvocation()).create();
Task task = service.execute(opInvocation, resource.getId()); Task task = service.execute(opInvocation, resource.getId());
while (task.getStatus() != ActivityStatus.FAILED while (task.getStatus() != TaskStatus.FAILED
&& task.getStatus() != ActivityStatus.SUCCEDED) { && task.getStatus() != TaskStatus.SUCCEDED) {
System.out.println(task.getStatus() + " " System.out.println(task.getStatus() + " "
+ task.getStartTime().getTime()); + task.getStartTime().getTime());
@ -74,10 +79,10 @@ public class TestService {
+ task.getStartTime().getTime() + " " + task.getStartTime().getTime() + " "
+ task.getEndTime().getTime()); + task.getEndTime().getTime());
System.out.println("Task Progress:"+task.getProgress()); System.out.println("Task Progress:" + task.getProgress());
Assert.assertNotNull(task.getResult()); Assert.assertNotNull(task.getResult());
System.out.println("Task getResult: "+task.getResult()); System.out.println("Task getResult: " + task.getResult());
Table resultTable = task.getResult().getOutput(); Table resultTable = task.getResult().getPrimaryTable();
System.out.println("resultTable :" + resultTable); System.out.println("resultTable :" + resultTable);
@ -89,6 +94,4 @@ public class TestService {
} }
} }

View File

@ -3,10 +3,8 @@ package org.gcube.portlets.user.td.gwtservice.client;
import java.util.List; import java.util.List;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.data.analysis.tabulardata.operation.worker.EligibleOperation; import org.gcube.data.analysis.tabulardata.operation.OperationDescriptor;
import org.gcube.data.analysis.tabulardata.service.TabularDataService; import org.gcube.data.analysis.tabulardata.service.TabularDataService;
import org.gcube.data.analysis.tabulardata.service.exception.InvalidTabularResourceException;
import org.gcube.data.analysis.tabulardata.service.exception.NoSuchTabularResourceException;
import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactory; import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactory;
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource; import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource;
import org.gcube.portlets.user.td.gwtservice.shared.Constants; import org.gcube.portlets.user.td.gwtservice.shared.Constants;
@ -20,11 +18,11 @@ public class TestServiceOperations {
ScopeProvider.instance.set(Constants.DEFAULT_SCOPE); ScopeProvider.instance.set(Constants.DEFAULT_SCOPE);
TabularDataService service = TabularDataServiceFactory TabularDataService service = TabularDataServiceFactory
.getService(Constants.DEFAULT_USER); .getService(Constants.DEFAULT_USER);
List<EligibleOperation> trOperations = service.getCapabilities(); List<OperationDescriptor> trOperations = service.getCapabilities();
Assert.assertTrue(trOperations.size() > 0); Assert.assertTrue(trOperations.size() > 0);
System.out System.out
.println("------------Tabular Resource Operation--------------"); .println("------------Tabular Resource Operation--------------");
for (EligibleOperation operation : trOperations) { for (OperationDescriptor operation : trOperations) {
System.out.println(operation.toString()); System.out.println(operation.toString());
} }
@ -37,26 +35,7 @@ public class TestServiceOperations {
System.out.println("TabularResource:"+tr.getId()); System.out.println("TabularResource:"+tr.getId());
} }
List<EligibleOperation> tableOperations = null;
try {
tableOperations = service.getCapabilities(trs.get(0).getId());
} catch (NoSuchTabularResourceException e) {
e.printStackTrace();
Assert.fail("No Tabular Resource on Service: "
+ e.getLocalizedMessage());
} catch (InvalidTabularResourceException e) {
e.printStackTrace();
Assert.fail("Invalid Tabular Resource on Service: "
+ e.getLocalizedMessage());
}
Assert.assertTrue("No operations present",
tableOperations.size() > 0);
System.out.println("------------Table Operation--------------");
for (EligibleOperation operation : tableOperations) {
System.out.println(operation.toString());
}
} }
} }