91 lines
3.3 KiB
Java
91 lines
3.3 KiB
Java
package org.gcube.data.spd.client.manager;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
import org.gcube.data.spd.client.plugins.AbstractPlugin;
|
|
import org.gcube.data.spd.client.proxies.ExecutorClient;
|
|
import org.gcube.data.spd.client.proxies.ManagerClient;
|
|
import org.gcube.data.spd.model.products.Product;
|
|
import org.gcube.data.spd.model.products.Product.ProductType;
|
|
import org.gcube.data.spd.model.products.ResultItem;
|
|
import org.gcube.data.spd.model.service.types.CompleteJobStatus;
|
|
import org.gcube.data.spd.model.service.types.JobStatus;
|
|
import org.gcube.data.spd.model.service.types.NodeStatus;
|
|
import org.gcube.data.streams.Stream;
|
|
import org.gcube.data.streams.dsl.Streams;
|
|
import org.junit.Test;
|
|
|
|
|
|
public class DWCATest {
|
|
|
|
|
|
@Test
|
|
public void OccurrenceJobFromSardaSarda() throws Exception{
|
|
|
|
SecurityTokenProvider.instance.set("94a3b80a-c66f-4000-ae2f-230f5dfad793-98187548");
|
|
ScopeProvider.instance.set("/gcube/devsec");
|
|
ExecutorClient creator = AbstractPlugin.executor().build();
|
|
|
|
//"CatalogueOfLife:13445516" chordata
|
|
//"CatalogueOfLife:13446218" cervidae
|
|
String jobId = createOccurrence(creator);
|
|
//String jobId = createOccurrence(creator);
|
|
CompleteJobStatus response= null;
|
|
do{
|
|
Thread.sleep(10000);
|
|
response= creator.getStatus(jobId);
|
|
System.out.println("thes status is "+response.getStatus());
|
|
System.out.println("the number of element read are "+response.getCompletedEntries());
|
|
if(response.getSubNodes()!=null)
|
|
for (NodeStatus status : response.getSubNodes())
|
|
System.out.println(status.getScientificName()+"--"+status.getStatus());
|
|
|
|
}while(response.getStatus()!=JobStatus.FAILED && response.getStatus()!=JobStatus.COMPLETED);
|
|
|
|
System.out.println("result uri "+creator.getResultLink(jobId));
|
|
System.out.println("error uri "+creator.getErrorLink(jobId));
|
|
|
|
|
|
}
|
|
|
|
|
|
private static String createDWCAJobTest(ExecutorClient creator, String id) throws Exception {
|
|
return creator.createDwCAByChildren(id);
|
|
}
|
|
|
|
private static String createOccurrence(ExecutorClient creator) throws Exception {
|
|
Stream<String> keyStream =Streams.convert(new String[]{"Obis:522634-1695----", "Obis:465686-1695----", "Obis:429081-721----", "Obis:822676-1691----", "Obis:742361-119----", "Obis:447539-1695----", "GBIF:sarda||130||11956||57744173||","GBIF:sarda||82||400||50917042||","GBIF:sarda||427||14113||60499431||"});
|
|
return creator.createDarwincoreFromOccurrenceKeys(keyStream);
|
|
}
|
|
|
|
private static String createOccurrenceFromSardasarda(ExecutorClient creator) throws Exception {
|
|
|
|
ManagerClient manager = AbstractPlugin.manager().build();
|
|
|
|
Stream<ResultItem> rsStream = manager.search("SEARCH BY SN 'sarda sarda'");
|
|
|
|
List<String> keylist = new ArrayList<String>();
|
|
int i =0;
|
|
while (rsStream.hasNext()){
|
|
ResultItem rs = rsStream.next();
|
|
for (Product product: rs.getProducts())
|
|
if (product.getCount()>0 && product.getType()==ProductType.Occurrence) keylist.add(product.getKey());
|
|
if (i++>=5)
|
|
break;
|
|
}
|
|
rsStream.close();
|
|
|
|
System.out.println("keyList is "+keylist.size());
|
|
|
|
System.in.read();
|
|
|
|
Stream<String> keyStream =Streams.convert(keylist);
|
|
return creator.createCSV(keyStream);
|
|
}
|
|
|
|
|
|
}
|