Search in sources :

Example 31 with DecodeException

use of io.vertx.core.json.DecodeException in project okapi by folio-org.

the class InternalModule method listModules.

private void listModules(ProxyContext pc, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        ModuleId filter = null;
        String filterStr = pc.getCtx().request().getParam("filter");
        if (filterStr != null) {
            filter = new ModuleId(filterStr);
        }
        final String orderByStr = pc.getCtx().request().getParam("orderBy");
        final String orderStr = pc.getCtx().request().getParam("order");
        final boolean preRelease = getParamBoolean(pc.getCtx().request(), "preRelease", true);
        final boolean full = getParamBoolean(pc.getCtx().request(), "full", false);
        moduleManager.getModulesWithFilter(filter, preRelease, res -> {
            if (res.failed()) {
                fut.handle(new Failure<>(res.getType(), res.cause()));
                return;
            }
            List<ModuleDescriptor> mdl = res.result();
            if (orderByStr != null) {
                if (!"id".equals(orderByStr)) {
                    fut.handle(new Failure<>(USER, "unknown orderBy field: " + orderByStr));
                    return;
                }
                if (orderStr == null || "desc".equals(orderStr)) {
                    Collections.sort(mdl, Collections.reverseOrder());
                } else if ("asc".equals(orderStr)) {
                    Collections.sort(mdl);
                } else {
                    fut.handle(new Failure<>(USER, "invalid order value: " + orderStr));
                    return;
                }
            } else {
                Collections.sort(mdl, Collections.reverseOrder());
            }
            List<ModuleDescriptor> ml = new ArrayList<>(mdl.size());
            for (ModuleDescriptor md : mdl) {
                ml.add(new ModuleDescriptor(md, full));
            }
            String s = Json.encodePrettily(ml);
            fut.handle(new Success<>(s));
        });
    } catch (DecodeException ex) {
        fut.handle(new Failure<>(USER, ex));
    }
}
Also used : ModuleId(org.folio.okapi.common.ModuleId) ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) ArrayList(java.util.ArrayList) DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure)

Example 32 with DecodeException

use of io.vertx.core.json.DecodeException in project okapi by folio-org.

the class InternalModule method upgradeModulesForTenant.

private void upgradeModulesForTenant(ProxyContext pc, String id, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        TenantInstallOptions options = createTenantOptions(pc.getCtx());
        tenantManager.installUpgradeModules(id, pc, options, null, res -> {
            if (res.failed()) {
                fut.handle(new Failure<>(res.getType(), res.cause()));
            } else {
                logger.info("installUpgradeModules returns:\n" + Json.encodePrettily(res.result()));
                fut.handle(new Success<>(Json.encodePrettily(res.result())));
            }
        });
    } catch (DecodeException ex) {
        fut.handle(new Failure<>(USER, ex));
    }
}
Also used : DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure) TenantInstallOptions(org.folio.okapi.util.TenantInstallOptions)

Example 33 with DecodeException

use of io.vertx.core.json.DecodeException in project okapi by folio-org.

the class InternalModule method enableModuleForTenant.

private void enableModuleForTenant(ProxyContext pc, String id, String body, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        final TenantModuleDescriptor td = Json.decodeValue(body, TenantModuleDescriptor.class);
        String moduleTo = td.getId();
        tenantManager.enableAndDisableModule(id, null, moduleTo, pc, eres -> {
            if (eres.failed()) {
                fut.handle(new Failure<>(eres.getType(), eres.cause()));
                return;
            }
            td.setId(eres.result());
            location(pc, td.getId(), null, Json.encodePrettily(td), fut);
        });
    } catch (DecodeException ex) {
        fut.handle(new Failure<>(USER, ex));
    }
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure)

Example 34 with DecodeException

use of io.vertx.core.json.DecodeException in project okapi by folio-org.

the class InternalModule method createEnv.

private void createEnv(ProxyContext pc, String body, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        final EnvEntry pmd = Json.decodeValue(body, EnvEntry.class);
        envManager.add(pmd, res -> {
            if (res.failed()) {
                fut.handle(new Failure<>(res.getType(), res.cause()));
                return;
            }
            final String js = Json.encodePrettily(pmd);
            location(pc, pmd.getName(), null, js, fut);
        });
    } catch (DecodeException ex) {
        fut.handle(new Failure<>(USER, ex));
    }
}
Also used : DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure) EnvEntry(org.folio.okapi.bean.EnvEntry)

Example 35 with DecodeException

use of io.vertx.core.json.DecodeException in project okapi by folio-org.

the class InternalModule method discoveryDeploy.

private void discoveryDeploy(ProxyContext pc, String body, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        final DeploymentDescriptor pmd = Json.decodeValue(body, DeploymentDescriptor.class);
        discoveryManager.addAndDeploy(pmd, pc, res -> {
            if (res.failed()) {
                fut.handle(new Failure<>(res.getType(), res.cause()));
                return;
            }
            DeploymentDescriptor md = res.result();
            final String s = Json.encodePrettily(md);
            final String baseuri = pc.getCtx().request().uri() + "/" + md.getSrvcId();
            location(pc, md.getInstId(), baseuri, s, fut);
        });
    } catch (DecodeException ex) {
        fut.handle(new Failure<>(USER, ex));
    }
}
Also used : DeploymentDescriptor(org.folio.okapi.bean.DeploymentDescriptor) DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure)

Aggregations

DecodeException (io.vertx.core.json.DecodeException)42 JsonObject (io.vertx.core.json.JsonObject)17 Failure (org.folio.okapi.common.Failure)13 Test (org.junit.Test)8 File (java.io.File)6 DeploymentDescriptor (org.folio.okapi.bean.DeploymentDescriptor)6 TenantModuleDescriptor (org.folio.okapi.bean.TenantModuleDescriptor)6 JsonArray (io.vertx.core.json.JsonArray)4 ArrayList (java.util.ArrayList)4 ModuleDescriptor (org.folio.okapi.bean.ModuleDescriptor)4 Buffer (io.vertx.rxjava.core.buffer.Buffer)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Tuple2 (io.vavr.Tuple2)2 Vertx (io.vertx.core.Vertx)2 Buffer (io.vertx.core.buffer.Buffer)2 FileNotFoundException (java.io.FileNotFoundException)2 ByteBuffer (java.nio.ByteBuffer)2 Scanner (java.util.Scanner)2 AmqpClient (io.enmasse.iot.transport.AmqpClient)1