[kune-commits] r838 - in trunk/src:
main/java/org/ourproject/kune/platf/server/domain
test/java/org/ourproject/kune/platf/server/manager
vjrj
vjrj at ourproject.org
Sat Aug 9 16:49:38 CEST 2008
Author: vjrj
Date: 2008-08-09 16:49:34 +0200 (Sat, 09 Aug 2008)
New Revision: 838
Added:
trunk/src/main/java/org/ourproject/kune/platf/server/domain/ChatUserParams.java
trunk/src/main/java/org/ourproject/kune/platf/server/domain/CustomProperties.java
Removed:
trunk/src/main/java/org/ourproject/kune/platf/server/domain/UserParams.java
Modified:
trunk/src/main/java/org/ourproject/kune/platf/server/domain/User.java
trunk/src/test/java/org/ourproject/kune/platf/server/manager/UserManagerTest.java
Log:
Incomplete - task 1: User parameters Server
Added: trunk/src/main/java/org/ourproject/kune/platf/server/domain/ChatUserParams.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/domain/ChatUserParams.java 2008-08-08 23:52:38 UTC (rev 837)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/domain/ChatUserParams.java 2008-08-09 14:49:34 UTC (rev 838)
@@ -0,0 +1,64 @@
+package org.ourproject.kune.platf.server.domain;
+
+import java.io.Serializable;
+
+import com.calclab.emite.client.im.roster.RosterManager;
+import com.calclab.emite.client.im.roster.RosterManager.SubscriptionMode;
+
+public class ChatUserParams implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private String avatar;
+
+ private boolean publishRoster;
+
+ private SubscriptionMode subscriptionMode;
+
+ private String chatColor;
+
+ public ChatUserParams() {
+ this(null, false, SubscriptionMode.autoAcceptAll, null);
+ };
+
+ public ChatUserParams(final String avatar, final boolean publishRoster, final SubscriptionMode subscriptionMode,
+ final String chatColor) {
+ this.avatar = avatar;
+ this.publishRoster = publishRoster;
+ this.subscriptionMode = subscriptionMode;
+ this.chatColor = chatColor;
+ }
+
+ public String getAvatar() {
+ return avatar;
+ }
+
+ public String getChatColor() {
+ return chatColor;
+ }
+
+ public RosterManager.SubscriptionMode getSubscriptionMode() {
+ return subscriptionMode;
+ }
+
+ public boolean isPublishRoster() {
+ return publishRoster;
+ }
+
+ public void setAvatar(final String avatar) {
+ this.avatar = avatar;
+ }
+
+ public void setChatColor(final String chatColor) {
+ this.chatColor = chatColor;
+ }
+
+ public void setPublishRoster(final boolean publishRoster) {
+ this.publishRoster = publishRoster;
+ }
+
+ public void setSubscriptionMode(final RosterManager.SubscriptionMode subscriptionMode) {
+ this.subscriptionMode = subscriptionMode;
+ }
+
+}
Added: trunk/src/main/java/org/ourproject/kune/platf/server/domain/CustomProperties.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/domain/CustomProperties.java 2008-08-08 23:52:38 UTC (rev 837)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/domain/CustomProperties.java 2008-08-09 14:49:34 UTC (rev 838)
@@ -0,0 +1,52 @@
+package org.ourproject.kune.platf.server.domain;
+
+import java.util.HashMap;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+import javax.persistence.Table;
+
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Indexed;
+
+ at Entity
+ at Indexed
+ at Table(name = "customproperties")
+public class CustomProperties implements HasId {
+
+ @Id
+ @DocumentId
+ @GeneratedValue
+ private Long id;
+
+ @Lob
+ private final HashMap<Class<?>, Object> data;
+
+ public CustomProperties() {
+ data = new HashMap<Class<?>, Object>();
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T getData(final Class<T> type) {
+ return (T) data.get(type);
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public <T> boolean hasPropertie(final Class<T> type) {
+ return data.containsKey(type);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T setData(final Class<T> type, final T value) {
+ return (T) data.put(type, value);
+ }
+
+ public void setId(final Long id) {
+ this.id = id;
+ }
+}
Modified: trunk/src/main/java/org/ourproject/kune/platf/server/domain/User.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/domain/User.java 2008-08-08 23:52:38 UTC (rev 837)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/domain/User.java 2008-08-09 14:49:34 UTC (rev 838)
@@ -98,6 +98,9 @@
@NotNull
private TimeZone timezone;
+ @OneToOne(cascade = CascadeType.ALL)
+ private final CustomProperties customProperties;
+
public User() {
this(null, null, null, null, null, null, null);
}
@@ -112,6 +115,7 @@
this.language = language;
this.country = country;
this.timezone = timezone;
+ customProperties = new CustomProperties();
}
@Finder(query = "from User")
@@ -135,6 +139,10 @@
return country;
}
+ public CustomProperties getCustomProperties() {
+ return customProperties;
+ }
+
public String getEmail() {
return email;
}
Deleted: trunk/src/main/java/org/ourproject/kune/platf/server/domain/UserParams.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/domain/UserParams.java 2008-08-08 23:52:38 UTC (rev 837)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/domain/UserParams.java 2008-08-09 14:49:34 UTC (rev 838)
@@ -1,80 +0,0 @@
-package org.ourproject.kune.platf.server.domain;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-import org.hibernate.search.annotations.DocumentId;
-import org.hibernate.search.annotations.Indexed;
-import org.hibernate.validator.NotNull;
-
-import com.calclab.emite.client.im.roster.RosterManager;
-import com.calclab.emite.client.im.roster.RosterManager.SubscriptionMode;
-
- at Entity
- at Indexed
- at Table(name = "usersparams")
-public class UserParams {
-
- @Id
- @DocumentId
- @GeneratedValue
- private Long id;
-
- private String avatar;
-
- @NotNull
- private boolean publishRoster;
-
- @NotNull
- private SubscriptionMode subscriptionMode;
-
- @NotNull
- private String chatColor;
-
- public UserParams(final String avatar, final boolean publishRoster, final SubscriptionMode subscriptionMode,
- final String chatColor) {
- this.avatar = avatar;
- this.publishRoster = publishRoster;
- this.subscriptionMode = subscriptionMode;
- this.chatColor = chatColor;
- }
-
- public String getAvatar() {
- return avatar;
- }
-
- public String getChatColor() {
- return chatColor;
- }
-
- public Long getId() {
- return id;
- }
-
- public RosterManager.SubscriptionMode getSubscriptionMode() {
- return subscriptionMode;
- }
-
- public boolean isPublishRoster() {
- return publishRoster;
- }
-
- public void setAvatar(final String avatar) {
- this.avatar = avatar;
- }
-
- public void setChatColor(final String chatColor) {
- this.chatColor = chatColor;
- }
-
- public void setPublishRoster(final boolean publishRoster) {
- this.publishRoster = publishRoster;
- }
-
- public void setSubscriptionMode(final RosterManager.SubscriptionMode subscriptionMode) {
- this.subscriptionMode = subscriptionMode;
- }
-
-}
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 2008-08-08 23:52:38 UTC (rev 837)
+++ trunk/src/test/java/org/ourproject/kune/platf/server/manager/UserManagerTest.java 2008-08-09 14:49:34 UTC (rev 838)
@@ -15,12 +15,15 @@
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.domain.ChatUserParams;
+import org.ourproject.kune.platf.server.domain.CustomProperties;
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.calclab.emite.client.im.roster.RosterManager.SubscriptionMode;
import com.google.inject.Inject;
public class UserManagerTest extends PersistenceTest {
@@ -46,99 +49,116 @@
@After
public void close() {
- if (getTransaction().isActive()) {
- getTransaction().rollback();
- }
+ if (getTransaction().isActive()) {
+ getTransaction().rollback();
+ }
}
@Test
public void emailCorrect() {
- user = new User("test1", "test1 name", "test at example.com", "some passwd", english, gb, getTimeZone());
- persist(user);
+ user = new User("test1", "test1 name", "test at example.com", "some passwd", english, gb, getTimeZone());
+ persist(user);
}
@Test(expected = InvalidStateException.class)
public void emailEmpty() {
- user = new User("test1", "test1 name", "", "some passwd", english, gb, getTimeZone());
- persist(user);
+ user = new User("test1", "test1 name", "", "some passwd", english, gb, getTimeZone());
+ persist(user);
}
@Test(expected = InvalidStateException.class)
public void emailIncorrect() {
- user = new User("test1", "test1 name", "falseEmail@", "some passwd", english, gb, getTimeZone());
- persist(user);
+ user = new User("test1", "test1 name", "falseEmail@", "some passwd", english, gb, getTimeZone());
+ 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);
+ 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");
- assertNull(result);
+ final User result = userManager.login("test", "test");
+ assertNull(result);
}
@Test
public void loginWithEmailCorrect() {
- final User result = userManager.login(USER_EMAIL, USER_PASSWORD);
- assertNotNull(result.getId());
+ final User result = userManager.login(USER_EMAIL, USER_PASSWORD);
+ assertNotNull(result.getId());
}
@Test
public void loginWithNickCorrect() {
- final User result = userManager.login(USER_SHORT_NAME, USER_PASSWORD);
- assertNotNull(result.getId());
+ final User result = userManager.login(USER_SHORT_NAME, USER_PASSWORD);
+ assertNotNull(result.getId());
}
@Test(expected = InvalidStateException.class)
public void passwdLengthIncorrect() {
- user = new User("test1", "test1 name", "test at example.com", "pass", english, gb, getTimeZone());
- persist(user);
+ user = new User("test1", "test1 name", "test at example.com", "pass", english, gb, getTimeZone());
+ persist(user);
}
@Test(expected = EntityExistsException.class)
public void testUserExist() throws I18nNotFoundException {
- final User user1 = userManager.createUser("test", "test 1 name", "test1 at example.com", "some password", "en",
- "GB", "GMT");
- persist(user1);
- final User user2 = userManager.createUser("test", "test 1 name", "test1 at example.com", "some password", "en",
- "GB", "GMT");
- persist(user2);
+ final User user1 = userManager.createUser("test", "test 1 name", "test1 at example.com", "some password", "en",
+ "GB", "GMT");
+ persist(user1);
+ final User user2 = userManager.createUser("test", "test 1 name", "test1 at example.com", "some password", "en",
+ "GB", "GMT");
+ persist(user2);
}
@Test(expected = InvalidStateException.class)
public void userNameLengthIncorrect() {
- user = new User("test1", "te", "test at example.com", "some passwd", english, gb, getTimeZone());
- persist(user);
+ user = new User("test1", "te", "test at example.com", "some passwd", english, gb, getTimeZone());
+ persist(user);
}
@Test
+ public void userSaveAndGetCustomProperties() {
+ final User user1 = userManager.createUser("test", "test 1 name", "test1 at example.com", "some password", "en",
+ "GB", "GMT");
+ final ChatUserParams userChatParams = new ChatUserParams("avatar", true, SubscriptionMode.autoAcceptAll,
+ "color");
+ user1.getCustomProperties().setData(ChatUserParams.class, userChatParams);
+ persist(user1);
+ final User find = userManager.find(user1.getId());
+ final CustomProperties customProperties = find.getCustomProperties();
+ assertEquals("avatar", customProperties.getData(ChatUserParams.class).getAvatar());
+ assertEquals("color", customProperties.getData(ChatUserParams.class).getChatColor());
+ assertEquals(SubscriptionMode.autoAcceptAll, customProperties.getData(ChatUserParams.class)
+ .getSubscriptionMode());
+ assertEquals(true, customProperties.getData(ChatUserParams.class).isPublishRoster());
+ }
+
+ @Test
public void userSearch() throws Exception, ParseException {
- userManager.reIndex();
- final SearchResult<User> result = userManager.search(USER_SHORT_NAME);
- assertEquals(1, (long) result.getSize());
- assertEquals(USER_SHORT_NAME, result.getList().get(0).getShortName());
- rollbackTransaction();
+ userManager.reIndex();
+ final SearchResult<User> result = userManager.search(USER_SHORT_NAME);
+ assertEquals(1, (long) result.getSize());
+ assertEquals(USER_SHORT_NAME, result.getList().get(0).getShortName());
+ rollbackTransaction();
}
@Test(expected = InvalidStateException.class)
public void userShortNameIncorrect() {
- user = new User("test1A", "test1 name", "test at example.com", "some passwd", english, gb, getTimeZone());
- persist(user);
+ user = new User("test1A", "test1 name", "test at example.com", "some passwd", english, gb, getTimeZone());
+ persist(user);
}
private TimeZone getTimeZone() {
- return TimeZone.getDefault();
+ return TimeZone.getDefault();
}
}
More information about the kune-commits
mailing list