Refs #10247: Create Resource Registry Context Client
Task-Url: https://support.d4science.org/issues/10247 Initial import git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-context-client@158778 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
001bcda6ec
commit
39bb707725
|
@ -0,0 +1,36 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
</classpath>
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>resource-registry-context-client</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
|
@ -0,0 +1,6 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding//src/main/java=UTF-8
|
||||||
|
encoding//src/main/resources=UTF-8
|
||||||
|
encoding//src/test/java=UTF-8
|
||||||
|
encoding//src/test/resources=UTF-8
|
||||||
|
encoding/<project>=UTF-8
|
|
@ -0,0 +1,5 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
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.8
|
|
@ -0,0 +1,4 @@
|
||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
|
@ -0,0 +1,97 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>org.gcube.tools</groupId>
|
||||||
|
<artifactId>maven-parent</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<groupId>org.gcube.information-system</groupId>
|
||||||
|
<artifactId>resource-registry-context-client</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<name>Resource Registry Context Client</name>
|
||||||
|
<description>Contains Non Idempotent API to manage Contexts in Resource Registry</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
||||||
|
<serviceClass>InformationSystem</serviceClass>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<scm>
|
||||||
|
<connection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/${project.artifactId}</connection>
|
||||||
|
<developerConnection>scm:https://svn.d4science.research-infrastructures.eu/gcube//trunk/information-system/${project.artifactId}</developerConnection>
|
||||||
|
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/${project.artifactId}</url>
|
||||||
|
</scm>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.distribution</groupId>
|
||||||
|
<artifactId>gcube-bom</artifactId>
|
||||||
|
<version>LATEST</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.information-system</groupId>
|
||||||
|
<artifactId>information-system-bom</artifactId>
|
||||||
|
<version>LATEST</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.common</groupId>
|
||||||
|
<artifactId>authorization-client</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.resources.discovery</groupId>
|
||||||
|
<artifactId>ic-client</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.information-system</groupId>
|
||||||
|
<artifactId>resource-registry-api</artifactId>
|
||||||
|
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.information-system</groupId>
|
||||||
|
<artifactId>information-system-model</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Test Dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.11</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
<version>1.0.13</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>make-servicearchive</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,48 @@
|
||||||
|
package org.gcube.informationsystem.resourceregistry.client;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.model.entity.Context;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextAlreadyPresentException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
|
public interface ResourceRegistryContextClient {
|
||||||
|
|
||||||
|
public Context create(Context context)
|
||||||
|
throws ContextAlreadyPresentException, ResourceRegistryException;
|
||||||
|
|
||||||
|
public String create(String context)
|
||||||
|
throws ContextAlreadyPresentException, ResourceRegistryException;
|
||||||
|
|
||||||
|
|
||||||
|
public Context read(Context context)
|
||||||
|
throws ContextNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
|
public Context read(UUID uuid)
|
||||||
|
throws ContextNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
|
public String read(String uuid)
|
||||||
|
throws ContextNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
|
|
||||||
|
public Context update(Context context)
|
||||||
|
throws ContextAlreadyPresentException, ResourceRegistryException;
|
||||||
|
|
||||||
|
public String update(String context)
|
||||||
|
throws ContextAlreadyPresentException, ResourceRegistryException;
|
||||||
|
|
||||||
|
|
||||||
|
public boolean delete(Context context)
|
||||||
|
throws ContextNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
|
public boolean delete(UUID uuid)
|
||||||
|
throws ContextNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
|
public boolean delete(String uuid)
|
||||||
|
throws ContextNotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,127 @@
|
||||||
|
package org.gcube.informationsystem.resourceregistry.client;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.Constants;
|
||||||
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
|
import org.gcube.resources.discovery.icclient.ICFactory;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
|
public class ResourceRegistryContextClientFactory {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryContextClientFactory.class);
|
||||||
|
|
||||||
|
protected static Map<String, ResourceRegistryContextClient> clients;
|
||||||
|
|
||||||
|
static {
|
||||||
|
clients = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String FORCED_URL = null;
|
||||||
|
|
||||||
|
protected static void forceToURL(String url){
|
||||||
|
FORCED_URL = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String classFormat = "$resource/Profile/ServiceClass/text() eq '%1s'";
|
||||||
|
private static String nameFormat = "$resource/Profile/ServiceName/text() eq '%1s'";
|
||||||
|
private static String statusFormat = "$resource/Profile/DeploymentData/Status/text() eq 'ready'";
|
||||||
|
private static String containsFormat = "$entry/@EntryName eq '%1s'";
|
||||||
|
|
||||||
|
|
||||||
|
private static String serviceEndpointCategoryFormat = "$resource/Profile/Category/text() eq '%1s'";
|
||||||
|
private static String serviceEndpointNameFormat = "$resource/Profile/Name/text() eq '%1s'";
|
||||||
|
private static String serviceEndpointstatusFormat = "$resource/Profile/RunTime/Status/text() eq 'READY'";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static SimpleQuery queryForService(){
|
||||||
|
return ICFactory.queryFor(GCoreEndpoint.class)
|
||||||
|
.addCondition(String.format(classFormat, Constants.SERVICE_CLASS))
|
||||||
|
.addCondition(String.format(nameFormat, Constants.SERVICE_NAME))
|
||||||
|
.addCondition(String.format(statusFormat))
|
||||||
|
.addVariable("$entry","$resource/Profile/AccessPoint/RunningInstanceInterfaces/Endpoint")
|
||||||
|
.addCondition(String.format(containsFormat, Constants.SERVICE_ENTRY_NAME))
|
||||||
|
.setResult("$entry/text()");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SimpleQuery queryForProxy(){
|
||||||
|
return ICFactory.queryFor(ServiceEndpoint.class)
|
||||||
|
.addCondition(String.format(serviceEndpointCategoryFormat, Constants.SERVICE_CLASS))
|
||||||
|
.addCondition(String.format(serviceEndpointNameFormat, Constants.SERVICE_NAME))
|
||||||
|
.addCondition(String.format(serviceEndpointstatusFormat))
|
||||||
|
.addVariable("$entry","$resource/Profile/AccessPoint/Interface/Endpoint")
|
||||||
|
.addCondition(String.format(containsFormat, Constants.SERVICE_ENTRY_NAME))
|
||||||
|
.setResult("$entry/text()");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected static List<String> getAddresses(){
|
||||||
|
List<String> addresses = new ArrayList<>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
SimpleQuery proxyQuery = queryForProxy();
|
||||||
|
addresses = ICFactory.client().submit(proxyQuery);
|
||||||
|
if(addresses==null || addresses.isEmpty()){
|
||||||
|
throw new Exception("No ResourceRegistry Proxy Found");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.debug("{}. Looking for RunningInstance.", e.getMessage());
|
||||||
|
SimpleQuery serviceQuery = queryForService();
|
||||||
|
addresses = ICFactory.client().submit(serviceQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
return addresses;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static ResourceRegistryContextClient create(){
|
||||||
|
if(FORCED_URL!=null){
|
||||||
|
return new ResourceRegistryContextClientImpl(FORCED_URL);
|
||||||
|
}
|
||||||
|
|
||||||
|
String key = null;
|
||||||
|
if (SecurityTokenProvider.instance.get() == null) {
|
||||||
|
if (ScopeProvider.instance.get() == null) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"Null Token and Scope. Please set your token first.");
|
||||||
|
}
|
||||||
|
key = ScopeProvider.instance.get();
|
||||||
|
} else {
|
||||||
|
key = SecurityTokenProvider.instance.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceRegistryContextClient client = clients.get(key);
|
||||||
|
|
||||||
|
if(client==null){
|
||||||
|
|
||||||
|
List<String> addresses = getAddresses();
|
||||||
|
|
||||||
|
if(addresses==null || addresses.isEmpty()){
|
||||||
|
String error = String.format("No %s:%s found in the current context", Constants.SERVICE_CLASS, Constants.SERVICE_NAME);
|
||||||
|
throw new RuntimeException(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
Random random = new Random();
|
||||||
|
int index = random.nextInt(addresses.size());
|
||||||
|
|
||||||
|
client = new ResourceRegistryContextClientImpl(addresses.get(index));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,200 @@
|
||||||
|
package org.gcube.informationsystem.resourceregistry.client;
|
||||||
|
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.impl.utils.ISMapper;
|
||||||
|
import org.gcube.informationsystem.model.entity.Context;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextAlreadyPresentException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall.HTTPMETHOD;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
|
public class ResourceRegistryContextClientImpl implements ResourceRegistryContextClient {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryContextClientImpl.class);
|
||||||
|
|
||||||
|
public static final String PATH_SEPARATOR = "/";
|
||||||
|
|
||||||
|
protected final String address;
|
||||||
|
protected HTTPCall httpCall;
|
||||||
|
|
||||||
|
public ResourceRegistryContextClientImpl(String address) {
|
||||||
|
this.address = address;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private HTTPCall getHTTPCall() throws MalformedURLException {
|
||||||
|
if (httpCall == null) {
|
||||||
|
httpCall = new HTTPCall(address, ResourceRegistryContextClient.class.getSimpleName());
|
||||||
|
}
|
||||||
|
return httpCall;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Context create(Context context) throws ContextAlreadyPresentException, ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
String contextString = ISMapper.marshal(context);
|
||||||
|
String res = create(contextString);
|
||||||
|
return ISMapper.unmarshal(Context.class, res);
|
||||||
|
} catch (ResourceRegistryException e) {
|
||||||
|
// logger.trace("Error Creating {}", facet, e);
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// logger.trace("Error Creating {}", facet, e);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String create(String context) throws ContextAlreadyPresentException, ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
logger.trace("Going to create: {}", context);
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
stringWriter.append(PATH_SEPARATOR);
|
||||||
|
stringWriter.append(ContextPath.CONTEXT_PATH_PART);
|
||||||
|
|
||||||
|
HTTPCall httpCall = getHTTPCall();
|
||||||
|
String c = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, context);
|
||||||
|
|
||||||
|
logger.trace("{} successfully created", c);
|
||||||
|
return c;
|
||||||
|
|
||||||
|
} catch (ResourceRegistryException e) {
|
||||||
|
// logger.trace("Error Creating {}", facet, e);
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// logger.trace("Error Creating {}", facet, e);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Context read(Context context) throws ContextNotFoundException, ResourceRegistryException {
|
||||||
|
return read(context.getHeader().getUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Context read(UUID uuid) throws ContextNotFoundException, ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
String res = read(uuid.toString());
|
||||||
|
return ISMapper.unmarshal(Context.class, res);
|
||||||
|
} catch (ResourceRegistryException e) {
|
||||||
|
// logger.trace("Error Creating {}", facet, e);
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// logger.trace("Error Creating {}", facet, e);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String read(String uuid) throws ContextNotFoundException, ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
logger.trace("Going to read {} with UUID {}", Context.NAME);
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
stringWriter.append(PATH_SEPARATOR);
|
||||||
|
stringWriter.append(ContextPath.CONTEXT_PATH_PART);
|
||||||
|
stringWriter.append(PATH_SEPARATOR);
|
||||||
|
stringWriter.append(uuid);
|
||||||
|
|
||||||
|
HTTPCall httpCall = getHTTPCall();
|
||||||
|
String c = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.GET);
|
||||||
|
|
||||||
|
logger.debug("Got {} is {}", Context.NAME, c);
|
||||||
|
return c;
|
||||||
|
|
||||||
|
} catch (ResourceRegistryException e) {
|
||||||
|
// logger.trace("Error Creating {}", facet, e);
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// logger.trace("Error Creating {}", facet, e);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Context update(Context context) throws ContextAlreadyPresentException, ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
String contextString = ISMapper.marshal(context);
|
||||||
|
String res = update(contextString);
|
||||||
|
return ISMapper.unmarshal(Context.class, res);
|
||||||
|
} catch (ResourceRegistryException e) {
|
||||||
|
// logger.trace("Error Updating {}", facet, e);
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// logger.trace("Error Updating {}", facet, e);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String update(String context) throws ContextAlreadyPresentException, ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
logger.trace("Going to update: {}", context);
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
stringWriter.append(PATH_SEPARATOR);
|
||||||
|
stringWriter.append(ContextPath.CONTEXT_PATH_PART);
|
||||||
|
|
||||||
|
HTTPCall httpCall = getHTTPCall();
|
||||||
|
String c = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.POST, context);
|
||||||
|
|
||||||
|
logger.trace("{} successfully updated", c);
|
||||||
|
return c;
|
||||||
|
|
||||||
|
} catch (ResourceRegistryException e) {
|
||||||
|
// logger.trace("Error Creating {}", facet, e);
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// logger.trace("Error Creating {}", facet, e);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean delete(Context context) throws ContextNotFoundException, ResourceRegistryException {
|
||||||
|
return delete(context.getHeader().getUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean delete(UUID uuid) throws ContextNotFoundException, ResourceRegistryException {
|
||||||
|
return delete(uuid.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean delete(String uuid) throws ContextNotFoundException, ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
logger.trace("Going to read {} with UUID {}", Context.NAME);
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
stringWriter.append(PATH_SEPARATOR);
|
||||||
|
stringWriter.append(ContextPath.CONTEXT_PATH_PART);
|
||||||
|
stringWriter.append(PATH_SEPARATOR);
|
||||||
|
stringWriter.append(uuid);
|
||||||
|
|
||||||
|
HTTPCall httpCall = getHTTPCall();
|
||||||
|
boolean deleted = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.DELETE);
|
||||||
|
|
||||||
|
logger.info("{} with UUID {} {}", Context.NAME, uuid,
|
||||||
|
deleted ? " successfully deleted" : "was NOT deleted");
|
||||||
|
return deleted;
|
||||||
|
} catch (ResourceRegistryException e) {
|
||||||
|
// logger.trace("Error Creating {}", facet, e);
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// logger.trace("Error Creating {}", facet, e);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE xml>
|
||||||
|
<configuration>
|
||||||
|
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
|
||||||
|
<logger name="org.gcube" level="INFO" />
|
||||||
|
<logger name="org.gcube.informationsystem.resourceregistry" level="TRACE" />
|
||||||
|
|
||||||
|
<root level="WARN">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</configuration>
|
Loading…
Reference in New Issue