Skip to content
Snippets Groups Projects
Commit b35ca131 authored by kaloyane's avatar kaloyane
Browse files

[LMS-2104]: change the DemoProcessing + DemoReporting plugins to use...

[LMS-2104]: change the DemoProcessing + DemoReporting plugins to use hierarchical content abstraction. This can be used to prove virtual data sets are working in processing/reporting.

SVN: 21334
parent 23e70fe9
No related branches found
No related tags found
No related merge requests found
Showing
with 268 additions and 67 deletions
Sample test file
used for test purposeses.
\ No newline at end of file
...@@ -20,9 +20,19 @@ import java.io.File; ...@@ -20,9 +20,19 @@ import java.io.File;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import ch.systemsx.cisd.common.io.IHierarchicalContentNode;
import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory;
import ch.systemsx.cisd.openbis.dss.generic.server.plugins.tasks.IProcessingPluginTask; import ch.systemsx.cisd.openbis.dss.generic.server.plugins.tasks.IProcessingPluginTask;
import ch.systemsx.cisd.openbis.dss.generic.shared.DataSetProcessingContext; import ch.systemsx.cisd.openbis.dss.generic.shared.DataSetProcessingContext;
import ch.systemsx.cisd.openbis.dss.generic.shared.HierarchicalContentTraverseUtil;
import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentNodeVisitor;
import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentProvider;
import ch.systemsx.cisd.openbis.dss.generic.shared.ProcessingStatus; import ch.systemsx.cisd.openbis.dss.generic.shared.ProcessingStatus;
import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider;
import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription; import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription;
/** /**
...@@ -34,6 +44,9 @@ public class DemoProcessingPlugin implements IProcessingPluginTask ...@@ -34,6 +44,9 @@ public class DemoProcessingPlugin implements IProcessingPluginTask
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION,
DemoProcessingPlugin.class);
public DemoProcessingPlugin(Properties properties, File storeRoot) public DemoProcessingPlugin(Properties properties, File storeRoot)
{ {
} }
...@@ -41,16 +54,33 @@ public class DemoProcessingPlugin implements IProcessingPluginTask ...@@ -41,16 +54,33 @@ public class DemoProcessingPlugin implements IProcessingPluginTask
public ProcessingStatus process(List<DatasetDescription> datasets, public ProcessingStatus process(List<DatasetDescription> datasets,
DataSetProcessingContext context) DataSetProcessingContext context)
{ {
System.out.println("Processing of the following datasets has been requested: " + datasets); operationLog.info("Processing of the following datasets has been requested: " + datasets);
System.out.println("sleeping for 2 sec"); IHierarchicalContentProvider contentProvider =
try ServiceProvider.getHierarchicalContentProvider();
{
Thread.sleep(2000); for (DatasetDescription dataset : datasets) {
} catch (InterruptedException ex) String dataSetCode = dataset.getDataSetCode();
{ IHierarchicalContentNodeVisitor printingVisitor = createPrintingVisitor(dataSetCode);
ex.printStackTrace(); HierarchicalContentTraverseUtil.traverse(contentProvider, dataSetCode, printingVisitor);
} }
System.out.println("Processing done."); operationLog.info("Processing done.");
return null; return null;
} }
private IHierarchicalContentNodeVisitor createPrintingVisitor(final String datasetCode)
{
return new IHierarchicalContentNodeVisitor()
{
public void visit(IHierarchicalContentNode node)
{
String relativePath = node.getRelativePath();
String fullPath = datasetCode + "/";
if (false == StringUtils.isBlank(relativePath))
{
fullPath += relativePath;
}
operationLog.info("Processing " + node.getRelativePath());
}
};
}
} }
...@@ -22,11 +22,13 @@ import java.util.Date; ...@@ -22,11 +22,13 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import org.apache.commons.io.FileUtils; import ch.systemsx.cisd.common.io.IHierarchicalContentNode;
import ch.systemsx.cisd.common.filesystem.FileUtilities;
import ch.systemsx.cisd.openbis.dss.generic.server.plugins.standard.AbstractTableModelReportingPlugin; import ch.systemsx.cisd.openbis.dss.generic.server.plugins.standard.AbstractTableModelReportingPlugin;
import ch.systemsx.cisd.openbis.dss.generic.shared.DataSetProcessingContext; import ch.systemsx.cisd.openbis.dss.generic.shared.DataSetProcessingContext;
import ch.systemsx.cisd.openbis.dss.generic.shared.HierarchicalContentTraverseUtil;
import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentNodeVisitor;
import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentProvider;
import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider;
import ch.systemsx.cisd.openbis.dss.generic.shared.utils.ImageUtil; import ch.systemsx.cisd.openbis.dss.generic.shared.utils.ImageUtil;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DateTableCell; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DateTableCell;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DoubleTableCell; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DoubleTableCell;
...@@ -61,77 +63,73 @@ public class DemoReportingPlugin extends AbstractTableModelReportingPlugin ...@@ -61,77 +63,73 @@ public class DemoReportingPlugin extends AbstractTableModelReportingPlugin
builder.addHeader("Size"); builder.addHeader("Size");
for (DatasetDescription dataset : datasets) for (DatasetDescription dataset : datasets)
{ {
File file = getDataSubDir(context.getDirectoryProvider(), dataset); describe(builder, dataset);
if (file.isDirectory())
{
describe(builder, dataset, file);
} else
{
describeUnknown(builder, dataset, file);
}
} }
return builder.getTableModel(); return builder.getTableModel();
} }
private static void describe(SimpleTableModelBuilder builder, DatasetDescription dataset, private void describe(SimpleTableModelBuilder builder, DatasetDescription dataset)
File file)
{ {
if (file.isFile()) IHierarchicalContentNodeVisitor visitor =
{ createFileDescribingVisitor(builder, dataset);
describeFile(builder, dataset, file); IHierarchicalContentProvider provider = ServiceProvider.getHierarchicalContentProvider();
} else HierarchicalContentTraverseUtil.traverse(provider, dataset.getDataSetCode(), visitor);
{
File[] datasetFiles = FileUtilities.listFiles(file);
for (File datasetFile : datasetFiles)
{
describe(builder, dataset, datasetFile);
}
}
} }
private void describeUnknown(SimpleTableModelBuilder builder, DatasetDescription dataset, private IHierarchicalContentNodeVisitor createFileDescribingVisitor(
File file) final SimpleTableModelBuilder builder, final DatasetDescription dataset)
{ {
String datasetCode = dataset.getDataSetCode(); return new IHierarchicalContentNodeVisitor()
ISerializableComparable image = createImageCell(dataset, file); {
List<ISerializableComparable> row =
Arrays.<ISerializableComparable> asList(new StringTableCell(datasetCode), image, public void visit(IHierarchicalContentNode node)
new StringTableCell(file.getName()), {
new DateTableCell(new Date(file.lastModified())), new DoubleTableCell(0)); if (false == node.isDirectory())
builder.addRow(row); {
describeFileNode(builder, dataset, node);
}
}
};
} }
private static ISerializableComparable createImageCell(DatasetDescription dataset, File file) private void describeFileNode(SimpleTableModelBuilder builder, DatasetDescription dataset,
IHierarchicalContentNode fileNode)
{ {
if (ImageUtil.isImageFile(file)) ISerializableComparable image = createPathOrImageCell(dataset, fileNode);
long lastModified = 0;
try
{
lastModified = fileNode.getFile().lastModified();
} catch (UnsupportedOperationException uoe)
{ {
String code = dataset.getDataSetCode(); // ignore exceptions
String location = dataset.getDataSetLocation();
return new ImageTableCell(code, location, file.getPath(), 100, 60);
} }
return new StringTableCell(file.getName());
}
private static void describeFile(SimpleTableModelBuilder builder, DatasetDescription dataset,
File file)
{
ISerializableComparable image = createImageCell(dataset, file);
List<ISerializableComparable> row = List<ISerializableComparable> row =
Arrays.<ISerializableComparable> asList( Arrays.<ISerializableComparable> asList(
new StringTableCell(dataset.getDataSetCode()), image, new StringTableCell( new StringTableCell(dataset.getDataSetCode()), image, new StringTableCell(
file.getName()), new DateTableCell(new Date(file.lastModified())), fileNode.getName()), new DateTableCell(new Date(lastModified)),
new DoubleTableCell(getSize(file))); new DoubleTableCell(fileNode.getFileLength()));
builder.addRow(row); builder.addRow(row);
} }
private static long getSize(File file) private ISerializableComparable createPathOrImageCell(DatasetDescription dataset,
IHierarchicalContentNode fileNode)
{ {
if (file.isFile()) File fileOnDisk = null;
try
{ {
return file.length(); fileOnDisk = fileNode.getFile();
} else } catch (UnsupportedOperationException uoe)
{ {
return FileUtils.sizeOfDirectory(file); // do not break
} }
if (fileOnDisk != null && ImageUtil.isImageFile(fileOnDisk))
{
return new ImageTableCell(dataset.getDataSetCode(), fileNode.getRelativePath(), 100,
60);
}
return new StringTableCell(fileNode.getName());
} }
} }
/*
* Copyright 2011 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.dss.generic.shared;
import ch.systemsx.cisd.common.io.IHierarchicalContent;
import ch.systemsx.cisd.common.io.IHierarchicalContentNode;
/**
* A utility class to abstract traversing of {@link IHierarchicalContentNode}-s.
*
* @author Kaloyan Enimanev
*/
public class HierarchicalContentTraverseUtil
{
/**
* Traverses all {@link IHierarchicalContentNode}-s within a data set specified by a data set
* code.
*
* @param provider a provider class used to construct {@link IHierarchicalContent}.
* @param dataSetCode the code of the data set to be traversed
* @param visitor a visitor that will be invoked for every traversed
* {@link IHierarchicalContentNode}.
*/
public static void traverse(IHierarchicalContentProvider provider, String dataSetCode,
IHierarchicalContentNodeVisitor visitor)
{
IHierarchicalContent content = null;
try
{
content = provider.asContent(dataSetCode);
visit(content.getRootNode(), visitor);
} finally
{
if (content != null)
{
content.close();
}
}
}
private static void visit(IHierarchicalContentNode node, IHierarchicalContentNodeVisitor visitor)
{
visitor.visit(node);
if (node.isDirectory())
{
for (IHierarchicalContentNode child : node.getChildNodes())
{
visit(child, visitor);
}
}
}
}
/*
* Copyright 2011 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.dss.generic.shared;
import ch.systemsx.cisd.common.io.IHierarchicalContentNode;
/**
* A visitor for {@link IHierarchicalContentNode}-s.
*
* @author Kaloyan Enimanev
*/
public interface IHierarchicalContentNodeVisitor
{
/**
* Visits a node.
*/
void visit(IHierarchicalContentNode node);
}
...@@ -26,16 +26,26 @@ import java.util.List; ...@@ -26,16 +26,26 @@ import java.util.List;
import java.util.Properties; import java.util.Properties;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.springframework.beans.factory.BeanFactory;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import ch.rinn.restrictions.Friend; import ch.rinn.restrictions.Friend;
import ch.systemsx.cisd.base.tests.AbstractFileSystemTestCase; import ch.systemsx.cisd.base.tests.AbstractFileSystemTestCase;
import ch.systemsx.cisd.common.exceptions.ConfigurationFailureException; import ch.systemsx.cisd.common.exceptions.ConfigurationFailureException;
import ch.systemsx.cisd.common.io.DefaultFileBasedHierarchicalContentFactory;
import ch.systemsx.cisd.common.io.IHierarchicalContent;
import ch.systemsx.cisd.common.utilities.IDelegatedAction;
import ch.systemsx.cisd.openbis.dss.generic.server.plugins.demo.DemoProcessingPlugin; import ch.systemsx.cisd.openbis.dss.generic.server.plugins.demo.DemoProcessingPlugin;
import ch.systemsx.cisd.openbis.dss.generic.server.plugins.demo.DemoReportingPlugin; import ch.systemsx.cisd.openbis.dss.generic.server.plugins.demo.DemoReportingPlugin;
import ch.systemsx.cisd.openbis.dss.generic.server.plugins.standard.MockDataSetDirectoryProvider;
import ch.systemsx.cisd.openbis.dss.generic.shared.DataSetProcessingContext; import ch.systemsx.cisd.openbis.dss.generic.shared.DataSetProcessingContext;
import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentProvider;
import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProviderTestWrapper;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatastoreServiceDescription; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatastoreServiceDescription;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IDatasetLocation;
import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription; import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription;
/** /**
...@@ -47,8 +57,55 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription; ...@@ -47,8 +57,55 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription;
{ PluginTaskProviders.class, AbstractPluginTaskFactory.class }) { PluginTaskProviders.class, AbstractPluginTaskFactory.class })
public class PluginTaskParametersTest extends AbstractFileSystemTestCase public class PluginTaskParametersTest extends AbstractFileSystemTestCase
{ {
private static final String SHARE_ID = "42"; private static final File STORE_ROOT = new File("./resource/test-data/"
private static final File STORE_ROOT = new File("."); + PluginTaskParametersTest.class.getSimpleName());
private Mockery context;
private IHierarchicalContentProvider contentProvider;
@BeforeMethod
public void beforeMethod()
{
context = new Mockery();
contentProvider = new IHierarchicalContentProvider()
{
public IHierarchicalContent asContent(String dataSetCode)
{
File dataSetFolder = new File(STORE_ROOT, dataSetCode);
return new DefaultFileBasedHierarchicalContentFactory().asHierarchicalContent(
dataSetFolder, IDelegatedAction.DO_NOTHING);
}
public IHierarchicalContent asContent(File datasetDirectory)
{
return null;
}
public IHierarchicalContent asContent(IDatasetLocation datasetLocation)
{
return null;
}
};
final BeanFactory beanFactory = context.mock(BeanFactory.class);
ServiceProviderTestWrapper.setApplicationContext(beanFactory);
context.checking(new Expectations()
{
{
allowing(beanFactory).getBean("hierarchical-content-provider");
will(returnValue(contentProvider));
}
});
}
@AfterMethod
public void afterTest()
{
ServiceProviderTestWrapper.restoreApplicationContext();
}
@Test @Test
public void testCreateReportingPluginsFactories() throws Exception public void testCreateReportingPluginsFactories() throws Exception
...@@ -71,7 +128,7 @@ public class PluginTaskParametersTest extends AbstractFileSystemTestCase ...@@ -71,7 +128,7 @@ public class PluginTaskParametersTest extends AbstractFileSystemTestCase
factories.logConfigurations(); factories.logConfigurations();
IReportingPluginTask pluginInstance1 = factories.getPluginInstance(plugin1); IReportingPluginTask pluginInstance1 = factories.getPluginInstance(plugin1);
pluginInstance1.createReport(createDatasetDescriptions(), new DataSetProcessingContext( pluginInstance1.createReport(createDatasetDescriptions(), new DataSetProcessingContext(
new MockDataSetDirectoryProvider(STORE_ROOT, SHARE_ID), null, null, null)); null, null, null, null));
List<DatastoreServiceDescription> descriptions = factories.getPluginDescriptions(); List<DatastoreServiceDescription> descriptions = factories.getPluginDescriptions();
assertEquals(2, descriptions.size()); assertEquals(2, descriptions.size());
...@@ -145,8 +202,9 @@ public class PluginTaskParametersTest extends AbstractFileSystemTestCase ...@@ -145,8 +202,9 @@ public class PluginTaskParametersTest extends AbstractFileSystemTestCase
private static List<DatasetDescription> createDatasetDescriptions() private static List<DatasetDescription> createDatasetDescriptions()
{ {
DatasetDescription description = new DatasetDescription(); DatasetDescription description = new DatasetDescription();
description.setDatasetCode("."); final String dataSetCode = "dataset-1";
description.setDataSetLocation("3123123123-123"); description.setDatasetCode(dataSetCode);
description.setDataSetLocation(dataSetCode);
description.setSampleCode("sampleCode"); description.setSampleCode("sampleCode");
description.setSpaceCode("groupCode"); description.setSpaceCode("groupCode");
description.setProjectCode("projCode"); description.setProjectCode("projCode");
......
...@@ -49,6 +49,17 @@ public class ImageTableCell implements ISerializableComparable ...@@ -49,6 +49,17 @@ public class ImageTableCell implements ISerializableComparable
this(getPath(dataSetCode, dataSetLocation, originalPath), maxThumbnailWidth, maxThumbnailHeight); this(getPath(dataSetCode, dataSetLocation, originalPath), maxThumbnailWidth, maxThumbnailHeight);
} }
/**
* @param relativePathFromDataSetRoot the relative path to this image file starting from the
* data set root.
*/
public ImageTableCell(String dataSetCode, String relativePathFromDataSetRoot,
int maxThumbnailWidth,
int maxThumbnailHeight)
{
this(dataSetCode + relativePathFromDataSetRoot, maxThumbnailWidth, maxThumbnailHeight);
}
public ImageTableCell(String path, int maxThumbnailWidth, int maxThumbnailHeight) public ImageTableCell(String path, int maxThumbnailWidth, int maxThumbnailHeight)
{ {
this.path = path; this.path = path;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment