2013-11-06 18:12:38 +01:00
|
|
|
package org.gcube.portlets.user.td.gwtservice.client;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
import org.gcube.data.analysis.tabulardata.model.table.Table;
|
2013-11-26 11:29:04 +01:00
|
|
|
import org.gcube.data.analysis.tabulardata.operation.OperationDescriptor;
|
|
|
|
import org.gcube.data.analysis.tabulardata.operation.invocation.InvocationCreator;
|
|
|
|
import org.gcube.data.analysis.tabulardata.operation.invocation.OperationInvocation;
|
|
|
|
|
2013-11-06 18:12:38 +01:00
|
|
|
import org.gcube.data.analysis.tabulardata.query.parameters.QueryPage;
|
|
|
|
import org.gcube.data.analysis.tabulardata.service.TabularDataService;
|
|
|
|
import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactory;
|
|
|
|
import org.gcube.data.analysis.tabulardata.service.operation.Task;
|
2013-11-26 11:29:04 +01:00
|
|
|
import org.gcube.data.analysis.tabulardata.service.operation.TaskStatus;
|
2013-11-06 18:12:38 +01:00
|
|
|
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.metadata.NameMetadata;
|
2013-11-20 09:45:53 +01:00
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.Constants;
|
2013-11-06 18:12:38 +01:00
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
2013-11-26 15:14:17 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author "Giancarlo Panichi"
|
|
|
|
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
|
|
*
|
|
|
|
*/
|
2013-11-06 18:12:38 +01:00
|
|
|
public class TestService {
|
|
|
|
|
|
|
|
protected Map<String, Object> getParameterInvocation() {
|
|
|
|
Map<String, Object> parameterInstances = new HashMap<String, Object>();
|
|
|
|
parameterInstances
|
|
|
|
.put("registryBaseUrl",
|
|
|
|
"http://node8.d.d4science.research-infrastructures.eu:8080/FusionRegistry/ws/rest/");
|
|
|
|
parameterInstances.put("id", "CL_SPECIES");
|
|
|
|
parameterInstances.put("version", "1.0");
|
|
|
|
parameterInstances.put("agency", "FAO");
|
|
|
|
return parameterInstances;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void create() throws Exception {
|
|
|
|
|
2013-11-20 09:45:53 +01:00
|
|
|
ScopeProvider.instance.set(Constants.DEFAULT_SCOPE);
|
2013-11-06 18:12:38 +01:00
|
|
|
TabularDataService service = TabularDataServiceFactory
|
2013-11-20 09:45:53 +01:00
|
|
|
.getService(Constants.DEFAULT_USER);
|
2013-11-06 18:12:38 +01:00
|
|
|
TabularResource resource = service.createTabularResource();
|
|
|
|
System.out.println("after createTabResource "
|
|
|
|
+ ScopeProvider.instance.get());
|
|
|
|
System.out.println("name: "
|
|
|
|
+ ((NameMetadata) resource.getMetadata(NameMetadata.class))
|
|
|
|
.getValue());
|
|
|
|
|
|
|
|
System.out.println("tabular data id: " + resource.getId().getValue());
|
|
|
|
TabularResourceId resourceId = resource.getId();
|
|
|
|
|
2013-11-26 11:29:04 +01:00
|
|
|
List<OperationDescriptor> ops = service.getCapabilities();
|
|
|
|
OperationDescriptor csvop = null;
|
|
|
|
for (OperationDescriptor op : ops) {
|
|
|
|
System.out.println(op.getName());
|
|
|
|
if (op.getName().equals("SDMX Codelist import"))
|
2013-11-06 18:12:38 +01:00
|
|
|
csvop = op;
|
|
|
|
}
|
|
|
|
|
2013-11-26 15:12:50 +01:00
|
|
|
InvocationCreator ic = InvocationCreator.getCreator(csvop);
|
2013-11-26 11:29:04 +01:00
|
|
|
|
2013-11-26 15:12:50 +01:00
|
|
|
OperationInvocation opInvocation = ic.setParameters(
|
|
|
|
getParameterInvocation()).create();
|
2013-11-06 18:12:38 +01:00
|
|
|
|
|
|
|
Task task = service.execute(opInvocation, resource.getId());
|
|
|
|
|
2013-11-26 11:29:04 +01:00
|
|
|
while (task.getStatus() != TaskStatus.FAILED
|
|
|
|
&& task.getStatus() != TaskStatus.SUCCEDED) {
|
2013-11-06 18:12:38 +01:00
|
|
|
System.out.println(task.getStatus() + " "
|
|
|
|
+ task.getStartTime().getTime());
|
|
|
|
|
|
|
|
Thread.sleep(3000);
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println(task.getStatus() + " "
|
|
|
|
+ task.getStartTime().getTime() + " "
|
|
|
|
+ task.getEndTime().getTime());
|
|
|
|
|
2013-11-26 11:29:04 +01:00
|
|
|
System.out.println("Task Progress:" + task.getProgress());
|
2013-11-06 18:12:38 +01:00
|
|
|
Assert.assertNotNull(task.getResult());
|
2013-11-26 11:29:04 +01:00
|
|
|
System.out.println("Task getResult: " + task.getResult());
|
|
|
|
Table resultTable = task.getResult().getPrimaryTable();
|
2013-11-06 18:12:38 +01:00
|
|
|
|
|
|
|
System.out.println("resultTable :" + resultTable);
|
|
|
|
|
|
|
|
System.out.println(service.getLastTable(resourceId).getName());
|
|
|
|
|
|
|
|
System.out.println(service.getQueryLenght(resultTable.getId(), null));
|
|
|
|
System.out.println(service.queryAsJson(resultTable.getId(),
|
|
|
|
new QueryPage(0, 200)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-11-26 15:12:50 +01:00
|
|
|
@Test
|
|
|
|
public void listTR() throws Exception {
|
|
|
|
ScopeProvider.instance.set(Constants.DEFAULT_SCOPE);
|
|
|
|
TabularDataService service = TabularDataServiceFactory
|
|
|
|
.getService(Constants.DEFAULT_USER);
|
|
|
|
List<TabularResource> trs = service.getTabularResources();
|
|
|
|
Assert.assertTrue(trs.size() > 0);
|
|
|
|
System.out.println("------------Tabular Resource--------------");
|
|
|
|
for (TabularResource tr : trs) {
|
|
|
|
System.out.println("TabularResource:" + tr.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-06 18:12:38 +01:00
|
|
|
}
|