Search in sources :

Example 11 with Tenant

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

Example 12 with Tenant

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

the class TenantManager method loadTenants2.

private void loadTenants2(Handler<ExtendedAsyncResult<Void>> fut) {
    tenantStore.listTenants(lres -> {
        if (lres.failed()) {
            fut.handle(new Failure<>(lres.getType(), lres.cause()));
        } else {
            CompList<List<Void>> futures = new CompList<>(INTERNAL);
            for (Tenant t : lres.result()) {
                Future<Void> f = Future.future();
                tenants.add(t.getId(), t, f::handle);
                futures.add(f);
            }
            futures.all(fut);
        }
    });
}
Also used : Tenant(org.folio.okapi.bean.Tenant) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) PermissionList(org.folio.okapi.bean.PermissionList) CompList(org.folio.okapi.util.CompList) CompList(org.folio.okapi.util.CompList)

Example 13 with Tenant

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

the class TenantManager method listModulesFromInterface.

public void listModulesFromInterface(String tenantId, String interfaceName, String interfaceType, Handler<ExtendedAsyncResult<List<ModuleDescriptor>>> fut) {
    tenants.get(tenantId, tres -> {
        if (tres.failed()) {
            fut.handle(new Failure<>(tres.getType(), tres.cause()));
            return;
        }
        Tenant tenant = tres.result();
        List<ModuleDescriptor> mdList = new LinkedList<>();
        moduleManager.getEnabledModules(tenant, mres -> {
            if (mres.failed()) {
                fut.handle(new Failure<>(mres.getType(), mres.cause()));
                return;
            }
            List<ModuleDescriptor> modlist = mres.result();
            for (ModuleDescriptor md : modlist) {
                for (InterfaceDescriptor provide : md.getProvidesList()) {
                    if (interfaceName.equals(provide.getId()) && (interfaceType == null || provide.isType(interfaceType))) {
                        mdList.add(md);
                        break;
                    }
                }
            }
            fut.handle(new Success<>(mdList));
        });
    // modlist
    });
// tenant
}
Also used : ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) Tenant(org.folio.okapi.bean.Tenant) LinkedList(java.util.LinkedList) InterfaceDescriptor(org.folio.okapi.bean.InterfaceDescriptor)

Example 14 with Tenant

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

the class TenantStoreMongo method updateDescriptor.

@Override
public void updateDescriptor(TenantDescriptor td, Handler<ExtendedAsyncResult<Void>> fut) {
    final String id = td.getId();
    JsonObject jq = new JsonObject().put("_id", id);
    cli.find(COLLECTION, jq, res -> {
        if (res.failed()) {
            logger.warn("updateDescriptor: find failed: " + res.cause().getMessage());
            fut.handle(new Failure<>(INTERNAL, res.cause()));
        } else {
            List<JsonObject> l = res.result();
            if (l.isEmpty()) {
                Tenant t = new Tenant(td);
                insert(t, ires -> {
                    if (ires.succeeded()) {
                        fut.handle(new Success<>());
                    } else {
                        fut.handle(new Failure<>(ires.getType(), ires.cause()));
                    }
                });
            } else {
                JsonObject d = l.get(0);
                final Tenant t = decodeTenant(d);
                Tenant nt = new Tenant(td, t.getEnabled());
                JsonObject document = encodeTenant(nt, id);
                cli.replaceDocuments(COLLECTION, jq, document, ures -> {
                    if (ures.succeeded()) {
                        fut.handle(new Success<>());
                    } else {
                        logger.warn("Failed to update descriptor for " + id + ": " + ures.cause().getMessage());
                        fut.handle(new Failure<>(INTERNAL, ures.cause()));
                    }
                });
            }
        }
    });
}
Also used : Tenant(org.folio.okapi.bean.Tenant) JsonObject(io.vertx.core.json.JsonObject)

Example 15 with Tenant

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

the class TenantStoreMongo method updateModules.

@Override
public void updateModules(String id, SortedMap<String, Boolean> enabled, Handler<ExtendedAsyncResult<Void>> fut) {
    JsonObject jq = new JsonObject().put("_id", id);
    cli.find(COLLECTION, jq, gres -> {
        if (gres.failed()) {
            logger.debug("disableModule: find failed: " + gres.cause().getMessage());
            fut.handle(new Failure<>(INTERNAL, gres.cause()));
        } else {
            List<JsonObject> l = gres.result();
            if (l.isEmpty()) {
                logger.debug("disableModule: not found: " + id);
                fut.handle(new Failure<>(NOT_FOUND, "Tenant " + id + " not found"));
            } else {
                JsonObject d = l.get(0);
                final Tenant t = decodeTenant(d);
                t.setEnabled(enabled);
                JsonObject document = encodeTenant(t, id);
                cli.save(COLLECTION, document, sres -> {
                    if (sres.failed()) {
                        logger.debug("TenantStoreMongo: disable: saving failed: " + sres.cause().getMessage());
                        fut.handle(new Failure<>(INTERNAL, sres.cause()));
                    } else {
                        fut.handle(new Success<>());
                    }
                });
            }
        }
    });
}
Also used : Tenant(org.folio.okapi.bean.Tenant) JsonObject(io.vertx.core.json.JsonObject)

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