Skip to content

Commit

Permalink
For #76: Merging master.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulodamaso committed Oct 31, 2018
2 parents f2ce7b9 + 16c98ad commit 9470856
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 10 deletions.
34 changes: 32 additions & 2 deletions src/main/java/io/wring/dynamo/DyError.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@
*/
package io.wring.dynamo;

import com.jcabi.dynamo.Attributes;
import com.jcabi.dynamo.Item;
import io.wring.model.Error;
import java.io.IOException;
import org.xembly.Directive;
import org.xembly.Directives;
import org.xembly.Xembler;

/**
* Dynamo Db implementation for {@link Error}.
Expand All @@ -40,14 +44,40 @@
* @version $Id$
* @since 1.0
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class DyError implements Error {
/**
* The item.
*/
private final transient Item item;

/**
* Ctor.
* @param itm Item
*/
public DyError(final Item itm) {
this.item = itm;
}

@Override
public Iterable<Directive> asXembly() throws IOException {
throw new UnsupportedOperationException("asXembly not implemented");
final String description = this.item.get("description").getS();
return new Directives()
.add("error")
.add("urn").set(this.item.get("urn").getS()).up()
.add("title")
.set(Xembler.escape(this.item.get("title").getS())).up()
.add("description")
.set(Xembler.escape(description)).up();
}

@Override
public void delete() throws IOException {
throw new UnsupportedOperationException("delete not implemented");
this.item.frame().table().delete(
new Attributes()
.with("urn", this.item.get("urn").getS())
.with("title", this.item.get("title").getS())
.with("time", this.item.get("time").getS())
);
}
}
74 changes: 66 additions & 8 deletions src/main/java/io/wring/dynamo/DyErrors.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,31 @@
*/
package io.wring.dynamo;

import com.amazonaws.services.dynamodbv2.model.Select;
import com.jcabi.aspects.Tv;
import com.jcabi.dynamo.Attributes;
import com.jcabi.dynamo.Conditions;
import com.jcabi.dynamo.Item;
import com.jcabi.dynamo.QueryValve;
import com.jcabi.dynamo.Region;
import com.jcabi.dynamo.Table;
import com.jcabi.log.Logger;
import io.wring.model.Error;
import io.wring.model.Errors;
import java.io.IOException;
import java.util.Iterator;

/**
* Errors stored in Dynamo database.
*
* @author Paulo Lobo ([email protected])
* @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.
* @todo #78:30min Add errors table to dynamo. This table must have the columns
* 'urn', 'title', 'description' and 'time' just like columns from events
* table. Then remove ignore annotation from DyErrorsTest and DyError test.
*/
@SuppressWarnings({"PMD.SingularField", "PMD.UnusedPrivateField"})
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class DyErrors implements Errors {

/**
Expand All @@ -70,11 +78,61 @@ public DyErrors(final Region reg, final String user) {

@Override
public Iterable<Error> iterate() {
throw new UnsupportedOperationException("iterate not implemented");
return () -> this.table()
.frame()
.through(
new QueryValve()
.withLimit(Tv.TWENTY)
.withIndexName("top")
.withSelect(Select.ALL_ATTRIBUTES)
.withScanIndexForward(false)
.withConsistentRead(false)
)
.where("urn", Conditions.equalTo(this.urn))
.stream()
.map(DyError::new)
.map(Error.class::cast)
.iterator();
}

@Override
public void register(final String title, final String description) {
throw new UnsupportedOperationException("register not implemented");
try {
this.table().put(
new Attributes()
.with("urn", this.urn)
.with("title", title)
.with("description", description)
.with("time", System.currentTimeMillis())
);
Logger.info(
this, "Error registered for %s: \"%s\"",
this.urn, title
);
} catch (final IOException err) {
throw new IllegalStateException(err);
}
}

/**
* Find items by title.
* @param title Unique title of the event
* @return Items or empty
*/
public Iterator<Item> items(final String title) {
return this.table()
.frame()
.through(new QueryValve())
.where("urn", Conditions.equalTo(this.urn))
.where("title", Conditions.equalTo(title))
.iterator();
}

/**
* Table to work with.
* @return Table
*/
private Table table() {
return this.region.table("errors");
}
}

3 comments on commit 9470856

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 9470856 Oct 31, 2018

Choose a reason for hiding this comment

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

Puzzle 72-f572f084 disappeared from src/main/java/io/wring/agents/Exec.java, that's why I closed #76. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 9470856 Oct 31, 2018

Choose a reason for hiding this comment

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

Puzzle 76-79d66798 discovered in src/main/java/io/wring/model/Error.java and submitted as #85. 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 9470856 Oct 31, 2018

Choose a reason for hiding this comment

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

Puzzle 76-1c475d69 discovered in src/main/java/io/wring/agents/Exec.java and submitted as #86. 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.