[jboss-svn-commits] JBL Code SVN: r5136 - in labs/shotoku/trunk: shotoku-feeds/src/java/org/jboss/shotoku/feeds/data shotoku-tags/src/java/org/jboss/shotoku/tags shotoku-tags/src/java/org/jboss/shotoku/tags/dal shotoku-tags/src/java/org/jboss/shotoku/tags/service
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Jul 18 09:46:22 EDT 2006
Author: adamw
Date: 2006-07-18 09:46:20 -0400 (Tue, 18 Jul 2006)
New Revision: 5136
Modified:
labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/TagFeed.java
labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/TagService.java
labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/TagEntity.java
labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java
Log:
http://jira.jboss.org/jira/browse/JBSHOTOKU-86
Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/TagFeed.java
===================================================================
--- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/TagFeed.java 2006-07-18 12:57:22 UTC (rev 5135)
+++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/TagFeed.java 2006-07-18 13:46:20 UTC (rev 5136)
@@ -165,7 +165,7 @@
// Getting the tags with the given names.
try {
- tags = service.getTags(Arrays.asList(tagNames));
+ tags = service.getUniqueTags(Arrays.asList(tagNames));
} catch (TagGetException e) {
throw new IOException(e.getMessage());
}
Modified: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/TagService.java
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/TagService.java 2006-07-18 12:57:22 UTC (rev 5135)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/TagService.java 2006-07-18 13:46:20 UTC (rev 5136)
@@ -45,6 +45,16 @@
public List<Tag> getTagsByAuthor(String author) throws TagGetException;
/**
+ * Gets unique tags (that is, all unique tag names)
+ * associated with the given names.
+ * @param tagNames Names of the tags to get.
+ * @return A list of DummyTag implementatinos with the author and data
+ * fields empty.
+ * @throws TagGetException
+ */
+ public List<Tag> getUniqueTags(List<String> tagNames) throws TagGetException;
+
+ /**
* Gets unique tags (that is, all unique tag names and authors)
* associated with the given author.
* @param author Author of the tags to get.
Modified: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/TagEntity.java
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/TagEntity.java 2006-07-18 12:57:22 UTC (rev 5135)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/TagEntity.java 2006-07-18 13:46:20 UTC (rev 5136)
@@ -4,14 +4,10 @@
import org.jboss.shotoku.tags.ShotokuTag;
import org.jboss.shotoku.tags.WebsiteTag;
import org.jboss.shotoku.tags.tools.Constants;
-import org.jboss.shotoku.service.AdministratedService;
-import org.apache.log4j.Logger;
import javax.persistence.*;
import java.util.Date;
import java.io.Serializable;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
/**
* @author Adam Warski (adamw at aster.pl)
@@ -154,4 +150,14 @@
dateCreated + Constants.SHOTOKU_TAG_REPR_SEPARATOR +
data;
}
+
+ @Transient
+ public TagEntity normalizeName() {
+ name = name.toLowerCase().trim();
+ while (name.contains(" ")) {
+ name = name.replace(" ", " ");
+ }
+
+ return this;
+ }
}
Modified: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java 2006-07-18 12:57:22 UTC (rev 5135)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java 2006-07-18 13:46:20 UTC (rev 5136)
@@ -234,7 +234,7 @@
public void addTag(Tag t) throws TagAddException {
try {
- manager.persist(getTagEntity(t));
+ manager.persist(getTagEntity(t).normalizeName());
} catch (Throwable e) {
throw new TagAddException(e);
}
@@ -248,6 +248,14 @@
}
}
+ private void sortTagsByDate(List<Tag> tags) {
+ Collections.sort(tags, new Comparator<Tag>() {
+ public int compare(Tag o1, Tag o2) {
+ return o1.getDateCreated().compareTo(o2.getDateCreated());
+ }
+ });
+ }
+
public List<Tag> getTags(String resourceId) throws TagGetException {
try {
// noinspection unchecked
@@ -286,7 +294,7 @@
public List<Tag> getTags(List<String> tagNames) throws TagGetException {
try {
- StringBuffer querySb = new StringBuffer("from TagEntity where ");
+ StringBuffer querySb = new StringBuffer("FROM TagEntity WHERE ");
int i = 0;
for (Iterator iter = tagNames.iterator(); iter.hasNext();) {
querySb.append("name").append(" = :name").append(i);
@@ -294,7 +302,7 @@
iter.next();
if (iter.hasNext()) {
- querySb.append(" and ");
+ querySb.append(" OR ");
}
i++;
@@ -320,6 +328,49 @@
}
}
+ public List<Tag> getUniqueTags(List<String> tagNames) throws TagGetException {
+ try {
+ StringBuffer querySb = new StringBuffer(
+ "SELECT name, resourceId, min(dateCreated) " +
+ "FROM TagEntity WHERE ");
+ int i = 0;
+ for (Iterator iter = tagNames.iterator(); iter.hasNext();) {
+ querySb.append("name").append(" = :name").append(i);
+
+ iter.next();
+
+ if (iter.hasNext()) {
+ querySb.append(" OR ");
+ }
+
+ i++;
+ }
+
+ querySb.append(" GROUP BY name, resourceId");
+
+ Query query = manager.createQuery(querySb.toString());
+ i = 0;
+ for (String tagName : tagNames) {
+ query.setParameter("name" + i++, tagName);
+ }
+
+ // noinspection unchecked
+ List<Object[]> result = query.getResultList();
+
+ List<Tag> ret = new ArrayList<Tag>();
+ for (Object[] o : result) {
+ ret.add(new DummyTag((String) o[0], null, (String) o[1],
+ null, (Date) o[2]));
+ }
+
+ sortTagsByDate(ret);
+
+ return ret;
+ } catch (Throwable e) {
+ throw new TagGetException(e);
+ }
+ }
+
@SuppressWarnings({"unchecked"})
public List<Tag> getRelatedTags(List<Tag> relateTo) throws TagGetException {
List<Tag> ret = new ArrayList<Tag>();
@@ -415,11 +466,7 @@
null, (Date) o[1]));
}
- Collections.sort(ret, new Comparator<Tag>() {
- public int compare(Tag o1, Tag o2) {
- return o1.getDateCreated().compareTo(o2.getDateCreated());
- }
- });
+ sortTagsByDate(ret);
return ret;
} catch (Throwable e) {
@@ -469,11 +516,7 @@
null, (Date) o[1]));
}
- Collections.sort(ret, new Comparator<Tag>() {
- public int compare(Tag o1, Tag o2) {
- return o1.getDateCreated().compareTo(o2.getDateCreated());
- }
- });
+ sortTagsByDate(ret);
return ret;
} catch (Throwable e) {
More information about the jboss-svn-commits
mailing list