This commit is contained in:
Fabio Sinibaldi 2019-04-01 14:23:05 +00:00
parent 4e512ef3d1
commit 6100cf8afb
16 changed files with 138 additions and 65 deletions

View File

@ -6,11 +6,11 @@ import java.util.Set;
import org.gcube.data.analysis.dataminermanagercl.server.DataMinerService;
import org.gcube.data.analysis.dataminermanagercl.server.dmservice.SClient;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.Parameter;
import org.gcube.data.analysis.dataminermanagercl.shared.process.Operator;
import org.gcube.data.analysis.dataminermanagercl.shared.process.OperatorCategory;
import org.gcube.data.analysis.dataminermanagercl.shared.process.OperatorsClassification;
import org.gcube.data.publishing.gCatFeeder.collectors.dm.model.InternalAlgorithmDescriptor;
import org.gcube.data.publishing.gCatFeeder.collectors.dm.model.InternalAlgorithmDescriptor.Parameter;
import org.gcube.data.publishing.gCatfeeder.collectors.DataCollector;
import org.gcube.data.publishing.gCatfeeder.collectors.model.faults.CollectorFault;
@ -70,18 +70,22 @@ public class DMAlgorithmsInfoCollector implements DataCollector<InternalAlgorith
desc.setId(opID);
desc.setName(operatorName);
desc.setAuthor(DataMinerCollectorProperties.getProperty(DataMinerCollectorProperties.DEFAULT_AUTHOR));
desc.setMaintainer(DataMinerCollectorProperties.getProperty(DataMinerCollectorProperties.DEFAULT_AUTHOR));
// Parameters info
for(Parameter param:op.getOperatorParameters()) {
for(org.gcube.data.analysis.dataminermanagercl.shared.parameters.Parameter param:op.getOperatorParameters()) {
String paramDescription=param.getDescription();
String paramName=param.getName();
String paramType=param.getTypology().toString();
String paramValue=param.getValue();
desc.getParameters().add(
new Parameter(paramName, paramType, paramDescription, paramValue));
}
// op.get
desc.getTags().add(categoryName);
toReturn.add(desc);
}

View File

@ -0,0 +1,24 @@
package org.gcube.data.publishing.gCatFeeder.collectors.dm;
import java.io.IOException;
import java.util.Properties;
public class DataMinerCollectorProperties {
public static final String DEFAULT_AUTHOR="default_author";
private static Properties props;
public static void init() throws IOException {
props=new Properties();
props.load(DataMinerCollectorProperties.class.getResourceAsStream("config.properties"));
}
public static String getProperty(String key) {
return props.getProperty(key);
}
}

View File

@ -4,6 +4,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.Properties;
import java.util.Set;
import org.gcube.data.publishing.gCatFeeder.collectors.dm.model.InternalAlgorithmDescriptor;
@ -22,6 +23,10 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class DataMinerPlugin implements CollectorPlugin<InternalAlgorithmDescriptor> {
@Override
public PluginDescriptor getDescriptor() {
return new PluginDescriptor("DATA_MINER_ALGORITHMS");
@ -60,7 +65,10 @@ public class DataMinerPlugin implements CollectorPlugin<InternalAlgorithmDescrip
Path p=Paths.get(this.getClass().getResource( "profile.xml").toURI());
log.debug("Path is : {} ",p.toUri());
GCatModel.setProfile(
new String(Files.readAllBytes(p)));
new String(Files.readAllBytes(p)));
DataMinerCollectorProperties.init();
}
@Override

View File

