use of org.folio.okapi.common.ModuleId in project okapi by folio-org.
the class ModuleManager method getLatest.
public void getLatest(String id, Handler<ExtendedAsyncResult<ModuleDescriptor>> fut) {
ModuleId moduleId = id != null ? new ModuleId(id) : null;
if (moduleId == null || moduleId.hasSemVer()) {
get(id, fut);
} else {
modules.getKeys(res2 -> {
if (res2.failed()) {
fut.handle(new Failure<>(res2.getType(), res2.cause()));
} else {
String latest = moduleId.getLatest(res2.result());
get(latest, fut);
}
});
}
}
use of org.folio.okapi.common.ModuleId in project okapi by folio-org.
the class InternalModule method listModules.
private void listModules(ProxyContext pc, Handler<ExtendedAsyncResult<String>> fut) {
try {
ModuleId filter = null;
String filterStr = pc.getCtx().request().getParam("filter");
if (filterStr != null) {
filter = new ModuleId(filterStr);
}
final String orderByStr = pc.getCtx().request().getParam("orderBy");
final String orderStr = pc.getCtx().request().getParam("order");
final boolean preRelease = getParamBoolean(pc.getCtx().request(), "preRelease", true);
final boolean full = getParamBoolean(pc.getCtx().request(), "full", false);
moduleManager.getModulesWithFilter(filter, preRelease, res -> {
if (res.failed()) {
fut.handle(new Failure<>(res.getType(), res.cause()));
return;
}
List<ModuleDescriptor> mdl = res.result();
if (orderByStr != null) {
if (!"id".equals(orderByStr)) {
fut.handle(new Failure<>(USER, "unknown orderBy field: " + orderByStr));
return;
}
if (orderStr == null || "desc".equals(orderStr)) {
Collections.sort(mdl, Collections.reverseOrder());
} else if ("asc".equals(orderStr)) {
Collections.sort(mdl);
} else {
fut.handle(new Failure<>(USER, "invalid order value: " + orderStr));
return;
}
} else {
Collections.sort(mdl, Collections.reverseOrder());
}
List<ModuleDescriptor> ml = new ArrayList<>(mdl.size());
for (ModuleDescriptor md : mdl) {
ml.add(new ModuleDescriptor(md, full));
}
String s = Json.encodePrettily(ml);
fut.handle(new Success<>(s));
});
} catch (DecodeException ex) {
fut.handle(new Failure<>(USER, ex));
}
}
use of org.folio.okapi.common.ModuleId in project okapi by folio-org.
the class TenantManager method tmDisable.
private boolean tmDisable(String id, Map<String, ModuleDescriptor> modsAvailable, Map<String, ModuleDescriptor> modsEnabled, List<TenantModuleDescriptor> tml2, Handler<ExtendedAsyncResult<Boolean>> fut) {
ModuleId moduleId = new ModuleId(id);
if (!moduleId.hasSemVer()) {
id = moduleId.getLatest(modsEnabled.keySet());
}
if (tmUpToDate(modsEnabled, id, fut)) {
return true;
}
moduleManager.removeModuleDependencies(modsAvailable.get(id), modsEnabled, tml2);
return false;
}
use of org.folio.okapi.common.ModuleId in project okapi by folio-org.
the class TenantManager method tmEnable.
private boolean tmEnable(String id, Map<String, ModuleDescriptor> modsAvailable, Map<String, ModuleDescriptor> modsEnabled, List<TenantModuleDescriptor> tml, Handler<ExtendedAsyncResult<Boolean>> fut) {
ModuleId moduleId = new ModuleId(id);
if (!moduleId.hasSemVer()) {
id = moduleId.getLatest(modsAvailable.keySet());
}
if (!modsAvailable.containsKey(id)) {
fut.handle(new Failure<>(NOT_FOUND, id));
return true;
}
if (modsEnabled.containsKey(id)) {
boolean alreadyEnabled = false;
for (TenantModuleDescriptor tm : tml) {
if (tm.getId().equals(id)) {
alreadyEnabled = true;
}
}
if (!alreadyEnabled) {
TenantModuleDescriptor tmu = new TenantModuleDescriptor();
tmu.setAction("uptodate");
tmu.setId(id);
tml.add(tmu);
}
} else {
moduleManager.addModuleDependencies(modsAvailable.get(id), modsAvailable, modsEnabled, tml);
}
return false;
}
use of org.folio.okapi.common.ModuleId in project okapi by folio-org.
the class TenantManager method prepareTenantModuleList.
private List<TenantModuleDescriptor> prepareTenantModuleList(Map<String, ModuleDescriptor> modsAvailable, Map<String, ModuleDescriptor> modsEnabled, List<TenantModuleDescriptor> tml) {
if (tml == null) {
// upgrade case . Mark all newer modules for install
List<TenantModuleDescriptor> tml2 = new LinkedList<>();
for (String fId : modsEnabled.keySet()) {
ModuleId moduleId = new ModuleId(fId);
String uId = moduleId.getLatest(modsAvailable.keySet());
if (!uId.equals(fId)) {
TenantModuleDescriptor tmd = new TenantModuleDescriptor();
tmd.setAction("enable");
tmd.setId(uId);
logger.info("upgrade.. enable " + uId);
tmd.setFrom(fId);
tml2.add(tmd);
}
}
return tml2;
} else {
return tml;
}
}
Aggregations