Search in sources :

Example 1 with Validate

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

the class AdminAPI method putAdminLoglevel.

@Validate
@Override
public void putAdminLoglevel(Level level, String javaPackage, java.util.Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    try {
        JsonObject updatedLoggers = LogUtil.updateLogConfiguration(javaPackage, level.name());
        OutStream os = new OutStream();
        os.setData(updatedLoggers);
        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 2 with Validate

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

the class AdminAPI method getAdminPostgresTableAccessStats.

@Validate
@Override
public void getAdminPostgresTableAccessStats(Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    PostgresClient.getInstance(vertxContext.owner()).select("SELECT schemaname,relname,seq_scan,idx_scan,cast(idx_scan " + "AS numeric) / (idx_scan + seq_scan) AS idx_scan_pct " + "FROM pg_stat_user_tables WHERE (idx_scan + seq_scan)>0 " + "ORDER BY idx_scan_pct;", reply -> {
        if (reply.succeeded()) {
            OutStream stream = new OutStream();
            stream.setData(reply.result().getRows());
            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminPostgresTableAccessStatsResponse.withJsonOK(stream)));
        } else {
            log.error(reply.cause().getMessage(), reply.cause());
            asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply.cause().getMessage()));
        }
    });
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream) Validate(org.folio.rest.annotations.Validate)

Example 3 with Validate

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

the class AdminAPI method getAdminPostgresActiveSessions.

@Validate
@Override
public void getAdminPostgresActiveSessions(String dbname, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    PostgresClient.getInstance(vertxContext.owner(), "public").select("SELECT pid , usename, " + "application_name, client_addr, client_hostname, " + "query, state from pg_stat_activity where datname='" + dbname + "'", reply -> {
        if (reply.succeeded()) {
            OutStream stream = new OutStream();
            stream.setData(reply.result().getRows());
            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminPostgresActiveSessionsResponse.withJsonOK(stream)));
        } else {
            log.error(reply.cause().getMessage(), reply.cause());
            asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply.cause().getMessage()));
        }
    });
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream) Validate(org.folio.rest.annotations.Validate)

Example 4 with Validate

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

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

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