Search in sources :

Example 11 with ModuleDescriptor

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

the class InternalModule method createModule.

private void createModule(ProxyContext pc, String body, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        final ModuleDescriptor md = Json.decodeValue(body, ModuleDescriptor.class);
        final boolean check = getParamBoolean(pc.getCtx().request(), "check", true);
        String validerr = md.validate(pc);
        if (!validerr.isEmpty()) {
            fut.handle(new Failure<>(USER, validerr));
            return;
        }
        moduleManager.create(md, check, cres -> {
            if (cres.failed()) {
                fut.handle(new Failure<>(cres.getType(), cres.cause()));
                return;
            }
            location(pc, md.getId(), null, Json.encodePrettily(md), fut);
        });
    } catch (DecodeException ex) {
        pc.debug("Failed to decode md: " + pc.getCtx().getBodyAsString());
        fut.handle(new Failure<>(USER, ex));
    }
}
Also used : ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure)

Example 12 with ModuleDescriptor

use of org.folio.okapi.bean.ModuleDescriptor 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 13 with ModuleDescriptor

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

the class InternalModule method listModulesFromInterface.

private void listModulesFromInterface(ProxyContext pc, String id, String intId, Handler<ExtendedAsyncResult<String>> fut) {
    final String type = pc.getCtx().request().getParam("type");
    tenantManager.listModulesFromInterface(id, intId, type, res -> {
        if (res.failed()) {
            fut.handle(new Failure<>(res.getType(), res.cause()));
            return;
        }
        List<ModuleDescriptor> mdL = res.result();
        ArrayList<TenantModuleDescriptor> ta = new ArrayList<>();
        for (ModuleDescriptor md : mdL) {
            TenantModuleDescriptor tmd = new TenantModuleDescriptor();
            tmd.setId(md.getId());
            ta.add(tmd);
        }
        String s = Json.encodePrettily(ta);
        fut.handle(new Success<>(s));
    });
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) ArrayList(java.util.ArrayList)

Example 14 with ModuleDescriptor

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

the class InternalModule method updateModule.

private void updateModule(ProxyContext pc, String id, String body, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        final ModuleDescriptor md = Json.decodeValue(body, ModuleDescriptor.class);
        if (!id.equals(md.getId())) {
            fut.handle(new Failure<>(USER, "Module.id=" + md.getId() + " id=" + id));
            return;
        }
        String validerr = md.validate(pc);
        if (!validerr.isEmpty()) {
            fut.handle(new Failure<>(USER, validerr));
            return;
        }
        moduleManager.update(md, res -> {
            if (res.failed()) {
                fut.handle(new Failure<>(res.getType(), res.cause()));
                return;
            }
            final String s = Json.encodePrettily(md);
            fut.handle(new Success<>(s));
        });
    } catch (DecodeException ex) {
        fut.handle(new Failure<>(USER, ex));
    }
}
Also used : ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure)

Example 15 with ModuleDescriptor

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

the class BeanTest method testModuleDescriptor1.

@Test
public void testModuleDescriptor1() {
    int fail = 0;
    final String docModuleDescriptor = "{" + LS + "  \"id\" : \"sample-module-1\"," + LS + "  \"name\" : \"sample module\"," + LS + "  \"provides\" : [ {" + LS + "    \"id\" : \"sample\"," + LS + "    \"version\" : \"1.0.0\"," + LS + "    \"handlers\" : [ {" + LS + "      \"methods\" : [ \"GET\", \"POST\" ]," + LS + "      \"pathPattern\" : \"/users/{id}\"," + LS + "      \"level\" : \"30\"," + LS + "      \"type\" : \"request-response\"," + LS + "      \"permissionsRequired\" : [ \"sample.needed\" ]," + LS + "      \"permissionsDesired\" : [ \"sample.extra\" ]," + LS + "      \"modulePermissions\" : [ \"sample.modperm\" ]" + LS + "    } ]" + LS + "  }, {" + LS + "    \"id\" : \"_tenant\"," + LS + "    \"version\" : \"1.0.0\"," + LS + "    \"interfaceType\" : \"system\"," + LS + "    \"handlers\" : [ {" + LS + "      \"methods\" : [ \"POST\", \"DELETE\" ]," + LS + "      \"path\" : \"/_/tenant\"," + LS + "      \"level\" : \"10\"," + LS + "      \"type\" : \"system\"" + LS + "    } ]" + LS + "  } ]" + LS + "}";
    try {
        final ModuleDescriptor md = Json.decodeValue(docModuleDescriptor, ModuleDescriptor.class);
        String pretty = Json.encodePrettily(md);
        assertEquals(docModuleDescriptor, pretty);
    } catch (DecodeException ex) {
        ex.printStackTrace();
        fail = 400;
    }
    assertEquals(0, fail);
}
Also used : ModuleDescriptor(org.folio.okapi.bean.ModuleDescriptor) DecodeException(io.vertx.core.json.DecodeException) Test(org.junit.Test)

Aggregations

ModuleDescriptor (org.folio.okapi.bean.ModuleDescriptor)34 TenantModuleDescriptor (org.folio.okapi.bean.TenantModuleDescriptor)24 InterfaceDescriptor (org.folio.okapi.bean.InterfaceDescriptor)7 LinkedList (java.util.LinkedList)6 DecodeException (io.vertx.core.json.DecodeException)4 HashMap (java.util.HashMap)4 Failure (org.folio.okapi.common.Failure)4 Buffer (io.vertx.core.buffer.Buffer)3 ArrayList (java.util.ArrayList)3 ModuleInstance (org.folio.okapi.bean.ModuleInstance)3 RoutingEntry (org.folio.okapi.bean.RoutingEntry)3 Tenant (org.folio.okapi.bean.Tenant)3 HttpClientRequest (io.vertx.core.http.HttpClientRequest)2 LinkedHashMap (java.util.LinkedHashMap)2 ModuleId (org.folio.okapi.common.ModuleId)2 CompList (org.folio.okapi.util.CompList)2 HttpServerRequest (io.vertx.core.http.HttpServerRequest)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1