Search in sources :

Example 6 with OutStream

use of org.folio.rest.tools.utils.OutStream in project raml-module-builder by folio-org.

the class AdminAPI method postAdminPostgresMaintenance.

@Validate
@Override
public void postAdminPostgresMaintenance(String table, Command command, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    String tenantId = TenantTool.calculateTenantId(okapiHeaders.get(ClientGenerator.OKAPI_HEADER_TENANT));
    String module = PomReader.INSTANCE.getModuleName();
    String querySuffix = tenantId + "_" + module + "." + table + ";";
    String query = null;
    if (Command.ANALYZE == command) {
        query = "analyze " + querySuffix;
    } else if (Command.VACUUM == command) {
        query = "vacuum " + querySuffix;
    } else if (Command.VACUUM_ANALYZE == command) {
        query = "vacuum analyze " + querySuffix;
    } else if (Command.VACUUM_VERBOSE == command) {
        query = "vacuum verbose " + querySuffix;
    }
    try {
        PostgresClient.getInstance(vertxContext.owner()).select(query, reply -> {
            if (reply.succeeded()) {
                OutStream stream = new OutStream();
                stream.setData(reply.result().getRows());
                asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PostAdminPostgresMaintenanceResponse.withJsonCreated(stream)));
            } else {
                log.error(reply.cause().getMessage(), reply.cause());
                asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply.cause().getMessage()));
            }
        });
    } catch (Exception e) {
        log.error(e.getMessage());
        asyncResultHandler.handle(io.vertx.core.Future.failedFuture(e.getMessage()));
    }
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream) Validate(org.folio.rest.annotations.Validate)

Example 7 with OutStream

use of org.folio.rest.tools.utils.OutStream in project raml-module-builder by folio-org.

the class AdminAPI method getAdminLoglevel.

@Validate
@Override
public void getAdminLoglevel(java.util.Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    try {
        JsonObject loggers = LogUtil.getLogConfiguration();
        OutStream os = new OutStream();
        os.setData(loggers);
        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutAdminLoglevelResponse.withJsonOK(os)));
    } catch (Exception e) {
        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PutAdminLoglevelResponse.withPlainInternalServerError("ERROR" + e.getMessage())));
        log.error(e.getMessage(), e);
    }
}
Also used : JsonObject(io.vertx.core.json.JsonObject) OutStream(org.folio.rest.tools.utils.OutStream) Validate(org.folio.rest.annotations.Validate)

Example 8 with OutStream

use of org.folio.rest.tools.utils.OutStream in project raml-module-builder by folio-org.

the class BooksDemoAPI method postRmbtestsBooks.

@Validate
@Override
public void postRmbtestsBooks(Book entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    OutStream stream = new OutStream();
    stream.setData(entity);
    asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PostRmbtestsBooksResponse.withJsonCreated("/dummy/location", stream)));
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream) Validate(org.folio.rest.annotations.Validate)

Example 9 with OutStream

use of org.folio.rest.tools.utils.OutStream in project raml-module-builder by folio-org.

the class JobAPI method postJobsJobconfsByJobconfsIdJobs.

@Validate
@Override
public void postJobsJobconfsByJobconfsIdJobs(String jobconfsId, String lang, Job entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    System.out.println("sending... postJobsJobconfsByJobconfsIdJobs");
    entity.setJobConfId(jobconfsId);
    try {
        vertxContext.runOnContext(v -> {
            try {
                PostgresClient.getInstance(vertxContext.owner()).save(RTFConsts.JOBS_COLLECTION, entity, reply -> {
                    try {
                        OutStream stream = new OutStream();
                        stream.setData(entity);
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PostJobsJobconfsByJobconfsIdJobsResponse.withJsonCreated(reply.result(), stream)));
                    } catch (Exception e) {
                        log.error(e);
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PostJobsJobconfsByJobconfsIdJobsResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
                    }
                });
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PostJobsJobconfsByJobconfsIdJobsResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
            }
        });
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PostJobsJobconfsByJobconfsIdJobsResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
    }
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream) Validate(org.folio.rest.annotations.Validate)

Example 10 with OutStream

use of org.folio.rest.tools.utils.OutStream in project raml-module-builder by folio-org.

the class JobAPI method postJobsJobconfs.

@Validate
@Override
public void postJobsJobconfs(String lang, JobConf entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    System.out.println("sending... postJobsJobconfs");
    try {
        vertxContext.runOnContext(v -> {
            try {
                PostgresClient.getInstance(vertxContext.owner()).save(RTFConsts.JOB_CONF_COLLECTION, entity, reply -> {
                    OutStream stream = new OutStream();
                    stream.setData(entity);
                    asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PostJobsJobconfsResponse.withJsonCreated(reply.result(), stream)));
                });
            } catch (Exception e) {
                log.error(e);
                asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PostJobsJobconfsResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
            }
        });
    } catch (Exception e) {
        log.error(e);
        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PostJobsJobconfsResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
    }
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream) Validate(org.folio.rest.annotations.Validate)

Aggregations

OutStream (org.folio.rest.tools.utils.OutStream)40 Validate (org.folio.rest.annotations.Validate)26 FieldException (org.z3950.zing.cql.cql2pgjson.FieldException)13 CQLParseException (org.z3950.zing.cql.CQLParseException)8 PostgresClient (org.folio.rest.persist.PostgresClient)7 List (java.util.List)5 JsonObject (io.vertx.core.json.JsonObject)4 Response (javax.ws.rs.core.Response)4 CQLWrapper (org.folio.rest.persist.cql.CQLWrapper)4 Map (java.util.Map)3 Limit (org.folio.rest.persist.Criteria.Limit)3 Offset (org.folio.rest.persist.Criteria.Offset)3 TenantTool (org.folio.rest.tools.utils.TenantTool)3 CQL2PgJSON (org.z3950.zing.cql.cql2pgjson.CQL2PgJSON)3 io.vertx.core (io.vertx.core)2 AsyncResult (io.vertx.core.AsyncResult)2 JsonArray (io.vertx.core.json.JsonArray)2 Logger (io.vertx.core.logging.Logger)2 LoggerFactory (io.vertx.core.logging.LoggerFactory)2 InputStream (java.io.InputStream)2