[jboss-svn-commits] JBL Code SVN: r5123 - in labs/shotoku/trunk: shotoku-feeds/src/java/org/jboss/shotoku/feeds shotoku-feeds/src/java/org/jboss/shotoku/feeds/data shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag 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 shotoku-tags/src/java/org/jboss/shotoku/tags/test shotoku-tags/src/java/org/jboss/shotoku/tags/tools
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Jul 17 17:27:15 EDT 2006
Author: adamw
Date: 2006-07-17 17:27:10 -0400 (Mon, 17 Jul 2006)
New Revision: 5123
Added:
labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/DummyTag.java
labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/HitsEntity.java
labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/HitsIdEntity.java
labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/VisitsEntity.java
labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/VisitsIdEntity.java
labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/VisitsIpsEntity.java
labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/VisitsIpsIdEntity.java
Removed:
labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/CountersEntity.java
labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/CountersIdEntity.java
Modified:
labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsServlet.java
labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/ConcreteTagFeed.java
labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Feed.java
labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/FileBasedFeed.java
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/tag/TagFeedTagHandler.java
labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/AbstractTag.java
labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/Tag.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/service/TagServiceImpl.java
labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/test/TagsTestServlet.java
labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/tools/FeedType.java
Log:
http://jira.jboss.org/jira/browse/JBSHOTOKU-86
Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsServlet.java
===================================================================
--- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsServlet.java 2006-07-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsServlet.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -77,7 +77,7 @@
return;
}
- feed.write(response);
+ feed.write(response, request);
}
}
Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/ConcreteTagFeed.java
===================================================================
--- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/ConcreteTagFeed.java 2006-07-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/ConcreteTagFeed.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -1,6 +1,7 @@
package org.jboss.shotoku.feeds.data;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletRequest;
import java.io.OutputStream;
import java.io.IOException;
@@ -16,12 +17,14 @@
this.fullName = fullName;
}
- public void write(OutputStream os) throws IOException {
- tagFeed.write(os, fullName);
+ public void write(OutputStream os, HttpServletRequest request)
+ throws IOException {
+ tagFeed.write(os, fullName, request);
}
- public void write(HttpServletResponse response) throws IOException {
- tagFeed.write(response, fullName);
+ public void write(HttpServletResponse response, HttpServletRequest request)
+ throws IOException {
+ tagFeed.write(response, fullName, request);
}
public String getName() {
Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Feed.java
===================================================================
--- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Feed.java 2006-07-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Feed.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -1,6 +1,7 @@
package org.jboss.shotoku.feeds.data;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletRequest;
import java.io.OutputStream;
import java.io.IOException;
@@ -12,16 +13,20 @@
/**
* Writes the feed data to the given output stream.
* @param os Output stream to write to.
+ * @param request
* @throws java.io.IOException
*/
- public void write(OutputStream os) throws IOException;
+ public void write(OutputStream os,
+ HttpServletRequest request) throws IOException;
/**
* Writes the feed data to the given http servlet response, setting an
* appropriate content type.
* @param response Response to write to.
+ * @param request
* @throws IOException
*/
- public void write(HttpServletResponse response) throws IOException;
+ public void write(HttpServletResponse response,
+ HttpServletRequest request) throws IOException;
/**
* Gets the name of this feed.
* @return Name of this feed.
Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/FileBasedFeed.java
===================================================================
--- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/FileBasedFeed.java 2006-07-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/FileBasedFeed.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -37,89 +37,90 @@
import java.net.URL;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletRequest;
public abstract class FileBasedFeed implements NormalFeed {
- private File file;
+ private File file;
private String name;
private String displayName;
private String type;
public FileBasedFeed(String name, String displayName, String type, File file) {
- this.name = name;
+ this.name = name;
this.displayName = displayName;
this.type = type;
this.file = file;
- }
+ }
- public void generate(URL url) throws IOException {
- InputStream is = null;
-
- try {
- is = url.openStream();
- generate(is);
- } finally {
- if (is != null) {
- is.close();
- }
- }
- }
-
- public void generate(InputStream is) throws IOException {
- OutputStream os = null;
-
- try {
- file.createNewFile();
- os = new BufferedOutputStream(new FileOutputStream(file));
- Tools.transfer(is, os);
- } finally {
- if (os != null) {
- os.close();
- }
- }
- }
-
- public void write(OutputStream os) throws IOException {
- InputStream is = null;
- try {
- is = new BufferedInputStream(new FileInputStream(file));
- Tools.transfer(is, os);
- } finally {
- if (is != null) {
- is.close();
- }
- }
- }
-
- public Writer getWriter() throws IOException {
- return new FileWriter(file);
- }
-
- protected abstract String getContentType();
-
- public void write(HttpServletResponse response) throws IOException {
- response.setContentType(getContentType());
- write(response.getOutputStream());
- }
-
- protected File getFile() {
- return file;
- }
-
- @Override
+ public void generate(URL url) throws IOException {
+ InputStream is = null;
+
+ try {
+ is = url.openStream();
+ generate(is);
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ }
+ }
+
+ public void generate(InputStream is) throws IOException {
+ OutputStream os = null;
+
+ try {
+ file.createNewFile();
+ os = new BufferedOutputStream(new FileOutputStream(file));
+ Tools.transfer(is, os);
+ } finally {
+ if (os != null) {
+ os.close();
+ }
+ }
+ }
+
+ public void write(OutputStream os, HttpServletRequest request) throws IOException {
+ InputStream is = null;
+ try {
+ is = new BufferedInputStream(new FileInputStream(file));
+ Tools.transfer(is, os);
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ }
+ }
+
+ public Writer getWriter() throws IOException {
+ return new FileWriter(file);
+ }
+
+ protected abstract String getContentType();
+
+ public void write(HttpServletResponse response, HttpServletRequest request) throws IOException {
+ response.setContentType(getContentType());
+ write(response.getOutputStream(), request);
+ }
+
+ protected File getFile() {
+ return file;
+ }
+
+ @Override
public void finalize() throws Throwable {
super.finalize();
file.delete();
}
-
- public InputStream getInputStream() {
- try {
- return new FileInputStream(file);
- } catch (FileNotFoundException e) {
- return null;
- }
- }
+ public InputStream getInputStream() {
+ try {
+ return new FileInputStream(file);
+ } catch (FileNotFoundException e) {
+ return null;
+ }
+ }
+
public String getName() {
return name;
}
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-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/TagFeed.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -10,6 +10,7 @@
import org.jboss.shotoku.tags.exceptions.TagGetException;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletRequest;
import java.io.OutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
@@ -60,7 +61,8 @@
return tags.get(0).getDateCreated();
}
- public void write(OutputStream os, String fullName) throws IOException {
+ public void write(OutputStream os, String fullName,
+ HttpServletRequest request) throws IOException {
// Computing the type of the feed to generate.
if (fullName.length() < nameLength+1) {
throw new IOException("Invalid tag feed request.");
@@ -86,7 +88,7 @@
// Getting the list of tags.
try {
- tags = TagTools.getService().getTags(infoDataDecoded);
+ tags = TagTools.getService().getUniqueTags(infoDataDecoded);
} catch (TagGetException e) {
throw new IOException(e.getMessage());
}
@@ -94,21 +96,61 @@
template = template.replace(Constants.TAG_FEED_TYPE_VARIABLE,
FeedType.RESOURCE.toString());
- service.increaseFeedCount(FeedType.RESOURCE, infoDataDecoded);
- } else if (FeedType.AUTHOR.toString().equals(infoTokens[0])) {
- vc.put(FeedType.AUTHOR.toString(), infoDataDecoded);
+ service.increaseFeedCounters(FeedType.RESOURCE, infoDataDecoded,
+ request.getRemoteAddr());
+ } else if (FeedType.AUTHOR_UNIQUE.toString().equals(infoTokens[0])) {
+ vc.put("author", infoDataDecoded);
// Getting the list of tags.
try {
+ tags = TagTools.getService().getUniqueTagsByAuthor(
+ infoDataDecoded);
+ } catch (TagGetException e) {
+ throw new IOException(e.getMessage());
+ }
+
+ template = template.replace(Constants.TAG_FEED_TYPE_VARIABLE,
+ FeedType.AUTHOR_UNIQUE.toString());
+
+ service.increaseFeedCounters(FeedType.AUTHOR_UNIQUE, infoDataDecoded,
+ request.getRemoteAddr());
+ } else if (FeedType.AUTHOR_ALL.toString().equals(infoTokens[0])) {
+ vc.put("author", infoDataDecoded);
+
+ // Getting the list of tags.
+ try {
tags = TagTools.getService().getTagsByAuthor(infoDataDecoded);
} catch (TagGetException e) {
throw new IOException(e.getMessage());
}
template = template.replace(Constants.TAG_FEED_TYPE_VARIABLE,
- FeedType.AUTHOR.toString());
+ FeedType.AUTHOR_ALL.toString());
- service.increaseFeedCount(FeedType.AUTHOR, infoDataDecoded);
+ service.increaseFeedCounters(FeedType.AUTHOR_ALL, infoDataDecoded,
+ request.getRemoteAddr());
+ } else if (FeedType.AUTHOR_TAG.toString().equals(infoTokens[0])) {
+ String[] tagData = infoDataDecoded.split("[+]");
+ if (tagData.length != 2) {
+ throw new IOException("Not enough data for a tag-author" +
+ " feed.");
+ }
+
+ vc.put("tagName", tagData[0]);
+ vc.put("author", tagData[1]);
+
+ // Getting the list of tags.
+ try {
+ tags = TagTools.getService().getTags(tagData[0], tagData[1]);
+ } catch (TagGetException e) {
+ throw new IOException(e.getMessage());
+ }
+
+ template = template.replace(Constants.TAG_FEED_TYPE_VARIABLE,
+ FeedType.AUTHOR_TAG.toString());
+
+ service.increaseFeedCounters(FeedType.AUTHOR_TAG, infoDataDecoded,
+ request.getRemoteAddr());
} else if (FeedType.TAGS.toString().equals(infoTokens[0])) {
String[] tagNames = infoDataDecoded.split("[+]");
@@ -125,7 +167,6 @@
try {
tags = service.getTags(Arrays.asList(tagNames));
} catch (TagGetException e) {
- e.printStackTrace();
throw new IOException(e.getMessage());
}
@@ -133,7 +174,8 @@
FeedType.TAGS.toString());
for (String tagName : tagNames) {
- service.increaseFeedCount(FeedType.TAGS, tagName);
+ service.increaseFeedCounters(FeedType.TAGS, tagName,
+ request.getRemoteAddr());
}
} else {
throw new IOException("Invalid tag feed request.");
@@ -155,16 +197,17 @@
}
}
- public void write(HttpServletResponse response, String fullName) throws IOException {
+ public void write(HttpServletResponse response, String fullName,
+ HttpServletRequest request) throws IOException {
response.setContentType(getContentType());
- write(response.getOutputStream(), fullName);
+ write(response.getOutputStream(), fullName, request);
}
- public void write(OutputStream os) throws IOException {
+ public void write(OutputStream os, HttpServletRequest request) throws IOException {
throw new IOException("Can't write a non-concrete tag feed");
}
- public void write(HttpServletResponse response) throws IOException {
+ public void write(HttpServletResponse response, HttpServletRequest request) throws IOException {
throw new IOException("Can't write a non-concrete tag feed");
}
Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/TagFeedTagHandler.java
===================================================================
--- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/TagFeedTagHandler.java 2006-07-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/TagFeedTagHandler.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -3,7 +3,6 @@
import org.apache.log4j.Logger;
import org.apache.velocity.VelocityContext;
import org.jboss.shotoku.feeds.FeedsDescriptor;
-import org.jboss.shotoku.feeds.tools.Constants;
import org.jboss.shotoku.feeds.FeedFactory;
import org.jboss.shotoku.feeds.data.SpecialFeed;
import org.jboss.shotoku.feeds.tools.FeedsTools;
@@ -12,7 +11,6 @@
import org.w3c.dom.Node;
import java.util.Map;
-import java.util.HashMap;
/**
* @author Adam Warski (adamw at aster.pl)
Modified: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/AbstractTag.java
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/AbstractTag.java 2006-07-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/AbstractTag.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -71,7 +71,11 @@
return false;
}
- public Integer getFeedCounter() {
- return TagTools.getService().getFeedCount(FeedType.TAGS, getName());
+ public Integer getFeedHits() {
+ return TagTools.getService().getFeedHits(FeedType.TAGS, getName());
}
+
+ public Integer getFeedVisits() {
+ return TagTools.getService().getFeedVisits(FeedType.TAGS, getName());
+ }
}
Added: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/DummyTag.java
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/DummyTag.java 2006-07-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/DummyTag.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -0,0 +1,17 @@
+package org.jboss.shotoku.tags;
+
+import java.util.Date;
+
+/**
+ * @author Adam Warski (adamw at aster.pl)
+ */
+public class DummyTag extends AbstractTag {
+ public DummyTag(String name, String author, String resourceId,
+ String data, Date dateCreated) {
+ super(name, author, resourceId, data, dateCreated);
+ }
+
+ public String getType() {
+ return "";
+ }
+}
Modified: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/Tag.java
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/Tag.java 2006-07-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/Tag.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -1,7 +1,5 @@
package org.jboss.shotoku.tags;
-import org.jboss.shotoku.tags.dal.TagEntity;
-
import java.util.Date;
/**
@@ -14,5 +12,6 @@
public String getData();
public String getType();
public Date getDateCreated();
- public Integer getFeedCounter();
+ public Integer getFeedHits();
+ public Integer getFeedVisits();
}
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-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/TagService.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -16,10 +16,63 @@
public void deleteTag(Tag t) throws TagDeleteException;
public Tag getTag(String tagName) throws TagGetException;
-
+
+ /**
+ * Gets all tags (that is, all tag name, author and resource ids
+ * combinations) associated with the given names.
+ * @param tagNames Names of the tags to get.
+ * @return A list of appropriate tags implementations.
+ * @throws TagGetException
+ */
public List<Tag> getTags(List<String> tagNames) throws TagGetException;
+
+ /**
+ * Gets all tags (that is, all tag name, author and resource ids
+ * combinations) associated with the given resource.
+ * @param resourceId Resouce id of the tags to get.
+ * @return A list of appropriate tags implementations.
+ * @throws TagGetException
+ */
public List<Tag> getTags(String resourceId) throws TagGetException;
+
+ /**
+ * Gets all tags (that is, all tag name, author and resource ids
+ * combinations) associated with the given author.
+ * @param author Author of the tags to get.
+ * @return A list of appropriate tags implementations.
+ * @throws TagGetException
+ */
public List<Tag> getTagsByAuthor(String author) 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.
+ * @return A list of DummyTag implementations with the resource id
+ * and data field empty.
+ * @throws TagGetException
+ */
+ public List<Tag> getUniqueTagsByAuthor(String author) throws TagGetException;
+
+ /**
+ * Gets all tags (that is, all tag name, author and resource ids
+ * combinations) associated with the given tag name and author.
+ * @param tagName Name of tags to get.
+ * @param author Author of tags to get.
+ * @return A list of appropriate tags implementations.
+ * @throws TagGetException
+ */
+ public List<Tag> getTags(String tagName, String author) throws TagGetException;
+
+ /**
+ * Gets unique tags (that is, all unique tag names)
+ * associated with the given resource Id.
+ * @param resourceId Resource id of the tags to get.
+ * @return A list of DummyTag implementations with the author and
+ * data field empty.
+ * @throws TagGetException
+ */
+ public List<Tag> getUniqueTags(String resourceId) throws TagGetException;
public List<Tag> getRelatedTags(List<Tag> relateTo) throws TagGetException;
/**
@@ -34,24 +87,26 @@
/**
* Gets a link to a tag feed.
* @param feedType Type of the tag feed - resource feed, author feed etc.
- * @param dataList Additinal multiple data. This will be encoded into a single string.
+ * @param dataList Additional multiple data. This will be encoded into
+ * a single string. For a author-tag feed, the first element should
+ * be the name of tag, the second - author's name.
* @param type Type of the feed - rss2, atom or rdf.
* @return A relative link to a feed with the given parameters.
*/
public String getFeedLink(FeedType feedType, List<String> dataList, String type);
-
+
/**Gets all the tag names.
* @return Tag list
* @throws TagGetException
*/
public List<String> getAllTagsNames() throws TagGetException;
-
+
/**Gets all the tags
* @return Tag list
* @throws TagGetException
*/
public List<Tag> getAllTags() throws TagGetException;
-
+
/**
* @param tag String query for tags
* @param author String query for authors
@@ -62,19 +117,31 @@
/**
* Gets count of number of times a feed of the given type and data
- * was opened. Data for feed types is: author name, resource id or
- * tag name.
+ * was opened. Data for feed types is: author name, resource id,
+ * tag name or tag name '+' author name.
* @param feedType Type of the feed to which the data corresponds to.
* @param data Data of the feed for which the counter is read.
* @return Number of times a given feed was opened.
*/
- public int getFeedCount(FeedType feedType, String data);
+ public int getFeedHits(FeedType feedType, String data);
/**
+ * Gets count of number of times a feed of the given type and data
+ * was opened by a unique IP address. Data for feed types is:
+ * author name, resource id tag name or tag name '+' author name.
+ * @param feedType Type of the feed to which the data corresponds to.
+ * @param data Data of the feed for which the counter is read.
+ * @return Number of times a given feed was opened by unique clients.
+ */
+ public int getFeedVisits(FeedType feedType, String data);
+
+ /**
* Increases the number of times a feed of the given type and data
* was opened.
* @param feedType Type of the feed for which to increase the counter.
* @param data Data of the feed for which to increase the counter.
+ * @param ipAddress IP address of the client that opened this feed.
*/
- public void increaseFeedCount(FeedType feedType, String data);
+ public void increaseFeedCounters(FeedType feedType, String data,
+ String ipAddress);
}
Deleted: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/CountersEntity.java
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/CountersEntity.java 2006-07-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/CountersEntity.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -1,49 +0,0 @@
-package org.jboss.shotoku.tags.dal;
-
-import javax.persistence.*;
-
-/**
- * @author Adam Warski (adamw at aster.pl)
- */
- at Entity
- at Table(name = "ShotokuTagsCounters")
-public class CountersEntity {
- private CountersIdEntity id;
- private int count;
-
- public CountersEntity() {
-
- }
-
- public CountersEntity(CountersIdEntity id, int count) {
- this.id = id;
- this.count = count;
- }
-
- @EmbeddedId
- public CountersIdEntity getId() {
- return id;
- }
-
- public void setId(CountersIdEntity id) {
- this.id = id;
- }
-
- @Transient
- public String getType() {
- return id.getType();
- }
-
- @Transient
- public String getData() {
- return id.getData();
- }
-
- public int getCount() {
- return count;
- }
-
- public void setCount(int count) {
- this.count = count;
- }
-}
Deleted: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/CountersIdEntity.java
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/CountersIdEntity.java 2006-07-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/CountersIdEntity.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -1,55 +0,0 @@
-package org.jboss.shotoku.tags.dal;
-
-import org.jboss.shotoku.tools.Tools;
-
-import javax.persistence.Embeddable;
-import javax.persistence.Column;
-import java.io.Serializable;
-
-/**
- * @author Adam Warski (adamw at aster.pl)
- */
- at Embeddable
-public class CountersIdEntity implements Serializable {
- private String data;
- private String type;
-
- public CountersIdEntity() {
-
- }
-
- public CountersIdEntity(String data, String type) {
- this.data = data;
- this.type = type;
- }
-
- public String getData() {
- return data;
- }
-
- public void setData(String data) {
- this.data = data;
- }
-
- @Column(length = 32)
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public int hashCode() {
- return (data == null ? 0 : data.hashCode()) +
- (type == null ? 0 : type.hashCode());
- }
-
- public boolean equals(Object obj) {
- if (obj == this) return true;
- if (!(obj instanceof CountersIdEntity)) return false;
- CountersIdEntity cie = (CountersIdEntity) obj;
- return Tools.objectsEqual(type, cie.type) &&
- Tools.objectsEqual(data, cie.data);
- }
-}
Copied: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/HitsEntity.java (from rev 5121, labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/CountersEntity.java)
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/CountersEntity.java 2006-07-17 12:29:02 UTC (rev 5121)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/HitsEntity.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -0,0 +1,49 @@
+package org.jboss.shotoku.tags.dal;
+
+import javax.persistence.*;
+
+/**
+ * @author Adam Warski (adamw at aster.pl)
+ */
+ at Entity
+ at Table(name = "ShotokuTagsHits")
+public class HitsEntity {
+ private HitsIdEntity id;
+ private int count;
+
+ public HitsEntity() {
+
+ }
+
+ public HitsEntity(HitsIdEntity id, int count) {
+ this.id = id;
+ this.count = count;
+ }
+
+ @EmbeddedId
+ public HitsIdEntity getId() {
+ return id;
+ }
+
+ public void setId(HitsIdEntity id) {
+ this.id = id;
+ }
+
+ @Transient
+ public String getType() {
+ return id.getType();
+ }
+
+ @Transient
+ public String getData() {
+ return id.getData();
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public void setCount(int count) {
+ this.count = count;
+ }
+}
Copied: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/HitsIdEntity.java (from rev 5121, labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/CountersIdEntity.java)
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/CountersIdEntity.java 2006-07-17 12:29:02 UTC (rev 5121)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/HitsIdEntity.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -0,0 +1,55 @@
+package org.jboss.shotoku.tags.dal;
+
+import org.jboss.shotoku.tools.Tools;
+
+import javax.persistence.Embeddable;
+import javax.persistence.Column;
+import java.io.Serializable;
+
+/**
+ * @author Adam Warski (adamw at aster.pl)
+ */
+ at Embeddable
+public class HitsIdEntity implements Serializable {
+ private String data;
+ private String type;
+
+ public HitsIdEntity() {
+
+ }
+
+ public HitsIdEntity(String data, String type) {
+ this.data = data;
+ this.type = type;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ @Column(length = 32)
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public int hashCode() {
+ return (data == null ? 0 : data.hashCode()) +
+ (type == null ? 0 : type.hashCode());
+ }
+
+ public boolean equals(Object obj) {
+ if (obj == this) return true;
+ if (!(obj instanceof HitsIdEntity)) return false;
+ HitsIdEntity cie = (HitsIdEntity) obj;
+ return Tools.objectsEqual(type, cie.type) &&
+ Tools.objectsEqual(data, cie.data);
+ }
+}
Added: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/VisitsEntity.java
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/VisitsEntity.java 2006-07-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/VisitsEntity.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -0,0 +1,52 @@
+package org.jboss.shotoku.tags.dal;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Transient;
+
+/**
+ * @author Adam Warski (adamw at aster.pl)
+ */
+ at Entity
+ at Table(name = "ShotokuTagsVisits")
+public class VisitsEntity {
+ private VisitsIdEntity id;
+ private int count;
+
+ public VisitsEntity() {
+
+ }
+
+ public VisitsEntity(VisitsIdEntity id, int count) {
+ this.id = id;
+ this.count = count;
+ }
+
+ @EmbeddedId
+ public VisitsIdEntity getId() {
+ return id;
+ }
+
+ public void setId(VisitsIdEntity id) {
+ this.id = id;
+ }
+
+ @Transient
+ public String getType() {
+ return id.getType();
+ }
+
+ @Transient
+ public String getData() {
+ return id.getData();
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public void setCount(int count) {
+ this.count = count;
+ }
+}
Added: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/VisitsIdEntity.java
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/VisitsIdEntity.java 2006-07-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/VisitsIdEntity.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -0,0 +1,55 @@
+package org.jboss.shotoku.tags.dal;
+
+import org.jboss.shotoku.tools.Tools;
+
+import javax.persistence.Embeddable;
+import javax.persistence.Column;
+import java.io.Serializable;
+
+/**
+ * @author Adam Warski (adamw at aster.pl)
+ */
+ at Embeddable
+public class VisitsIdEntity implements Serializable {
+ private String data;
+ private String type;
+
+ public VisitsIdEntity() {
+
+ }
+
+ public VisitsIdEntity(String data, String type) {
+ this.data = data;
+ this.type = type;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ @Column(length = 32)
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public int hashCode() {
+ return (data == null ? 0 : data.hashCode()) +
+ (type == null ? 0 : type.hashCode());
+ }
+
+ public boolean equals(Object obj) {
+ if (obj == this) return true;
+ if (!(obj instanceof VisitsIdEntity)) return false;
+ VisitsIdEntity cie = (VisitsIdEntity) obj;
+ return Tools.objectsEqual(type, cie.type) &&
+ Tools.objectsEqual(data, cie.data);
+ }
+}
Added: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/VisitsIpsEntity.java
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/VisitsIpsEntity.java 2006-07-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/VisitsIpsEntity.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -0,0 +1,48 @@
+package org.jboss.shotoku.tags.dal;
+
+import javax.persistence.*;
+
+/**
+ * @author Adam Warski (adamw at aster.pl)
+ */
+ at Entity
+ at Table(name = "ShotokuTagsVisitsIps")
+public class VisitsIpsEntity {
+ private VisitsIpsIdEntity viie;
+
+ public VisitsIpsEntity(VisitsIpsIdEntity viie) {
+ this.viie = viie;
+ }
+
+ public VisitsIpsEntity(String data, String type, String ip) {
+ this(new VisitsIpsIdEntity(data, type, ip));
+ }
+
+ public VisitsIpsEntity() {
+
+ }
+
+ @EmbeddedId
+ public VisitsIpsIdEntity getViie() {
+ return viie;
+ }
+
+ public void setViie(VisitsIpsIdEntity viie) {
+ this.viie = viie;
+ }
+
+ @Transient
+ public String getData() {
+ return viie.getData();
+ }
+
+ @Transient
+ public String getType() {
+ return viie.getType();
+ }
+
+ @Transient
+ public String getIp() {
+ return viie.getIp();
+ }
+}
Added: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/VisitsIpsIdEntity.java
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/VisitsIpsIdEntity.java 2006-07-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/VisitsIpsIdEntity.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -0,0 +1,67 @@
+package org.jboss.shotoku.tags.dal;
+
+import org.jboss.shotoku.tools.Tools;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+/**
+ * @author Adam Warski (adamw at aster.pl)
+ */
+ at Embeddable
+public class VisitsIpsIdEntity implements Serializable {
+ private String data;
+ private String type;
+ private String ip;
+
+ public VisitsIpsIdEntity(String data, String type, String ip) {
+ this.data = data;
+ this.type = type;
+ this.ip = ip;
+ }
+
+ public VisitsIpsIdEntity() {
+
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ @Column(length = 32)
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ @Column(length=15)
+ public String getIp() {
+ return ip;
+ }
+
+ public void setIp(String ip) {
+ this.ip = ip;
+ }
+
+ public int hashCode() {
+ return (data == null ? 0 : data.hashCode()) +
+ (type == null ? 0 : type.hashCode()) +
+ (ip == null ? 0 : ip.hashCode());
+ }
+
+ public boolean equals(Object obj) {
+ if (obj == this) return true;
+ if (!(obj instanceof VisitsIpsIdEntity)) return false;
+ VisitsIpsIdEntity viie = (VisitsIpsIdEntity) obj;
+ return Tools.objectsEqual(type, viie.type) &&
+ Tools.objectsEqual(data, viie.data) &&
+ Tools.objectsEqual(ip, viie.ip);
+ }
+}
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-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -43,9 +43,7 @@
import org.jboss.shotoku.tags.exceptions.TagGetException;
import org.jboss.shotoku.tags.exceptions.TagAddException;
import org.jboss.shotoku.tags.exceptions.TagDeleteException;
-import org.jboss.shotoku.tags.dal.TagEntity;
-import org.jboss.shotoku.tags.dal.CountersIdEntity;
-import org.jboss.shotoku.tags.dal.CountersEntity;
+import org.jboss.shotoku.tags.dal.*;
import org.jboss.shotoku.ContentManager;
import org.jboss.shotoku.Resource;
import org.jboss.shotoku.Node;
@@ -399,6 +397,90 @@
}
}
+ public List<Tag> getUniqueTagsByAuthor(String author)
+ throws TagGetException {
+ try {
+ // noinspection unchecked
+ List<Object[]> result = manager
+ .createQuery(
+ "SELECT name, min(dateCreated) FROM TagEntity " +
+ "WHERE author = :author " +
+ "GROUP BY name") //+
+ //"ORDER BY mdc DESC")
+ .setParameter("author", author).getResultList();
+
+ List<Tag> ret = new ArrayList<Tag>();
+ for (Object[] o : result) {
+ ret.add(new DummyTag((String) o[0], author, null,
+ null, (Date) o[1]));
+ }
+
+ Collections.sort(ret, new Comparator<Tag>() {
+ public int compare(Tag o1, Tag o2) {
+ return o1.getDateCreated().compareTo(o2.getDateCreated());
+ }
+ });
+
+ return ret;
+ } catch (Throwable e) {
+ throw new TagGetException(e);
+ }
+ }
+
+ public List<Tag> getTags(String name, String author)
+ throws TagGetException {
+ try {
+ // noinspection unchecked
+ List<TagEntity> result = (List<TagEntity>) manager.createQuery(
+ "FROM TagEntity WHERE name = :name AND " +
+ "author = :author").setParameter("name", name).
+ setParameter("author", author).getResultList();
+
+ if (result == null) {
+ return null;
+ }
+
+ List<Tag> ret = new ArrayList<Tag>();
+ for (TagEntity te : result) {
+ ret.add(te.getTag());
+ }
+
+ return ret;
+ } catch (Throwable e) {
+ throw new TagGetException(e);
+ }
+ }
+
+ public List<Tag> getUniqueTags(String resourceId)
+ throws TagGetException {
+ try {
+ // noinspection unchecked
+ List<Object[]> result = manager
+ .createQuery(
+ "SELECT name, min(dateCreated) FROM TagEntity " +
+ "WHERE resourceId = :resourceId " +
+ "GROUP BY name") // +
+ //"ORDER BY min(dateCreated) DESC")
+ .setParameter("resourceId", resourceId).getResultList();
+
+ List<Tag> ret = new ArrayList<Tag>();
+ for (Object[] o : result) {
+ ret.add(new DummyTag((String) o[0], null, resourceId,
+ null, (Date) o[1]));
+ }
+
+ Collections.sort(ret, new Comparator<Tag>() {
+ public int compare(Tag o1, Tag o2) {
+ return o1.getDateCreated().compareTo(o2.getDateCreated());
+ }
+ });
+
+ return ret;
+ } catch (Throwable e) {
+ throw new TagGetException(e);
+ }
+ }
+
public String getFeedLink(FeedType feedType, String data, String type) {
try {
return "/feeds/tag/" + feedType.toString() + "/"
@@ -468,23 +550,59 @@
return searchResult;
}
- public int getFeedCount(FeedType feedType, String data) {
- CountersEntity ce = manager.find(CountersEntity.class,
- new CountersIdEntity(data, feedType.toString()));
+ public int getFeedHits(FeedType feedType, String data) {
+ HitsEntity ce = manager.find(HitsEntity.class,
+ new HitsIdEntity(data, feedType.toString()));
return ce == null ? 0 : ce.getCount();
}
- public void increaseFeedCount(FeedType feedType, String data) {
- CountersEntity ce = manager.find(CountersEntity.class,
- new CountersIdEntity(data, feedType.toString()));
+ public int getFeedVisits(FeedType feedType, String data) {
+ HitsEntity ce = manager.find(HitsEntity.class,
+ new HitsIdEntity(data, feedType.toString()));
+ return ce == null ? 0 : ce.getCount();
+ }
+
+ public void increaseFeedCounters(FeedType feedType, String data,
+ String ipAddress) {
+ // 1. Increasing the hit counter.
+ HitsEntity ce = manager.find(HitsEntity.class,
+ new HitsIdEntity(data, feedType.toString()));
+
if (ce == null) {
- manager.persist(new CountersEntity(
- new CountersIdEntity(data, feedType.toString()), 1));
+ manager.persist(new HitsEntity(
+ new HitsIdEntity(data, feedType.toString()), 1));
} else {
ce.setCount(ce.getCount()+1);
manager.flush();
}
+
+ // 2. Increasing the visits counter.
+ VisitsIpsEntity dbVie = manager.find(VisitsIpsEntity.class,
+ new VisitsIpsIdEntity(data, feedType.toString(), ipAddress));
+
+ if (dbVie == null) {
+ // Storing the new ip address.
+ try {
+ manager.persist(new VisitsIpsEntity(data,
+ feedType.toString(), ipAddress));
+ } catch (Exception e) {
+ // Somebody must have already added it.
+ return;
+ }
+
+ // Increasing the counter.
+ VisitsEntity ve = manager.find(VisitsEntity.class,
+ new VisitsIdEntity(data, feedType.toString()));
+
+ if (ve == null) {
+ manager.persist(new VisitsEntity(
+ new VisitsIdEntity(data, feedType.toString()), 1));
+ } else {
+ ve.setCount(ve.getCount()+1);
+ manager.flush();
+ }
+ }
}
}
Modified: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/test/TagsTestServlet.java
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/test/TagsTestServlet.java 2006-07-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/test/TagsTestServlet.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -13,16 +13,30 @@
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.Calendar;
+import java.util.List;
+import java.util.ArrayList;
/**
* @author Adam Warski (adamw at aster.pl)
*/
public class TagsTestServlet extends HttpServlet {
-
static int i = 2;
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
httpServletResponse.setContentType("text/html");
+
+ List<String> params = new ArrayList<String>();
+ params.add("adamw");
+ params.add("default/members/default/freezone/welcome.html");
+ httpServletResponse.getWriter().println(
+ TagTools.getService().getFeedLink(FeedType.AUTHOR_TAG,
+ params, "rss2"));
+ httpServletResponse.getWriter().println("<br />");
+ httpServletResponse.getWriter().println(
+ TagTools.getService().getFeedLink(FeedType.RESOURCE,
+ "default/members/default/freezone/welcome.html",
+ "rss2"));
+
/*httpServletResponse.getWriter().println(TagTools.getService().getServiceName());
try {
@@ -40,10 +54,16 @@
e.printStackTrace();
} */
+ /*httpServletResponse.getWriter().println(
+ TagTools.getService().getFeedCount(FeedType.AUTHOR_ALL, "adamw"));
+ TagTools.getService().increaseFeedCount(FeedType.AUTHOR_ALL, "adamw");
httpServletResponse.getWriter().println(
- TagTools.getService().getFeedCount(FeedType.AUTHOR, "adamw"));
- TagTools.getService().increaseFeedCount(FeedType.AUTHOR, "adamw");
- httpServletResponse.getWriter().println(
- TagTools.getService().getFeedCount(FeedType.AUTHOR, "adamw"));
+ TagTools.getService().getFeedCount(FeedType.AUTHOR_ALL, "adamw"));*/
+
+ /*try {
+ TagTools.getService().getUniqueTagsByAuthor("adamw");
+ } catch (TagGetException e) {
+ throw new ServletException(e);
+ }*/
}
}
Modified: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/tools/FeedType.java
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/tools/FeedType.java 2006-07-17 20:18:53 UTC (rev 5122)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/tools/FeedType.java 2006-07-17 21:27:10 UTC (rev 5123)
@@ -4,8 +4,22 @@
* @author Adam Warski (adamw at aster.pl)
*/
public enum FeedType {
+ /**
+ * A feed of unique tags (unique tag names) on a given resource.
+ */
RESOURCE("resource"),
- AUTHOR("author"),
+ /**
+ * A feed of all tags with a given author.
+ */
+ AUTHOR_ALL("author"),
+ /**
+ * A feed of unique tags (unique tag names) with a given author.
+ */
+ AUTHOR_UNIQUE("author_tags"),
+ /**
+ * A feed of all tags with a given name and author.
+ */
+ AUTHOR_TAG("author_res"),
TAGS("tags");
private String strRep;
More information about the jboss-svn-commits
mailing list