use of me.retrodaredevil.solarthing.config.databases.DatabaseSettings in project solarthing by wildmountainfarms.
the class SolarMain method doMain.
private static int doMain(String[] args) {
String logMessage = "Beginning main. Jar: " + getJarInfo();
LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "[LOG] " + logMessage);
System.out.println("[stdout] " + logMessage);
System.err.println("[stderr] " + logMessage);
Cli<CommandOptions> cli = CliFactory.createCli(CommandOptions.class);
final CommandOptions commandOptions;
try {
commandOptions = cli.parseArguments(args);
} catch (ArgumentValidationException ex) {
System.out.println(cli.getHelpMessage());
if (ex instanceof HelpRequestedException) {
return 0;
}
LOGGER.error(SolarThingConstants.SUMMARY_MARKER, ex.getMessage());
LOGGER.error(SolarThingConstants.SUMMARY_MARKER, "(Fatal)Incorrect args");
return SolarThingConstants.EXIT_CODE_INVALID_OPTIONS;
}
if (commandOptions.getBaseConfigFile() != null) {
return doMainCommand(commandOptions, commandOptions.getBaseConfigFile());
}
if (commandOptions.getCouchDbSetupFile() != null) {
final DatabaseConfig config;
try {
config = ConfigUtil.MAPPER.readValue(commandOptions.getCouchDbSetupFile(), DatabaseConfig.class);
} catch (IOException e) {
e.printStackTrace();
System.err.println("Problem reading CouchDB database settings file.");
return SolarThingConstants.EXIT_CODE_INVALID_CONFIG;
}
DatabaseSettings settings = config.getSettings();
if (!(settings instanceof CouchDbDatabaseSettings)) {
System.err.println("Must be CouchDB database settings!");
return SolarThingConstants.EXIT_CODE_INVALID_CONFIG;
}
try {
return CouchDbSetupMain.createFrom((CouchDbDatabaseSettings) settings).doCouchDbSetupMain();
} catch (CouchDbException e) {
if (e instanceof CouchDbCodeException) {
ErrorResponse error = ((CouchDbCodeException) e).getErrorResponse();
if (error != null) {
System.err.println(error.getError());
System.err.println(error.getReason());
}
}
throw new RuntimeException(e);
}
}
List<String> legacyArguments = commandOptions.getLegacyOptionsRaw();
if (legacyArguments == null || legacyArguments.isEmpty()) {
System.err.println(cli.getHelpMessage());
return SolarThingConstants.EXIT_CODE_INVALID_OPTIONS;
}
System.err.println("Invalid sub command: " + legacyArguments.get(0));
return SolarThingConstants.EXIT_CODE_INVALID_OPTIONS;
}
use of me.retrodaredevil.solarthing.config.databases.DatabaseSettings in project solarthing by wildmountainfarms.
the class CommonProvider method init.
@PostConstruct
public void init() {
defaultInstanceOptions = DefaultInstanceOptions.create(getDefaultSourceId(), getDefaultFragmentId());
LOGGER.debug("Using defaultInstanceOptions=" + defaultInstanceOptions);
LOGGER.debug("Database file: " + databaseFile.getAbsolutePath());
LOGGER.debug("Working directory: " + new File(".").getAbsolutePath());
ObjectMapper objectMapper = JacksonUtil.defaultMapper();
objectMapper.getSubtypeResolver().registerSubtypes(DatabaseSettings.class, CouchDbDatabaseSettings.class);
final FileInputStream reader;
try {
reader = new FileInputStream(databaseFile);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
final DatabaseConfig databaseConfig;
try {
databaseConfig = objectMapper.readValue(reader, DatabaseConfig.class);
} catch (IOException e) {
throw new RuntimeException("Couldn't parse data!", e);
}
DatabaseSettings databaseSettings = databaseConfig.getSettings();
if (!(databaseSettings instanceof CouchDbDatabaseSettings)) {
throw new UnsupportedOperationException("Only CouchDB is supported right now!");
}
couchDbDatabaseSettings = (CouchDbDatabaseSettings) databaseSettings;
}
Aggregations