@Override
public ReportSchedule update(String name, ReportSchedule schedule) {
if (schedule instanceof ReportScheduleImpl) {
final ReportScheduleImpl scheduleImpl = (ReportScheduleImpl) schedule;
LOG.debug("updated schedule: " + scheduleImpl);
final Set<ConstraintViolation<ReportScheduleImpl>> violations = validator.validate(scheduleImpl);
if (violations.isEmpty()) {
//return coll.update(DBQuery.is("name", name), ruleImpl, false, false).getSavedObject();
return coll.findAndModify(DBQuery.is("name", name), new BasicDBObject(), new BasicDBObject(),
false, scheduleImpl, true, false);
} else {
throw new IllegalArgumentException("Specified object failed validation: " + violations);
}
} else
throw new IllegalArgumentException(
"Specified object is not of correct implementation type (" + schedule.getClass() + ")!");
}
public static void main(String[] args) throws Exception {
CLIUtil cliUtil = new CLIUtil(WikiWebServicesExporter.class, HELP_MESSAGE, OPTION_BUILDERS);
CommandLine cl = cliUtil.parseCommandLine(args);
String host = cl.getOptionValue(OPTION_INPUT_DB_HOST, DEFAULT_HOST);
Integer port = Integer.parseInt(cl.getOptionValue(OPTION_INPUT_DB_PORT, DEFAULT_PORT));
String dbName = cl.getOptionValue(OPTION_INPUT_DB, DEFAULT_DB);
String collection = cl.getOptionValue(OPTION_INPUT_DB_COLLECTION, DEFAULT_COLLECTION);
String sequenceCollection = cl.getOptionValue(OPTION_INPUT_SEQUENCE_COLLECTION, DEFAULT_SEQUENCES_COLLECTION);
LOGGER.info("Attempting to connect to DB %s:%d/%s, collection %s", host, port, dbName, collection);
Loader loader = new Loader(host, port, UNUSED_SOURCE_DB, dbName, collection, sequenceCollection, DEFAULT_RENDERING_CACHE);
JacksonDBCollection<Reachable, String> reachables = loader.getJacksonReachablesCollection();
LOGGER.info("Connected to DB, reading reachables");
List<Long> exportIds = !cl.hasOption(OPTION_EXPORT_SOME) ?
Collections.emptyList() :
Arrays.stream(cl.getOptionValues(OPTION_EXPORT_SOME))
.map(Long::valueOf)
.collect(Collectors.toList());
TSVWriter<String, String> tsvWriter = new TSVWriter<>(HEADER);
tsvWriter.open(new File(cl.getOptionValue(OPTION_OUTPUT_FILE)));
try {
DBCursor<Reachable> cursor = exportIds.isEmpty() ? reachables.find() :
reachables.find(DBQuery.in("_id", exportIds));
int written = 0;
while (cursor.hasNext()) {
final Reachable r = cursor.next();
Map<String, String> row = new HashMap<String, String>() {{
put("inchi", r.getInchi());
put("inchi_key", r.getInchiKey());
put("display_name", r.getPageName());
put("image_name", r.getStructureFilename());
}};
tsvWriter.append(row);
tsvWriter.flush();
written++;
}
LOGGER.info("Wrote %d reachables to output TSV", written);
} finally {
tsvWriter.close();
}
}
@Override
public int destroy(String ruleName) {
Rule rule = coll.findOne(DBQuery.is("name", ruleName));
removeAlertCondition(rule);
return coll.remove(DBQuery.is("name", ruleName)).getN();
}
@Override
public ReportSchedule get(String id) {
ReportSchedule reportSchedule = coll.find(DBQuery.is("_id", id)).next();
return reportSchedule;
}
@Override
public List<Fortune> list() {
return fortuneCollection.find(DBQuery.empty(), DBProjection.include("_id", "message")).toArray();
}