@ -58,6 +58,9 @@ public class InternalAlgorithmDescriptor implements CustomData {
private String briefDescription;
private String id;
private String author;
private String maintainer;
//category info
private String categoryBriefDescription;

View File

@ -30,16 +30,21 @@ public class GCatModel implements CatalogueFormatData {
public GCatModel(InternalAlgorithmDescriptor desc) {
item=new CkanItem();
// item.setAuthor(desc.getAuthor());
item.setAuthor(desc.getAuthor());
item.setDescription(desc.getDescription());
item.setTitle(desc.getName()+" in "+ContextUtils.getCurrentScopeName());
item.setLicense("CC-BY-NC-SA-4.0");
// item.setMaintainer(desc.getAuthor());
item.setMaintainer(desc.getMaintainer());
item.setName(item.getTitle().toLowerCase().toLowerCase().replaceAll(" ", "_"));
for(String tag:desc.getTags()) {
item.getTags().add(fixTag(tag));
}
item.getExtras().add(new CKanExtraField("system", "Algorithm"));
// TODO ADD PARAMETERS
// TODO ADD RESOURCES
}

View File

@ -0,0 +1 @@
org.gcube.data.publishing.gCataFeeder.catalogues.gCat.GCatPlugin

View File

@ -12,24 +12,24 @@ import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.WrongObjectF
import org.gcube.data.publishing.gCatFeeder.model.CatalogueFormatData;
import org.gcube.data.publishing.gCatFeeder.model.CatalogueInstanceDescriptor;
import org.gcube.data.publishing.gCatFeeder.model.InternalConversionException;
import org.gcube.data.publishing.gCatFeeder.tests.TokenSetter;
import org.gcube.data.publishing.gCatFeeder.tests.BaseCataloguePluginTest;
import org.gcube.data.publishing.gCataFeeder.catalogues.gCat.GCatPlugin;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Assume;
import org.junit.Test;
public class Interactions {
public class Interactions extends BaseCataloguePluginTest{
private static class CustomTargetFormat implements CatalogueFormatData{
private String fileName;
public CustomTargetFormat(String fileName) {
super();
this.fileName = fileName;
}
@Override
public String toCatalogueFormat() {
try {
@ -39,67 +39,69 @@ public class Interactions {
}
}
}
@Before
public void setToken() {
TokenSetter.set("/gcube/preprod/preVRE");
}
public CatalogueController getController() throws ControllerInstantiationFault {
GCatPlugin plugin=new GCatPlugin();
return plugin.instantiateController(new CatalogueInstanceDescriptor());
}
@Test(expected=ControllerInstantiationFault.class)
public void testFailInstance() throws ControllerInstantiationFault {
GCatPlugin plugin=new GCatPlugin();
plugin.instantiateController(new CatalogueInstanceDescriptor().setUrl("http://no.where.com"));
}
@Test
public void duplicates() {
try {
publish(getController(),"full.json");
publish(getController(),"full.json");
}catch(Exception e) {
Assert.fail(e.getMessage());
}
Assume.assumeTrue(isTestInfrastructureEnabled());
try {
publish(getController(),"full.json");
publish(getController(),"full.json");
}catch(Exception e) {
Assert.fail(e.getMessage());
}
}
@Test(expected=WrongObjectFormatException.class)
public void empties() throws CatalogueInteractionException, WrongObjectFormatException, PublicationException, ControllerInstantiationFault, InternalConversionException {
publish(getController(),"empties.json");
Assume.assumeTrue(isTestInfrastructureEnabled());
publish(getController(),"empties.json");
}
@Test(expected=PublicationException.class)
public void missingProfile() throws CatalogueInteractionException, WrongObjectFormatException, PublicationException, ControllerInstantiationFault, InternalConversionException {
publish(getController(),"missingProfile.json");
Assume.assumeTrue(isTestInfrastructureEnabled());
publish(getController(),"missingProfile.json");
}
@Test(expected=WrongObjectFormatException.class)
public void noitem() throws CatalogueInteractionException, WrongObjectFormatException, PublicationException, ControllerInstantiationFault, InternalConversionException {
publish(getController(),"noItem.json");
Assume.assumeTrue(isTestInfrastructureEnabled());
publish(getController(),"noItem.json");
}
@Test
public void item() {
Assume.assumeTrue(isTestInfrastructureEnabled());
try {
publish(getController(),"onlyItem.json");
} catch (WrongObjectFormatException | PublicationException | ControllerInstantiationFault | InternalConversionException e) {
Assert.fail(e.getMessage());
}
}
private static PublishReport publish(CatalogueController controller, String filename) throws CatalogueInteractionException, WrongObjectFormatException, PublicationException, InternalConversionException {
return controller.publishItem(new CustomTargetFormat(filename));
}

View File

@ -0,0 +1 @@
org.gcube.data.publishing.gCataFeeder.catalogues.gCat.GCatPlugin

View File

@ -10,7 +10,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BaseCataloguePluginTest {
public class BaseCataloguePluginTest extends InfrastructureTests{
private static final Logger log= LoggerFactory.getLogger(BaseCataloguePluginTest.class);
@ -19,7 +19,7 @@ public class BaseCataloguePluginTest {
@BeforeClass
public void checkPluginRegistration() {
public static void checkPluginRegistration() {
int pluginsCounter=0;
for(CataloguePlugin pl:cataloguePluginsLoader) {
pluginsCounter++;

View File

@ -1,13 +1,9 @@
package org.gcube.data.publishing.gCatFeeder.tests;
import java.io.IOException;
import java.util.Collection;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.Set;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.data.publishing.gCatFeeder.model.CatalogueFormatData;
import org.gcube.data.publishing.gCatFeeder.model.InternalConversionException;
import org.gcube.data.publishing.gCatfeeder.collectors.CollectorPlugin;
@ -20,9 +16,9 @@ import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BaseCollectorTest {
public class BaseCollectorTest extends InfrastructureTests{
private static String testContext=null;
private static final Logger log= LoggerFactory.getLogger(BaseCollectorTest.class);
@ -67,18 +63,11 @@ public class BaseCollectorTest {
// Check if instrastructure is enabled
testContext=System.getProperty("testContext");
System.out.println("TEST CONTEXT = "+testContext);
if(isTestInfrastructureEnabled()) {
Properties props=new Properties();
try{
props.load(BaseCollectorTest.class.getResourceAsStream("/tokens.properties"));
}catch(IOException e) {throw new RuntimeException(e);}
if(!props.containsKey(testContext)) throw new RuntimeException("No token found for scope : "+testContext);
SecurityTokenProvider.instance.set(props.getProperty(testContext));
ScopeProvider.instance.set(testContext);
for(CollectorPlugin<? extends CustomData> plugin:collectorPluginsLoader) {
@ -112,8 +101,6 @@ public class BaseCollectorTest {
protected static boolean isTestInfrastructureEnabled() {
return testContext!=null;
}
}

View File

@ -0,0 +1,37 @@
package org.gcube.data.publishing.gCatFeeder.tests;
import java.io.IOException;
import java.util.Properties;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.junit.BeforeClass;
public class InfrastructureTests {
private static String testContext=null;
static {
testContext=System.getProperty("testContext");
System.out.println("TEST CONTEXT = "+testContext);
}
protected static boolean isTestInfrastructureEnabled() {
return testContext!=null;
}
@BeforeClass
public static void setTestContext() {
if(isTestInfrastructureEnabled()) {
Properties props=new Properties();
try{
props.load(BaseCollectorTest.class.getResourceAsStream("/tokens.properties"));
}catch(IOException e) {throw new RuntimeException(e);}
if(!props.containsKey(testContext)) throw new RuntimeException("No token found for scope : "+testContext);
SecurityTokenProvider.instance.set(props.getProperty(testContext));
ScopeProvider.instance.set(testContext);
}
}
}