Skip to content

Commit

Permalink
Importer: Send Scan File Location to Spectral Storage
Browse files Browse the repository at this point in the history
When configured, the Importer will send the scan file location to
Spectral Storage Service.
If scan file location is not accepted, the importer will fall back to
sending the file contents.
  • Loading branch information
danjasuw committed Jun 21, 2019
1 parent 65b7210 commit 7b911ea
Show file tree
Hide file tree
Showing 6 changed files with 470 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,26 @@ dbPort=
# override database names if changed from defaults

proxl.db.name=

###################

## Non-DB Configuration.

## !!! These Only read if the config file location is passed in on the command line, not embedded in the JAR.

###########

# Send Scan File location to Spectral Storage Service rather than the file contents

spectral.storage.send.scan.file.location=

# spectral.storage.send.scan.file.location=true

###

# Only send if scan file path start with this string.
# (Set to match configuration in spectral storage accept value of: submitted.scan.file.path.restrictions=)

# spectral.storage.send.scan.file.location.if.path.starts.with=

###########
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Original author: Daniel Jaschob <djaschob .at. uw.edu>
*
* Copyright 2019 University of Washington - Seattle, WA
*
* 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 org.yeastrc.proxl.import_xml_to_db.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Values from the config file, other than the DB configuration, which is processed elsewhere
*
*/
public class ImporterConfigFileData_OtherThanDBConfig {

private static final Logger log = LoggerFactory.getLogger( ImporterConfigFileData_OtherThanDBConfig.class );

private static boolean spectralStorageService_sendScanFileLocation;

private static String spectralStorageService_sendScanFileLocation_IfPathStartsWith;


private static boolean configured = false;


public static boolean isSpectralStorageService_sendScanFileLocation() {
if ( ! configured ) {
String msg = "ImporterConfigFileData_OtherThanDBConfig not configured";
log.error( msg );
throw new IllegalStateException(msg);
}
return spectralStorageService_sendScanFileLocation;
}


public static String getSpectralStorageService_sendScanFileLocation_IfPathStartsWith() {
if ( ! configured ) {
String msg = "ImporterConfigFileData_OtherThanDBConfig not configured";
log.error( msg );
throw new IllegalStateException(msg);
}
return spectralStorageService_sendScanFileLocation_IfPathStartsWith;
}


public static boolean isConfigured() {
return configured;
}

// Setters Package Private

static void setSpectralStorageService_sendScanFileLocation(boolean spectralStorageService_sendScanFileLocation) {
ImporterConfigFileData_OtherThanDBConfig.spectralStorageService_sendScanFileLocation = spectralStorageService_sendScanFileLocation;
}


static void setSpectralStorageService_sendScanFileLocation_IfPathStartsWith(
String spectralStorageService_sendScanFileLocation_IfPathStartsWith) {
ImporterConfigFileData_OtherThanDBConfig.spectralStorageService_sendScanFileLocation_IfPathStartsWith = spectralStorageService_sendScanFileLocation_IfPathStartsWith;
}


static void setConfigured(boolean configured) {
ImporterConfigFileData_OtherThanDBConfig.configured = configured;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Original author: Daniel Jaschob <djaschob .at. uw.edu>
*
* Copyright 2019 University of Washington - Seattle, WA
*
* 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 org.yeastrc.proxl.import_xml_to_db.config;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Process Values from the config file, other than the DB configuration, which is processed elsewhere
*
*/
public class Process_ConfigFileData_OtherThanDBConfig {

private static final Logger log = LoggerFactory.getLogger( Process_ConfigFileData_OtherThanDBConfig.class );

private static final String PROPERTY_NAME__SPECTRAL_STORAGE_SEND_SCAN_FILE_LOCATION = "spectral.storage.send.scan.file.location";

private static final String SPECTRAL_STORAGE_SEND_SCAN_FILE_LOCATION__TRUE = "true";

private static final String PROPERTY_NAME__SPECTRAL_STORAGE_SEND_SCAN_FILE_LOCATION_IF_STARTS_WITH =
"spectral.storage.send.scan.file.location.if.path.starts.with";


/**
* private constructor
*/
private Process_ConfigFileData_OtherThanDBConfig() { }

/**
* @return newly created instance
*/
public static Process_ConfigFileData_OtherThanDBConfig getInstance() {
return new Process_ConfigFileData_OtherThanDBConfig();
}



/**
* Process the import runner config file, saving the config and
* return a IDBConnectionParametersProvider object configured with DB params
*
*
* @param configFileFromCommandLine
* @return
* @throws Exception
*/
public void processConfigFile( File configFileFromCommandLine ) throws Exception {

InputStream propertiesFileAsStream = null;
try {

propertiesFileAsStream = new FileInputStream( configFileFromCommandLine );

Properties configProps = new Properties();
configProps.load( propertiesFileAsStream );

String propertyValue = null;

propertyValue = configProps.getProperty( PROPERTY_NAME__SPECTRAL_STORAGE_SEND_SCAN_FILE_LOCATION );
if ( StringUtils.isNotEmpty( propertyValue ) ) {
if ( SPECTRAL_STORAGE_SEND_SCAN_FILE_LOCATION__TRUE.equals( propertyValue ) ) {
ImporterConfigFileData_OtherThanDBConfig.setSpectralStorageService_sendScanFileLocation(true);
}
}

propertyValue = configProps.getProperty( PROPERTY_NAME__SPECTRAL_STORAGE_SEND_SCAN_FILE_LOCATION_IF_STARTS_WITH );
if ( StringUtils.isNotEmpty( propertyValue ) ) {
ImporterConfigFileData_OtherThanDBConfig.setSpectralStorageService_sendScanFileLocation_IfPathStartsWith( propertyValue );

log.warn( "INFO: Config file property '"
+ PROPERTY_NAME__SPECTRAL_STORAGE_SEND_SCAN_FILE_LOCATION_IF_STARTS_WITH
+ "' is set to '"
+ SPECTRAL_STORAGE_SEND_SCAN_FILE_LOCATION__TRUE
+ "'.");
}

ImporterConfigFileData_OtherThanDBConfig.setConfigured(true);

if ( ImporterConfigFileData_OtherThanDBConfig.isSpectralStorageService_sendScanFileLocation()
&& ImporterConfigFileData_OtherThanDBConfig.getSpectralStorageService_sendScanFileLocation_IfPathStartsWith() != null ) {

log.warn( "INFO: Config file property '"
+ PROPERTY_NAME__SPECTRAL_STORAGE_SEND_SCAN_FILE_LOCATION
+ "' is set to '"
+ SPECTRAL_STORAGE_SEND_SCAN_FILE_LOCATION__TRUE
+ "'. "
+ " and config file property '"
+ PROPERTY_NAME__SPECTRAL_STORAGE_SEND_SCAN_FILE_LOCATION_IF_STARTS_WITH
+ "' is set to '"
+ SPECTRAL_STORAGE_SEND_SCAN_FILE_LOCATION__TRUE
+ "'."
+ " So will be sending Scan file location to Spectral Storage Service. If the location is not accepted, the scan file contents will be sent."
);
}

} catch ( RuntimeException e ) {

log.error( "In processConfigFile(), Properties file '" + configFileFromCommandLine.getAbsolutePath() + "', exception: " + e.toString(), e );

throw e;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;

import org.yeastrc.proxl.import_xml_to_db.config.Process_ConfigFileData_OtherThanDBConfig;
import org.yeastrc.proxl.import_xml_to_db.constants.DataErrorsFileConstants;
import org.yeastrc.proxl.import_xml_to_db.constants.ImporterProgramExitCodes;
import org.yeastrc.proxl.import_xml_to_db.constants.ScanFilenameConstants;
Expand Down Expand Up @@ -308,6 +308,9 @@ public ImportResults importerDefaultMainProgramEntryPassingArgsAndProxlXMLObject
importResults.setProgramExitCode( ImporterProgramExitCodes.PROGRAM_EXIT_CODE_INVALID_COMMAND_LINE_PARAMETER_VALUES );
return importResults; // EARLY EXIT
}

Process_ConfigFileData_OtherThanDBConfig.getInstance().processConfigFile( dbConfigFile );

}
// TODO Not currently used
// outputImportResultFileName = (String)cmdLineParser.getOptionValue( outputImportResultFileCommandLineOpt );
Expand Down

0 comments on commit 7b911ea

Please sign in to comment.