-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
98 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
||
/** | ||
|
@@ -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"); | ||
} | ||
} |
9470856
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
72-f572f084
disappeared fromsrc/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.9470856
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
76-79d66798
discovered insrc/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.9470856
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
76-1c475d69
discovered insrc/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.