Search in sources :

Example 36 with DecodeException

use of io.vertx.core.json.DecodeException in project okapi by folio-org.

the class InternalModule method createTenant.

private void createTenant(ProxyContext pc, String body, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        final TenantDescriptor td = Json.decodeValue(body, TenantDescriptor.class);
        if (td.getId() == null || td.getId().isEmpty()) {
            td.setId(UUID.randomUUID().toString());
        }
        final String id = td.getId();
        if (!id.matches("^[a-z0-9_-]+$")) {
            fut.handle(new Failure<>(USER, "Invalid tenant id '" + id + "'"));
            return;
        }
        Tenant t = new Tenant(td);
        tenantManager.insert(t, res -> {
            if (res.failed()) {
                fut.handle(new Failure<>(res.getType(), res.cause()));
                return;
            }
            location(pc, id, null, Json.encodePrettily(t.getDescriptor()), fut);
        });
    } catch (DecodeException ex) {
        fut.handle(new Failure<>(USER, ex));
    }
}
Also used : Tenant(org.folio.okapi.bean.Tenant) TenantDescriptor(org.folio.okapi.bean.TenantDescriptor) DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure)

Example 37 with DecodeException

use of io.vertx.core.json.DecodeException 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 38 with DecodeException

use of io.vertx.core.json.DecodeException 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)

Example 39 with DecodeException

use of io.vertx.core.json.DecodeException in project okapi by folio-org.

the class BeanTest method testDeploymentDescriptor4.

@Test
public void testDeploymentDescriptor4() {
    int fail = 0;
    final String docSampleDeployment = "{" + LS + "  \"srvcId\" : \"sample-module-1\"," + LS + "  \"descriptor\" : {" + LS + "    \"dockerImage\" : \"my-image\"," + LS + "    \"dockerArgs\" : {" + LS + "      \"Hostname\" : \"localhost\"," + LS + "      \"User\" : \"nobody\"" + LS + "    }" + LS + "  }" + LS + "}";
    try {
        final DeploymentDescriptor md = Json.decodeValue(docSampleDeployment, DeploymentDescriptor.class);
        String pretty = Json.encodePrettily(md);
        assertEquals(docSampleDeployment, pretty);
    } catch (DecodeException ex) {
        ex.printStackTrace();
        fail = 400;
    }
    assertEquals(0, fail);
}
Also used : DeploymentDescriptor(org.folio.okapi.bean.DeploymentDescriptor) DecodeException(io.vertx.core.json.DecodeException) Test(org.junit.Test)

Example 40 with DecodeException

use of io.vertx.core.json.DecodeException in project okapi by folio-org.

the class BeanTest method testDeploymentDescriptor1.

@Test
public void testDeploymentDescriptor1() {
    int fail = 0;
    final String docSampleDeployment = "{" + LS + "  \"srvcId\" : \"sample-module-1\"," + LS + "  \"descriptor\" : {" + LS + "    \"exec\" : " + "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"," + LS + "    \"env\" : [ {" + LS + "      \"name\" : \"helloGreeting\"," + LS + "      \"value\" : \"hej\"" + LS + "    } ]" + LS + "  }" + LS + "}";
    try {
        final DeploymentDescriptor md = Json.decodeValue(docSampleDeployment, DeploymentDescriptor.class);
        String pretty = Json.encodePrettily(md);
        assertEquals(docSampleDeployment, pretty);
    } catch (DecodeException ex) {
        ex.printStackTrace();
        fail = 400;
    }
    assertEquals(0, fail);
}
Also used : DeploymentDescriptor(org.folio.okapi.bean.DeploymentDescriptor) DecodeException(io.vertx.core.json.DecodeException) Test(org.junit.Test)

Aggregations

DecodeException (io.vertx.core.json.DecodeException)42 JsonObject (io.vertx.core.json.JsonObject)17 Failure (org.folio.okapi.common.Failure)13 Test (org.junit.Test)8 File (java.io.File)6 DeploymentDescriptor (org.folio.okapi.bean.DeploymentDescriptor)6 TenantModuleDescriptor (org.folio.okapi.bean.TenantModuleDescriptor)6 JsonArray (io.vertx.core.json.JsonArray)4 ArrayList (java.util.ArrayList)4 ModuleDescriptor (org.folio.okapi.bean.ModuleDescriptor)4 Buffer (io.vertx.rxjava.core.buffer.Buffer)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Tuple2 (io.vavr.Tuple2)2 Vertx (io.vertx.core.Vertx)2 Buffer (io.vertx.core.buffer.Buffer)2 FileNotFoundException (java.io.FileNotFoundException)2 ByteBuffer (java.nio.ByteBuffer)2 Scanner (java.util.Scanner)2 AmqpClient (io.enmasse.iot.transport.AmqpClient)1