Lucio Lelii 6 years ago
parent bb7c69e897
commit 95babfe62b

@ -31,13 +31,7 @@
<artifactId>common-scope</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.resources</groupId>
<artifactId>registry-publisher</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT]</version>
</dependency>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>discovery-client</artifactId>

@ -1,140 +0,0 @@
package org.acme;
import static org.gcube.common.clients.stubs.jaxws.StubFactory.stubFor;
import static org.gcube.resources.discovery.icclient.stubs.CollectorConstants.collector;
import static org.gcube.resources.discovery.icclient.stubs.CollectorConstants.localname;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.ws.soap.SOAPFaultException;
import org.gcube.common.clients.stubs.jaxws.JAXWSUtils;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.resources.gcore.Resource;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.api.ServiceMap;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.informationsystem.publisher.RegistryPublisher;
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.Query;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
import org.gcube.resources.discovery.icclient.Helper;
import org.gcube.resources.discovery.icclient.ICFactory;
import org.gcube.resources.discovery.icclient.stubs.CollectorStub;
import org.junit.Test;
public class StubClient {
final static List<String> voDevScopes = Arrays.asList("/gcube","/gcube/devsec","/gcube/devNext","/gcube/preprod");
final static List<String> voProdScopes = Arrays.asList("/d4science.research-infrastructures.eu","/d4science.research-infrastructures.eu/SoBigData", "/d4science.research-infrastructures.eu/FARM","/d4science.research-infrastructures.eu/gCubeApps", "/d4science.research-infrastructures.eu/D4Research",
"/d4science.research-infrastructures.eu/OpenAIRE","/d4science.research-infrastructures.eu/SmartArea");
public static void main(String[] args) throws Exception {
//when needed, setup tcpmon and decomment to see messages on the wire for debugging purposes
//StubFactory.setProxy("localhost", 8081);
ScopeProvider.instance.set("/gcube/devNext/NextNext");
String address = ServiceMap.instance.endpoint(localname);
CollectorStub proxy = stubFor(collector).at(URI.create(address));
//SimpleQuery query = queryFor(GCoreEndpoint.class);
String queryString ="declare namespace ic = 'http://gcube-system.org/namespaces/informationsystem/registry'; "+
"for $profiles in collection('/db/Profiles/GenericResource')//Document/Data/ic:Profile/Resource "+
" let $scopes := string-join( $profiles/Scopes//Scope/text(), ';') "+
" let $subtype := $profiles/Profile/SecondaryType/text() "+
" return $profiles";
Query query = new QueryBox(queryString);
try {
System.out.println(query.expression());
String response = proxy.execute(Helper.queryAddAuthenticationControl(query.expression()));
System.err.println(response);
}
catch(SOAPFaultException e) {
throw new RuntimeException(JAXWSUtils.remoteCause(e));
}
}
@Test
public void synchResourceOnAllScopes(){
accessPointQuery(voProdScopes, "00502ca0-f9b4-11e2-ae96-bc1961394f34", ServiceEndpoint.class);
}
private <T extends Resource> void accessPointQuery(List<String> voScopes, String resourceID, Class<T> resourceType){
String currentScope = voScopes.get(0);
ScopeProvider.instance.set(currentScope);
SimpleQuery query = ICFactory.queryFor(resourceType);
DiscoveryClient<T> client = ICFactory.clientFor(resourceType);
query.addCondition("$resource/ID/text() = '"+resourceID+"'");
T resource = client.submit(query).get(0);
HashSet<String> scopeSet = new HashSet<String>();
SimpleQuery queryVRE = ICFactory.queryFor(GenericResource.class);
queryVRE.addCondition("$resource/Profile/SecondaryType/text() = 'VRE'");
queryVRE.setResult("$resource/Profile/Body/Scope/string()");
DiscoveryClient<String> vREScopeClient = ICFactory.client();
scopeSet.addAll(voScopes);
for (String scope: voScopes){
ScopeProvider.instance.set(scope);
List<String> vresscope = vREScopeClient.submit(queryVRE);
System.out.println("vres found "+vresscope.size()+ " in "+scope);
scopeSet.addAll(vresscope);
}
ScopeProvider.instance.set(currentScope);
resource.scopes().asCollection().retainAll(Collections.emptyList());
resource.scopes().asCollection().addAll(scopeSet);
ScopeProvider.instance.set(currentScope);
RegistryPublisher pub = RegistryPublisherFactory.create();
pub.vosUpdate(resource);
}
@XmlRootElement(name = "accesspoint")
static class AccessPointResult {
@XmlElement(name = "id")
String id;
@XmlElementRef
AccessPoint ap;
@Override
public String toString() {
return "AccessPointResult [id=" + id + ", ap=" + ap + "]";
}
}
}
Loading…
Cancel
Save