use of org.folio.rest.jaxrs.model.JobConf in project raml-module-builder by folio-org.
the class JobAPI method getJobsJobconfs.
@Validate
@Override
public void getJobsJobconfs(String query, String orderBy, Order order, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
try {
Criterion criterion = Criterion.json2Criterion(query);
criterion.setLimit(new Limit(limit)).setOffset(new Offset(offset));
org.folio.rest.persist.Criteria.Order or = getOrder(order, orderBy);
if (or != null) {
criterion.setOrder(or);
}
System.out.println("sending... getJobsJobconfs");
vertxContext.runOnContext(v -> {
try {
PostgresClient.getInstance(vertxContext.owner()).get(RTFConsts.JOB_CONF_COLLECTION, JobConf.class, criterion, true, reply -> {
JobsConfs ps = new JobsConfs();
@SuppressWarnings("unchecked") List<JobConf> jobConfs = (List<JobConf>) reply.result().getResults();
ps.setJobConfs(jobConfs);
ps.setTotalRecords(jobConfs.size());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetJobsJobconfsResponse.withJsonOK(ps)));
});
} catch (Exception e) {
log.error(e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetJobsJobconfsResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
});
} catch (Exception e) {
log.error(e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetJobsJobconfsResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
}
use of org.folio.rest.jaxrs.model.JobConf in project raml-module-builder by folio-org.
the class ProcessUploads method init.
@Override
public void init(Vertx vertx) {
this.vertx = vertx;
/*
* get all importer implementations in the classpath
*/
ArrayList<Class<?>> impls = new ArrayList<>();
try {
impls = InterfaceToImpl.convert2Impl(RTFConsts.PACKAGE_OF_IMPLEMENTATIONS, RTFConsts.PACKAGE_OF_HOOK_INTERFACES + ".Importer", true);
} catch (Exception e) {
// no impl found
log.error(e);
}
/*
* loop on importer impl, extract the address field and create a event bus handler on each
* of the implementation's addresses
*/
for (int i = 0; i < impls.size(); i++) {
Importer importer = null;
String[] address = new String[] { null };
try {
importer = (Importer) impls.get(i).newInstance();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
if (importer != null) {
address[0] = importer.getImportAddress();
if (address[0] == null) {
// throw exception
log.error("Notification address is null, can not register job ");
} else {
// cache the importer impl
importerCache.put(address[0], importer);
/*
* register each address from each Importer impl on the event bus
*/
MessageConsumer<Object> consumer = vertx.eventBus().consumer(address[0]);
consumer.handler(message -> {
log.debug("Received a message to " + address[0] + ": " + message.body());
JobConf cObj = (JobConf) message.body();
registerJob(cObj, message);
});
log.info("Import Job " + impls.get(i).getName() + " Initialized, registered on address " + address[0]);
}
}
}
}
use of org.folio.rest.jaxrs.model.JobConf in project raml-module-builder by folio-org.
the class JobAPI method getJobsJobconfsByJobconfsId.
@Validate
@Override
public void getJobsJobconfsByJobconfsId(String jobconfsId, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
System.out.println("sending... getJobsJobconfsByJobconfsId");
try {
Criteria c = new Criteria();
c.addField("_id");
c.setOperation("=");
c.setValue(jobconfsId);
c.setJSONB(false);
vertxContext.runOnContext(v -> {
try {
PostgresClient.getInstance(vertxContext.owner()).get(RTFConsts.JOB_CONF_COLLECTION, JobConf.class, new Criterion(c), true, reply -> {
@SuppressWarnings("unchecked") List<JobConf> confs = (List<JobConf>) reply.result().getResults();
if (confs.isEmpty()) {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetJobsJobconfsByJobconfsIdResponse.withPlainNotFound("JobConf " + messages.getMessage(lang, "10008"))));
return;
}
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetJobsJobconfsByJobconfsIdResponse.withJsonOK(confs.get(0))));
});
} catch (Exception e) {
log.error(e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetJobsJobconfsByJobconfsIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
});
} catch (Exception e) {
log.error(e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetJobsJobconfsByJobconfsIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
}
use of org.folio.rest.jaxrs.model.JobConf in project raml-module-builder by folio-org.
the class JobAPI method putJobsJobconfsByJobconfsId.
@Validate
@Override
public void putJobsJobconfsByJobconfsId(String jobconfsId, String lang, JobConf entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
JobConf query = new JobConf();
query.setId(jobconfsId);
System.out.println("sending... putJobsJobconfsByJobconfsId");
try {
vertxContext.runOnContext(v -> {
try {
PostgresClient.getInstance(vertxContext.owner()).update(RTFConsts.JOB_CONF_COLLECTION, entity, jobconfsId, reply -> {
if (reply.succeeded() && reply.result().getUpdated() == 0) {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutJobsJobconfsByJobconfsIdResponse.withPlainNotFound(jobconfsId)));
} else {
try {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutJobsJobconfsByJobconfsIdResponse.withNoContent()));
} catch (Exception e) {
log.error(e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutJobsJobconfsByJobconfsIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
}
});
} catch (Exception e) {
log.error(e.getMessage(), e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutJobsJobconfsByJobconfsIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
});
} catch (Exception e) {
log.error(e.getMessage(), e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutJobsJobconfsByJobconfsIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
}
Aggregations