add method for retrieving a single field in accesspoint
This commit is contained in:
parent
d9e6f95837
commit
99e3f05ea5
4
pom.xml
4
pom.xml
|
@ -27,6 +27,8 @@
|
||||||
<properties>
|
<properties>
|
||||||
<webappDirectory>${project.basedir}/src/main/webapp/WEB-INF</webappDirectory>
|
<webappDirectory>${project.basedir}/src/main/webapp/WEB-INF</webappDirectory>
|
||||||
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
@ -104,7 +106,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.14.8</version>
|
<version>1.18.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -5,6 +5,7 @@ import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
|
@ -15,10 +16,11 @@ import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
import org.gcube.common.resources.gcore.*;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
|
import org.gcube.resources.discovery.client.queries.impl.XQuery;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Path("ServiceEndpoint")
|
@Path("ServiceEndpoint")
|
||||||
|
@ -51,6 +53,39 @@ public class ServiceEndpointResource {
|
||||||
return endpoints;
|
return endpoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{category}/{name}/{ap}")
|
||||||
|
@Produces(MediaType.TEXT_XML)
|
||||||
|
public String retrieve(@NotNull @PathParam("name") String resourceName,
|
||||||
|
@NotNull @PathParam("category") String resourceCategory,
|
||||||
|
@NotNull @PathParam("ap") String accessPoint) {
|
||||||
|
log.info("ServiceEndpoint called with category {}, name {} and accessPoint {} in scope {}",resourceCategory, resourceName, accessPoint, ScopeProvider.instance.get());
|
||||||
|
// SimpleQuery query = getQuery(resourceName, resourceCategory);
|
||||||
|
// query.setResult("$resource/Profile/AccessPoint/Interface/Endpoint[@EntryName='"+accessPoint+"'");
|
||||||
|
//// DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||||
|
// DiscoveryClient<String> client = client();
|
||||||
|
//// List<ServiceEndpoint> endpoints = client.submit(query);
|
||||||
|
// log.debug("retrieved endpoint is "+endpoints);
|
||||||
|
// if (Objects.nonNull(endpoints))
|
||||||
|
// return endpoints.get(0).toString();
|
||||||
|
// else
|
||||||
|
// log.warn("endpoint not found with following coordinates: {} {} and accesspoint: {}", resourceCategory, resourceName,accessPoint);
|
||||||
|
// return null;
|
||||||
|
|
||||||
|
|
||||||
|
XQuery query=queryFor(ServiceEndpoint.class);
|
||||||
|
query.addCondition(String.format("$resource/Profile/Name/text() eq '%s'",resourceName));
|
||||||
|
query.addCondition(String.format("$resource/Profile/Category/text() eq '%s'",resourceCategory));
|
||||||
|
query.setResult("$resource/Profile/AccessPoint/Interface/Endpoint[@EntryName='"+accessPoint+"']/text()");
|
||||||
|
DiscoveryClient<String> client = client();
|
||||||
|
List<String> accessList= client.submit(query);
|
||||||
|
if (Objects.nonNull(accessList))
|
||||||
|
return accessList.get(0).toString();
|
||||||
|
else
|
||||||
|
log.warn("endpoint not found with following coordinates: {} {} and accesspoint: {}", resourceCategory, resourceName,accessPoint);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/{category}/{name}/Result/{result:([^$\\?]+)}")
|
@Path("/{category}/{name}/Result/{result:([^$\\?]+)}")
|
||||||
@Produces(MediaType.TEXT_XML)
|
@Produces(MediaType.TEXT_XML)
|
||||||
|
@ -90,5 +125,21 @@ public class ServiceEndpointResource {
|
||||||
query.addCondition(String.format("$resource/Profile/Category/text() eq '%s'",resourceCategory));
|
query.addCondition(String.format("$resource/Profile/Category/text() eq '%s'",resourceCategory));
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T extends Resource> XQuery getSpecificXQuery(T resource) {
|
||||||
|
XQuery query = null;
|
||||||
|
if(resource.type().toString().equalsIgnoreCase("RuntimeResource")){
|
||||||
|
query = queryFor(ServiceEndpoint.class);
|
||||||
|
}else if(resource.type().toString().equalsIgnoreCase("GenericResource")){
|
||||||
|
query = queryFor(GenericResource.class);
|
||||||
|
}else if(resource.type().toString().equalsIgnoreCase("RunningInstance")){
|
||||||
|
query = queryFor(GCoreEndpoint.class);
|
||||||
|
}else if(resource.type().toString().equalsIgnoreCase("GHN")){
|
||||||
|
query = queryFor(HostingNode.class);
|
||||||
|
}else{
|
||||||
|
throw new RuntimeException("The following resource type is not managed: "+resource);
|
||||||
|
}
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package org.gcube.informationsystem.icproxy;
|
||||||
|
|
||||||
import javax.ws.rs.core.Application;
|
import javax.ws.rs.core.Application;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.informationsystem.icproxy.resources.GCoreEndpointResource;
|
import org.gcube.informationsystem.icproxy.resources.GCoreEndpointResource;
|
||||||
import org.gcube.informationsystem.icproxy.resources.GenericResourceResource;
|
import org.gcube.informationsystem.icproxy.resources.GenericResourceResource;
|
||||||
import org.gcube.informationsystem.icproxy.resources.HostingNodeResource;
|
import org.gcube.informationsystem.icproxy.resources.HostingNodeResource;
|
||||||
|
@ -16,6 +18,7 @@ public class TestCall extends JerseyTest{
|
||||||
@Override
|
@Override
|
||||||
protected Application configure() {
|
protected Application configure() {
|
||||||
return new ResourceConfig(ICResource.class,GCoreEndpointResource.class, ServiceEndpointResource.class, HostingNodeResource.class, GenericResourceResource.class);
|
return new ResourceConfig(ICResource.class,GCoreEndpointResource.class, ServiceEndpointResource.class, HostingNodeResource.class, GenericResourceResource.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -34,8 +37,8 @@ public class TestCall extends JerseyTest{
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void gcoreEndpointWithResult() {
|
public void gcoreEndpointWithResult() {
|
||||||
|
|
||||||
|
|
||||||
final String ret = target("GCoreEndpoint").path("DataAnalysis")
|
final String ret = target("GCoreEndpoint").path("DataAnalysis")
|
||||||
.queryParam("result","/Profile/AccessPoint/RunningInstanceInterfaces//Endpoint[@EntryName/string() eq \"querymanager\"]")
|
.queryParam("result","/Profile/AccessPoint/RunningInstanceInterfaces//Endpoint[@EntryName/string() eq \"querymanager\"]")
|
||||||
.queryParam("scope", "/gcube/devsec").request().get(String.class);
|
.queryParam("scope", "/gcube/devsec").request().get(String.class);
|
||||||
|
@ -44,12 +47,24 @@ public class TestCall extends JerseyTest{
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void serviceEndpoint() {
|
public void serviceEndpoint() {
|
||||||
|
ScopeProvider.instance.set("/gcube/devsec");
|
||||||
|
//SecurityTokenProvider.instance.set("/gcube/devsec");
|
||||||
final String ret = target("ServiceEndpoint").path("BiodiversityRepository").path("CatalogueOfLife").queryParam("scope", "/gcube/devsec").request().get(String.class);
|
final String ret = target("ServiceEndpoint").path("BiodiversityRepository").path("CatalogueOfLife").queryParam("scope", "/gcube/devsec").request().get(String.class);
|
||||||
System.out.println(ret);
|
System.out.println(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void serviceEndpointAP() {
|
||||||
|
ScopeProvider.instance.set("/gcube/devsec");
|
||||||
|
//SecurityTokenProvider.instance.set("/gcube/devsec");
|
||||||
|
final String ret = target("ServiceEndpoint").path("Storage").path("StorageManager").path("server1").queryParam("scope", "/gcube/devsec").request().get(String.class);
|
||||||
|
System.out.println(ret);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void hostingNode() {
|
public void hostingNode() {
|
||||||
|
ScopeProvider.instance.set("/gcube/devsec");
|
||||||
final String ret = target("HostingNode").queryParam("scope", "/gcube/devsec").request().get(String.class);
|
final String ret = target("HostingNode").queryParam("scope", "/gcube/devsec").request().get(String.class);
|
||||||
System.out.println(ret);
|
System.out.println(ret);
|
||||||
}
|
}
|
||||||
|
@ -62,7 +77,8 @@ public class TestCall extends JerseyTest{
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getById() {
|
public void getById() {
|
||||||
final String ret = target("/").path("92ee1020-5604-11e3-8182-e7053f61b8fe").queryParam("scope", "/gcube/devsec").request().get(String.class);
|
ScopeProvider.instance.set("/gcube/devsec");
|
||||||
|
final String ret = target("/").path("aab08cf4-ed27-406c-b4a2-89888300976f").queryParam("scope", "/gcube/devsec").request().get(String.class);
|
||||||
System.out.println(ret);
|
System.out.println(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue