This commit is contained in:
Fabio Sinibaldi 2019-03-19 17:02:08 +00:00
parent d0c06a0fec
commit 9be8b0dbb2
33 changed files with 707 additions and 59 deletions

View File

@ -1,12 +1,15 @@
package org.gcube.data.publishing.gCatFeeder.catalogues;
import org.gcube.data.publishing.gCatFeeder.catalogues.model.PublishReport;
import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.CatalogueInteractionException;
import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.PublicationException;
import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.WrongObjectFormatException;
import org.gcube.data.publishing.gCatFeeder.model.CatalogueFormatData;
import org.gcube.data.publishing.gCatFeeder.model.ControllerConfiguration;
public interface CatalogueController {
public PublishReport publishItem(CatalogueFormatData toPublish) throws WrongObjectFormatException;
public PublishReport publishItem(CatalogueFormatData toPublish) throws WrongObjectFormatException,CatalogueInteractionException,PublicationException;
public void configure (ControllerConfiguration config);
}

View File

@ -0,0 +1,30 @@
package org.gcube.data.publishing.gCatFeeder.catalogues.model.faults;
public class CatalogueInteractionException extends PublicationException {
public CatalogueInteractionException() {
// TODO Auto-generated constructor stub
}
public CatalogueInteractionException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
// TODO Auto-generated constructor stub
}
public CatalogueInteractionException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
}
public CatalogueInteractionException(String message) {
super(message);
// TODO Auto-generated constructor stub
}
public CatalogueInteractionException(Throwable cause) {
super(cause);
// TODO Auto-generated constructor stub
}
}

View File

@ -18,11 +18,7 @@
</dependency>
<dependency>
<groupId>org.gcube.data-publishing</groupId>
<artifactId>gcat-client</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT]</version>
</dependency>
</dependencies>

View File

@ -0,0 +1,5 @@
Manifest-Version: 1.0
Built-By: fabio
Build-Jdk: 1.8.0_201
Created-By: Maven Integration for Eclipse

View File

@ -0,0 +1,7 @@
#Generated by Maven Integration for Eclipse
#Tue Mar 19 16:04:16 CET 2019
version=1.0.0-SNAPSHOT
groupId=org.gcube.data-publishing.gCat-Feeder
m2e.projectName=ckan-controller-plugin
m2e.projectLocation=/home/fabio/workspaces/DEV/gCat-Feeder-Suite/ckan-controller-plugin
artifactId=ckan-controller-plugin

View File

@ -0,0 +1,26 @@
<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.data-publishing.gCat-Feeder</groupId>
<artifactId>gCat-Feeder-Suite</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>ckan-controller-plugin</artifactId>
<name>ckan-controller-plugin</name>
<description>controller plugin for gCat-Feeder aimed to publish metadata to CKAN catalogue</description>
<dependencies>
<dependency>
<groupId>org.gcube.data-publishing.gCat-Feeder</groupId>
<artifactId>catalogue-plugin-framework</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
</dependencies>
</project>

View File

@ -3,6 +3,7 @@ package org.gcube.data.publishing.gCatfeeder.collectors;
import java.util.Set;
import org.gcube.data.publishing.gCatFeeder.model.CatalogueFormatData;
import org.gcube.data.publishing.gCatFeeder.model.ControllerConfiguration;
import org.gcube.data.publishing.gCatfeeder.collectors.model.CustomData;
import org.gcube.data.publishing.gCatfeeder.collectors.model.PluginDescriptor;
import org.gcube.data.publishing.gCatfeeder.collectors.model.faults.CatalogueNotSupportedException;
@ -18,4 +19,6 @@ public interface CollectorPlugin<E extends CustomData>{
public DataTransformer<? extends CatalogueFormatData,E> getTransformerByCatalogueType(String catalogueType)throws CatalogueNotSupportedException;
public DataCollector<E> getCollector();
public ControllerConfiguration getPublisherControllerConfiguration(String catalogueType)throws CatalogueNotSupportedException;;
}

View File

@ -0,0 +1,16 @@
package org.gcube.data.publishing.gCatFeeder.model;
public class ControllerConfiguration {
public static enum PublishingPolicy{
FAIL,UPDATE,SKIP
}
private PublishingPolicy onClash=PublishingPolicy.UPDATE;
public PublishingPolicy getOnClash() {
return onClash;
}
}

View File

@ -23,6 +23,14 @@
<artifactId>gcat-client</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT]</version>
</dependency>
<dependency>
<groupId>org.gcube.data-publishing.gCat-Feeder</groupId>
<artifactId>test-commons</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT]</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -1,52 +0,0 @@
package org.gcube.data.pu;
import org.gcube.data.publishing.gCatFeeder.catalogues.CatalogueController;
import org.gcube.data.publishing.gCatFeeder.catalogues.model.PublishReport;
import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.WrongObjectFormatException;
import org.gcube.data.publishing.gCatFeeder.model.CatalogueFormatData;
import org.gcube.data.publishing.gCatFeeder.model.CatalogueInstanceDescriptor;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class GCatController implements CatalogueController{
private static ObjectMapper mapper=new ObjectMapper();
private CatalogueInstanceDescriptor desc;
public GCatController(CatalogueInstanceDescriptor instance) {
this.desc=instance;
}
/**
* Expected structure
*
* {
* "profile" : "<serialized_profile>",
* "item" : "<serialized_item>",
* "resources" : [
* "<serialized_resource>",
* "<serialized_resource>",
* ....]
* }
*
* NB serialized resources are updated with "package_id" set as the published item id
*
*
*/
@Override
public PublishReport publishItem(CatalogueFormatData arg0) throws WrongObjectFormatException {
log.debug("Publishing {} ",arg0);
String serialized=arg0.toCatalogueFormat();
}
}

View File

@ -0,0 +1,371 @@
package org.gcube.data.publishing.gCataFeeder.catalogues.gCat;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import javax.ws.rs.WebApplicationException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.data.publishing.gCatFeeder.catalogues.CatalogueController;
import org.gcube.data.publishing.gCatFeeder.catalogues.model.PublishReport;
import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.CatalogueInteractionException;
import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.ControllerInstantiationFault;
import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.PublicationException;
import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.WrongObjectFormatException;
import org.gcube.data.publishing.gCatFeeder.model.CatalogueFormatData;
import org.gcube.data.publishing.gCatFeeder.model.CatalogueInstanceDescriptor;
import org.gcube.data.publishing.gCatFeeder.model.ControllerConfiguration;
import org.gcube.data.publishing.gCatFeeder.model.ControllerConfiguration.PublishingPolicy;
import org.gcube.gcat.client.Item;
import org.gcube.gcat.client.Profile;
import org.gcube.gcat.client.Resource;
import org.w3c.dom.Document;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class GCatController implements CatalogueController{
private static ObjectMapper mapper;
private static DocumentBuilderFactory factory;
private static DocumentBuilder builder;
private static XPathFactory xPathfactory;
private static XPath xpath;
private static XPathExpression expr;
static {
mapper=new ObjectMapper();
factory= DocumentBuilderFactory.newInstance();
xPathfactory = XPathFactory.newInstance();
xpath = xPathfactory.newXPath();
try {
builder= factory.newDocumentBuilder();
expr= xpath.compile("");
} catch (ParserConfigurationException | XPathExpressionException e) {
throw new RuntimeException("Unable to initialize Controller");
}
}
private CatalogueInstanceDescriptor desc;
private String callerToken=null;
private ControllerConfiguration config;
public GCatController(CatalogueInstanceDescriptor instance) throws ControllerInstantiationFault {
try{
this.desc=instance;
if(isCustomToken())
setCustomToken();
checkInstance();
if(isCustomToken())
resetToken();
}catch(ControllerInstantiationFault e) {
throw e;
}
}
@Override
public void configure(ControllerConfiguration config) {
this.config = config;
}
/**
* Expected structure
*
* {
* "profile" : "<xml_profile>",
* "item" : "<json_item>",
* "resources" : [
* "<json_resource>",
* "<json_resource>",
* ....]
* }
*
* NB serialized resources are updated with "package_id" set as the published item id
*
*
*/
@Override
public PublishReport publishItem(CatalogueFormatData arg0) throws WrongObjectFormatException,CatalogueInteractionException,PublicationException{
log.debug("Publishing {} ",arg0);
String serialized=arg0.toCatalogueFormat();
try {
if(isCustomToken())
setCustomToken();
log.debug("Parsing data..");
JsonNode node=mapper.readTree(serialized);
if(!node.hasNonNull("item")) throw new WrongObjectFormatException("No \"item\" specified in serialized object");
JsonNode itemNode=node.path("item");
if(node.hasNonNull("profile")) {
log.debug("Publishing profile..");
String xmlProfile=node.path("profile").asText();
String profileName=getProfileName(xmlProfile);
createProfile(profileName, xmlProfile);
}
log.debug("Publishing Item..");
String itemResp=createItem(itemNode.asText());
String itemId = getId(itemResp);
log.debug("Pubilshed Item with ID {} ",itemId);
if(node.hasNonNull("resources")) {
log.debug("Pubilshing resources for {} ",itemId);
Iterator<JsonNode> resIterator=node.path("resources").elements();
while(resIterator.hasNext()) {
JsonNode resNode=resIterator.next();
String resourceName=resNode.path("name").asText();
createResource(itemId, resourceName, resNode.asText());
}
}
return new PublishReport(true, itemId);
} catch(WrongObjectFormatException | PublicationException e) {
throw e;
} catch (Throwable e) {
throw new WrongObjectFormatException("Unable to read format ",e);
}finally{
if(isCustomToken())
resetToken();
}
}
private String createProfile(String profileName,String xmlProfile) throws WrongObjectFormatException, PublicationException{
Profile profile=null;
try{
if(isForcedUrl())
profile = new Profile(getForcedUrl());
else profile=new Profile();
// check if exists
boolean exists=false;
try {
profile.read(profileName);
exists=true;
}catch(Throwable t) {
exists=false;
}
switch(getOnClash()) {
case SKIP : return null;
case FAIL : {
if(exists) throw new PublicationException("Profile "+profileName+" already existing");
break;
}
case UPDATE : {
if(exists) return profile.update(profileName, xmlProfile);
break;
}
}
return profile.create(profileName, xmlProfile);
}catch(WebApplicationException e) {
handleWebException(e);
return null;
}catch(MalformedURLException e) {
throw new CatalogueInteractionException(e);
}
}
private String createResource(String itemId,String resourceName,String toCreate) throws WrongObjectFormatException, PublicationException{
Resource resource=null;
try{
if(isForcedUrl())
resource = new Resource(getForcedUrl());
else resource=new Resource();
// Try to create
try {
log.debug("Trying to create resource {} for package {} ",resourceName,itemId);
return resource.create(itemId, toCreate);
}catch(WebApplicationException e) {
// Conflict = resource already existing
if(e.getResponse().getStatus()==409) {
switch(getOnClash()) {
case SKIP : return null;
case FAIL : throw new PublicationException("Resource "+resourceName+" already existing");
case UPDATE : {
// Look for resource id
log.debug("Looking for resource with name {} under item {} ",resourceName,itemId);
String resourceList=resource.list(itemId);
JsonNode listNode=mapper.readTree(resourceList);
Iterator<JsonNode> iterator=listNode.elements();
String resourceId=null;
while(iterator.hasNext()) {
JsonNode res=iterator.next();
if(res.path("name").asText().equals(resourceName)) {
resourceId=res.path("id").asText();
break;
}
}
log.debug("Found id {} for resource Name {} ",resourceId,resourceName);
return resource.update(itemId, resourceId, toCreate);
}
default : return null;
}
}else throw e;
}
}catch(WebApplicationException e) {
handleWebException(e);
return null;
}catch(MalformedURLException e) {
throw new CatalogueInteractionException(e);
}catch(IOException e) {
throw new CatalogueInteractionException(e);
}
}
private String createItem(String toCreate) throws WrongObjectFormatException, PublicationException{
Item item=null;
try{
if(isForcedUrl())
item = new Item(getForcedUrl());
else item=new Item();
return item.create(toCreate);
}catch(WebApplicationException e) {
handleWebException(e);
return null;
}catch(MalformedURLException e) {
throw new CatalogueInteractionException(e);
}
}
// instance utils
private PublishingPolicy getOnClash() {
return config.getOnClash();
}
private boolean isForcedUrl() {
return desc.getCustomToken()==null&&desc.getUrl()!=null;
}
private URL getForcedUrl() throws MalformedURLException {
return new URL(desc.getUrl());
}
private boolean isCustomToken() {
return desc.getCustomToken()!=null;
}
private void setCustomToken() {
callerToken=SecurityTokenProvider.instance.get();
SecurityTokenProvider.instance.set(desc.getCustomToken());
}
private void resetToken() {
SecurityTokenProvider.instance.set(callerToken);
}
private void checkInstance() throws ControllerInstantiationFault{
Item item=null;
try{
if(isForcedUrl())
item=new Item(getForcedUrl());
else item=new Item();
item.list(10, 0);
}catch(Throwable t) {
String msg=String.format("Unable to contact gCat with configuration %1$s ",desc);
log.error(msg,t);
throw new ControllerInstantiationFault(msg,t);
}
}
// Static utils from catalogue-ws
private static String getProfileName(String xmlProfile) throws WrongObjectFormatException {
try{
Document doc = builder.parse(xmlProfile);
return (String) expr.evaluate(doc, XPathConstants.STRING);
}catch(Throwable t) {
throw new WrongObjectFormatException("Unable to parse profile. ",t);
}
}
private static String getId(String publishResponse) {
try {
return mapper.readTree(publishResponse).path("result").path("id").asText();
} catch (Throwable t) {
t.printStackTrace();
throw new RuntimeException("FAILED Parsing of "+publishResponse);
}
}
private static String getPublishedUrl(String publishResponse) {
try {
Iterator<JsonNode> iterator=mapper.readTree(publishResponse).path("result").path("extras").elements();
while(iterator.hasNext()) {
JsonNode node=iterator.next();
if(node.path("key").asText().equals("Item URL"))
return node.path("value").asText();
}
return "N/A";
} catch (Throwable t) {
t.printStackTrace();
throw new RuntimeException("FAILED Parsing of "+publishResponse);
}
}
private static void handleWebException(WebApplicationException e) throws WrongObjectFormatException, PublicationException {
log.debug("Received Web Exception {} ",e);
String msg=e.getResponse().readEntity(String.class);
switch(e.getResponse().getStatus()) {
case 400 : throw new WrongObjectFormatException("BAD Request : "+msg,e);
case 401 : throw new CatalogueInteractionException("Unauthorized : "+msg,e);
case 404 : throw new CatalogueInteractionException("NOT FOUND : "+msg,e);
case 405 : throw new CatalogueInteractionException("Method Not Allowed : "+msg,e);
case 409 : throw new CatalogueInteractionException("Conflict : "+msg,e);
case 500 : throw new CatalogueInteractionException("Remote Error : "+msg,e);
default : throw new PublicationException("Unexpected error code : "+msg,e);
}
}
}

View File

@ -0,0 +1,22 @@
package org.gcube.data.publishing.gCataFeeder.catalogues.gCat;
import org.gcube.data.publishing.gCatFeeder.catalogues.CatalogueController;
import org.gcube.data.publishing.gCatFeeder.catalogues.CataloguePlugin;
import org.gcube.data.publishing.gCatFeeder.catalogues.model.CataloguePluginDescriptor;
import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.ControllerInstantiationFault;
import org.gcube.data.publishing.gCatFeeder.model.CatalogueInstanceDescriptor;
public class GCatPlugin implements CataloguePlugin {
@Override
public CataloguePluginDescriptor getDescriptor() {
return new CataloguePluginDescriptor("GCAT");
}
@Override
public CatalogueController instantiateController(CatalogueInstanceDescriptor desc)
throws ControllerInstantiationFault {
return new GCatController(desc);
}
}

View File

@ -0,0 +1,15 @@
package org.gcube.data.publishing.gCatFeeder.catalogues.gCat;
import org.gcube.data.publishing.gCatFeeder.tests.TokenSetter;
import org.gcube.data.publishing.gCatFeeder.utils.TokenUtils;
import org.junit.Before;
public class Interactions {
@Before
private void setToken() {
TokenSetter.set("/gcube/devsec");
}
}

View File

@ -0,0 +1,5 @@
Manifest-Version: 1.0
Built-By: fabio
Build-Jdk: 1.8.0_201
Created-By: Maven Integration for Eclipse

View File

@ -0,0 +1,7 @@
#Generated by Maven Integration for Eclipse
#Tue Mar 19 16:05:42 CET 2019
version=1.0.0-SNAPSHOT
groupId=org.gcube.data-publishing.gCat-Feeder
m2e.projectName=gCat-Controller
m2e.projectLocation=/home/fabio/workspaces/DEV/gCat-Feeder-Suite/gCat-Controller
artifactId=gCat-Controller

View File

@ -0,0 +1,39 @@
<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.data-publishing.gCat-Feeder</groupId>
<artifactId>gCat-Feeder-Suite</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>gCat-Controller</artifactId>
<name>gCat Controller</name>
<description>Controller implementation for GCat Service</description>
<dependencies>
<dependency>
<groupId>org.gcube.data-publishing.gCat-Feeder</groupId>
<artifactId>catalogue-plugin-framework</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.data-publishing</groupId>
<artifactId>gcat-client</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT]</version>
</dependency>
<dependency>
<groupId>org.gcube.data-publishing.gCat-Feeder</groupId>
<artifactId>test-commons</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT]</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -22,6 +22,7 @@
<module>catalogue-plugin-framework</module>
<module>ckan-controller-plugin</module>
<module>gCat-Controller</module>
<module>test-commons</module>
</modules>
<dependencyManagement>

36
test-commons/.classpath Normal file
View File

@ -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>

23
test-commons/.project Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>test-commons</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>

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

11
test-commons/pom.xml Normal file
View File

@ -0,0 +1,11 @@
<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.data-publishing.gCat-Feeder</groupId>
<artifactId>gCat-Feeder-Suite</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>test-commons</artifactId>
<name>test commons</name>
<description>Utility classes for test purposes</description>
</project>

View File

@ -0,0 +1,38 @@
package org.gcube.data.publishing.gCatFeeder.tests;
import java.util.Properties;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TokenSetter {
private static Properties props=new Properties();
private static final Logger log= LoggerFactory.getLogger(TokenSetter.class);
static{
try {
props.load(TokenSetter.class.getResourceAsStream("/tokens.properties"));
} catch (Exception e) {
throw new RuntimeException("YOU NEED TO SET TOKEN FILE IN CONFIGURATION");
}
}
public static void set(String scope){
try{
if(!props.containsKey(scope)) throw new RuntimeException("No token found for scope : "+scope);
SecurityTokenProvider.instance.set(props.getProperty(scope));
}catch(Throwable e){
log.warn("Unable to set token for scope "+scope,e);
}
ScopeProvider.instance.set(scope);
}
}

View File

@ -0,0 +1,5 @@
Manifest-Version: 1.0
Built-By: fabio
Build-Jdk: 1.8.0_201
Created-By: Maven Integration for Eclipse

View File

@ -0,0 +1,7 @@
#Generated by Maven Integration for Eclipse
#Tue Mar 19 16:04:13 CET 2019
version=1.0.0-SNAPSHOT
groupId=org.gcube.data-publishing.gCat-Feeder
m2e.projectName=test-commons
m2e.projectLocation=/home/fabio/workspaces/DEV/gCat-Feeder-Suite/test-commons
artifactId=test-commons

View File

@ -0,0 +1,11 @@
<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.data-publishing.gCat-Feeder</groupId>
<artifactId>gCat-Feeder-Suite</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>test-commons</artifactId>
<name>test commons</name>
<description>Utility classes for test purposes</description>
</project>