Search in sources :

Example 1 with Job

use of org.folio.rest.jaxrs.model.Job in project raml-module-builder by folio-org.

the class JobAPI method getJobsJobconfsByJobconfsIdJobs.

@Validate
@Override
public void getJobsJobconfsByJobconfsIdJobs(String jobconfsId, String query, String orderBy, Order order, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    System.out.println("sending... getJobsJobconfsByJobconfsIdJobs");
    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);
        }
        vertxContext.runOnContext(v -> {
            try {
                PostgresClient.getInstance(vertxContext.owner()).get(RTFConsts.JOBS_COLLECTION, Job.class, criterion, true, reply -> {
                    try {
                        @SuppressWarnings("unchecked") List<Job> jobs = (List<Job>) reply.result().getResults();
                        Jobs jobList = new Jobs();
                        jobList.setJobs(jobs);
                        jobList.setTotalRecords(jobs.size());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetJobsJobconfsByJobconfsIdJobsResponse.withJsonOK(jobList)));
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetJobsJobconfsByJobconfsIdJobsResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
                    }
                });
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetJobsJobconfsByJobconfsIdJobsResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
            }
        });
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetJobsJobconfsByJobconfsIdJobsResponse.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) Jobs(org.folio.rest.jaxrs.model.Jobs) List(java.util.List) Limit(org.folio.rest.persist.Criteria.Limit) Job(org.folio.rest.jaxrs.model.Job) Validate(org.folio.rest.annotations.Validate)

Example 2 with Job

use of org.folio.rest.jaxrs.model.Job in project raml-module-builder by folio-org.

the class JobAPI method deleteJobsJobconfsByJobconfsIdJobsByJobId.

@Validate
@Override
public void deleteJobsJobconfsByJobconfsIdJobsByJobId(String jobId, String jobconfsId, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    Job query = new Job();
    query.setId(jobId);
    query.setJobConfId(jobconfsId);
    System.out.println("sending... deleteJobsJobconfsByJobconfsIdJobsByJobId");
    try {
        vertxContext.runOnContext(v -> {
            try {
                PostgresClient.getInstance(vertxContext.owner()).delete(RTFConsts.JOBS_COLLECTION, query, reply -> {
                    if (reply.succeeded()) {
                        if (reply.result().getUpdated() == 1) {
                            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(DeleteJobsJobconfsByJobconfsIdJobsByJobIdResponse.withNoContent()));
                        } else {
                            String message = messages.getMessage(lang, MessageConsts.DeletedCountError, 1, reply.result().getUpdated());
                            log.error(message);
                            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(DeleteJobsJobconfsByJobconfsIdJobsByJobIdResponse.withPlainNotFound(message)));
                        }
                    } else {
                        log.error(reply.cause());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(DeleteJobsJobconfsByJobconfsIdJobsByJobIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
                    }
                });
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(DeleteJobsJobconfsByJobconfsIdJobsByJobIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
            }
        });
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(DeleteJobsJobconfsByJobconfsIdJobsByJobIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
    }
}
Also used : Job(org.folio.rest.jaxrs.model.Job) Validate(org.folio.rest.annotations.Validate)

Example 3 with Job

use of org.folio.rest.jaxrs.model.Job in project raml-module-builder by folio-org.

the class JobAPI method getJobsJobconfsByJobconfsIdJobsByJobId.

@Validate
@Override
public void getJobsJobconfsByJobconfsIdJobsByJobId(String jobId, String jobconfsId, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    Job query = new Job();
    query.setId(jobId);
    query.setJobConfId(jobconfsId);
    System.out.println("sending... getJobsJobconfsByJobconfsIdJobsByJobId");
    try {
        vertxContext.runOnContext(v -> {
            try {
                PostgresClient.getInstance(vertxContext.owner()).get(RTFConsts.JOBS_COLLECTION, query, true, reply -> {
                    try {
                        @SuppressWarnings("unchecked") List<Job> job = (List<Job>) reply.result().getResults();
                        if (job.isEmpty()) {
                            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetJobsJobconfsByJobconfsIdJobsByJobIdResponse.withPlainNotFound("Job " + messages.getMessage(lang, "10008"))));
                            return;
                        }
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetJobsJobconfsByJobconfsIdJobsByJobIdResponse.withJsonOK(job.get(0))));
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetJobsJobconfsByJobconfsIdJobsByJobIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
                    }
                });
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetJobsJobconfsByJobconfsIdJobsByJobIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
            }
        });
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetJobsJobconfsByJobconfsIdJobsByJobIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
    }
}
Also used : List(java.util.List) Job(org.folio.rest.jaxrs.model.Job) Validate(org.folio.rest.annotations.Validate)

