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));
}
}
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);
}
});
}
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
}
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()));
}
});
}
}
});
}
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<>());
}
});
}
}
});
}
Aggregations