Search in sources :

Example 6 with Tenant

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

the class TenantManager method listModules.

/**
 * List modules for a given tenant.
 *
 * @param id Tenant ID
 * @param fut callback with a list of moduleIds
 */
public void listModules(String id, Handler<ExtendedAsyncResult<List<String>>> fut) {
    tenants.get(id, gres -> {
        if (gres.failed()) {
            fut.handle(new Failure<>(gres.getType(), gres.cause()));
        } else {
            Tenant t = gres.result();
            List<String> tl = new ArrayList<>(t.listModules());
            tl.sort(null);
            fut.handle(new Success<>(tl));
        }
    });
}
Also used : Tenant(org.folio.okapi.bean.Tenant) ArrayList(java.util.ArrayList)

Example 7 with Tenant

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

the class TenantStorePostgres method updateModuleR.

private void updateModuleR(PostgresQuery q, String id, SortedMap<String, Boolean> enabled, Iterator<JsonObject> it, Handler<ExtendedAsyncResult<Void>> fut) {
    if (it.hasNext()) {
        JsonObject r = it.next();
        String sql = "UPDATE " + TABLE + " SET " + JSON_COLUMN + " = ? WHERE " + ID_SELECT;
        String tj = r.getString(JSON_COLUMN);
        Tenant t = Json.decodeValue(tj, Tenant.class);
        t.setEnabled(enabled);
        String s = Json.encode(t);
        JsonObject doc = new JsonObject(s);
        JsonArray jsa = new JsonArray();
        jsa.add(doc.encode());
        jsa.add(id);
        q.queryWithParams(sql, jsa, res -> {
            if (res.failed()) {
                fut.handle(new Failure<>(INTERNAL, res.cause()));
            } else {
                updateModuleR(q, id, enabled, it, fut);
            }
        });
    } else {
        fut.handle(new Success<>());
        q.close();
    }
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Tenant(org.folio.okapi.bean.Tenant) JsonObject(io.vertx.core.json.JsonObject)

Example 8 with Tenant

use of org.folio.okapi.bean.Tenant 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 9 with Tenant

use of org.folio.okapi.bean.Tenant 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 10 with Tenant

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

the class InternalModule method getModuleForTenant.

private void getModuleForTenant(String id, String mod, Handler<ExtendedAsyncResult<String>> fut) {
    tenantManager.get(id, res -> {
        if (res.failed()) {
            fut.handle(new Failure<>(res.getType(), res.cause()));
            return;
        }
        Tenant t = res.result();
        // Convert the list of module names
        Set<String> ml = t.listModules();
        if (!ml.contains(mod)) {
            fut.handle(new Failure<>(NOT_FOUND, mod));
            return;
        }
        TenantModuleDescriptor tmd = new TenantModuleDescriptor();
        tmd.setId(mod);
        String s = Json.encodePrettily(tmd);
        fut.handle(new Success<>(s));
    });
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) Tenant(org.folio.okapi.bean.Tenant)

Aggregations

Tenant (org.folio.okapi.bean.Tenant)17 JsonObject (io.vertx.core.json.JsonObject)3 ModuleDescriptor (org.folio.okapi.bean.ModuleDescriptor)3 TenantDescriptor (org.folio.okapi.bean.TenantDescriptor)3 TenantModuleDescriptor (org.folio.okapi.bean.TenantModuleDescriptor)3 DecodeException (io.vertx.core.json.DecodeException)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Failure (org.folio.okapi.common.Failure)2 Buffer (io.vertx.core.buffer.Buffer)1 JsonArray (io.vertx.core.json.JsonArray)1 HashMap (java.util.HashMap)1 List (java.util.List)1 InterfaceDescriptor (org.folio.okapi.bean.InterfaceDescriptor)1 ModuleInstance (org.folio.okapi.bean.ModuleInstance)1 PermissionList (org.folio.okapi.bean.PermissionList)1 CompList (org.folio.okapi.util.CompList)1 ProxyContext (org.folio.okapi.util.ProxyContext)1