Example 4 with Job

use of org.folio.rest.jaxrs.model.Job in project raml-module-builder by folio-org.

the class ProcessUploads method parseFile.

/**
 * Main work done by the FileDataHandler which reads in line by line and passes on that line
 * to the correct Importer implementation for line processing
 * @param fileSize
 * @param conf
 * @param replyHandler - the handler returns a job object with success and error counter parameters
 * to be persisted by the job runner
 */
private void parseFile(long fileSize, Job conf, Handler<AsyncResult<Job>> replyHandler) {
    String file = conf.getParameters().get(0).getValue();
    vertx.fileSystem().open(file, new OpenOptions(), ar -> {
        if (ar.succeeded()) {
            AsyncFile rs = ar.result();
            rs.handler(new FileDataHandler(vertx, conf, fileSize, importerCache.get(conf.getName()), reply -> {
                if (reply.failed()) {
                    if (reply.cause().getMessage().contains(RTFConsts.STATUS_ERROR_THRESHOLD)) {
                        log.error("Stopping import... Error threshold exceeded for file " + file);
                        try {
                            // can throw an exception if the error threshold is met at
                            // the last bulk where the endHandler is called before the stop on error is called
                            rs.pause().close();
                        } catch (Exception e) {
                            log.error("Error threshold hit on last block of data ", e);
                        }
                        replyHandler.handle(io.vertx.core.Future.failedFuture(RTFConsts.STATUS_ERROR_THRESHOLD));
                    }
                } else {
                    replyHandler.handle(io.vertx.core.Future.succeededFuture(reply.result()));
                }
            }));
            rs.exceptionHandler(t -> {
                log.error("Error reading from file " + file, t);
                replyHandler.handle(io.vertx.core.Future.failedFuture(RTFConsts.STATUS_ERROR));
            });
            rs.endHandler(v -> {
                rs.close(ar2 -> {
                    if (ar2.failed()) {
                        log.error("Error closing file " + file, ar2.cause());
                    }
                });
            });
        } else {
            log.error("Error opening file " + file, ar.cause());
            replyHandler.handle(io.vertx.core.Future.failedFuture(RTFConsts.STATUS_ERROR));
        }
    });
}
Also used : OpenOptions(io.vertx.core.file.OpenOptions) Importer(org.folio.rest.resource.interfaces.Importer) AsyncFile(io.vertx.core.file.AsyncFile) OpenOptions(io.vertx.core.file.OpenOptions) FileDataHandler(org.folio.rest.resource.handlers.FileDataHandler) Vertx(io.vertx.core.Vertx) Message(io.vertx.core.eventbus.Message) HashMap(java.util.HashMap) Job(org.folio.rest.jaxrs.model.Job) LoggerFactory(io.vertx.core.logging.LoggerFactory) ArrayList(java.util.ArrayList) Messages(org.folio.rest.tools.messages.Messages) InterfaceToImpl(org.folio.rest.tools.utils.InterfaceToImpl) Map(java.util.Map) JobAPI(org.folio.rest.resource.interfaces.JobAPI) JsonObject(io.vertx.core.json.JsonObject) RTFConsts(org.folio.rest.tools.RTFConsts) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) MessageConsumer(io.vertx.core.eventbus.MessageConsumer) Logger(io.vertx.core.logging.Logger) JobConf(org.folio.rest.jaxrs.model.JobConf) AsyncFile(io.vertx.core.file.AsyncFile) FileDataHandler(org.folio.rest.resource.handlers.FileDataHandler)

Aggregations

Job (org.folio.rest.jaxrs.model.Job)4 Validate (org.folio.rest.annotations.Validate)3 List (java.util.List)2 AsyncResult (io.vertx.core.AsyncResult)1 Handler (io.vertx.core.Handler)1 Vertx (io.vertx.core.Vertx)1 Message (io.vertx.core.eventbus.Message)1 MessageConsumer (io.vertx.core.eventbus.MessageConsumer)1 AsyncFile (io.vertx.core.file.AsyncFile)1 OpenOptions (io.vertx.core.file.OpenOptions)1 JsonObject (io.vertx.core.json.JsonObject)1 Logger (io.vertx.core.logging.Logger)1 LoggerFactory (io.vertx.core.logging.LoggerFactory)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JobConf (org.folio.rest.jaxrs.model.JobConf)1 Jobs (org.folio.rest.jaxrs.model.Jobs)1 Criteria (org.folio.rest.persist.Criteria.Criteria)1 Criterion (org.folio.rest.persist.Criteria.Criterion)1