Search in sources :

Example 1 with JobConf

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))));
    }
}
Also used : Criteria(org.folio.rest.persist.Criteria.Criteria) Offset(org.folio.rest.persist.Criteria.Offset) Criterion(org.folio.rest.persist.Criteria.Criterion) JobsConfs(org.folio.rest.jaxrs.model.JobsConfs) List(java.util.List) Limit(org.folio.rest.persist.Criteria.Limit) JobConf(org.folio.rest.jaxrs.model.JobConf) Validate(org.folio.rest.annotations.Validate)

Example 2 with JobConf

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]);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) JobConf(org.folio.rest.jaxrs.model.JobConf) Importer(org.folio.rest.resource.interfaces.Importer)

Example 3 with JobConf

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))));
    }
}
Also used : Criterion(org.folio.rest.persist.Criteria.Criterion) List(java.util.List) Criteria(org.folio.rest.persist.Criteria.Criteria) JobConf(org.folio.rest.jaxrs.model.JobConf) Validate(org.folio.rest.annotations.Validate)

Example 4 with JobConf

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))));
    }
}
Also used : JobConf(org.folio.rest.jaxrs.model.JobConf) Validate(org.folio.rest.annotations.Validate)

Aggregations

JobConf (org.folio.rest.jaxrs.model.JobConf)4 Validate (org.folio.rest.annotations.Validate)3 List (java.util.List)2 Criteria (org.folio.rest.persist.Criteria.Criteria)2 Criterion (org.folio.rest.persist.Criteria.Criterion)2 JsonObject (io.vertx.core.json.JsonObject)1 ArrayList (java.util.ArrayList)1 JobsConfs (org.folio.rest.jaxrs.model.JobsConfs)1 Limit (org.folio.rest.persist.Criteria.Limit)1 Offset (org.folio.rest.persist.Criteria.Offset)1 Importer (org.folio.rest.resource.interfaces.Importer)1