diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/ChainedDataSetMigrationTask.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/ChainedDataSetMigrationTask.java deleted file mode 100644 index 203d4b48bfa43e9e37d7c0c480a655abddd95bee..0000000000000000000000000000000000000000 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/ChainedDataSetMigrationTask.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright 2010 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.etlserver.plugins; - -import java.io.File; -import java.io.FileFilter; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import java.util.regex.Pattern; - -import org.apache.log4j.Logger; - -import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; -import ch.systemsx.cisd.common.logging.LogCategory; -import ch.systemsx.cisd.common.logging.LogFactory; -import ch.systemsx.cisd.common.maintenance.IMaintenanceTask; -import ch.systemsx.cisd.common.utilities.ClassUtils; -import ch.systemsx.cisd.common.utilities.PropertyParametersUtil; -import ch.systemsx.cisd.common.utilities.PropertyUtils; -import ch.systemsx.cisd.common.utilities.PropertyParametersUtil.SectionProperties; - -/** - * Maintenance task migrating all data sets of a store by a chain of {@link IMigrator} instances. - * - * @author Franz-Josef Elmer - */ -public class ChainedDataSetMigrationTask implements IMaintenanceTask -{ - public static final String MIGRATORS_PROPERTY = "migrators"; - - public static final String STORE_ROOT_PROPERTY = "storeRoot"; - - private static final Pattern UUID_PATTERN = - Pattern.compile("[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"); - - private static final Logger operationLog = - LogFactory.getLogger(LogCategory.OPERATION, ChainedDataSetMigrationTask.class); - - private File storeRoot; - - private List<IMigrator> migrators; - - public void setUp(String pluginName, Properties properties) - { - String storeRootPath = PropertyUtils.getMandatoryProperty(properties, STORE_ROOT_PROPERTY); - storeRoot = new File(storeRootPath); - if (storeRoot.isDirectory() == false) - { - throw new EnvironmentFailureException(storeRoot - + " does not exist or is not a directory."); - } - SectionProperties[] sectionProperties = - PropertyParametersUtil.extractSectionProperties(properties, MIGRATORS_PROPERTY, - false); - migrators = new ArrayList<IMigrator>(); - for (SectionProperties props : sectionProperties) - { - Properties migratorProperties = props.getProperties(); - IMigrator migrator = - ClassUtils.create(IMigrator.class, PropertyUtils.getMandatoryProperty( - migratorProperties, "class"), migratorProperties); - migrators.add(migrator); - } - if (operationLog.isInfoEnabled()) - { - StringBuilder builder = new StringBuilder(); - for (IMigrator migrator : migrators) - { - if (builder.length() > 0) - { - builder.append(", "); - } - builder.append(migrator.getDescription()); - } - operationLog.info("Chain of migrators have been set up: " + builder); - } - } - - public void execute() - { - File dbInstanceDir = tryGetDatabaseInstanceDir(storeRoot); - if (dbInstanceDir == null) - { - operationLog.warn("Store is empty, there is nothing to migrate"); - return; - } - for (IMigrator migrator : migrators) - { - boolean success = migrate(dbInstanceDir, migrator); - if (success == false) - { - operationLog.error("Migration stopped at: " + migrator.getDescription()); - break; - } - } - } - - /** - * For a given datastore store directory returns the instance directory inside or null if it - * does not exist. - */ - public static File tryGetDatabaseInstanceDir(File storeRoot) - { - File[] files = storeRoot.listFiles(new FileFilter() - { - public boolean accept(File pathname) - { - String name = pathname.getName().toLowerCase(); - return pathname.isDirectory() && UUID_PATTERN.matcher(name).matches(); - } - }); - if (files == null || files.length == 0) - { - return null; - } - if (files.length > 1) - { - throw new EnvironmentFailureException("At most one folder with UUID expected in " - + storeRoot); - } - File dbInstanceDir = files[0]; - return dbInstanceDir; - } - - private boolean migrate(File dbInstanceDir, IMigrator migrator) - { - List<File> migratedDataSets = new ArrayList<File>(); - List<File> failedDataSets = new ArrayList<File>(); - for (File l1 : dbInstanceDir.listFiles()) - { - // The OS may put files into these folders (e.g., .DS_Store) - if (false == l1.isDirectory()) - { - continue; - } - for (File l2 : l1.listFiles()) - { - if (false == l2.isDirectory()) - { - continue; - } - for (File l3 : l2.listFiles()) - { - if (false == l3.isDirectory()) - { - continue; - } - for (File dataset : l3.listFiles()) - { - boolean success = migrator.migrate(dataset); - if (success) - { - migratedDataSets.add(dataset); - } else - { - failedDataSets.add(dataset); - } - } - } - } - } - if (failedDataSets.isEmpty()) - { - operationLog.info(migratedDataSets.size() + " data sets have been migrated with '" - + migrator.getDescription() + "'."); - } else - { - operationLog.error("Migration with '" + migrator.getDescription() - + "' failed for the following " + failedDataSets.size() + " data sets: " - + failedDataSets); - } - return failedDataSets.isEmpty(); - } - -} diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/IMigrator.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/IMigrator.java deleted file mode 100644 index 4d0f177e8895765479ff2590266d653482dd5584..0000000000000000000000000000000000000000 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/IMigrator.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2010 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.etlserver.plugins; - -import java.io.File; -import java.util.Properties; - -/** - * Interface of classes which are able to migrate a single data set. Classes implementing this - * interface should have a public constructor with a single argument of type {@link Properties}. - * - * @author Tomasz Pylak - * @author Franz-Josef Elmer - */ -public interface IMigrator -{ - /** - * Migrates specified dataset. - * - * @return <code>true</code> if migration was successful. - */ - boolean migrate(File dataset); - - /** user-friendly description of the migrator */ - String getDescription(); - - /** - * Free any held resources. Called once when migration is finished. - */ - void close(); - -} diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/featurevector/AbstractFeatureVectorMigrator.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/featurevector/AbstractFeatureVectorMigrator.java deleted file mode 100644 index 466577d6179dcf898840e3173fdecf285a0bcebc..0000000000000000000000000000000000000000 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/featurevector/AbstractFeatureVectorMigrator.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright 2010 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.etl.featurevector; - -import java.io.File; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Properties; - -import javax.sql.DataSource; - -import net.lemnik.eodsql.QueryTool; - -import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; -import ch.systemsx.cisd.etlserver.plugins.IMigrator; -import ch.systemsx.cisd.openbis.dss.etl.HCSContainerDatasetInfo; -import ch.systemsx.cisd.openbis.dss.etl.dataaccess.IImagingQueryDAO; -import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; -import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; -import ch.systemsx.cisd.openbis.generic.shared.dto.SimpleDataSetInformationDTO; -import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; -import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifierFactory; -import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SpaceIdentifier; -import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.ScreeningConstants; -import ch.systemsx.cisd.openbis.plugin.screening.shared.imaging.dataaccess.ImgDatasetDTO; - -/** - * Imports individual data sets into the imaging db. - * - * @author Chandrasekhar Ramakrishnan - */ -public abstract class AbstractFeatureVectorMigrator implements IMigrator -{ - protected final IImagingQueryDAO dao; - - protected final IEncapsulatedOpenBISService openBisService; - - protected final List<SimpleDataSetInformationDTO> knownDataSets; - - protected final HashMap<String, SimpleDataSetInformationDTO> knownDataSetsByCode; - - public AbstractFeatureVectorMigrator(Properties properties) - { - DataSource dataSource = ServiceProvider.getDataSourceProvider().getDataSource(properties); - dao = QueryTool.getQuery(dataSource, IImagingQueryDAO.class); - openBisService = ServiceProvider.getOpenBISService(); - knownDataSets = openBisService.listDataSets(); - knownDataSetsByCode = - new HashMap<String, SimpleDataSetInformationDTO>(knownDataSets.size()); - - initializeDataSetsByCode(); - } - - /** - * Create a map of associations from code to data set info. Assumes knownDataSets and been - * initialized. - */ - private void initializeDataSetsByCode() - { - for (SimpleDataSetInformationDTO dataSetInfo : knownDataSets) - { - knownDataSetsByCode.put(dataSetInfo.getDataSetCode(), dataSetInfo); - } - } - - public String getDescription() - { - return "uploading feature vectors to the imaging database"; - } - - public boolean migrate(File dataset) - { - AbstractMigrationDecision decision = createMigrationDecision(dataset); - decision.process(); - if (false == decision.shouldMigrate) - { - // Vacuously true - return true; - } - - ImgDatasetDTO imgDataset = dao.tryGetDatasetByPermId(decision.dataSetInfo.getDataSetCode()); - if (null != imgDataset) - { - // Has already been imported into the db - return true; - } - - AbstractImageDbImporter importer; - importer = - createImporter(createScreeningDatasetInfo(decision.getDataSetInfo()), - decision.fileToMigrate); - - importer.doImport(); - - return importer.isSuccessful; - } - - protected abstract AbstractMigrationDecision createMigrationDecision(File dataset); - - protected abstract AbstractImageDbImporter createImporter(HCSContainerDatasetInfo dataSetInfo, - File fileToMigrate); - - private HCSContainerDatasetInfo createScreeningDatasetInfo( - SimpleDataSetInformationDTO dataSetInfo) - { - Sample sample = findSampleCodeForDataSet(dataSetInfo); - assert sample != null : "no sample connected to a dataset"; - - Experiment experiment = sample.getExperiment(); - HCSContainerDatasetInfo info = new HCSContainerDatasetInfo(); - info.setExperimentPermId(experiment.getPermId()); - info.setContainerPermId(sample.getPermId()); - info.setDatasetPermId(dataSetInfo.getDataSetCode()); - - return info; - } - - private Sample findSampleCodeForDataSet(SimpleDataSetInformationDTO dataSetInfo) - { - String sampleCodeOrNull = dataSetInfo.getSampleCode(); - SampleIdentifier sampleId = null; - if (null == sampleCodeOrNull) - { - // check the parent data sets for a sample - Collection<String> parentDataSetCodes = dataSetInfo.getParentDataSetCodes(); - for (String dataSetCode : parentDataSetCodes) - { - ExternalData externalData = openBisService.tryGetDataSetForServer(dataSetCode); - if (externalData == null) - { - throw new EnvironmentFailureException( - "Cannot find a parent dataset in openBIS: " + dataSetCode); - } - if (externalData.getSample() != null) - { - sampleId = SampleIdentifierFactory.parse(externalData.getSampleIdentifier()); - break; - } - } - } else - { - sampleId = - new SampleIdentifier(new SpaceIdentifier(dataSetInfo.getDatabaseInstanceCode(), - dataSetInfo.getGroupCode()), dataSetInfo.getSampleCode()); - } - - return openBisService.tryGetSampleWithExperiment(sampleId); - } - - public void close() - { - // close the dao - dao.close(); - } - - /** - * Helper class for figuring out what to do with files - * - * @author Chandrasekhar Ramakrishnan - */ - protected abstract static class AbstractMigrationDecision - { - protected final File dataset; - - private final HashMap<String, SimpleDataSetInformationDTO> knownDataSetsByCode; - - private SimpleDataSetInformationDTO dataSetInfo; - - private boolean shouldMigrate = false; - - private File fileToMigrate = null; - - public AbstractMigrationDecision(File dataset, - HashMap<String, SimpleDataSetInformationDTO> knownDataSetsByCode) - { - this.dataset = dataset; - this.knownDataSetsByCode = knownDataSetsByCode; - } - - protected void setDataSetInfo(SimpleDataSetInformationDTO dataSetInfo) - { - this.dataSetInfo = dataSetInfo; - } - - public SimpleDataSetInformationDTO getDataSetInfo() - { - return dataSetInfo; - } - - // Figure out what to do with this file - public void process() - { - setDataSetInfo(tryDataSetInformation()); - if (null == getDataSetInfo()) - { - shouldMigrate = false; - return; - } - - // Only import this data set if it is of an analysis type - if (false == getDataSetInfo().getDataSetType().matches( - ScreeningConstants.HCS_IMAGE_ANALYSIS_DATASET_TYPE_PATTERN)) - { - shouldMigrate = false; - return; - } - - // Figure out which file we need to migrate - fileToMigrate = tryFileToMigrate(); - - if (null == fileToMigrate) - { - shouldMigrate = false; - return; - } - - shouldMigrate = true; - return; - } - - protected abstract File tryFileToMigrate(); - - private SimpleDataSetInformationDTO tryDataSetInformation() - { - String dataSetCode = dataset.getName(); - SimpleDataSetInformationDTO dsInfo = knownDataSetsByCode.get(dataSetCode); - return dsInfo; - } - } - - /** - * Helper class for importing data into the image db. - * - * @author Chandrasekhar Ramakrishnan - */ - protected abstract static class AbstractImageDbImporter - { - protected final IImagingQueryDAO dao; - - protected final HCSContainerDatasetInfo screeningDataSetInfo; - - protected final File fileToMigrate; - - protected boolean isSuccessful = false; - - protected AbstractImageDbImporter(IImagingQueryDAO dao, - HCSContainerDatasetInfo screeningDataSetInfo, File fileToMigrate) - { - this.dao = dao; - this.screeningDataSetInfo = screeningDataSetInfo; - this.fileToMigrate = fileToMigrate; - } - - public abstract void doImport(); - } -} diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/featurevector/CsvFeatureVectorMigrator.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/featurevector/CsvFeatureVectorMigrator.java deleted file mode 100644 index b2497efa30d9829c6cd8e22c235aa4f789a84e8b..0000000000000000000000000000000000000000 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/featurevector/CsvFeatureVectorMigrator.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright 2010 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.etl.featurevector; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Properties; - -import ch.systemsx.cisd.base.exceptions.IOExceptionUnchecked; -import ch.systemsx.cisd.etlserver.DefaultStorageProcessor; -import ch.systemsx.cisd.openbis.dss.etl.HCSContainerDatasetInfo; -import ch.systemsx.cisd.openbis.dss.etl.dataaccess.IImagingQueryDAO; -import ch.systemsx.cisd.openbis.dss.etl.featurevector.CsvFeatureVectorParser.CsvFeatureVectorParserConfiguration; -import ch.systemsx.cisd.openbis.dss.generic.shared.utils.CsvFileReaderHelper; -import ch.systemsx.cisd.openbis.dss.generic.shared.utils.DatasetFileLines; -import ch.systemsx.cisd.openbis.generic.shared.dto.SimpleDataSetInformationDTO; - -/** - * @author Chandrasekhar Ramakrishnan - */ -public class CsvFeatureVectorMigrator extends AbstractFeatureVectorMigrator -{ - protected final FeatureVectorStorageProcessorConfiguration configuration; - - protected final CsvFeatureVectorParserConfiguration convertorConfig; - - /** - * @param properties - */ - public CsvFeatureVectorMigrator(Properties properties) - { - super(properties); - - this.configuration = new FeatureVectorStorageProcessorConfiguration(properties); - convertorConfig = new CsvFeatureVectorParserConfiguration(configuration); - } - - @Override - protected AbstractImageDbImporter createImporter(HCSContainerDatasetInfo dataSetInfo, - File fileToMigrate) - { - AbstractImageDbImporter importer; - - importer = new ImporterCsv(dao, dataSetInfo, fileToMigrate, configuration, convertorConfig); - - return importer; - } - - @Override - protected AbstractMigrationDecision createMigrationDecision(File dataset) - { - AbstractMigrationDecision decision = new MigrationDecision(dataset, knownDataSetsByCode); - return decision; - } - - /** - * Helper class for deciding if a file needs to be migrated. - * - * @author Chandrasekhar Ramakrishnan - */ - private static class MigrationDecision extends AbstractMigrationDecision - { - - /** - * @param dataset - * @param knownDataSetsByCode - */ - public MigrationDecision(File dataset, - HashMap<String, SimpleDataSetInformationDTO> knownDataSetsByCode) - { - super(dataset, knownDataSetsByCode); - } - - @Override - protected File tryFileToMigrate() - { - File originalDataset = DefaultStorageProcessor.getOriginalDirectory(dataset); - File[] files = originalDataset.listFiles(); - - if (files.length == 1) - { - File file = files[0]; - if (file.isDirectory()) - { - return null; - } - return file; - } - return null; - } - - } - - /** - * Helper class for importing CSV feature vector files - * - * @author Chandrasekhar Ramakrishnan - */ - private static class ImporterCsv extends AbstractImageDbImporter - { - private final FeatureVectorStorageProcessorConfiguration configuration; - - private final CsvFeatureVectorParserConfiguration convertorConfig; - - protected ImporterCsv(IImagingQueryDAO dao, HCSContainerDatasetInfo screeningDataSetInfo, - File fileToMigrate, FeatureVectorStorageProcessorConfiguration configuration, - CsvFeatureVectorParserConfiguration convertorConfig) - { - super(dao, screeningDataSetInfo, fileToMigrate); - this.configuration = configuration; - this.convertorConfig = convertorConfig; - } - - @Override - public void doImport() - { - DatasetFileLines fileLines; - try - { - fileLines = getDatasetFileLines(fileToMigrate); - CsvToCanonicalFeatureVector convertor = - new CsvToCanonicalFeatureVector(fileLines, convertorConfig, - screeningDataSetInfo.getContainerRows(), - screeningDataSetInfo.getContainerColumns()); - List<CanonicalFeatureVector> fvecs = convertor.convert(); - - FeatureVectorUploader uploader = - new FeatureVectorUploader(dao, screeningDataSetInfo); - uploader.uploadFeatureVectors(fvecs); - dao.commit(); - isSuccessful = true; - } catch (IOException ex) - { - throw new IOExceptionUnchecked(ex); - } - - } - - /** - * Return the tabular data as a DatasetFileLines. - */ - private DatasetFileLines getDatasetFileLines(File file) throws IOException - { - return CsvFileReaderHelper.getDatasetFileLines(file, configuration); - } - - } - -} diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/genedata/GenedataFeatureVectorMigrator.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/genedata/GenedataFeatureVectorMigrator.java deleted file mode 100644 index 4aa15db2ba049bc2848029dbcd7fb77abbd8aaaa..0000000000000000000000000000000000000000 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/genedata/GenedataFeatureVectorMigrator.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2010 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.etl.genedata; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Properties; - -import ch.systemsx.cisd.common.filesystem.FileUtilities; -import ch.systemsx.cisd.etlserver.DefaultStorageProcessor; -import ch.systemsx.cisd.openbis.dss.etl.HCSContainerDatasetInfo; -import ch.systemsx.cisd.openbis.dss.etl.dataaccess.IImagingQueryDAO; -import ch.systemsx.cisd.openbis.dss.etl.featurevector.AbstractFeatureVectorMigrator; -import ch.systemsx.cisd.openbis.dss.etl.featurevector.CanonicalFeatureVector; -import ch.systemsx.cisd.openbis.dss.etl.featurevector.FeatureVectorUploader; -import ch.systemsx.cisd.openbis.generic.shared.dto.SimpleDataSetInformationDTO; - -/** - * Imports Genedata feature vectors into the database. - * - * @author Chandrasekhar Ramakrishnan - */ -public class GenedataFeatureVectorMigrator extends AbstractFeatureVectorMigrator -{ - - private static final String GENEDATA_FEATURES_EXTENSION = ".stat"; - - /** - * @param properties - */ - public GenedataFeatureVectorMigrator(Properties properties) - { - super(properties); - } - - @Override - protected AbstractImageDbImporter createImporter(HCSContainerDatasetInfo dataSetInfo, - File fileToMigrate) - { - AbstractImageDbImporter importer; - importer = new ImporterGenedata(dao, dataSetInfo, fileToMigrate); - - return importer; - } - - @Override - protected AbstractMigrationDecision createMigrationDecision(File dataset) - { - AbstractMigrationDecision decision = new MigrationDecision(dataset, knownDataSetsByCode); - return decision; - } - - /** - * Helper class for deciding if a file needs to be migrated. - * - * @author Chandrasekhar Ramakrishnan - */ - private static class MigrationDecision extends AbstractMigrationDecision - { - /** - * @param dataset - * @param knownDataSetsByCode - */ - public MigrationDecision(File dataset, - HashMap<String, SimpleDataSetInformationDTO> knownDataSetsByCode) - { - super(dataset, knownDataSetsByCode); - } - - @Override - protected File tryFileToMigrate() - { - File originalDataset = DefaultStorageProcessor.getOriginalDirectory(dataset); - File[] files = originalDataset.listFiles(); - - for (File file : files) - { - if (file.getName().endsWith(GENEDATA_FEATURES_EXTENSION)) - { - return file; - } - } - - return null; - } - } - - /** - * Helper class for importing genedata feature vecotr files. - * - * @author Chandrasekhar Ramakrishnan - */ - private static class ImporterGenedata extends AbstractImageDbImporter - { - - /** - * @param fileToMigrate - */ - private ImporterGenedata(IImagingQueryDAO dao, - HCSContainerDatasetInfo screeningDataSetInfo, File fileToMigrate) - { - super(dao, screeningDataSetInfo, fileToMigrate); - } - - @Override - public void doImport() - { - List<String> lines = FileUtilities.loadToStringList(fileToMigrate); - GenedataFormatToCanonicalFeatureVector convertor = - new GenedataFormatToCanonicalFeatureVector(lines, - FeatureStorageProcessor.LAYER_PREFIX); - ArrayList<CanonicalFeatureVector> fvecs = convertor.convert(); - - FeatureVectorUploader uploader = new FeatureVectorUploader(dao, screeningDataSetInfo); - uploader.uploadFeatureVectors(fvecs); - dao.commit(); - isSuccessful = true; - } - } - -}