2017-05-09 15:41:59 +02:00
|
|
|
package org.gcube.informationsystem.exporter.mapper;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2017-09-05 16:14:57 +02:00
|
|
|
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
2017-05-09 15:41:59 +02:00
|
|
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
|
|
|
import org.gcube.informationsystem.exporter.ScopedTest;
|
2019-02-06 10:01:35 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
2017-05-09 15:41:59 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
|
2018-10-02 09:06:41 +02:00
|
|
|
import org.gcube.resourcemanagement.model.reference.entity.resource.EService;
|
2017-05-09 15:41:59 +02:00
|
|
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
|
|
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
|
|
|
import org.gcube.resources.discovery.icclient.ICFactory;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*/
|
|
|
|
public class ServiceEndpointExporterTest extends ScopedTest{
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(ServiceEndpointExporterTest.class);
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void export(){
|
2017-09-05 16:14:57 +02:00
|
|
|
ServiceEndpointExporter see = new ServiceEndpointExporter(false);
|
2017-05-09 15:41:59 +02:00
|
|
|
see.export();
|
|
|
|
}
|
2017-09-05 16:14:57 +02:00
|
|
|
|
|
|
|
public void removeExported() throws ObjectNotFound, Exception{
|
2017-05-09 15:41:59 +02:00
|
|
|
ResourceRegistryClient client = ResourceRegistryClientFactory.create();
|
|
|
|
ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create();
|
|
|
|
|
2017-12-07 13:58:32 +01:00
|
|
|
List<EService> eServices = client.getInstances(EService.class, false);
|
2017-05-09 15:41:59 +02:00
|
|
|
List<EService> failed = new ArrayList<>();
|
|
|
|
|
|
|
|
logger.debug("Going to delete {} {}s",
|
|
|
|
eServices.size(), EService.NAME);
|
|
|
|
|
|
|
|
int excluded = 0;
|
|
|
|
|
|
|
|
for(EService eService : eServices){
|
|
|
|
try {
|
|
|
|
Facet facet = eService.getIdentificationFacets().get(0);
|
|
|
|
String string = (String) facet.getAdditionalProperty(GCoreResourceMapper.EXPORTED);
|
|
|
|
if(string!=null && string.compareTo(GCoreResourceMapper.EXPORTED_FROM_OLD_GCORE_IS)==0){
|
|
|
|
publisher.deleteResource(eService);
|
|
|
|
}else{
|
|
|
|
excluded++;
|
|
|
|
}
|
|
|
|
}catch (Exception e) {
|
|
|
|
failed.add(eService);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.debug("{} of {} ({} failures) {}s were deleted. {} {}s were excluded because there was not exported from gCore IS.",
|
|
|
|
eServices.size()-failed.size()-excluded, eServices.size(), failed.size(), EService.NAME, excluded, EService.NAME);
|
|
|
|
}
|
|
|
|
|
2017-09-05 16:14:57 +02:00
|
|
|
// @Test
|
2017-05-09 15:41:59 +02:00
|
|
|
public void investigateSingleResource() throws Exception {
|
2017-09-05 16:14:57 +02:00
|
|
|
// ScopedTest.setContext(GCUBE);
|
|
|
|
|
|
|
|
UUID uuid = UUID.fromString("");
|
|
|
|
//ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create();
|
|
|
|
//publisher.deleteResource(uuid);
|
2017-05-09 15:41:59 +02:00
|
|
|
//ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
|
|
|
|
|
|
|
|
|
|
|
|
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class)
|
|
|
|
.addCondition(String.format("$resource/ID/text() eq '%1s'", uuid.toString()));
|
|
|
|
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
|
|
|
|
List<ServiceEndpoint> seList = client.submit(query);
|
|
|
|
|
2017-09-05 16:14:57 +02:00
|
|
|
ServiceEndpointExporter see = new ServiceEndpointExporter(false);
|
2017-05-09 15:41:59 +02:00
|
|
|
see.notifyFailures(seList.size(), seList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|