Search in sources :

Example 1 with ModuleId

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);
            }
        });
    }
}
Also used : ModuleId(org.folio.okapi.common.ModuleId)

Example 2 with ModuleId

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));
    }
}
Also used : ModuleId(org.folio.okapi.common.ModuleId) ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) ArrayList(java.util.ArrayList) DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure)

Example 3 with ModuleId

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;
}
Also used : ModuleId(org.folio.okapi.common.ModuleId)

Example 4 with ModuleId

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;
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) ModuleId(org.folio.okapi.common.ModuleId)

Example 5 with ModuleId

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;
    }
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) ModuleId(org.folio.okapi.common.ModuleId) LinkedList(java.util.LinkedList)

Aggregations

ModuleId (org.folio.okapi.common.ModuleId)6 TenantModuleDescriptor (org.folio.okapi.bean.TenantModuleDescriptor)4 LinkedList (java.util.LinkedList)2 ModuleDescriptor (org.folio.okapi.bean.ModuleDescriptor)2 DecodeException (io.vertx.core.json.DecodeException)1 ArrayList (java.util.ArrayList)1 Failure (org.folio.okapi.common.Failure)1