package at.gv.egovernment.moa.id.commons.config.cli;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.MissingOptionException;
/**
* The result set for the parsed command line arguments
* @author Christian Wagner
*
*/
public class MigrateConfigurationParams {
private String inputFile = null;
private String outputFile = null;
private String inputDbConfigFile = null;
private String outputDbConfigFile = null;
private boolean overwriteData = false;
/**
* Get the path to the input source which is MOAID 2.x config file in XML-format.
* @return the path to the input source or {@code null} if not set.
*/
public String getInputTarget() {
return this.inputFile;
}
/**
* Get the path to the output file to write to.
* @return the path to the output file or {@code null} if not set.
*/
public String getOutputFile() {
return outputFile;
}
/**
* Get the path to the configuration file for the input database.
* @return the path to the config file or {@code null} if not set.
*/
public String getInputDBConfig() {
return inputDbConfigFile;
}
/**
* Get the path to the configuration file for the output database.
* @return the path to the config file or {@code null} if not set.
*/
public String getOutputDBConfig() {
return outputDbConfigFile;
}
/**
* Returns whether the desired input is a config file for a database.
* @return true
if the stored path points at a database config file; false
otherwise.
*/
public boolean isInputDB() {
return inputDbConfigFile != null;
}
/**
* Returns whether the desired output is a config file for a database.
* @return true
if the stored path points at a database config file; false
otherwise.
*/
public boolean isOutputDB() {
return outputDbConfigFile != null;
}
/**
* Returns whether existing data should be overwritten by the imported data or not.
* @return true
if the existing data should be overwritten; false
otherwise.
*/
public boolean isOverwriteData() {
return overwriteData;
}
/**
*
* @param cmdLine
* @throws MissingOptionException
*/
public MigrateConfigurationParams(CommandLine cmdLine) throws MissingOptionException {
inputFile = cmdLine.getOptionValue(CLIConstants.CLI_PARAM_IN);
inputDbConfigFile = cmdLine.getOptionValue(CLIConstants.CLI_PARAM_INDB);
outputFile = cmdLine.getOptionValue(CLIConstants.CLI_PARAM_OUT);
outputDbConfigFile = cmdLine.getOptionValue(CLIConstants.CLI_PARAM_OUTDB);
overwriteData = cmdLine.hasOption(CLIConstants.CLI_PARAM_FORCE);
if (null == inputFile && null == inputDbConfigFile) {
throw new MissingOptionException("One of [-" + CLIConstants.CLI_PARAM_IN + ", -" + CLIConstants.CLI_PARAM_INDB + "] required.");
}
if (null == outputFile && null == outputDbConfigFile) {
throw new MissingOptionException("One of [-" + CLIConstants.CLI_PARAM_OUT + ", -" + CLIConstants.CLI_PARAM_OUTDB + "] required.");
}
if (null != inputFile && null != inputDbConfigFile) {
throw new MissingOptionException("Only one of [-" + CLIConstants.CLI_PARAM_IN + ", -" + CLIConstants.CLI_PARAM_INDB + "] allowed.");
}
if (null != outputFile && null != outputDbConfigFile) {
throw new MissingOptionException("Only one of [-" + CLIConstants.CLI_PARAM_OUT + ", -" + CLIConstants.CLI_PARAM_OUTDB + "] allowed.");
}
}
}