use of me.retrodaredevil.solarthing.config.databases.DatabaseType in project solarthing by wildmountainfarms.
the class PVOutputUploadMain method startPVOutputUpload.
// TODO Make this an action for the automation program
@SuppressWarnings({ "SameReturnValue", "deprecation" })
public static int startPVOutputUpload(PVOutputUploadProgramOptions options, CommandOptions commandOptions, File dataDirectory) {
LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Starting PV Output upload program");
ZoneId zoneId = options.getZoneId();
// Use US local since I (retrodaredevil) am the one debugging
LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Using time zone: {}", zoneId.getDisplayName(TextStyle.FULL, Locale.US));
LOGGER.info("Using default instance options: " + options.getDefaultInstanceOptions());
DatabaseConfig databaseConfig = ConfigUtil.getDatabaseConfig(options.getDatabase());
DatabaseType databaseType = databaseConfig.getType();
if (databaseType != CouchDbDatabaseSettings.TYPE) {
LOGGER.error(SolarThingConstants.SUMMARY_MARKER, "(Fatal)Only CouchDb can be used for this program type right now!");
return SolarThingConstants.EXIT_CODE_INVALID_CONFIG;
}
CouchDbDatabaseSettings couchDbDatabaseSettings = (CouchDbDatabaseSettings) databaseConfig.getSettings();
SolarThingDatabase database = CouchDbSolarThingDatabase.create(CouchDbUtil.createInstance(couchDbDatabaseSettings.getCouchProperties(), couchDbDatabaseSettings.getOkHttpProperties()));
OkHttpClient client = PVOutputOkHttpUtil.configure(new OkHttpClient.Builder(), options.getApiKey(), options.getSystemId()).addInterceptor(new HttpLoggingInterceptor(LOGGER::debug).setLevel(HttpLoggingInterceptor.Level.BASIC)).build();
Retrofit retrofit = PVOutputRetrofitUtil.defaultBuilder().client(client).build();
PVOutputService service = retrofit.create(PVOutputService.class);
PVOutputHandler handler = new PVOutputHandler(zoneId, options.getRequiredIdentifierMap(), options.getVoltageIdentifierFragmentMatcher(), options.getTemperatureIdentifierFragmentMatcher());
String fromDateString = commandOptions.getPVOutputFromDate();
String toDateString = commandOptions.getPVOutputToDate();
if (fromDateString != null && toDateString != null) {
System.out.println("Starting range upload");
final SimpleDate fromDate;
final SimpleDate toDate;
try {
// TODO Don't use SimpleDateFormat anymore and remove supress warnings for deprecation
fromDate = SimpleDate.fromDate(DATE_FORMAT.parse(fromDateString));
toDate = SimpleDate.fromDate(DATE_FORMAT.parse(toDateString));
} catch (ParseException e) {
e.printStackTrace();
System.err.println("Unable to parser either from date or to date. Use the yyyy-MM-dd format");
return SolarThingConstants.EXIT_CODE_INVALID_OPTIONS;
}
return startRangeUpload(fromDate, toDate, options, database, handler, service, options.getZoneId());
} else if ((fromDateString == null) != (toDateString == null)) {
LOGGER.error(SolarThingConstants.SUMMARY_MARKER, "(Fatal)You need to define both from and to, or define neither to do the normal PVOutput program!");
return SolarThingConstants.EXIT_CODE_INVALID_OPTIONS;
}
AnalyticsManager analyticsManager = new AnalyticsManager(options.isAnalyticsEnabled(), dataDirectory);
analyticsManager.sendStartUp(ProgramType.PVOUTPUT_UPLOAD);
return startRealTimeProgram(options, database, handler, service, options.getZoneId());
}
use of me.retrodaredevil.solarthing.config.databases.DatabaseType in project solarthing by wildmountainfarms.
the class ConfigUtil method expectCouchDbDatabaseSettings.
public static CouchDbDatabaseSettings expectCouchDbDatabaseSettings(DatabaseOption options) {
DatabaseConfig databaseConfig = getDatabaseConfig(options.getDatabase());
DatabaseType databaseType = databaseConfig.getType();
if (databaseType != CouchDbDatabaseSettings.TYPE) {
throw new IllegalArgumentException("Only CouchDb can be used for this program type right now!");
}
return (CouchDbDatabaseSettings) databaseConfig.getSettings();
}
Aggregations