Skip to content

Commit

Permalink
#83 .all()
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 1, 2017
1 parent 071dbb0 commit 42562c6
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 31 deletions.
91 changes: 65 additions & 26 deletions src/main/java/org/jpeek/web/Results.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
*/
package org.jpeek.web;

import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.ComparisonOperator;
import com.amazonaws.services.dynamodbv2.model.Condition;
import com.jcabi.dynamo.Attributes;
import com.jcabi.dynamo.QueryValve;
import com.jcabi.dynamo.ScanValve;
import com.jcabi.dynamo.Table;
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
Expand Down Expand Up @@ -93,34 +97,67 @@ public void add(final String artifact, final Path dir)
rank = (long) (new DyNum(10L).doubleValue()
+ (double) rank * (1.0d - diff.doubleValue()));
}
this.table.put(
new Attributes()
.with("good", "true")
.with("artifact", artifact)
.with("rank", rank)
.with("score", score)
.with("diff", diff.longValue())
.with(
"defects",
new DyNum(index.xpath("/index/@defects").get(0)).longValue()
)
.with("classes", classes)
.with("version", new Version().value())
.with("added", System.currentTimeMillis())
.with(
"ttl",
System.currentTimeMillis() / TimeUnit.SECONDS.toMillis(1L)
if (classes > 0) {
this.table.put(
new Attributes()
.with("good", "true")
.with("artifact", artifact)
.with("rank", rank)
.with("score", score)
.with("diff", diff.longValue())
.with(
"defects",
new DyNum(
index.xpath("/index/@defects").get(0)
).longValue()
)
.with("classes", classes)
.with("version", new Version().value())
.with("added", System.currentTimeMillis())
.with(
"ttl",
System.currentTimeMillis()
/ TimeUnit.SECONDS.toMillis(1L)
// @checkstyle MagicNumber (1 line)
+ TimeUnit.DAYS.toSeconds(100L)
)
);
}
}

/**
* Recent artifacts..
* @return List of them
*/
public Iterable<Iterable<Directive>> recent() {
return new Mapped<>(
item -> {
final String[] parts = item.get("artifact").getS().split(":");
return new Directives()
.add("repo")
.add("group").set(parts[0]).up()
.add("artifact").set(parts[1]).up()
.up();
},
this.table.frame()
.where("good", "true")
.through(
new QueryValve()
.withScanIndexForward(false)
.withIndexName("recent")
.withConsistentRead(false)
// @checkstyle MagicNumber (1 line)
+ TimeUnit.DAYS.toSeconds(100L)
.withLimit(25)
.withAttributesToGet("artifact")
)
);
}

/**
* Recent artifacts..
* All of them.
* @return List of them
*/
public Iterable<Iterable<Directive>> recent() {
public Iterable<Iterable<Directive>> all() {
return new Mapped<>(
item -> {
final String[] parts = item.get("artifact").getS().split(":");
Expand All @@ -138,15 +175,17 @@ public Iterable<Iterable<Directive>> recent() {
.up();
},
this.table.frame()
.where("good", "true")
.where(
"classes",
new Condition()
.withAttributeValueList(new AttributeValue().withN("0"))
.withComparisonOperator(ComparisonOperator.GT)
)
.through(
new QueryValve()
.withScanIndexForward(false)
.withIndexName("recent")
.withConsistentRead(false)
new ScanValve()
// @checkstyle MagicNumber (1 line)
.withLimit(25)
.withAttributesToGet(
.withAttributeToGet(
"artifact", "classes", "defects", "version"
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jpeek/web/TkAll.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Response act(final Request req) {
"recent",
new XeDirectives(
new Joined<>(
new Results().recent()
new Results().all()
)
)
)
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/org/jpeek/web/all.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ SOFTWARE.
</xsl:template>
<xsl:template match="/page" mode="body">
<xsl:apply-templates select="recent"/>
</xsl:template>
<xsl:template match="recent">
<script>
<xsl:text>
function ping() {
Expand All @@ -48,12 +50,10 @@ SOFTWARE.
$span.text(status);
}
);
})
});
}
</xsl:text>
</script>
</xsl:template>
<xsl:template match="recent">
<p>
<xsl:text>There are </xsl:text>
<xsl:value-of select="count(repo)"/>
Expand Down
1 change: 0 additions & 1 deletion src/test/java/org/jpeek/web/TkAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public void pingsSimplePages() throws IOException {
"/jpeek.css",
"/",
"/mistakes",
"/all",
"/robots.txt",
};
final Take app = new TkApp(Files.createTempDirectory("x"));
Expand Down

0 comments on commit 42562c6

Please sign in to comment.