aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com/juick/www/User.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-12-01 13:56:53 +0300
committerGravatar Vitaly Takmazov2016-12-01 13:56:53 +0300
commit3d7f60c1c0b48dad2f58bffe3352d1c5c1b93f00 (patch)
treeab311d5d6102b2c76c03b266fc1b794108cba0fc /juick-www/src/main/java/com/juick/www/User.java
parent92d6700919e87c81db4a42a4b286257f62566cbf (diff)
juick-api: Tags controller from perl, refactoring
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/User.java')
-rw-r--r--juick-www/src/main/java/com/juick/www/User.java19
1 files changed, 10 insertions, 9 deletions
diff --git a/juick-www/src/main/java/com/juick/www/User.java b/juick-www/src/main/java/com/juick/www/User.java
index 3cc38b37..088fb004 100644
--- a/juick-www/src/main/java/com/juick/www/User.java
+++ b/juick-www/src/main/java/com/juick/www/User.java
@@ -17,10 +17,10 @@
*/
package com.juick.www;
-import com.juick.Tag;
import com.juick.server.MessagesQueries;
import com.juick.server.TagQueries;
import com.juick.server.UserQueries;
+import com.juick.server.helpers.TagStats;
import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -32,6 +32,7 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
+import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
@@ -323,22 +324,22 @@ public class User {
}
public static String pageUserTags(JdbcTemplate sql, com.juick.User user, com.juick.User visitor, int cnt) {
- List<Tag> tags = TagQueries.getUserTagsAll(sql, user.getUid()).stream()
- .sorted((e1, e2) -> Integer.compare(e2.UsageCnt, e1.UsageCnt)).collect(Collectors.toList());
- int maxUsageCnt = tags.stream().map(t -> t.UsageCnt).max(Integer::max).orElse(0);
+ List<TagStats> tags = TagQueries.getTagsStats(sql, user.getUid()).stream()
+ .sorted((e1, e2) -> Integer.compare(e2.getUsageCount(), e1.getUsageCount())).collect(Collectors.toList());
+ int maxUsageCnt = tags.stream().map(TagStats::getUsageCount).max(Comparator.naturalOrder()).orElse(0);
String ret = "";
int count = cnt > 0 ? Math.min(tags.size(), cnt) : tags.size();
for (int i = 0; i < count; i++) {
- String tag = StringEscapeUtils.escapeHtml4(tags.get(i).getName());
+ String tag = StringEscapeUtils.escapeHtml4(tags.get(i).getTag().getName());
try {
- tag = "<a href=\"./?tag=" + URLEncoder.encode(tags.get(i).getName(), "UTF-8") + "\" title=\""
- + tags.get(i).UsageCnt + "\" rel=\"nofollow\">" + tag + "</a>";
+ tag = "<a href=\"./?tag=" + URLEncoder.encode(tags.get(i).getTag().getName(), "UTF-8") + "\" title=\""
+ + tags.get(i).getUsageCount() + "\" rel=\"nofollow\">" + tag + "</a>";
} catch (UnsupportedEncodingException e) {
}
- if (tags.get(i).UsageCnt > maxUsageCnt / 3 * 2) {
+ if (tags.get(i).getUsageCount() > maxUsageCnt / 3 * 2) {
ret += "<big>" + tag + "</big> ";
- } else if (tags.get(i).UsageCnt > maxUsageCnt / 3) {
+ } else if (tags.get(i).getUsageCount() > maxUsageCnt / 3) {
ret += "<small>" + tag + "</small> ";
} else {
ret += tag + " ";