Search in sources :

Example 1 with Pipe

use of io.wring.model.Pipe in project wring by yegor256.

the class TkPipeDelete method act.

@Override
public Response act(final Request req) throws IOException {
    final Pipe pipe = this.base.user(new RqUser(req).urn()).pipes().pipe(Long.parseLong(new RqHref.Base(req).href().param("id").iterator().next()));
    final String msg = new XePrint(pipe.asXembly()).text("Pipe #{/pipe/id/text()} deleted");
    pipe.delete();
    return new RsForward(new RsFlash(msg), "/pipes");
}
Also used : RsFlash(org.takes.facets.flash.RsFlash) XePrint(io.wring.model.XePrint) RsForward(org.takes.facets.forward.RsForward) Pipe(io.wring.model.Pipe) Base(io.wring.model.Base)

Example 2 with Pipe

use of io.wring.model.Pipe in project wring by yegor256.

the class Cycle method exec.

@Override
public void exec(final Pipe pipe) throws Exception {
    final XePrint print = new XePrint(pipe.asXembly());
    final Events events = this.base.user(print.text("{/pipe/urn/text()}")).events();
    final String json = print.text("{/pipe/json/text()}");
    new UncheckedFunc<>(new FuncWithFallback<String, JsonObject>(str -> Json.createReader(new ReaderOf(str)).readObject(), new FuncOf<>(error -> events.post(Cycle.class.getCanonicalName(), String.format("Failed to parse JSON:\n%s\n\n%s", json, new TextOf(new BytesOf(error)).asString()))), obj -> {
        if (obj != null) {
            new Exec(new JsonAgent(this.base, obj), new IgnoreEvents(new BoostEvents(events, obj), obj), pipe).run();
        }
        return obj;
    })).apply(json);
}
Also used : JsonObject(javax.json.JsonObject) Events(io.wring.model.Events) FuncOf(org.cactoos.func.FuncOf) UncheckedFunc(org.cactoos.func.UncheckedFunc) Proc(org.cactoos.Proc) Base(io.wring.model.Base) BytesOf(org.cactoos.io.BytesOf) XePrint(io.wring.model.XePrint) Json(javax.json.Json) Pipe(io.wring.model.Pipe) ReaderOf(org.cactoos.io.ReaderOf) TextOf(org.cactoos.text.TextOf) FuncWithFallback(org.cactoos.func.FuncWithFallback) BytesOf(org.cactoos.io.BytesOf) FuncWithFallback(org.cactoos.func.FuncWithFallback) Events(io.wring.model.Events) ReaderOf(org.cactoos.io.ReaderOf) XePrint(io.wring.model.XePrint) TextOf(org.cactoos.text.TextOf)

Example 3 with Pipe

use of io.wring.model.Pipe in project wring by yegor256.

the class CycleTest method processesSinglePipe.

/**
 * Cycle can process a single pipe.
 * @throws Exception If some problem inside
 */
@Test
public void processesSinglePipe() throws Exception {
    final Base base = new FkBase();
    final Pipe pipe = new FkPipe();
    new Cycle(base).exec(pipe);
}
Also used : FkBase(io.wring.fake.FkBase) Pipe(io.wring.model.Pipe) FkPipe(io.wring.fake.FkPipe) Base(io.wring.model.Base) FkBase(io.wring.fake.FkBase) FkPipe(io.wring.fake.FkPipe) Test(org.junit.Test)

Example 4 with Pipe

use of io.wring.model.Pipe in project wring by yegor256.

the class CycleTest method processesSinglePipeWithBrokenJson.

/**
 * Cycle can process a single pipe with broken JSOn.
 * @throws Exception If some problem inside
 */
@Test
public void processesSinglePipeWithBrokenJson() throws Exception {
    final Base base = new FkBase();
    final Pipe pipe = new FkPipe(new Directives().add("pipe").add("urn").set("urn:test:1").up().add("json").set("{\"a\":\"/@[a-z0-9\\\\-]\\\\s+\"}").up().up());
    new Cycle(base).exec(pipe);
}
Also used : FkBase(io.wring.fake.FkBase) Directives(org.xembly.Directives) Pipe(io.wring.model.Pipe) FkPipe(io.wring.fake.FkPipe) Base(io.wring.model.Base) FkBase(io.wring.fake.FkBase) FkPipe(io.wring.fake.FkPipe) Test(org.junit.Test)

Example 5 with Pipe

use of io.wring.model.Pipe in project wring by yegor256.

the class DyPipesITCase method addsAndRemovePipes.

/**
 * DyPipes can add and remove pipes.
 * @throws Exception If some problem inside
 */
@Test
public void addsAndRemovePipes() throws Exception {
    final User user = new DyUser(new Dynamo(), "jeffrey");
    final Pipes pipes = user.pipes();
    pipes.add("{\"name\": \"hello\"}");
    final Pipe pipe = pipes.iterate().iterator().next();
    MatcherAssert.assertThat(new Xembler(pipe.asXembly()).xml(), XhtmlMatchers.hasXPaths("/pipe/json", "/pipe/id"));
    pipe.delete();
}
Also used : User(io.wring.model.User) Pipe(io.wring.model.Pipe) Xembler(org.xembly.Xembler) Pipes(io.wring.model.Pipes) Test(org.junit.Test)

Aggregations

Pipe (io.wring.model.Pipe)5 Base (io.wring.model.Base)4 Test (org.junit.Test)3 FkBase (io.wring.fake.FkBase)2 FkPipe (io.wring.fake.FkPipe)2 XePrint (io.wring.model.XePrint)2 Events (io.wring.model.Events)1 Pipes (io.wring.model.Pipes)1 User (io.wring.model.User)1 Json (javax.json.Json)1 JsonObject (javax.json.JsonObject)1 Proc (org.cactoos.Proc)1 FuncOf (org.cactoos.func.FuncOf)1 FuncWithFallback (org.cactoos.func.FuncWithFallback)1 UncheckedFunc (org.cactoos.func.UncheckedFunc)1 BytesOf (org.cactoos.io.BytesOf)1 ReaderOf (org.cactoos.io.ReaderOf)1 TextOf (org.cactoos.text.TextOf)1 RsFlash (org.takes.facets.flash.RsFlash)1 RsForward (org.takes.facets.forward.RsForward)1