Search in sources :

Example 1 with TenantDescriptor

use of org.folio.okapi.bean.TenantDescriptor in project okapi by folio-org.

the class InternalModule method getTenant.

private void getTenant(String id, Handler<ExtendedAsyncResult<String>> fut) {
    tenantManager.get(id, res -> {
        if (res.failed()) {
            fut.handle(new Failure<>(res.getType(), res.cause()));
            return;
        }
        Tenant te = res.result();
        TenantDescriptor td = te.getDescriptor();
        String s = Json.encodePrettily(td);
        fut.handle(new Success<>(s));
    });
}
Also used : Tenant(org.folio.okapi.bean.Tenant) TenantDescriptor(org.folio.okapi.bean.TenantDescriptor)

Example 2 with TenantDescriptor

use of org.folio.okapi.bean.TenantDescriptor 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));
    }
}
Also used : Tenant(org.folio.okapi.bean.Tenant) TenantDescriptor(org.folio.okapi.bean.TenantDescriptor) DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure)

Example 3 with TenantDescriptor

use of org.folio.okapi.bean.TenantDescriptor in project okapi by folio-org.

the class InternalModule method createTenant.

private void createTenant(ProxyContext pc, String body, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        final TenantDescriptor td = Json.decodeValue(body, TenantDescriptor.class);
        if (td.getId() == null || td.getId().isEmpty()) {
            td.setId(UUID.randomUUID().toString());
        }
        final String id = td.getId();
        if (!id.matches("^[a-z0-9_-]+$")) {
            fut.handle(new Failure<>(USER, "Invalid tenant id '" + id + "'"));
            return;
        }
        Tenant t = new Tenant(td);
        tenantManager.insert(t, res -> {
            if (res.failed()) {
                fut.handle(new Failure<>(res.getType(), res.cause()));
                return;
            }
            location(pc, id, null, Json.encodePrettily(t.getDescriptor()), fut);
        });
    } catch (DecodeException ex) {
        fut.handle(new Failure<>(USER, ex));
    }
}
Also used : Tenant(org.folio.okapi.bean.Tenant) TenantDescriptor(org.folio.okapi.bean.TenantDescriptor) DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure)

Aggregations

Tenant (org.folio.okapi.bean.Tenant)3 TenantDescriptor (org.folio.okapi.bean.TenantDescriptor)3 DecodeException (io.vertx.core.json.DecodeException)2 Failure (org.folio.okapi.common.Failure)2