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