Search in sources :

Example 6 with Failure

use of org.folio.okapi.common.Failure in project okapi by folio-org.

the class InternalModule method installModulesForTenant.

private void installModulesForTenant(ProxyContext pc, String id, String body, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        TenantInstallOptions options = createTenantOptions(pc.getCtx());
        final TenantModuleDescriptor[] tml = Json.decodeValue(body, TenantModuleDescriptor[].class);
        List<TenantModuleDescriptor> tm = new LinkedList<>();
        Collections.addAll(tm, tml);
        tenantManager.installUpgradeModules(id, pc, options, tm, 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 : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) DecodeException(io.vertx.core.json.DecodeException) LinkedList(java.util.LinkedList) Failure(org.folio.okapi.common.Failure) TenantInstallOptions(org.folio.okapi.util.TenantInstallOptions)

Example 7 with Failure

use of org.folio.okapi.common.Failure in project okapi by folio-org.

the class InternalModule method createDeployment.

private void createDeployment(ProxyContext pc, String body, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        final DeploymentDescriptor pmd = Json.decodeValue(body, DeploymentDescriptor.class);
        deploymentManager.deploy(pmd, res -> {
            if (res.failed()) {
                fut.handle(new Failure<>(res.getType(), res.cause()));
                return;
            }
            final String s = Json.encodePrettily(res.result());
            location(pc, res.result().getInstId(), null, 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)

Example 8 with Failure

use of org.folio.okapi.common.Failure in project okapi by folio-org.

the class InternalModule method upgradeModuleForTenant.

private void upgradeModuleForTenant(ProxyContext pc, String id, String mod, String body, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        final String module_from = mod;
        final TenantModuleDescriptor td = Json.decodeValue(body, TenantModuleDescriptor.class);
        final String module_to = td.getId();
        tenantManager.enableAndDisableModule(id, module_from, module_to, pc, res -> {
            if (res.failed()) {
                fut.handle(new Failure<>(res.getType(), res.cause()));
                return;
            }
            td.setId(res.result());
            final String uri = pc.getCtx().request().uri();
            final String regex = "^(.*)/" + module_from + "$";
            final String newuri = uri.replaceAll(regex, "$1");
            location(pc, td.getId(), newuri, 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 9 with Failure

use of org.folio.okapi.common.Failure in project okapi by folio-org.

the class InternalModule method createModule.

private void createModule(ProxyContext pc, String body, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        final ModuleDescriptor md = Json.decodeValue(body, ModuleDescriptor.class);
        final boolean check = getParamBoolean(pc.getCtx().request(), "check", true);
        String validerr = md.validate(pc);
        if (!validerr.isEmpty()) {
            fut.handle(new Failure<>(USER, validerr));
            return;
        }
        moduleManager.create(md, check, cres -> {
            if (cres.failed()) {
                fut.handle(new Failure<>(cres.getType(), cres.cause()));
                return;
            }
            location(pc, md.getId(), null, Json.encodePrettily(md), fut);
        });
    } catch (DecodeException ex) {
        pc.debug("Failed to decode md: " + pc.getCtx().getBodyAsString());
        fut.handle(new Failure<>(USER, ex));
    }
}
Also used : ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure)

Example 10 with Failure

use of org.folio.okapi.common.Failure 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)

Aggregations

Failure (org.folio.okapi.common.Failure)18 DecodeException (io.vertx.core.json.DecodeException)13 ModuleDescriptor (org.folio.okapi.bean.ModuleDescriptor)6 TenantModuleDescriptor (org.folio.okapi.bean.TenantModuleDescriptor)6 Buffer (io.vertx.core.buffer.Buffer)4 HttpClientRequest (io.vertx.core.http.HttpClientRequest)4 DeploymentDescriptor (org.folio.okapi.bean.DeploymentDescriptor)4 Tenant (org.folio.okapi.bean.Tenant)4 JsonObject (io.vertx.core.json.JsonObject)3 ArrayList (java.util.ArrayList)3 Handler (io.vertx.core.Handler)2 MultiMap (io.vertx.core.MultiMap)2 Vertx (io.vertx.core.Vertx)2 HttpClient (io.vertx.core.http.HttpClient)2 HttpClientOptions (io.vertx.core.http.HttpClientOptions)2 HttpClientResponse (io.vertx.core.http.HttpClientResponse)2 HttpMethod (io.vertx.core.http.HttpMethod)2 HttpServerRequest (io.vertx.core.http.HttpServerRequest)2 HttpServerResponse (io.vertx.core.http.HttpServerResponse)2 Json (io.vertx.core.json.Json)2