Search in sources :

Example 1 with InterfaceDescriptor

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

the class ModuleManager method checkAllConflicts.

/**
 * Check a module list for conflicts.
 *
 * @param modlist modules to be checked
 * @return error message listing conflicts, or "" if no problems
 */
public String checkAllConflicts(Map<String, ModuleDescriptor> modlist) {
    // interface name to module name
    Map<String, String> provs = new HashMap<>();
    StringBuilder conflicts = new StringBuilder();
    for (ModuleDescriptor md : modlist.values()) {
        InterfaceDescriptor[] provides = md.getProvidesList();
        for (InterfaceDescriptor mi : provides) {
            if (mi.isRegularHandler()) {
                String confl = provs.get(mi.getId());
                if (confl == null || confl.isEmpty()) {
                    provs.put(mi.getId(), md.getId());
                } else {
                    String msg = "Interface " + mi.getId() + " is provided by " + md.getId() + " and " + confl + ". ";
                    conflicts.append(msg);
                }
            }
        }
    }
    logger.debug("checkAllConflicts: " + conflicts.toString());
    return conflicts.toString();
}
Also used : ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) InterfaceDescriptor(org.folio.okapi.bean.InterfaceDescriptor)

Example 2 with InterfaceDescriptor

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

the class ModuleManager method resolveModuleConflicts.

private int resolveModuleConflicts(ModuleDescriptor md, Map<String, ModuleDescriptor> modsEnabled, List<TenantModuleDescriptor> tml, List<ModuleDescriptor> fromModule) {
    int v = 0;
    Iterator<String> it = modsEnabled.keySet().iterator();
    while (it.hasNext()) {
        String runningmodule = it.next();
        ModuleDescriptor rm = modsEnabled.get(runningmodule);
        if (md.getProduct().equals(rm.getProduct())) {
            logger.info("resolveModuleConflicts from " + runningmodule);
            fromModule.add(rm);
            modsEnabled.remove(runningmodule);
            it = modsEnabled.keySet().iterator();
            v++;
        } else {
            for (InterfaceDescriptor pi : rm.getProvidesList()) {
                if (pi.isRegularHandler()) {
                    String confl = pi.getId();
                    for (InterfaceDescriptor mi : md.getProvidesList()) {
                        if (mi.getId().equals(confl) && mi.isRegularHandler() && modsEnabled.containsKey(runningmodule)) {
                            logger.info("resolveModuleConflicts remove " + runningmodule);
                            TenantModuleDescriptor tm = new TenantModuleDescriptor();
                            tm.setAction("disable");
                            tm.setId(runningmodule);
                            tml.add(tm);
                            modsEnabled.remove(runningmodule);
                            it = modsEnabled.keySet().iterator();
                            v++;
                        }
                    }
                }
            }
        }
    }
    return v;
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) InterfaceDescriptor(org.folio.okapi.bean.InterfaceDescriptor)

Example 3 with InterfaceDescriptor

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

the class ModuleManager method removeModuleDependencies.

public int removeModuleDependencies(ModuleDescriptor md, Map<String, ModuleDescriptor> modsEnabled, List<TenantModuleDescriptor> tml) {
    int sum = 0;
    logger.info("removeModuleDependencies " + md.getId());
    if (!modsEnabled.containsKey(md.getId())) {
        return 0;
    }
    InterfaceDescriptor[] provides = md.getProvidesList();
    for (InterfaceDescriptor prov : provides) {
        if (prov.isRegularHandler()) {
            Iterator<String> it = modsEnabled.keySet().iterator();
            while (it.hasNext()) {
                String runningmodule = it.next();
                ModuleDescriptor rm = modsEnabled.get(runningmodule);
                InterfaceDescriptor[] requires = rm.getRequiresList();
                for (InterfaceDescriptor ri : requires) {
                    if (prov.getId().equals(ri.getId())) {
                        sum += removeModuleDependencies(rm, modsEnabled, tml);
                        it = modsEnabled.keySet().iterator();
                    }
                }
            }
        }
    }
    modsEnabled.remove(md.getId());
    TenantModuleDescriptor tm = new TenantModuleDescriptor();
    tm.setAction("disable");
    tm.setId(md.getId());
    tml.add(tm);
    return sum + 1;
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) InterfaceDescriptor(org.folio.okapi.bean.InterfaceDescriptor)

