use of io.vertx.core.json.DecodeException in project okapi by folio-org.
the class InternalModule method updateTenant.
private void updateTenant(String id, String body, Handler<ExtendedAsyncResult<String>> fut) {
try {
final TenantDescriptor td = Json.decodeValue(body, TenantDescriptor.class);
if (!id.equals(td.getId())) {
fut.handle(new Failure<>(USER, "Tenant.id=" + td.getId() + " id=" + id));
return;
}
Tenant t = new Tenant(td);
tenantManager.updateDescriptor(td, res -> {
if (res.failed()) {
fut.handle(new Failure<>(res.getType(), res.cause()));
return;
}
final String s = Json.encodePrettily(t.getDescriptor());
fut.handle(new Success<>(s));
});
} catch (DecodeException ex) {
fut.handle(new Failure<>(USER, ex));
}
}
use of io.vertx.core.json.DecodeException 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));
}
}
use of io.vertx.core.json.DecodeException 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));
}
}
use of io.vertx.core.json.DecodeException 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));
}
}
use of io.vertx.core.json.DecodeException 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));
}
}
Aggregations