diff --git a/dataset_download/.checkstyle b/dataset_download/.checkstyle new file mode 100644 index 0000000000000000000000000000000000000000..f048a51b5309c86d8eceafaf3fc75d9f236f7526 --- /dev/null +++ b/dataset_download/.checkstyle @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<fileset-config file-format-version="1.2.0" simple-config="false"> + <local-check-config name="CISD Checks" location="/build_resources/checkstyle/cisd_checkstyle.xml" type="project" description=""> + <additional-data name="protect-config-file" value="false"/> + </local-check-config> + <fileset name="all" enabled="true" check-config-name="CISD Checks" local="true"> + <file-match-pattern match-pattern=".+ch/systemsx/cisd.+" include-pattern="true"/> + </fileset> +</fileset-config> diff --git a/dataset_download/.classpath b/dataset_download/.classpath index d245161bedf5ccc0d0ca1c477f8cc1ea76ed7bd7..89dadcb102a90b0b8516968afa700234a3023fd5 100644 --- a/dataset_download/.classpath +++ b/dataset_download/.classpath @@ -1,6 +1,17 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="source/java"/> + <classpathentry kind="src" path="sourceTest/java"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry combineaccessrules="false" kind="src" path="/common"/> + <classpathentry kind="lib" path="/libraries/log4j/log4j.jar" sourcepath="/libraries/log4j/src.zip"/> + <classpathentry kind="lib" path="/libraries/jetty/servlet-api-2.5.jar" sourcepath="/libraries/jetty/src/servlet-api-2.5.zip"/> + <classpathentry kind="lib" path="/libraries/testng/testng-jdk15.jar" sourcepath="/libraries/testng/src.zip"/> + <classpathentry kind="lib" path="/libraries/jmock/third-party-libs/cglib-2.1_3-src.jar"/> + <classpathentry kind="lib" path="/libraries/jmock/third-party-libs/cglib-nodep-2.1_3.jar"/> + <classpathentry kind="lib" path="/libraries/jmock/third-party-libs/hamcrest-api-1.0.jar"/> + <classpathentry kind="lib" path="/libraries/jmock/third-party-libs/hamcrest-library-1.0.jar"/> + <classpathentry kind="lib" path="/libraries/jmock/third-party-libs/objenesis-1.0.jar"/> + <classpathentry kind="lib" path="/libraries/jmock/jmock.jar"/> <classpathentry kind="output" path="targets/classes"/> </classpath> diff --git a/dataset_download/build/antrun.sh b/dataset_download/build/antrun.sh new file mode 100755 index 0000000000000000000000000000000000000000..5ff1a62b259d6011d228440f2fb89ec0dbecf747 --- /dev/null +++ b/dataset_download/build/antrun.sh @@ -0,0 +1,6 @@ +#! /bin/bash + +ME="$0" +MYDIR=${ME%/*} +cd $MYDIR +ant -lib ../../build_resources/lib/ecj.jar "$@" diff --git a/dataset_download/build/build.xml b/dataset_download/build/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..a805b0fce85ff920bd5a65dd6e3539c31849a58c --- /dev/null +++ b/dataset_download/build/build.xml @@ -0,0 +1,6 @@ +<project name="authentication" basedir=".."> + <import file="../../build_resources/ant/build-common.xml" /> + <project-classpath name="ecp" classes="${classes}" /> + + <target name="ci" depends="build-common.ci, check-dependencies"/> +</project> \ No newline at end of file diff --git a/dataset_download/source/java/.gitignore b/dataset_download/source/java/.gitignore deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/dataset_download/source/java/ch/systemsx/cisd/openbis/datasetdownload/DatasetDownloadServlet.java b/dataset_download/source/java/ch/systemsx/cisd/openbis/datasetdownload/DatasetDownloadServlet.java new file mode 100644 index 0000000000000000000000000000000000000000..dacbcf1bc51ec6f288d80ac70a07a9ad86daeb84 --- /dev/null +++ b/dataset_download/source/java/ch/systemsx/cisd/openbis/datasetdownload/DatasetDownloadServlet.java @@ -0,0 +1,81 @@ +/* + * Copyright 2008 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.datasetdownload; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import ch.systemsx.cisd.common.logging.LogCategory; +import ch.systemsx.cisd.common.logging.LogFactory; +import ch.systemsx.cisd.common.logging.LogInitializer; + +/** + * @author Franz-Josef Elmer + */ +public class DatasetDownloadServlet extends HttpServlet +{ + static final String DATASET_CODE_KEY = "datasetCode"; + + static final String SESSION_ID_KEY = "sessionID"; + + private static final long serialVersionUID = 1L; + + protected static final Logger operationLog = + LogFactory.getLogger(LogCategory.OPERATION, DatasetDownloadServlet.class); + + protected static final Logger notificationLog = + LogFactory.getLogger(LogCategory.NOTIFY, DatasetDownloadServlet.class); + + // + // HttpServlet + // + + @Override + public final void init(final ServletConfig servletConfig) throws ServletException + { + super.init(servletConfig); + LogInitializer.init(); + try + { + } catch (Exception ex) + { + notificationLog.fatal("Failure during '" + servletConfig.getServletName() + + "' servlet initialization.", ex); + throw new ServletException(ex); + } + } + + @Override + protected final void doGet(final HttpServletRequest request, final HttpServletResponse response) + throws ServletException, IOException + { + final String datasetCode = request.getParameter(DATASET_CODE_KEY); + final String sessionID = request.getParameter(SESSION_ID_KEY); + final PrintWriter writer = response.getWriter(); + writer.write("<html><body>Download dataset " + datasetCode + " (sessionID:" + sessionID + ")</body></html>"); + writer.flush(); + writer.close(); + } +} diff --git a/dataset_download/source/java/service.properties b/dataset_download/source/java/service.properties new file mode 100644 index 0000000000000000000000000000000000000000..c1a16d948b76c4d8e0f865467b2df9844318a658 --- /dev/null +++ b/dataset_download/source/java/service.properties @@ -0,0 +1,12 @@ +# The root directory of the data store +storeroot-dir = targets/store + +# The URL of the openBIS server +server-url = http://localhost:8080/openbis + +# The username to use when contacting the openBIS server +username = etlserver + +# The password to use when contacting the openBIS server +password = doesnotmatter + diff --git a/dataset_download/sourceTest/java/ch/systemsx/cisd/openbis/datasetdownload/DatasetDownloadServletTest.java b/dataset_download/sourceTest/java/ch/systemsx/cisd/openbis/datasetdownload/DatasetDownloadServletTest.java new file mode 100644 index 0000000000000000000000000000000000000000..0f3507ea1b741b2cd22ed89002699d9fc418a8e9 --- /dev/null +++ b/dataset_download/sourceTest/java/ch/systemsx/cisd/openbis/datasetdownload/DatasetDownloadServletTest.java @@ -0,0 +1,95 @@ +/* + * Copyright 2008 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.datasetdownload; + +import static org.testng.AssertJUnit.assertEquals; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Level; +import org.jmock.Expectations; +import org.jmock.Mockery; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import ch.systemsx.cisd.common.logging.BufferedAppender; + + +/** + * + * + * @author Franz-Josef Elmer + */ +public class DatasetDownloadServletTest +{ + private BufferedAppender logRecorder; + + private Mockery context; + + private HttpServletRequest request; + + private HttpServletResponse response; + + @BeforeMethod + public void setUp() + { + logRecorder = new BufferedAppender("%-5p %c - %m%n", Level.DEBUG); + context = new Mockery(); + request = context.mock(HttpServletRequest.class); + response = context.mock(HttpServletResponse.class); + } + + @AfterMethod + public void tearDown() + { + logRecorder.reset(); + // To following line of code should also be called at the end of each test method. + // Otherwise one do not known which test failed. + context.assertIsSatisfied(); + } + + @Test + public void testDoGet() throws Exception + { + final StringWriter writer = new StringWriter(); + context.checking(new Expectations() + { + { + one(request).getParameter(DatasetDownloadServlet.DATASET_CODE_KEY); + will(returnValue("1234-1")); + + one(request).getParameter(DatasetDownloadServlet.SESSION_ID_KEY); + will(returnValue("AV76CF")); + + one(response).getWriter(); + will(returnValue(new PrintWriter(writer))); + } + }); + DatasetDownloadServlet servlet = new DatasetDownloadServlet(); + servlet.init(); + + servlet.doGet(request, response); + + assertEquals("<html><body>Download dataset 1234-1 (sessionID:AV76CF)</body></html>", writer.toString()); + } + +} diff --git a/dataset_download/sourceTest/java/tests.xml b/dataset_download/sourceTest/java/tests.xml new file mode 100644 index 0000000000000000000000000000000000000000..dc3a928c6f8b38263a812739e8066bfbb4a92020 --- /dev/null +++ b/dataset_download/sourceTest/java/tests.xml @@ -0,0 +1,12 @@ +<suite name="All" verbose="1"> + <test name="All"> + <groups> + <run> + <exclude name="broken" /> + </run> + </groups> + <packages> + <package name="ch.systemsx.cisd.openbis.datasetdownload.*" /> + </packages> + </test> +</suite>