[kune-commits] r1050 - in trunk: .
src/main/java/org/ourproject/kune/platf/server
src/main/java/org/ourproject/kune/platf/server/content
src/main/java/org/ourproject/kune/platf/server/domain
src/main/java/org/ourproject/kune/platf/server/manager
src/main/java/org/ourproject/kune/platf/server/manager/impl
src/main/java/org/ourproject/kune/platf/server/rpc
src/main/java/org/ourproject/kune/platf/server/state
src/main/java/org/ourproject/kune/workspace/client/options
src/test/java/org/ourproject/kune/platf/server
src/test/java/org/ourproject/kune/platf/server/finders
src/test/java/org/ourproject/kune/platf/server/manager
vjrj
vjrj at ourproject.org
Fri Feb 20 14:41:19 CET 2009
Author: vjrj
Date: 2009-02-20 14:41:17 +0100 (Fri, 20 Feb 2009)
New Revision: 1050
Added:
trunk/src/main/java/org/ourproject/kune/platf/server/domain/TagUserContent.java
trunk/src/main/java/org/ourproject/kune/platf/server/manager/TagUserContentManager.java
trunk/src/main/java/org/ourproject/kune/platf/server/manager/TagUserContentManagerDefault.java
trunk/src/test/java/org/ourproject/kune/platf/server/PersistencePreLoadedDataTest.java
trunk/src/test/java/org/ourproject/kune/platf/server/manager/TagUserContentTest.java
Modified:
trunk/TODO
trunk/src/main/java/org/ourproject/kune/platf/server/PlatformServerModule.java
trunk/src/main/java/org/ourproject/kune/platf/server/content/ContainerManager.java
trunk/src/main/java/org/ourproject/kune/platf/server/content/ContentManagerDefault.java
trunk/src/main/java/org/ourproject/kune/platf/server/domain/Content.java
trunk/src/main/java/org/ourproject/kune/platf/server/domain/Tag.java
trunk/src/main/java/org/ourproject/kune/platf/server/manager/TagManager.java
trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/TagManagerDefault.java
trunk/src/main/java/org/ourproject/kune/platf/server/rpc/ContentRPC.java
trunk/src/main/java/org/ourproject/kune/platf/server/state/StateServiceDefault.java
trunk/src/main/java/org/ourproject/kune/workspace/client/options/AbstractOptionsPanel.java
trunk/src/test/java/org/ourproject/kune/platf/server/PersistenceTest.java
trunk/src/test/java/org/ourproject/kune/platf/server/finders/RateFinderTest.java
trunk/src/test/java/org/ourproject/kune/platf/server/finders/UserFinderTest.java
trunk/src/test/java/org/ourproject/kune/platf/server/manager/ContentManagerTest.java
trunk/src/test/java/org/ourproject/kune/platf/server/manager/GroupManagerTest.java
trunk/src/test/java/org/ourproject/kune/platf/server/manager/UserManagerTest.java
Log:
Complete - task Tags refactorization (Samer recomendations)
Modified: trunk/TODO
===================================================================
--- trunk/TODO 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/TODO 2009-02-20 13:41:17 UTC (rev 1050)
@@ -464,3 +464,4 @@
http://toolserver.org/~merphant/wiki2html/
* IDEAS
** <d> Try to find a way dozer maps directly without use getters/setters (less js code and better performance)
+
Modified: trunk/src/main/java/org/ourproject/kune/platf/server/PlatformServerModule.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/PlatformServerModule.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/PlatformServerModule.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -60,6 +60,8 @@
import org.ourproject.kune.platf.server.manager.RateManager;
import org.ourproject.kune.platf.server.manager.SocialNetworkManager;
import org.ourproject.kune.platf.server.manager.TagManager;
+import org.ourproject.kune.platf.server.manager.TagUserContentManager;
+import org.ourproject.kune.platf.server.manager.TagUserContentManagerDefault;
import org.ourproject.kune.platf.server.manager.ToolConfigurationManager;
import org.ourproject.kune.platf.server.manager.UserManager;
import org.ourproject.kune.platf.server.manager.file.EntityLogoDownloadManager;
@@ -135,6 +137,7 @@
bind(I18nLanguageManager.class).to(I18nLanguageManagerDefault.class);
bind(I18nTranslationManager.class).to(I18nTranslationManagerDefault.class);
bind(TagManager.class).to(TagManagerDefault.class);
+ bind(TagUserContentManager.class).to(TagUserContentManagerDefault.class);
bind(CommentManager.class).to(CommentManagerDefault.class);
bind(FileManager.class).to(FileManagerDefault.class);
}
Modified: trunk/src/main/java/org/ourproject/kune/platf/server/content/ContainerManager.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/content/ContainerManager.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/content/ContainerManager.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -24,9 +24,10 @@
import org.ourproject.kune.platf.server.domain.Container;
import org.ourproject.kune.platf.server.domain.Group;
import org.ourproject.kune.platf.server.domain.I18nLanguage;
+import org.ourproject.kune.platf.server.manager.Manager;
import org.ourproject.kune.platf.server.manager.impl.SearchResult;
-public interface ContainerManager {
+public interface ContainerManager extends Manager<Container, Long> {
Container createFolder(Group group, Container parent, String name, I18nLanguage language, String typeId);
Modified: trunk/src/main/java/org/ourproject/kune/platf/server/content/ContentManagerDefault.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/content/ContentManagerDefault.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/content/ContentManagerDefault.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -19,11 +19,9 @@
*/
package org.ourproject.kune.platf.server.content;
-import java.util.ArrayList;
import java.util.Date;
import javax.persistence.EntityManager;
-import javax.persistence.NoResultException;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.queryParser.MultiFieldQueryParser;
@@ -33,7 +31,6 @@
import org.ourproject.kune.platf.client.errors.I18nNotFoundException;
import org.ourproject.kune.platf.client.errors.NameInUseException;
import org.ourproject.kune.platf.client.errors.UserNotFoundException;
-import org.ourproject.kune.platf.client.ui.TextUtils;
import org.ourproject.kune.platf.server.access.FinderService;
import org.ourproject.kune.platf.server.domain.Container;
import org.ourproject.kune.platf.server.domain.Content;
@@ -42,9 +39,8 @@
import org.ourproject.kune.platf.server.domain.Rate;
import org.ourproject.kune.platf.server.domain.RateResult;
import org.ourproject.kune.platf.server.domain.Revision;
-import org.ourproject.kune.platf.server.domain.Tag;
import org.ourproject.kune.platf.server.domain.User;
-import org.ourproject.kune.platf.server.manager.TagManager;
+import org.ourproject.kune.platf.server.manager.TagUserContentManager;
import org.ourproject.kune.platf.server.manager.file.FileUtils;
import org.ourproject.kune.platf.server.manager.impl.DefaultManager;
import org.ourproject.kune.platf.server.manager.impl.SearchResult;
@@ -60,17 +56,19 @@
private final FinderService finder;
private final User userFinder;
private final I18nLanguage languageFinder;
- private final TagManager tagManager;
private final Content contentFinder;
private final Container containerFinder;
+ private final TagUserContentManager tagManager;
+ private final Provider<EntityManager> provider;
@Inject
public ContentManagerDefault(final Content contentFinder, final Container containerFinder,
final Provider<EntityManager> provider, final FinderService finder, final User userFinder,
- final I18nLanguage languageFinder, final TagManager tagManager) {
+ final I18nLanguage languageFinder, final TagUserContentManager tagManager) {
super(provider, Content.class);
this.contentFinder = contentFinder;
this.containerFinder = containerFinder;
+ this.provider = provider;
this.finder = finder;
this.userFinder = userFinder;
this.languageFinder = languageFinder;
@@ -223,21 +221,7 @@
public void setTags(final User user, final Long contentId, final String tags) throws DefaultException {
final Content content = finder.getContent(contentId);
- final ArrayList<String> tagsStripped = TextUtils.splitTags(tags);
- final ArrayList<Tag> tagList = new ArrayList<Tag>();
- for (String tagString : tagsStripped) {
- Tag tag;
- try {
- tag = tagManager.findByTagName(tagString);
- } catch (final NoResultException e) {
- tag = new Tag(tagString);
- tagManager.persist(tag);
- }
- if (!tagList.contains(tag)) {
- tagList.add(tag);
- }
- }
- content.setTags(tagList);
+ tagManager.setTags(user, content, tags);
}
private String findInexistentTitle(Container container, String title) {
Modified: trunk/src/main/java/org/ourproject/kune/platf/server/domain/Content.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/domain/Content.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/domain/Content.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -22,7 +22,6 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -43,7 +42,6 @@
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
-import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;
@@ -74,11 +72,6 @@
@Version
private int version;
- @OrderBy("name DESC")
- @IndexedEmbedded
- @ManyToMany(cascade = { CascadeType.MERGE, CascadeType.PERSIST })
- private List<Tag> tags;
-
@OneToOne
private License license;
@@ -136,7 +129,6 @@
public Content() {
translations = new ArrayList<ContentTranslation>();
authors = new ArrayList<User>();
- tags = new ArrayList<Tag>();
comments = new HashSet<Comment>();
this.createdOn = System.currentTimeMillis();
this.lastRevision = new Revision(this);
@@ -242,22 +234,6 @@
return status;
}
- public List<Tag> getTags() {
- return tags;
- }
-
- public String getTagsAsString() {
- String tagConcatenated = "";
- for (final Iterator<Tag> iterator = tags.iterator(); iterator.hasNext();) {
- final Tag tag = iterator.next();
- tagConcatenated = tagConcatenated + tag.getName();
- if (iterator.hasNext()) {
- tagConcatenated = tagConcatenated + " ";
- }
- }
- return tagConcatenated;
- }
-
public String getTitle() {
return lastRevision.getTitle();
}
@@ -339,10 +315,6 @@
this.status = status;
}
- public void setTags(final List<Tag> tags) {
- this.tags = tags;
- }
-
public void setTranslations(final List<ContentTranslation> translations) {
this.translations = translations;
}
Modified: trunk/src/main/java/org/ourproject/kune/platf/server/domain/Tag.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/domain/Tag.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/domain/Tag.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -23,8 +23,6 @@
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
import javax.persistence.Table;
import org.hibernate.search.annotations.DocumentId;
@@ -39,17 +37,7 @@
@Entity
@Indexed
@Table(name = "tags")
-// See:
-// http://openjpa.apache.org/docs/latest/manual/manual.html#jpa_langref_resulttype
- at NamedQueries( {
- @NamedQuery(name = "tagsgrouped", query = "SELECT NEW org.ourproject.kune.platf.server.domain.TagCount(t.name, COUNT(c.id)) "
- + "FROM Content c JOIN c.tags t WHERE c.container.owner = :group " + "GROUP BY t.name ORDER BY t.name"),
- @NamedQuery(name = "tagsmaxgrouped", query = "SELECT Count(c.id) FROM Content c JOIN c.tags t WHERE c.container.owner = :group GROUP BY t.name ORDER BY count(*) DESC LIMIT 0,1"),
- @NamedQuery(name = "tagsmingrouped", query = "SELECT Count(c.id) FROM Content c JOIN c.tags t WHERE c.container.owner = :group GROUP BY t.name ORDER BY count(*) ASC LIMIT 0,1") })
public class Tag implements HasId {
- public static final String TAGSGROUPED = "tagsgrouped";
- public static final String TAGSMINGROUPED = "tagsmingrouped";
- public static final String TAGSMAXGROUPED = "tagsmaxgrouped";
@Id
@GeneratedValue
Added: trunk/src/main/java/org/ourproject/kune/platf/server/domain/TagUserContent.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/domain/TagUserContent.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/domain/TagUserContent.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -0,0 +1,109 @@
+package org.ourproject.kune.platf.server.domain;
+
+import java.util.List;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.IndexedEmbedded;
+import org.hibernate.validator.NotNull;
+
+import com.google.inject.name.Named;
+import com.wideplay.warp.persist.dao.Finder;
+
+//See:
+//http://openjpa.apache.org/docs/latest/manual/manual.html#jpa_langref_resulttype
+ at NamedQueries( {
+ @NamedQuery(name = "tagsgrouped", query = "SELECT NEW org.ourproject.kune.platf.server.domain.TagCount(t.name, COUNT(tuc.content.id)) "
+ + "FROM TagUserContent tuc JOIN tuc.tag t WHERE tuc.content.container.owner = :group "
+ + "GROUP BY t.name ORDER BY t.name"),
+ @NamedQuery(name = "tagsmaxgrouped", query = "SELECT Count(tuc.content.id) FROM TagUserContent tuc JOIN tuc.tag t WHERE tuc.content.container.owner = :group GROUP BY t.name ORDER BY count(*) DESC LIMIT 0,1"),
+ @NamedQuery(name = "tagsmingrouped", query = "SELECT Count(tuc.content.id) FROM TagUserContent tuc JOIN tuc.tag t WHERE tuc.content.container.owner = :group GROUP BY t.name ORDER BY count(*) ASC LIMIT 0,1") })
+ at Entity
+ at Indexed
+ at Table(name = "tag_user_content")
+public class TagUserContent implements HasId {
+ public static final String TAGSGROUPED = "tagsgrouped";
+ public static final String TAGSMINGROUPED = "tagsmingrouped";
+ public static final String TAGSMAXGROUPED = "tagsmaxgrouped";
+
+ @Id
+ @GeneratedValue
+ @DocumentId
+ private Long id;
+
+ @IndexedEmbedded
+ @NotNull
+ @ManyToOne(fetch = FetchType.LAZY)
+ private Tag tag;
+
+ @IndexedEmbedded
+ @NotNull
+ @ManyToOne(fetch = FetchType.LAZY)
+ private Content content;
+
+ @IndexedEmbedded
+ @NotNull
+ @ManyToOne(fetch = FetchType.LAZY)
+ private User user;
+
+ public TagUserContent() {
+ this(null, null, null);
+ }
+
+ public TagUserContent(Tag tag, User user, Content content) {
+ this.tag = tag;
+ this.user = user;
+ this.content = content;
+ }
+
+ @Finder(query = "FROM TagUserContent t WHERE t.user = :user AND t.content = :content")
+ public List<TagUserContent> find(@Named("user") final User user, @Named("content") final Content content) {
+ return null;
+ }
+
+ @Finder(query = "SELECT t.tag FROM TagUserContent t WHERE t.user = :user AND t.content = :content")
+ public List<Tag> findTags(@Named("user") final User user, @Named("content") final Content content) {
+ return null;
+ }
+
+ public Content getContent() {
+ return content;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public Tag getTag() {
+ return tag;
+ }
+
+ public User getUser() {
+ return user;
+ }
+
+ public void setContent(Content content) {
+ this.content = content;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public void setTag(Tag tag) {
+ this.tag = tag;
+ }
+
+ public void setUser(User user) {
+ this.user = user;
+ }
+}
Modified: trunk/src/main/java/org/ourproject/kune/platf/server/manager/TagManager.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/manager/TagManager.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/manager/TagManager.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -19,14 +19,10 @@
*/
package org.ourproject.kune.platf.server.manager;
-import org.ourproject.kune.platf.server.domain.Group;
import org.ourproject.kune.platf.server.domain.Tag;
-import org.ourproject.kune.platf.server.domain.TagCloudResult;
public interface TagManager extends Manager<Tag, Long> {
Tag findByTagName(String tag);
- TagCloudResult getTagCloudResultByGroup(Group group);
-
}
Added: trunk/src/main/java/org/ourproject/kune/platf/server/manager/TagUserContentManager.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/manager/TagUserContentManager.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/manager/TagUserContentManager.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -0,0 +1,24 @@
+package org.ourproject.kune.platf.server.manager;
+
+import java.util.List;
+
+import org.ourproject.kune.platf.server.domain.Content;
+import org.ourproject.kune.platf.server.domain.Group;
+import org.ourproject.kune.platf.server.domain.Tag;
+import org.ourproject.kune.platf.server.domain.TagCloudResult;
+import org.ourproject.kune.platf.server.domain.TagUserContent;
+import org.ourproject.kune.platf.server.domain.User;
+
+public interface TagUserContentManager extends Manager<TagUserContent, Long> {
+
+ List<Tag> find(User user, Content content);
+
+ TagCloudResult getTagCloudResultByGroup(Group group);
+
+ String getTagsAsString(User user, Content content);
+
+ void remove(User user, Content content);
+
+ void setTags(User user, Content content, String tags);
+
+}
Added: trunk/src/main/java/org/ourproject/kune/platf/server/manager/TagUserContentManagerDefault.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/manager/TagUserContentManagerDefault.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/manager/TagUserContentManagerDefault.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -0,0 +1,110 @@
+package org.ourproject.kune.platf.server.manager;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
+import javax.persistence.Query;
+
+import org.ourproject.kune.platf.client.ui.TextUtils;
+import org.ourproject.kune.platf.server.domain.Content;
+import org.ourproject.kune.platf.server.domain.Group;
+import org.ourproject.kune.platf.server.domain.Tag;
+import org.ourproject.kune.platf.server.domain.TagCloudResult;
+import org.ourproject.kune.platf.server.domain.TagCount;
+import org.ourproject.kune.platf.server.domain.TagUserContent;
+import org.ourproject.kune.platf.server.domain.User;
+import org.ourproject.kune.platf.server.manager.impl.DefaultManager;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+
+ at Singleton
+public class TagUserContentManagerDefault extends DefaultManager<TagUserContent, Long> implements TagUserContentManager {
+ private final Provider<EntityManager> provider;
+ private final TagManager tagManager;
+ private final TagUserContent finder;
+
+ @Inject
+ public TagUserContentManagerDefault(Provider<EntityManager> provider, TagManager tagManager, TagUserContent finder) {
+ super(provider, TagUserContent.class);
+ this.provider = provider;
+ this.tagManager = tagManager;
+ this.finder = finder;
+ }
+
+ public List<Tag> find(User user, Content content) {
+ return finder.findTags(user, content);
+ }
+
+ public TagCloudResult getTagCloudResultByGroup(Group group) {
+ return new TagCloudResult(getSummaryByGroup(group), getMaxCount(group), getMinCount(group));
+ }
+
+ public String getTagsAsString(User user, Content content) {
+ String tagConcatenated = "";
+ if (user.getId() != null) {
+ // FIXME: User must be persisted (this fails on tests)
+ List<Tag> tags = find(user, content);
+ for (Tag tag : tags) {
+ tagConcatenated += " " + tag.getName();
+ }
+ }
+ return tagConcatenated.replaceFirst(" ", "");
+ }
+
+ public void remove(User user, Content content) {
+ for (TagUserContent item : finder.find(user, content)) {
+ provider.get().remove(item);
+ }
+ }
+
+ public void setTags(User user, Content content, String tags) {
+ final ArrayList<String> tagsStripped = TextUtils.splitTags(tags);
+ final ArrayList<Tag> tagList = new ArrayList<Tag>();
+
+ for (String tagString : tagsStripped) {
+ Tag tag;
+ try {
+ tag = tagManager.findByTagName(tagString);
+ } catch (final NoResultException e) {
+ tag = new Tag(tagString);
+ tagManager.persist(tag);
+ }
+ if (!tagList.contains(tag)) {
+ tagList.add(tag);
+ }
+ }
+ remove(user, content);
+ for (Tag tag : tagList) {
+ TagUserContent tagUserContent = new TagUserContent(tag, user, content);
+ persist(tagUserContent);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private int getMaxCount(Group group) {
+ Query q = provider.get().createNamedQuery(TagUserContent.TAGSMAXGROUPED);
+ q.setParameter("group", group);
+ List resultList = q.getResultList();
+ return (resultList.size() == 0 ? 0 : ((Long) resultList.get(0)).intValue());
+ }
+
+ @SuppressWarnings("unchecked")
+ private int getMinCount(Group group) {
+ Query q = provider.get().createNamedQuery(TagUserContent.TAGSMINGROUPED);
+ q.setParameter("group", group);
+ List resultList = q.getResultList();
+ return (resultList.size() == 0 ? 0 : ((Long) resultList.get(0)).intValue());
+ }
+
+ @SuppressWarnings("unchecked")
+ private List<TagCount> getSummaryByGroup(final Group group) {
+ Query q = provider.get().createNamedQuery(TagUserContent.TAGSGROUPED);
+ q.setParameter("group", group);
+ List<TagCount> results = q.getResultList();
+ return results;
+ }
+}
Modified: trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/TagManagerDefault.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/TagManagerDefault.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/TagManagerDefault.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -19,15 +19,9 @@
*/
package org.ourproject.kune.platf.server.manager.impl;
-import java.util.List;
-
import javax.persistence.EntityManager;
-import javax.persistence.Query;
-import org.ourproject.kune.platf.server.domain.Group;
import org.ourproject.kune.platf.server.domain.Tag;
-import org.ourproject.kune.platf.server.domain.TagCloudResult;
-import org.ourproject.kune.platf.server.domain.TagCount;
import org.ourproject.kune.platf.server.manager.TagManager;
import com.google.inject.Inject;
@@ -38,44 +32,14 @@
public class TagManagerDefault extends DefaultManager<Tag, Long> implements TagManager {
private final Tag tagFinder;
- private final Provider<EntityManager> provider;
@Inject
public TagManagerDefault(final Provider<EntityManager> provider, final Tag tagFinder) {
super(provider, Tag.class);
- this.provider = provider;
this.tagFinder = tagFinder;
}
public Tag findByTagName(final String tag) {
return tagFinder.findByTagName(tag);
}
-
- public TagCloudResult getTagCloudResultByGroup(Group group) {
- return new TagCloudResult(getSummaryByGroup(group), getMaxCount(group), getMinCount(group));
- }
-
- @SuppressWarnings("unchecked")
- private int getMaxCount(Group group) {
- Query q = provider.get().createNamedQuery(Tag.TAGSMAXGROUPED);
- q.setParameter("group", group);
- List resultList = q.getResultList();
- return (resultList.size() == 0 ? 0 : ((Long) resultList.get(0)).intValue());
- }
-
- @SuppressWarnings("unchecked")
- private int getMinCount(Group group) {
- Query q = provider.get().createNamedQuery(Tag.TAGSMINGROUPED);
- q.setParameter("group", group);
- List resultList = q.getResultList();
- return (resultList.size() == 0 ? 0 : ((Long) resultList.get(0)).intValue());
- }
-
- @SuppressWarnings("unchecked")
- private List<TagCount> getSummaryByGroup(final Group group) {
- Query q = provider.get().createNamedQuery(Tag.TAGSGROUPED);
- q.setParameter("group", group);
- List<TagCount> results = q.getResultList();
- return results;
- }
}
Modified: trunk/src/main/java/org/ourproject/kune/platf/server/rpc/ContentRPC.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/rpc/ContentRPC.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/rpc/ContentRPC.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -69,7 +69,7 @@
import org.ourproject.kune.platf.server.domain.TagCloudResult;
import org.ourproject.kune.platf.server.domain.User;
import org.ourproject.kune.platf.server.manager.GroupManager;
-import org.ourproject.kune.platf.server.manager.TagManager;
+import org.ourproject.kune.platf.server.manager.TagUserContentManager;
import org.ourproject.kune.platf.server.mapper.Mapper;
import org.ourproject.kune.platf.server.state.StateContainer;
import org.ourproject.kune.platf.server.state.StateContent;
@@ -92,7 +92,7 @@
private final XmppManager xmppManager;
private final ContentManager contentManager;
private final ContainerManager containerManager;
- private final TagManager tagManager;
+ private final TagUserContentManager tagManager;
private final CommentManager commentManager;
private final AccessRightsService rightsService;
private final FinderService finderService;
@@ -102,8 +102,8 @@
final AccessService accessService, final AccessRightsService rightsService,
final StateService stateService, final CreationService creationService, final GroupManager groupManager,
final XmppManager xmppManager, final ContentManager contentManager,
- final ContainerManager containerManager, final TagManager tagManager, final CommentManager commentManager,
- final Mapper mapper) {
+ final ContainerManager containerManager, final TagUserContentManager tagManager,
+ final CommentManager commentManager, final Mapper mapper) {
this.finderService = finderService;
this.userSessionProvider = userSessionProvider;
this.accessService = accessService;
Modified: trunk/src/main/java/org/ourproject/kune/platf/server/state/StateServiceDefault.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/state/StateServiceDefault.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/state/StateServiceDefault.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -30,7 +30,7 @@
import org.ourproject.kune.platf.server.domain.User;
import org.ourproject.kune.platf.server.manager.GroupManager;
import org.ourproject.kune.platf.server.manager.SocialNetworkManager;
-import org.ourproject.kune.platf.server.manager.TagManager;
+import org.ourproject.kune.platf.server.manager.TagUserContentManager;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -41,13 +41,13 @@
private final AccessRightsService rightsService;
private final SocialNetworkManager socialNetworkManager;
private final GroupManager groupManager;
- private final TagManager tagManager;
+ private final TagUserContentManager tagManager;
private final ContentManager contentManager;
private final I18nTranslationService i18n;
@Inject
public StateServiceDefault(GroupManager groupManager, SocialNetworkManager socialNetworkManager,
- ContentManager contentManager, TagManager tagManager, AccessRightsService rightsService,
+ ContentManager contentManager, TagUserContentManager tagManager, AccessRightsService rightsService,
I18nTranslationService i18n) {
this.groupManager = groupManager;
this.socialNetworkManager = socialNetworkManager;
@@ -79,7 +79,7 @@
state.setLanguage(content.getLanguage());
state.setPublishedOn(content.getPublishedOn());
state.setAuthors(content.getAuthors());
- state.setTags(content.getTagsAsString());
+ state.setTags(tagManager.getTagsAsString(userLogged, content));
state.setStatus(content.getStatus());
state.setStateToken(content.getStateToken());
Revision revision = content.getLastRevision();
Modified: trunk/src/main/java/org/ourproject/kune/workspace/client/options/AbstractOptionsPanel.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/workspace/client/options/AbstractOptionsPanel.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/main/java/org/ourproject/kune/workspace/client/options/AbstractOptionsPanel.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -35,19 +35,19 @@
public abstract class AbstractOptionsPanel {
private BasicDialog dialog;
+ private final String dialogId;
+ private TabPanel tabPanel;
private MessageToolbar messageErrorBar;
- private TabPanel tabPanel;
private String title;
private final int width;
private final int height;
private final int minWidth;
private final int minHeight;
+ private final boolean modal;
private final Images images;
private final String errorLabelId;
private String iconCls;
- private final String dialogId;
private Listener0 onHideListener;
- private final boolean modal;
public AbstractOptionsPanel(String dialogId, String title, int width, int height, int minWidth, int minHeight,
boolean modal, Images images, String errorLabelId) {
Added: trunk/src/test/java/org/ourproject/kune/platf/server/PersistencePreLoadedDataTest.java
===================================================================
--- trunk/src/test/java/org/ourproject/kune/platf/server/PersistencePreLoadedDataTest.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/test/java/org/ourproject/kune/platf/server/PersistencePreLoadedDataTest.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -0,0 +1,97 @@
+package org.ourproject.kune.platf.server;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.TimeZone;
+
+import org.junit.After;
+import org.junit.Before;
+import org.ourproject.kune.docs.server.DocumentServerTool;
+import org.ourproject.kune.platf.server.content.ContainerManager;
+import org.ourproject.kune.platf.server.content.ContentManager;
+import org.ourproject.kune.platf.server.domain.Container;
+import org.ourproject.kune.platf.server.domain.Content;
+import org.ourproject.kune.platf.server.domain.Group;
+import org.ourproject.kune.platf.server.domain.I18nCountry;
+import org.ourproject.kune.platf.server.domain.I18nLanguage;
+import org.ourproject.kune.platf.server.domain.License;
+import org.ourproject.kune.platf.server.domain.User;
+import org.ourproject.kune.platf.server.manager.GroupManager;
+import org.ourproject.kune.platf.server.manager.I18nCountryManager;
+import org.ourproject.kune.platf.server.manager.I18nLanguageManager;
+import org.ourproject.kune.platf.server.manager.LicenseManager;
+import org.ourproject.kune.platf.server.manager.UserManager;
+
+import com.google.inject.Inject;
+
+public abstract class PersistencePreLoadedDataTest extends PersistenceTest {
+ protected static final String USER_SHORT_NAME = "user-shortname";
+ protected static final String USER_LONG_NAME = "the user long name";
+ protected static final String USER_PASSWORD = "userPassword";
+ protected static final String USER_EMAIL = "useremail at example.com";
+
+ @Inject
+ protected User userFinder;
+ @Inject
+ protected Group groupFinder;
+ @Inject
+ protected License licenseFinder;
+ @Inject
+ protected ContentManager contentManager;
+ @Inject
+ protected ContainerManager containerManager;
+ @Inject
+ protected GroupManager groupManager;
+ @Inject
+ protected UserManager userManager;
+ @Inject
+ protected LicenseManager licenseManager;
+ @Inject
+ protected I18nLanguageManager languageManager;
+ @Inject
+ protected I18nCountryManager countryManager;
+
+ protected User user;
+ protected License defLicense;
+ protected I18nLanguage english;
+ protected I18nCountry gb;
+ protected Content content;
+ protected Container container;
+
+ public PersistencePreLoadedDataTest() {
+ // test: use memory
+ // test_db: use mysql
+ super("test", "kune.properties");
+ }
+
+ @After
+ public void close() {
+ if (getTransaction().isActive()) {
+ getTransaction().rollback();
+ }
+ }
+
+ @Before
+ public void preLoadData() throws Exception {
+ openTransaction();
+ assertEquals(0, userFinder.getAll().size());
+ assertEquals(0, groupFinder.getAll().size());
+ assertEquals(0, licenseFinder.getAll().size());
+ english = new I18nLanguage(new Long(1819), "English", "English", "en");
+ languageManager.persist(english);
+ gb = new I18nCountry(new Long(75), "GB", "GBP", ".", "£%n", "", ".", "United Kingdom", "western", ",");
+ countryManager.persist(gb);
+ user = userManager.createUser(USER_SHORT_NAME, USER_LONG_NAME, USER_EMAIL, USER_PASSWORD, "en", "GB",
+ TimeZone.getDefault().getID());
+ defLicense = new License("by-sa-v3.0", "Creative Commons Attribution-ShareAlike", "",
+ "http://creativecommons.org/licenses/by-sa/3.0/", true, true, false, "", "");
+ licenseManager.persist(defLicense);
+ groupManager.createUserGroup(user, true);
+ content = new Content();
+ content.setLanguage(english);
+ contentManager.persist(content);
+ container = new Container();
+ container.setTypeId(DocumentServerTool.TYPE_FOLDER);
+ containerManager.persist(container);
+ }
+}
Modified: trunk/src/test/java/org/ourproject/kune/platf/server/PersistenceTest.java
===================================================================
--- trunk/src/test/java/org/ourproject/kune/platf/server/PersistenceTest.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/test/java/org/ourproject/kune/platf/server/PersistenceTest.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -61,7 +61,7 @@
getManager().getTransaction().rollback();
}
- private EntityManager getManager() {
+ protected EntityManager getManager() {
return provider.get();
}
Modified: trunk/src/test/java/org/ourproject/kune/platf/server/finders/RateFinderTest.java
===================================================================
--- trunk/src/test/java/org/ourproject/kune/platf/server/finders/RateFinderTest.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/test/java/org/ourproject/kune/platf/server/finders/RateFinderTest.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -6,55 +6,33 @@
import javax.persistence.EntityManager;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.ourproject.kune.platf.server.PersistenceTest;
+import org.ourproject.kune.platf.server.PersistencePreLoadedDataTest;
import org.ourproject.kune.platf.server.TestDomainHelper;
import org.ourproject.kune.platf.server.domain.Content;
-import org.ourproject.kune.platf.server.domain.I18nCountry;
-import org.ourproject.kune.platf.server.domain.I18nLanguage;
import org.ourproject.kune.platf.server.domain.Rate;
import org.ourproject.kune.platf.server.domain.User;
-import org.ourproject.kune.platf.server.manager.I18nCountryManager;
-import org.ourproject.kune.platf.server.manager.I18nLanguageManager;
import com.google.inject.Inject;
-public class RateFinderTest extends PersistenceTest {
+public class RateFinderTest extends PersistencePreLoadedDataTest {
@Inject
Rate rateFinder;
- @Inject
- I18nLanguageManager languageManager;
- @Inject
- I18nCountryManager countryManager;
- private I18nLanguage english;
- private I18nCountry gb;
+ private EntityManager entityManager;
- @After
- public void close() {
- if (getTransaction().isActive()) {
- getTransaction().rollback();
- }
- }
-
@Before
- public void insertData() throws Exception {
- english = new I18nLanguage(new Long(1819), "English", "English", "en");
- languageManager.persist(english);
- gb = new I18nCountry(new Long(75), "GB", "GBP", ".", "£%n", "", ".", "United Kingdom", "western", ",");
- countryManager.persist(gb);
+ public void before() {
+ entityManager = getManager();
}
@Test
public void testContentNotRated() {
- final EntityManager manager = openTransaction();
-
final Content cd = new Content();
cd.setLanguage(english);
cd.setPublishedOn(new Date());
- manager.persist(cd);
+ entityManager.persist(cd);
closeTransaction();
final Double rate = rateFinder.calculateRate(cd);
@@ -67,8 +45,6 @@
@Test
public void testContentRateAverage() {
- final EntityManager manager = openTransaction();
-
final User user1 = TestDomainHelper.createUser(1);
final User user2 = TestDomainHelper.createUser(2);
@@ -78,20 +54,20 @@
user1.setCountry(gb);
user2.setCountry(gb);
- manager.persist(user1);
- manager.persist(user2);
+ entityManager.persist(user1);
+ entityManager.persist(user2);
final Content cd = new Content();
cd.setLanguage(english);
cd.setPublishedOn(new Date());
- manager.persist(cd);
+ entityManager.persist(cd);
- manager.persist(new Rate(user1, cd, 1.3));
- manager.persist(new Rate(user2, cd, 3.3));
+ entityManager.persist(new Rate(user1, cd, 1.3));
+ entityManager.persist(new Rate(user2, cd, 3.3));
// same user and content other rate
final Rate rateFinded = rateFinder.find(user2, cd);
rateFinded.setValue(4.3);
- manager.persist(rateFinded);
+ entityManager.persist(rateFinded);
closeTransaction();
final Double rate = rateFinder.calculateRate(cd);
Modified: trunk/src/test/java/org/ourproject/kune/platf/server/finders/UserFinderTest.java
===================================================================
--- trunk/src/test/java/org/ourproject/kune/platf/server/finders/UserFinderTest.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/test/java/org/ourproject/kune/platf/server/finders/UserFinderTest.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -6,42 +6,21 @@
import java.util.List;
import java.util.TimeZone;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.ourproject.kune.platf.server.PersistenceTest;
-import org.ourproject.kune.platf.server.domain.I18nCountry;
-import org.ourproject.kune.platf.server.domain.I18nLanguage;
+import org.ourproject.kune.platf.server.PersistencePreLoadedDataTest;
import org.ourproject.kune.platf.server.domain.User;
-import org.ourproject.kune.platf.server.manager.I18nCountryManager;
-import org.ourproject.kune.platf.server.manager.I18nLanguageManager;
import com.google.inject.Inject;
-public class UserFinderTest extends PersistenceTest {
+public class UserFinderTest extends PersistencePreLoadedDataTest {
@Inject
User finder;
- @Inject
- I18nLanguageManager languageManager;
- @Inject
- I18nCountryManager countryManager;
- @Before
- public void initData() {
- openTransaction();
- I18nLanguage english = new I18nLanguage(new Long(1819), "English", "English", "en");
- languageManager.persist(english);
- I18nCountry gb = new I18nCountry(new Long(75), "GB", "GBP", ".", "£%n", "", ".", "United Kingdom", "western",
- ",");
- countryManager.persist(gb);
- persist(new User("shortname1", "the name1", "one at here.com", "password1", english, gb, TimeZone.getDefault()));
- persist(new User("shortname2", "the name2", "two at here.com", "password1", english, gb, TimeZone.getDefault()));
- }
-
@Test
public void findAll() {
List<User> all = finder.getAll();
- assertEquals(2, all.size());
+ assertEquals(3, all.size());
}
@Test
@@ -50,11 +29,10 @@
assertNotNull(user);
}
- @After
- public void close() {
- if (getTransaction().isActive()) {
- getTransaction().rollback();
- }
+ @Before
+ public void initData() {
+ persist(new User("shortname1", "the name1", "one at here.com", "password1", english, gb, TimeZone.getDefault()));
+ persist(new User("shortname2", "the name2", "two at here.com", "password1", english, gb, TimeZone.getDefault()));
}
}
Modified: trunk/src/test/java/org/ourproject/kune/platf/server/manager/ContentManagerTest.java
===================================================================
--- trunk/src/test/java/org/ourproject/kune/platf/server/manager/ContentManagerTest.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/test/java/org/ourproject/kune/platf/server/manager/ContentManagerTest.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -2,81 +2,14 @@
import static org.junit.Assert.assertEquals;
-import java.util.TimeZone;
-
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
-import org.mockito.Mockito;
import org.ourproject.kune.docs.server.DocumentServerTool;
-import org.ourproject.kune.platf.server.PersistenceTest;
-import org.ourproject.kune.platf.server.content.ContentManager;
+import org.ourproject.kune.platf.server.PersistencePreLoadedDataTest;
import org.ourproject.kune.platf.server.domain.BasicMimeType;
-import org.ourproject.kune.platf.server.domain.Container;
import org.ourproject.kune.platf.server.domain.Content;
-import org.ourproject.kune.platf.server.domain.Group;
-import org.ourproject.kune.platf.server.domain.I18nCountry;
-import org.ourproject.kune.platf.server.domain.I18nLanguage;
-import org.ourproject.kune.platf.server.domain.License;
-import org.ourproject.kune.platf.server.domain.User;
-import com.google.inject.Inject;
+public class ContentManagerTest extends PersistencePreLoadedDataTest {
-public class ContentManagerTest extends PersistenceTest {
-
- @Inject
- User userFinder;
- @Inject
- Group groupFinder;
- @Inject
- License licenseFinder;
- @Inject
- ContentManager contentManager;
- @Inject
- GroupManager groupManager;
- @Inject
- UserManager userManager;
- @Inject
- LicenseManager licenseManager;
- @Inject
- I18nLanguageManager languageManager;
- @Inject
- I18nCountryManager countryManager;
- private User user;
- private License defLicense;
-
- public ContentManagerTest() {
- // Testing with mysql because utf-8 normally fails with mysql and not in
- // memory
- super("test_db", "kune.properties");
- }
-
- @After
- public void close() {
- if (getTransaction().isActive()) {
- getTransaction().rollback();
- }
- }
-
- @Before
- public void insertData() throws Exception {
- openTransaction();
- assertEquals(0, userFinder.getAll().size());
- assertEquals(0, groupFinder.getAll().size());
- assertEquals(0, licenseFinder.getAll().size());
- final I18nLanguage english = new I18nLanguage(new Long(1819), "English", "English", "en");
- languageManager.persist(english);
- final I18nCountry gb = new I18nCountry(new Long(75), "GB", "GBP", ".", "£%n", "", ".", "United Kingdom",
- "western", ",");
- countryManager.persist(gb);
- user = userManager.createUser("username", "the user name", "email at example.com", "userPassword", "en", "GB",
- TimeZone.getDefault().getID());
- defLicense = new License("by-sa-v3.0", "Creative Commons Attribution-ShareAlike", "",
- "http://creativecommons.org/licenses/by-sa/3.0/", true, true, false, "", "");
- licenseManager.persist(defLicense);
- groupManager.createUserGroup(user, true);
- }
-
@Test
public void testBasicMimePersist() {
final String mimetype = "application/pdf";
@@ -95,8 +28,6 @@
*/
@Test
public void testUTF8Persist() {
- final Container container = Mockito.mock(Container.class);
- Mockito.when(container.getTypeId()).thenReturn(DocumentServerTool.TYPE_FOLDER);
final Content cnt = contentManager.createContent("汉语/漢語", "汉语/漢語", user, container,
DocumentServerTool.TYPE_DOCUMENT);
final Content newCnt = contentManager.find(cnt.getId());
@@ -104,8 +35,6 @@
}
private void createContentWithMime(final String mimetype) {
- final Container container = Mockito.mock(Container.class);
- Mockito.when(container.getTypeId()).thenReturn(DocumentServerTool.TYPE_FOLDER);
final Content cnt = contentManager.createContent("title", "body", user, container,
DocumentServerTool.TYPE_UPLOADEDFILE);
cnt.setMimeType(new BasicMimeType(mimetype));
Modified: trunk/src/test/java/org/ourproject/kune/platf/server/manager/GroupManagerTest.java
===================================================================
--- trunk/src/test/java/org/ourproject/kune/platf/server/manager/GroupManagerTest.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/test/java/org/ourproject/kune/platf/server/manager/GroupManagerTest.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -6,53 +6,20 @@
import java.util.TimeZone;
import org.apache.lucene.queryParser.ParseException;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
import org.ourproject.kune.platf.client.dto.GroupType;
import org.ourproject.kune.platf.client.errors.EmailAddressInUseException;
import org.ourproject.kune.platf.client.errors.GroupNameInUseException;
import org.ourproject.kune.platf.client.errors.I18nNotFoundException;
-import org.ourproject.kune.platf.server.PersistenceTest;
+import org.ourproject.kune.platf.server.PersistencePreLoadedDataTest;
import org.ourproject.kune.platf.server.domain.AccessLists;
import org.ourproject.kune.platf.server.domain.Group;
-import org.ourproject.kune.platf.server.domain.I18nCountry;
-import org.ourproject.kune.platf.server.domain.I18nLanguage;
-import org.ourproject.kune.platf.server.domain.License;
import org.ourproject.kune.platf.server.domain.SocialNetwork;
import org.ourproject.kune.platf.server.domain.User;
import org.ourproject.kune.platf.server.manager.impl.SearchResult;
-import com.google.inject.Inject;
+public class GroupManagerTest extends PersistencePreLoadedDataTest {
-public class GroupManagerTest extends PersistenceTest {
- @Inject
- User userFinder;
- @Inject
- Group groupFinder;
- @Inject
- License licenseFinder;
- @Inject
- GroupManager groupManager;
- @Inject
- UserManager userManager;
- @Inject
- LicenseManager licenseManager;
- @Inject
- I18nLanguageManager languageManager;
- @Inject
- I18nCountryManager countryManager;
-
- private User user;
- private License defLicense;
-
- @After
- public void close() {
- if (getTransaction().isActive()) {
- getTransaction().rollback();
- }
- }
-
@Test
public void createdGroupShoudHaveValidSocialNetwork() throws Exception {
final Group group = new Group("short", "longName", defLicense, GroupType.PROJECT);
@@ -151,15 +118,15 @@
@Test(expected = EmailAddressInUseException.class)
public void createUserWithExistingEmail() throws Exception {
- final User user2 = userManager.createUser("username2", "the user name 2", "email at example.com", "userPassword",
- "en", "GB", TimeZone.getDefault().getID());
+ final User user2 = userManager.createUser("username2", "the user name 2", USER_EMAIL, "userPassword", "en",
+ "GB", TimeZone.getDefault().getID());
groupManager.createUserGroup(user2);
rollbackTransaction();
}
@Test(expected = GroupNameInUseException.class)
public void createUserWithExistingLongName() throws Exception {
- final User user2 = userManager.createUser("username2", "the user name", "email2 at example.com", "userPassword",
+ final User user2 = userManager.createUser("username2", USER_LONG_NAME, "email2 at example.com", "userPassword",
"en", "GB", TimeZone.getDefault().getID());
groupManager.createUserGroup(user2);
rollbackTransaction();
@@ -167,8 +134,8 @@
@Test(expected = GroupNameInUseException.class)
public void createUserWithExistingShortName() throws Exception {
- final User user2 = userManager.createUser("username", "the user name 2", "email2 at example.com", "userPassword",
- "en", "GB", TimeZone.getDefault().getID());
+ final User user2 = userManager.createUser(USER_SHORT_NAME, "the user name 2", "email2 at example.com",
+ "userPassword", "en", "GB", TimeZone.getDefault().getID());
groupManager.createUserGroup(user2);
rollbackTransaction();
}
@@ -188,25 +155,6 @@
rollbackTransaction();
}
- @Before
- public void insertData() throws Exception {
- openTransaction();
- assertEquals(0, userFinder.getAll().size());
- assertEquals(0, groupFinder.getAll().size());
- assertEquals(0, licenseFinder.getAll().size());
- final I18nLanguage english = new I18nLanguage(new Long(1819), "English", "English", "en");
- languageManager.persist(english);
- final I18nCountry gb = new I18nCountry(new Long(75), "GB", "GBP", ".", "£%n", "", ".", "United Kingdom",
- "western", ",");
- countryManager.persist(gb);
- user = userManager.createUser("username", "the user name", "email at example.com", "userPassword", "en", "GB",
- TimeZone.getDefault().getID());
- defLicense = new License("by-sa-v3.0", "Creative Commons Attribution-ShareAlike", "",
- "http://creativecommons.org/licenses/by-sa/3.0/", true, true, false, "", "");
- licenseManager.persist(defLicense);
- groupManager.createUserGroup(user);
- }
-
private void createTestGroup(final int number) throws Exception {
final Group g = new Group("ysei" + number, "Yellow Submarine Environmental Initiative " + number, defLicense,
GroupType.PROJECT);
Added: trunk/src/test/java/org/ourproject/kune/platf/server/manager/TagUserContentTest.java
===================================================================
--- trunk/src/test/java/org/ourproject/kune/platf/server/manager/TagUserContentTest.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/test/java/org/ourproject/kune/platf/server/manager/TagUserContentTest.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -0,0 +1,87 @@
+package org.ourproject.kune.platf.server.manager;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.ourproject.kune.platf.server.PersistencePreLoadedDataTest;
+import org.ourproject.kune.platf.server.domain.Tag;
+import org.ourproject.kune.platf.server.domain.TagUserContent;
+
+import com.google.inject.Inject;
+
+public class TagUserContentTest extends PersistencePreLoadedDataTest {
+ private static final String DUMMY_TAG = "dummy";
+ @Inject
+ TagUserContentManager manager;
+ private Tag tag;
+ @Inject
+ TagManager tagManager;
+
+ @Before
+ public void before() {
+ tag = new Tag(DUMMY_TAG);
+ tagManager.persist(tag);
+ }
+
+ @Test
+ public void getTagsAsString() {
+ manager.setTags(user, content, DUMMY_TAG);
+ String tagS = manager.getTagsAsString(user, content);
+ assertEquals(DUMMY_TAG, tagS);
+ }
+
+ @Test
+ public void insertSomeUserContent() {
+ createSomeTagUserContent();
+ }
+
+ @Test
+ public void removeSomeUserContent() {
+ createSomeTagUserContent();
+ manager.remove(user, content);
+ List<Tag> tags = manager.find(user, content);
+ assertEquals(0, tags.size());
+ }
+
+ @Test
+ public void setTags() {
+ List<Tag> tags = manager.find(user, content);
+ assertEquals(0, tags.size());
+ manager.setTags(user, content, DUMMY_TAG + " " + DUMMY_TAG);
+ tags = manager.find(user, content);
+ assertEquals(1, tags.size());
+ }
+
+ @Test
+ public void setTagsRemoveBefore() {
+ manager.setTags(user, content, "foo");
+ manager.setTags(user, content, DUMMY_TAG);
+ List<Tag> tags = manager.find(user, content);
+ assertEquals(1, tags.size());
+ assertEquals(DUMMY_TAG, tags.get(0).getName());
+ }
+
+ @Test
+ public void testInsertData() {
+ TagUserContent tagUC = createTagUserContent();
+ assertNotNull(tagUC.getId());
+ }
+
+ private void createSomeTagUserContent() {
+ List<Tag> tags = manager.find(user, content);
+ assertEquals(0, tags.size());
+ createTagUserContent();
+ tags = manager.find(user, content);
+ assertEquals(1, tags.size());
+ }
+
+ private TagUserContent createTagUserContent() {
+ TagUserContent tagUC = new TagUserContent(tag, user, content);
+ manager.persist(tagUC);
+ return tagUC;
+ }
+}
Modified: trunk/src/test/java/org/ourproject/kune/platf/server/manager/UserManagerTest.java
===================================================================
--- trunk/src/test/java/org/ourproject/kune/platf/server/manager/UserManagerTest.java 2009-02-14 11:23:09 UTC (rev 1049)
+++ trunk/src/test/java/org/ourproject/kune/platf/server/manager/UserManagerTest.java 2009-02-20 13:41:17 UTC (rev 1050)
@@ -10,47 +10,21 @@
import org.apache.lucene.queryParser.ParseException;
import org.hibernate.validator.InvalidStateException;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
import org.ourproject.kune.platf.client.errors.I18nNotFoundException;
-import org.ourproject.kune.platf.server.PersistenceTest;
+import org.ourproject.kune.platf.server.PersistencePreLoadedDataTest;
import org.ourproject.kune.platf.server.domain.Group;
-import org.ourproject.kune.platf.server.domain.I18nCountry;
-import org.ourproject.kune.platf.server.domain.I18nLanguage;
import org.ourproject.kune.platf.server.domain.User;
import org.ourproject.kune.platf.server.manager.impl.SearchResult;
import com.google.inject.Inject;
-public class UserManagerTest extends PersistenceTest {
- private static final String USER_SHORT_NAME = "user-shortname";
- private static final String USER_LONG_NAME = "the user long name";
- private static final String USER_PASSWORD = "userPassword";
- private static final String USER_EMAIL = "useremail at example.com";
+public class UserManagerTest extends PersistencePreLoadedDataTest {
- @Inject
- UserManager userManager;
- @Inject
User userFinder;
@Inject
Group groupFinder;
- @Inject
- I18nLanguageManager languageManager;
- @Inject
- I18nCountryManager countryManager;
- private User user;
- private I18nCountry gb;
- private I18nLanguage english;
-
- @After
- public void close() {
- if (getTransaction().isActive()) {
- getTransaction().rollback();
- }
- }
-
@Test
public void emailCorrect() {
user = new User("test1", "test1 name", "test at example.com", "some passwd", english, gb, getTimeZone());
@@ -69,19 +43,6 @@
persist(user);
}
- @Before
- public void insertData() throws Exception {
- openTransaction();
- assertEquals(0, userFinder.getAll().size());
- assertEquals(0, groupFinder.getAll().size());
- english = new I18nLanguage(new Long(1819), "English", "English", "en");
- languageManager.persist(english);
- gb = new I18nCountry(new Long(75), "GB", "GBP", ".", "£%n", "", ".", "United Kingdom", "western", ",");
- countryManager.persist(gb);
- user = new User(USER_SHORT_NAME, USER_LONG_NAME, USER_EMAIL, USER_PASSWORD, english, gb, getTimeZone());
- persist(user);
- }
-
@Test
public void loginIncorrect() {
final User result = userManager.login("test", "test");
More information about the kune-commits
mailing list