diff --git a/pom.xml b/pom.xml index 25b4abd..daf8840 100644 --- a/pom.xml +++ b/pom.xml @@ -468,7 +468,6 @@ org.apache.maven.plugins maven-assembly-plugin - 2.2 ${distroDirectory}/descriptor.xml diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/blackbox/MainGenerator.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/blackbox/MainGenerator.java index 7a1e263..e517036 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/blackbox/MainGenerator.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/blackbox/MainGenerator.java @@ -105,7 +105,7 @@ public class MainGenerator { serviceCredentials.getUserName(), Files.newInputStream(producedScript, StandardOpenOption.READ), - producedScript.getFileName().toString(), R_DESCRIPTION+project.getProjectConfig().getLanguage(), + "Main.R", R_DESCRIPTION+project.getProjectConfig().getLanguage(), R_MIMETYPE, project.getProjectFolder().getFolder().getId()); } catch (IOException e) { logger.error(e.getLocalizedMessage()); diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/ProjectBuilder.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/ProjectBuilder.java index 1c7bcfa..d4aeee6 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/ProjectBuilder.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/generator/ProjectBuilder.java @@ -122,6 +122,7 @@ public class ProjectBuilder { public Project buildRepackage() throws StatAlgoImporterServiceException { checkInfoForRepackage(); createBackupOfPackageProject(); + createMainCodeIfRequest(); repackageProjectPackage(); return project; } diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/is/AvailableProjectConfigJAXB.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/is/AvailableProjectConfigJAXB.java index 5450c78..e60b2a6 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/is/AvailableProjectConfigJAXB.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/is/AvailableProjectConfigJAXB.java @@ -39,7 +39,9 @@ public class AvailableProjectConfigJAXB { @Override public String toString() { - return "ProjectConfigJAXB [language=" + language + ", support=" + support + "]"; + return "AvailableProjectConfigJAXB [language=" + language + ", support=" + support + "]"; } + + } diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/is/BuildSAIDescriptor.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/is/BuildSAIDescriptor.java index f6ac7ae..6f4dad4 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/is/BuildSAIDescriptor.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/is/BuildSAIDescriptor.java @@ -27,11 +27,11 @@ public class BuildSAIDescriptor { ArrayList availableProjectConfigurations = new ArrayList<>(); ProjectSetup r = new ProjectSetup("R", ProjectSupportType.REdit); availableProjectConfigurations.add(r); - ProjectSetup rBlackBox = new ProjectSetup("R-black box", ProjectSupportType.BlackBox); + ProjectSetup rBlackBox = new ProjectSetup("R-blackbox", ProjectSupportType.BlackBox); availableProjectConfigurations.add(rBlackBox); ProjectSetup java = new ProjectSetup("Java", ProjectSupportType.BlackBox); availableProjectConfigurations.add(java); - ProjectSetup knimeWorkflow = new ProjectSetup("Knime Workflow", ProjectSupportType.BlackBox); + ProjectSetup knimeWorkflow = new ProjectSetup("Knime-Workflow", ProjectSupportType.BlackBox); availableProjectConfigurations.add(knimeWorkflow); ProjectSetup linuxCompiled = new ProjectSetup("Linux-compiled", ProjectSupportType.BlackBox); availableProjectConfigurations.add(linuxCompiled); @@ -54,13 +54,13 @@ public class BuildSAIDescriptor { ArrayList availableProjectConfigurations = new ArrayList<>(); logger.debug("SAIDescriptorJAXB: " + saiDescriptorJAXB); - if (saiDescriptorJAXB != null && saiDescriptorJAXB.getAvailableprojectconfigurations() != null - && !saiDescriptorJAXB.getAvailableprojectconfigurations().isEmpty()) { + if (saiDescriptorJAXB != null && saiDescriptorJAXB.getAvailableprojectconfiguration() != null + && !saiDescriptorJAXB.getAvailableprojectconfiguration().isEmpty()) { ProjectSupportType type; for (AvailableProjectConfigJAXB availableProjectConfigJAXB : saiDescriptorJAXB - .getAvailableprojectconfigurations()) { + .getAvailableprojectconfiguration()) { type = ProjectSupportType.valueOf(availableProjectConfigJAXB.getSupport()); if (type != null) { availableProjectConfigurations @@ -73,11 +73,11 @@ public class BuildSAIDescriptor { ProjectSetup r = new ProjectSetup("R", ProjectSupportType.REdit); availableProjectConfigurations.add(r); - ProjectSetup rBlackBox = new ProjectSetup("R-black box", ProjectSupportType.BlackBox); + ProjectSetup rBlackBox = new ProjectSetup("R-blackbox", ProjectSupportType.BlackBox); availableProjectConfigurations.add(rBlackBox); ProjectSetup java = new ProjectSetup("Java", ProjectSupportType.BlackBox); availableProjectConfigurations.add(java); - ProjectSetup knimeWorkflow = new ProjectSetup("Knime Workflow", ProjectSupportType.BlackBox); + ProjectSetup knimeWorkflow = new ProjectSetup("Knime-Workflow", ProjectSupportType.BlackBox); availableProjectConfigurations.add(knimeWorkflow); ProjectSetup linuxCompiled = new ProjectSetup("Linux-compiled", ProjectSupportType.BlackBox); availableProjectConfigurations.add(linuxCompiled); diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/is/InformationSystemUtils.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/is/InformationSystemUtils.java index 1964e5c..718588a 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/is/InformationSystemUtils.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/is/InformationSystemUtils.java @@ -43,7 +43,7 @@ public class InformationSystemUtils { List accountingResources = client.submit(query); logger.debug("Resources: " + accountingResources); - SAIDescriptorJAXB enableTabs = null; + SAIDescriptorJAXB saiDescriptorJaxB = null; for (GenericResource genericResource : accountingResources) { if (genericResource.scopes() != null) { @@ -62,8 +62,8 @@ public class InformationSystemUtils { JAXBParser parser = new JAXBParser( SAIDescriptorJAXB.class); logger.debug("Body: " + genericResource.profile().bodyAsString()); - enableTabs = (SAIDescriptorJAXB) parser.parse(genericResource.profile().bodyAsString()); - logger.debug("Enable: " + enableTabs); + saiDescriptorJaxB = (SAIDescriptorJAXB) parser.parse(genericResource.profile().bodyAsString()); + logger.debug("Enable: " + saiDescriptorJaxB); } catch (Throwable e) { String error = "Error in discovery SAI profile generic resource on IS in scope " + scope + ". " + "Resource parsing failed!"; @@ -80,7 +80,7 @@ public class InformationSystemUtils { } } - return enableTabs; + return saiDescriptorJaxB; } catch (StatAlgoImporterServiceException e) { throw e; diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/is/SAIDescriptorJAXB.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/is/SAIDescriptorJAXB.java index 89ea444..55bc601 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/is/SAIDescriptorJAXB.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/is/SAIDescriptorJAXB.java @@ -1,5 +1,6 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.server.is; +import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; @@ -18,20 +19,20 @@ import javax.xml.bind.annotation.XmlRootElement; @XmlAccessorType(XmlAccessType.FIELD) public class SAIDescriptorJAXB { - @XmlElement(name = "availableprojectconfigurations") - private List availableprojectconfigurations = null; + @XmlElement(name = "availableprojectconfiguration") + private List availableprojectconfiguration = new ArrayList<>(); - public List getAvailableprojectconfigurations() { - return availableprojectconfigurations; + public List getAvailableprojectconfiguration() { + return availableprojectconfiguration; } - public void setAvailableprojectconfigurations(List availableprojectconfigurations) { - this.availableprojectconfigurations = availableprojectconfigurations; + public void setAvailableprojectconfiguration(List availableprojectconfiguration) { + this.availableprojectconfiguration = availableprojectconfiguration; } @Override public String toString() { - return "SAIDescriptorJAXB [availableprojectconfigurations=" + availableprojectconfigurations + "]"; + return "SAIDescriptorJAXB [availableprojectconfiguration=" + availableprojectconfiguration + "]"; } } diff --git a/src/test/java/org/gcube/portlets/user/statisticalalgorithmsimporter/ISResourceTest.java b/src/test/java/org/gcube/portlets/user/statisticalalgorithmsimporter/ISResourceTest.java new file mode 100644 index 0000000..488087c --- /dev/null +++ b/src/test/java/org/gcube/portlets/user/statisticalalgorithmsimporter/ISResourceTest.java @@ -0,0 +1,66 @@ +package org.gcube.portlets.user.statisticalalgorithmsimporter; + +import java.io.StringReader; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.JAXBContext; + +import org.gcube.portlets.user.statisticalalgorithmsimporter.server.is.AvailableProjectConfigJAXB; +import org.gcube.portlets.user.statisticalalgorithmsimporter.server.is.SAIDescriptorJAXB; +import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.Constants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import junit.framework.TestCase; + +/** + * + * @author Giancarlo Panichi + * + * + */ +public class ISResourceTest extends TestCase { + private static Logger logger = LoggerFactory.getLogger(ISResourceTest.class); + + public void test() { + if (Constants.TEST_ENABLE) { + + try { + JAXBContext jaxbContext = JAXBContext.newInstance(SAIDescriptorJAXB.class); + StringWriter sw = new StringWriter(); + + SAIDescriptorJAXB saiDescriptor = new SAIDescriptorJAXB(); + List list = new ArrayList<>(); + AvailableProjectConfigJAXB a1 = new AvailableProjectConfigJAXB(); + a1.setLanguage("R"); + a1.setSupport("REditor"); + list.add(a1); + a1 = new AvailableProjectConfigJAXB(); + a1.setLanguage("Linux"); + a1.setSupport("BlackBox"); + list.add(a1); + a1 = new AvailableProjectConfigJAXB(); + a1.setLanguage("Octave"); + a1.setSupport("BlackBox"); + list.add(a1); + saiDescriptor.setAvailableprojectconfiguration(list); + jaxbContext.createMarshaller().marshal(saiDescriptor, sw); + logger.debug(sw.toString()); + SAIDescriptorJAXB descr = (SAIDescriptorJAXB) jaxbContext.createUnmarshaller() + .unmarshal(new StringReader(sw.toString())); + logger.debug("SAIDescriptor: " + descr); + assertTrue("Success", true); + } catch (Throwable e) { + logger.error(e.getLocalizedMessage(), e); + fail("Error:" + e.getLocalizedMessage()); + + } + + } else { + assertTrue("Success", true); + } + } + +} diff --git a/src/test/java/org/gcube/portlets/user/statisticalalgorithmsimporter/TestStatAlgoImporter.java b/src/test/java/org/gcube/portlets/user/statisticalalgorithmsimporter/StatAlgoImporterTest.java similarity index 54% rename from src/test/java/org/gcube/portlets/user/statisticalalgorithmsimporter/TestStatAlgoImporter.java rename to src/test/java/org/gcube/portlets/user/statisticalalgorithmsimporter/StatAlgoImporterTest.java index 8e37168..d3b0172 100644 --- a/src/test/java/org/gcube/portlets/user/statisticalalgorithmsimporter/TestStatAlgoImporter.java +++ b/src/test/java/org/gcube/portlets/user/statisticalalgorithmsimporter/StatAlgoImporterTest.java @@ -11,13 +11,8 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter; * * */ -public class TestStatAlgoImporter { +public class StatAlgoImporterTest { - /** - * @param args - */ - public static void main(String[] args) { - - } + } diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties new file mode 100644 index 0000000..87b68a3 --- /dev/null +++ b/src/test/resources/log4j.properties @@ -0,0 +1,20 @@ +# A default log4j configuration for log4j users. +# +# To use this configuration, deploy it into your application's WEB-INF/classes +# directory. You are also encouraged to edit it as you like. + +log4j.rootLogger=DEBUG, stdout, rollingFile + +# Redirect log messages to console +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n + + +log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender +log4j.appender.rollingFile.File=test.log +log4j.appender.rollingFile.MaxFileSize=20MB +log4j.appender.rollingFile.MaxBackupIndex=2 +log4j.appender.rollingFile.layout = org.apache.log4j.PatternLayout +log4j.appender.rollingFile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n diff --git a/test.log b/test.log new file mode 100644 index 0000000..979c090 --- /dev/null +++ b/test.log @@ -0,0 +1,33 @@ +2017-06-14 14:35:14 DEBUG ISResourceTest:50 - RREditorLinuxBlackBoxOctaveBlackBox +2017-06-14 14:36:11 DEBUG ISResourceTest:49 - RREditorLinuxBlackBoxOctaveBlackBox +2017-06-14 14:36:11 ERROR ISResourceTest:55 - org.gcube.portlets.user.statisticalalgorithmsimporter.server.is.SAIDescriptorJAXB cannot be cast to org.gcube.portlets.user.statisticalalgorithmsimporter.shared.descriptor.SAIDescriptor +java.lang.ClassCastException: org.gcube.portlets.user.statisticalalgorithmsimporter.server.is.SAIDescriptorJAXB cannot be cast to org.gcube.portlets.user.statisticalalgorithmsimporter.shared.descriptor.SAIDescriptor + at org.gcube.portlets.user.statisticalalgorithmsimporter.ISResourceTest.test(ISResourceTest.java:50) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) + at java.lang.reflect.Method.invoke(Method.java:498) + at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) + at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) + at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) + at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) + at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76) + at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) + at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) + at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) + at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) + at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) + at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) + at org.junit.runners.ParentRunner.run(ParentRunner.java:236) + at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) + at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) + at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) +2017-06-14 14:36:58 DEBUG ISResourceTest:49 - RREditorLinuxBlackBoxOctaveBlackBox +2017-06-14 14:36:58 DEBUG ISResourceTest:52 - SAIDescriptor: SAIDescriptorJAXB [availableprojectconfigurations=[AvailableProjectConfigJAXB [language=R, support=REditor], AvailableProjectConfigJAXB [language=Linux, support=BlackBox], AvailableProjectConfigJAXB [language=Octave, support=BlackBox]]] +2017-06-14 14:42:05 DEBUG ISResourceTest:48 - RREditorLinuxBlackBoxOctaveBlackBox +2017-06-14 14:42:05 DEBUG ISResourceTest:51 - SAIDescriptor: SAIDescriptorJAXB [availableprojectconfiguration=[AvailableProjectConfigJAXB [language=R, support=REditor], AvailableProjectConfigJAXB [language=Linux, support=BlackBox], AvailableProjectConfigJAXB [language=Octave, support=BlackBox]]] +2017-06-14 14:47:07 DEBUG ISResourceTest:48 - RREditorLinuxBlackBoxOctaveBlackBox +2017-06-14 14:47:07 DEBUG ISResourceTest:51 - SAIDescriptor: SAIDescriptorJAXB [availableprojectconfiguration=[AvailableProjectConfigJAXB [language=R, support=REditor], AvailableProjectConfigJAXB [language=Linux, support=BlackBox], AvailableProjectConfigJAXB [language=Octave, support=BlackBox]]]