From e97ec6fbd183df8934a3a8d507580564d7153e4f Mon Sep 17 00:00:00 2001 From: lucio Date: Thu, 24 Oct 2019 19:03:32 +0200 Subject: [PATCH] added new IC REST calls --- .classpath | 15 +++++--- .settings/org.eclipse.jdt.core.prefs | 7 ++-- pom.xml | 2 +- .../stubs/registry/RegistryStub.java | 13 +++++-- .../publisher/utils/RegistryStubs.java | 37 ++++++++++++------- .../GCoreEndpointPublisherTests.java | 2 +- 6 files changed, 47 insertions(+), 29 deletions(-) diff --git a/.classpath b/.classpath index 0c7f994..69b26e5 100644 --- a/.classpath +++ b/.classpath @@ -6,19 +6,16 @@ - - - - - + + @@ -28,6 +25,12 @@ - + + + + + + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index ec4300d..b8947ec 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/pom.xml b/pom.xml index 313c877..703684b 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ org.gcube.resources registry-publisher - 1.3.0 + 1.3.0-SNAPSHOT diff --git a/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/RegistryStub.java b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/RegistryStub.java index eb12315..3da0701 100644 --- a/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/RegistryStub.java +++ b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/RegistryStub.java @@ -2,11 +2,15 @@ package org.gcube.informationsystem.publisher.stubs.registry; import static org.gcube.informationsystem.publisher.stubs.registry.RegistryConstants.*; +import java.io.StringWriter; + import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; +import org.gcube.common.resources.gcore.Resource; +import org.gcube.common.resources.gcore.Resources; import org.gcube.informationsystem.publisher.stubs.registry.faults.CreateException; import org.gcube.informationsystem.publisher.stubs.registry.faults.InvalidResourceException; import org.gcube.informationsystem.publisher.stubs.registry.faults.RemoveException; @@ -35,6 +39,7 @@ public interface RegistryStub { @WebResult() void create(@WebParam(name="profile") String profile, @WebParam(name="type") String type ) throws InvalidResourceException, ResourceNotAcceptedException, CreateException; + /** * * @param id the id of the resource to update @@ -48,7 +53,8 @@ public interface RegistryStub { @WebMethod(operationName="update") @WebResult() void update(@WebParam(name="uniqueID") String id, @WebParam(name="type") String type, @WebParam(name="xmlProfile") String profile ) throws InvalidResourceException, - ResourceNotAcceptedException, UpdateException; + ResourceNotAcceptedException, UpdateException; + /** * * @param id the id of the resource to remove @@ -60,7 +66,6 @@ public interface RegistryStub { @WebMethod(operationName="remove") @WebResult() void remove(@WebParam(name="uniqueID") String id, @WebParam(name="type") String type) throws ResourceDoesNotExistException, - RemoveException; - - + RemoveException; + } diff --git a/src/main/java/org/gcube/informationsystem/publisher/utils/RegistryStubs.java b/src/main/java/org/gcube/informationsystem/publisher/utils/RegistryStubs.java index 952a9b1..927161f 100644 --- a/src/main/java/org/gcube/informationsystem/publisher/utils/RegistryStubs.java +++ b/src/main/java/org/gcube/informationsystem/publisher/utils/RegistryStubs.java @@ -8,8 +8,10 @@ import java.util.List; import org.gcube.common.resources.gcore.GCoreEndpoint; import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.scope.api.ServiceMap; import org.gcube.informationsystem.publisher.cache.RegistryCache; import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException; +import org.gcube.informationsystem.publisher.stubs.registry.CollectorStubs; import org.gcube.informationsystem.publisher.stubs.registry.RegistryConstants; import org.gcube.informationsystem.publisher.stubs.registry.RegistryStub; import org.gcube.resources.discovery.client.api.DiscoveryClient; @@ -21,16 +23,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class RegistryStubs { - + private RegistryCache cache = new RegistryCache(10); private List endpoints; private static final Logger log = LoggerFactory.getLogger(RegistryStubs.class); - - + private static final String XMLSTOREACCESS_SERVICE ="XMLStoreService"; + + public List getEndPoints(){ String scope=ScopeProvider.instance.get(); -// able/disable cache + // able/disable cache endpoints=(List)cache.get(scope); if(endpoints==null){ SimpleQuery query = queryFor(GCoreEndpoint.class); @@ -40,30 +43,36 @@ public class RegistryStubs { public URI parse(String result) throws Exception { return new URI(result.replaceAll("\n", "")); } - + }; DiscoveryClient client = new DelegateClient(uriParser, new ICClient()); query.addCondition("$resource/Profile/ServiceClass/text() eq '"+RegistryConstants.service_class+"'") - .addCondition("$resource/Profile/ServiceName/text() eq '"+RegistryConstants.service_name+"'") - .setResult("$resource/Profile/AccessPoint/RunningInstanceInterfaces/Endpoint[string(@EntryName) eq '"+RegistryConstants.service_entrypoint+"']/string()"); + .addCondition("$resource/Profile/ServiceName/text() eq '"+RegistryConstants.service_name+"'") + .setResult("$resource/Profile/AccessPoint/RunningInstanceInterfaces/Endpoint[string(@EntryName) eq '"+RegistryConstants.service_entrypoint+"']/string()"); endpoints = client.submit(query); if (endpoints.size()==0){ throw new IllegalArgumentException("No registry endpoint founded"); } -// able/disable cache + // able/disable cache cache.put(scope, endpoints); } return endpoints; } + public RegistryStub getStubs() throws RegistryNotFoundException{ - URI endpoint=null; - //use another method to cache epr - endpoint = getEndPoints().get(0); - log.debug("get stubs from endpoint: "+ endpoint); - return stubFor(RegistryConstants.registry).at(endpoint); + ServiceMap serviceMap = ServiceMap.instance; + if (serviceMap!=null && serviceMap.version().equals("2.0.0")) { + String endpoint = serviceMap.endpoint(XMLSTOREACCESS_SERVICE); + return new CollectorStubs(endpoint); + } else { + //use another method to cache epr + URI endpoint = getEndPoints().get(0); + log.debug("get stubs from endpoint: "+ endpoint); + return stubFor(RegistryConstants.registry).at(endpoint); + } } - + public RegistryStub getStubs(URI endpoint) throws RegistryNotFoundException{ log.debug("get stubs from endpoint: "+ endpoint); return stubFor(RegistryConstants.registry).at(endpoint); diff --git a/src/test/java/org/gcube/informationsystem/publisher/GCoreEndpointPublisherTests.java b/src/test/java/org/gcube/informationsystem/publisher/GCoreEndpointPublisherTests.java index b92479e..b75f54e 100644 --- a/src/test/java/org/gcube/informationsystem/publisher/GCoreEndpointPublisherTests.java +++ b/src/test/java/org/gcube/informationsystem/publisher/GCoreEndpointPublisherTests.java @@ -23,7 +23,7 @@ public class GCoreEndpointPublisherTests { @BeforeClass public static void init(){ // ScopeProvider.instance.set("/d4science.research-infrastructures.eu/EUBrazilOpenBio"); - ScopeProvider.instance.set("/gcube/devsec"); + ScopeProvider.instance.set("/gcube/devNext"); running = Resources.unmarshal(GCoreEndpoint.class, PublisherTest.class.getClassLoader().getResourceAsStream("gCoreEndpoint.xml")); rp=RegistryPublisherFactory.create(); }