Example 4 with InterfaceDescriptor

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

the class TenantManager method getTenantInterface.

/**
 * Find the tenant API interface. Supports several deprecated versions of the
 * tenant interface: the 'tenantInterface' field in MD; if the module provides
 * a '_tenant' interface without RoutingEntries, and finally the proper way,
 * if the module provides a '_tenant' interface that is marked as a system
 * interface, and has a RoutingEntry that supports POST.
 *
 * @param module
 * @param fut callback with the getPath to the interface, "" if no interface,
 * or a failure
 */
private void getTenantInterface(ModuleDescriptor md, Handler<ExtendedAsyncResult<ModuleInstance>> fut) {
    InterfaceDescriptor[] prov = md.getProvidesList();
    logger.debug("findTenantInterface: prov: " + Json.encode(prov));
    for (InterfaceDescriptor pi : prov) {
        logger.debug("findTenantInterface: Looking at " + pi.getId());
        if ("_tenant".equals(pi.getId())) {
            getTenantInterface1(pi, md, fut);
            return;
        }
    }
    fut.handle(new Failure<>(NOT_FOUND, "No _tenant interface found for " + md.getId()));
}
Also used : InterfaceDescriptor(org.folio.okapi.bean.InterfaceDescriptor)

Example 5 with InterfaceDescriptor

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

the class TenantManager method tenantPerms.

/**
 * Helper to make the tenantPermissions call for one module. Used from
 * ead3RealoadPerms and ead4Permissions.
 */
private void tenantPerms(Tenant tenant, ModuleDescriptor mdTo, ModuleDescriptor permsModule, ProxyContext pc, Handler<ExtendedAsyncResult<Void>> fut) {
    pc.debug("Loading permissions for " + mdTo.getName() + " (using " + permsModule.getName() + ")");
    String moduleTo = mdTo.getId();
    PermissionList pl = new PermissionList(moduleTo, mdTo.getPermissionSets());
    String pljson = Json.encodePrettily(pl);
    pc.debug("tenantPerms Req: " + pljson);
    InterfaceDescriptor permInt = permsModule.getSystemInterface("_tenantPermissions");
    String permPath = "";
    List<RoutingEntry> routingEntries = permInt.getAllRoutingEntries();
    ModuleInstance permInst = null;
    if (!routingEntries.isEmpty()) {
        for (RoutingEntry re : routingEntries) {
            if (re.match(null, "POST")) {
                permPath = re.getPath();
                if (permPath == null || permPath.isEmpty()) {
                    permPath = re.getPathPattern();
                }
                permInst = new ModuleInstance(permsModule, re, permPath);
            }
        }
    }
    if (permInst == null) {
        fut.handle(new Failure<>(USER, "Bad _tenantPermissions interface in module " + permsModule.getId() + ". No path to POST to"));
        return;
    }
    pc.debug("tenantPerms: " + permsModule.getId() + " and " + permPath);
    proxyService.callSystemInterface(tenant, permInst, pljson, pc, cres -> {
        if (cres.failed()) {
            fut.handle(new Failure<>(cres.getType(), cres.cause()));
        } else {
            pc.debug("tenantPerms request to " + permsModule.getName() + " succeeded for module " + moduleTo + " and tenant " + tenant.getId());
            fut.handle(new Success<>());
        }
    });
}
Also used : RoutingEntry(org.folio.okapi.bean.RoutingEntry) PermissionList(org.folio.okapi.bean.PermissionList) ModuleInstance(org.folio.okapi.bean.ModuleInstance) InterfaceDescriptor(org.folio.okapi.bean.InterfaceDescriptor)

Aggregations

InterfaceDescriptor (org.folio.okapi.bean.InterfaceDescriptor)12 ModuleDescriptor (org.folio.okapi.bean.ModuleDescriptor)7 TenantModuleDescriptor (org.folio.okapi.bean.TenantModuleDescriptor)7 LinkedList (java.util.LinkedList)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ModuleInstance (org.folio.okapi.bean.ModuleInstance)1 PermissionList (org.folio.okapi.bean.PermissionList)1 RoutingEntry (org.folio.okapi.bean.RoutingEntry)1 Tenant (org.folio.okapi.bean.Tenant)1