Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Oct 26, 2018
2 parents 74bac4b + 5cbeaf9 commit 220aed2
Show file tree
Hide file tree
Showing 10 changed files with 424 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/io/wring/agents/Exec.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
* @author Yegor Bugayenko (yegor256@gmail.com)
* @version $Id$
* @since 0.13
* @todo #72:30min Errors occurred during execution must be saved and later
* listed to user in a page. User should be able to mark errors as `read`
* in this page. Wire Error and Errors implementations in Exec flow so
* these errors are properly saved once they happen. Cover this with tests.
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
final class Exec {
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/io/wring/dynamo/DyError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright (c) 2016, wring.io
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the wring.io nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package io.wring.dynamo;

import io.wring.model.Error;
import java.io.IOException;
import org.xembly.Directive;

/**
* Dynamo Db implementation for {@link Error}.
*
* @author Paulo Lobo (pauloeduardolobo@gmail.com)
* @version $Id$
* @since 1.0
*/
public final class DyError implements Error {
@Override
public Iterable<Directive> asXembly() throws IOException {
throw new UnsupportedOperationException("asXembly not implemented");
}

@Override
public void delete() throws IOException {
throw new UnsupportedOperationException("delete not implemented");
}
}
81 changes: 81 additions & 0 deletions src/main/java/io/wring/dynamo/DyErrors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Copyright (c) 2016, wring.io
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the wring.io nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package io.wring.dynamo;

import com.jcabi.dynamo.Region;
import io.wring.model.Error;
import io.wring.model.Errors;
import java.io.IOException;

/**
* Errors stored in Dynamo database.
*
* @author Paulo Lobo (pauloeduardolobo@gmail.com)
* @version $Id$
* @since 1.0
* @todo #72:30min Implement DyError and DyErrors classes. These
* methods must use dynamo database as persistence similar to DyEvents and
* DyEvent implementations. The tests are already made in DyErrorsITCase, so
* just un-ignore them after implementing these methods and remove PMD
* annotations below.
*/
@SuppressWarnings({"PMD.SingularField", "PMD.UnusedPrivateField"})
public final class DyErrors implements Errors {

/**
* The region to work with.
*/
private final transient Region region;

/**
* URN.
*/
private final transient String urn;

/**
* Ctor.
* @param reg Region
* @param user URN of the user
*/
public DyErrors(final Region reg, final String user) {
this.region = reg;
this.urn = user;
}

@Override
public Iterable<Error> iterate() throws IOException {
throw new UnsupportedOperationException("iterate not implemented");
}

@Override
public void register(final String title, final String description) {
throw new UnsupportedOperationException("register not implemented");
}
}
6 changes: 6 additions & 0 deletions src/main/java/io/wring/dynamo/DyUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
package io.wring.dynamo;

import com.jcabi.dynamo.Region;
import io.wring.model.Errors;
import io.wring.model.Events;
import io.wring.model.Pipes;
import io.wring.model.User;
Expand Down Expand Up @@ -73,4 +74,9 @@ public Events events() {
return new DyEvents(this.region, this.urn);
}

@Override
public Errors errors() {
return new DyErrors(this.region, this.urn);
}

}
6 changes: 6 additions & 0 deletions src/main/java/io/wring/fake/FkUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/
package io.wring.fake;

import io.wring.model.Errors;
import io.wring.model.Events;
import io.wring.model.Pipes;
import io.wring.model.User;
Expand All @@ -51,4 +52,9 @@ public Pipes pipes() {
public Events events() {
return new FkEvents();
}

@Override
public Errors errors() {
throw new UnsupportedOperationException("Not implemented");
}
}
56 changes: 56 additions & 0 deletions src/main/java/io/wring/model/Error.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright (c) 2016, wring.io
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the wring.io nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package io.wring.model;

import java.io.IOException;
import org.xembly.Directive;

/**
* Error occurred during pipe execution.
*
* @author Paulo Lobo (pauloeduardolobo@gmail.com)
* @version $Id$
* @since 1.0
*/
public interface Error {

/**
* Print it into xembly.
* @return Xembly directives
* @throws IOException If fails
*/
Iterable<Directive> asXembly() throws IOException;

/**
* Delete it.
* @throws IOException If fails
*/
void delete() throws IOException;
}
60 changes: 60 additions & 0 deletions src/main/java/io/wring/model/Errors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright (c) 2016, wring.io
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the wring.io nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package io.wring.model;

import java.io.IOException;

/**
* Errors.
*
* @author Paulo Lobo (pauloeduardolobo@gmail.com)
* @version $Id$
* @since 1.0
* @todo #72:30min Create a Errors page where we will show the errors in Errors
* to the user. We should use Errors/Error implementations and build the page
* in a similar manner that is done on TkEvents.
*/
public interface Errors {

/**
* Iterate first errors.
* @return Events
* @throws IOException If fails
*/
Iterable<Error> iterate() throws IOException;

/**
* Add a new error.
* @param title Title
* @param description Description
* @throws IOException If fails
*/
void register(String title, String description);
}
6 changes: 6 additions & 0 deletions src/main/java/io/wring/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@ public interface User {
*/
Events events();

/**
* Errors.
* @return Errors
*/
Errors errors();

}
66 changes: 66 additions & 0 deletions src/test/java/io/wring/dynamo/DyErrorITCase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Copyright (c) 2016, wring.io
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the wring.io nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package io.wring.dynamo;

import com.jcabi.matchers.XhtmlMatchers;
import io.wring.model.Errors;
import io.wring.model.User;
import org.hamcrest.MatcherAssert;
import org.junit.Ignore;
import org.junit.Test;
import org.xembly.Xembler;

/**
* IT cases for {@link DyError}.
*
* @author Paulo Lobo (pauloeduardolobo@gmail.com)
* @version $Id$
* @since 1.0
*/
@Ignore
public final class DyErrorITCase {

/**
* DyError can generate Xembly.
* @throws Exception If some problem inside
*/
@Test
public void asXembly() throws Exception {
final User user = new DyUser(new Dynamo(), "nick");
final Errors errors = user.errors();
errors.register("Fresh error", "description and message");
MatcherAssert.assertThat(
new Xembler(errors.iterate().iterator().next().asXembly()).xml(),
XhtmlMatchers.hasXPath(
"/error[title='Fresh error']"
)
);
}
}
Loading

3 comments on commit 220aed2

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 220aed2 Oct 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 72-f572f084 discovered in src/main/java/io/wring/agents/Exec.java and submitted as #76. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 220aed2 Oct 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 72-8df4b47a discovered in src/main/java/io/wring/model/Errors.java and submitted as #77. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 220aed2 Oct 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 72-df0429be discovered in src/main/java/io/wring/dynamo/DyErrors.java and submitted as #78. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.