Search in sources :

Example 61 with Validate

use of org.folio.rest.annotations.Validate 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 62 with Validate

use of org.folio.rest.annotations.Validate 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 63 with Validate

use of org.folio.rest.annotations.Validate 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 64 with Validate

use of org.folio.rest.annotations.Validate 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)

Example 65 with Validate

use of org.folio.rest.annotations.Validate in project raml-module-builder by folio-org.

the class JobAPI method putJobsJobconfsByJobconfsIdJobsByJobId.

@Validate
@Override
public void putJobsJobconfsByJobconfsIdJobsByJobId(String jobId, String jobconfsId, String lang, Job entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    System.out.println("sending... putJobsJobconfsByJobconfsId");
    try {
        Criteria c = new Criteria();
        c.addField("_id");
        c.setOperation("=");
        c.setValue(jobId);
        c.setJSONB(false);
        Criteria d = new Criteria();
        d.addField("job_conf_id");
        d.setOperation("=");
        d.setValue(jobconfsId);
        d.setJSONB(false);
        vertxContext.runOnContext(v -> {
            try {
                PostgresClient.getInstance(vertxContext.owner()).update(RTFConsts.JOBS_COLLECTION, entity, new Criterion().addCriterion(c, "AND", d), true, reply -> {
                    if (reply.succeeded() && reply.result().getUpdated() == 0) {
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutJobsJobconfsByJobconfsIdJobsByJobIdResponse.withPlainNotFound(jobId)));
                    } else {
                        try {
                            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutJobsJobconfsByJobconfsIdJobsByJobIdResponse.withNoContent()));
                        } catch (Exception e) {
                            log.error(e);
                            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutJobsJobconfsByJobconfsIdJobsByJobIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
                        }
                    }
                });
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutJobsJobconfsByJobconfsIdJobsByJobIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
            }
        });
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutJobsJobconfsByJobconfsIdJobsByJobIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
    }
}
Also used : Criterion(org.folio.rest.persist.Criteria.Criterion) Criteria(org.folio.rest.persist.Criteria.Criteria) Validate(org.folio.rest.annotations.Validate)

Aggregations

Validate (org.folio.rest.annotations.Validate)66 FieldException (org.z3950.zing.cql.cql2pgjson.FieldException)42 CQLParseException (org.z3950.zing.cql.CQLParseException)32 List (java.util.List)27 OutStream (org.folio.rest.tools.utils.OutStream)27 Criteria (org.folio.rest.persist.Criteria.Criteria)16 Criterion (org.folio.rest.persist.Criteria.Criterion)16 PostgresClient (org.folio.rest.persist.PostgresClient)16 CQLWrapper (org.folio.rest.persist.cql.CQLWrapper)13 JsonObject (io.vertx.core.json.JsonObject)4 Map (java.util.Map)4 Response (javax.ws.rs.core.Response)4 TenantTool (org.folio.rest.tools.utils.TenantTool)4 InputStream (java.io.InputStream)3 BodyPart (javax.mail.BodyPart)3 io.vertx.core (io.vertx.core)2 AsyncResult (io.vertx.core.AsyncResult)2 Context (io.vertx.core.Context)2 Handler (io.vertx.core.Handler)2 Logger (io.vertx.core.logging.Logger)2