You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by mf...@apache.org on 2012/06/20 17:59:58 UTC
svn commit: r1352182 - in /rave/branches/model_interfaces/rave-components:
rave-commons/src/main/java/org/apache/rave/util/
rave-core/src/main/java/org/apache/rave/portal/model/impl/
rave-jpa/src/test/java/org/apache/rave/portal/repository/impl/ rave-w...
Author: mfranklin
Date: Wed Jun 20 15:59:58 2012
New Revision: 1352182
URL: http://svn.apache.org/viewvc?rev=1352182&view=rev
Log:
Fixed todos RAVE-652
Modified:
rave/branches/model_interfaces/rave-components/rave-commons/src/main/java/org/apache/rave/util/CollectionUtils.java
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/impl/AuthorityImpl.java
rave/branches/model_interfaces/rave-components/rave-jpa/src/test/java/org/apache/rave/portal/repository/impl/JpaRegionRepositoryTest.java
rave/branches/model_interfaces/rave-components/rave-jpa/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRepositoryTest.java
rave/branches/model_interfaces/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/admin/UserController.java
rave/branches/model_interfaces/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/util/ModelUtils.java
rave/branches/model_interfaces/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/model/UserForm.java
rave/branches/model_interfaces/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/tag/RegionWidgetTagTest.java
Modified: rave/branches/model_interfaces/rave-components/rave-commons/src/main/java/org/apache/rave/util/CollectionUtils.java
URL: http://svn.apache.org/viewvc/rave/branches/model_interfaces/rave-components/rave-commons/src/main/java/org/apache/rave/util/CollectionUtils.java?rev=1352182&r1=1352181&r2=1352182&view=diff
==============================================================================
--- rave/branches/model_interfaces/rave-components/rave-commons/src/main/java/org/apache/rave/util/CollectionUtils.java (original)
+++ rave/branches/model_interfaces/rave-components/rave-commons/src/main/java/org/apache/rave/util/CollectionUtils.java Wed Jun 20 15:59:58 2012
@@ -107,20 +107,27 @@ public class CollectionUtils {
}
/**
- * Converts the wildcard list to a typed list
+ * Workaround for compile time checking of list types. Generics are not persisted through runtime. The compile time
+ * type system will still check that the items are castable to the base type.
* @param initial the wildcard list
* @param <T> the type constraint for the target list
* @return if initial is null, null otherwise the new, type constrained list
*/
+ @SuppressWarnings("unchecked")
public static <T> List<T> toBaseTypedList(List<? extends T> initial) {
- List<T> list = null;
- if (initial != null) {
- list = new ArrayList<T>();
- for (T f : initial) {
- list.add(f);
- }
- }
- return list;
+ return (List<T>)initial;
+ }
+
+ /**
+ * Workaround for compile time checking of list types. Generics are not persisted through runtime. The compile time
+ * type system will still check that the items are castable to the base type.
+ * @param initial the wildcard collection
+ * @param <T> the type constraint for the target collection
+ * @return if initial is null, null otherwise the new, type constrained collection
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> Collection<T> toBaseTypedCollection(Collection<? extends T> initial) {
+ return (Collection<T>)initial;
}
/**
Modified: rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/impl/AuthorityImpl.java
URL: http://svn.apache.org/viewvc/rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/impl/AuthorityImpl.java?rev=1352182&r1=1352181&r2=1352182&view=diff
==============================================================================
--- rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/impl/AuthorityImpl.java (original)
+++ rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/impl/AuthorityImpl.java Wed Jun 20 15:59:58 2012
@@ -17,9 +17,13 @@ public class AuthorityImpl implements Au
this.users = new ArrayList<User>();
}
- public AuthorityImpl(GrantedAuthority grantedAuthority) {
+ public AuthorityImpl(String grantedAuthority) {
this();
- this.authority = grantedAuthority.getAuthority();
+ this.authority = grantedAuthority;
+ }
+
+ public AuthorityImpl(GrantedAuthority grantedAuthority) {
+ this(grantedAuthority.getAuthority());
}
@Override
Modified: rave/branches/model_interfaces/rave-components/rave-jpa/src/test/java/org/apache/rave/portal/repository/impl/JpaRegionRepositoryTest.java
URL: http://svn.apache.org/viewvc/rave/branches/model_interfaces/rave-components/rave-jpa/src/test/java/org/apache/rave/portal/repository/impl/JpaRegionRepositoryTest.java?rev=1352182&r1=1352181&r2=1352182&view=diff
==============================================================================
--- rave/branches/model_interfaces/rave-components/rave-jpa/src/test/java/org/apache/rave/portal/repository/impl/JpaRegionRepositoryTest.java (original)
+++ rave/branches/model_interfaces/rave-components/rave-jpa/src/test/java/org/apache/rave/portal/repository/impl/JpaRegionRepositoryTest.java Wed Jun 20 15:59:58 2012
@@ -23,7 +23,7 @@ import org.apache.rave.portal.model.JpaR
import org.apache.rave.portal.model.JpaRegionWidget;
import org.apache.rave.portal.model.Region;
import org.apache.rave.portal.model.RegionWidget;
-import org.junit.Ignore;
+import org.apache.rave.portal.repository.RegionRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,13 +36,7 @@ import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.ArrayList;
-import org.apache.rave.portal.repository.RegionRepository;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.CoreMatchers.sameInstance;
+import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
@Transactional
@@ -134,7 +128,6 @@ public class JpaRegionRepositoryTest {
}
@Test
- @Ignore //TODO Failed test due to interface migration "No metadata was found for type "interface org.apache.rave.portal.model.RegionWidget". The class is not enhanced."
public void save_cascadeOrphan() {
JpaRegion region = (JpaRegion)repository.get(1L);
long id = region.getRegionWidgets().get(0).getId();
@@ -142,7 +135,7 @@ public class JpaRegionRepositoryTest {
Region saved = repository.save(region);
manager.flush();
- RegionWidget widget = manager.find(RegionWidget.class, id);
+ RegionWidget widget = manager.find(JpaRegionWidget.class, id);
assertThat(saved.getRegionWidgets().size(), is(equalTo(1)));
assertThat(widget, is(nullValue()));
Modified: rave/branches/model_interfaces/rave-components/rave-jpa/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRepositoryTest.java
URL: http://svn.apache.org/viewvc/rave/branches/model_interfaces/rave-components/rave-jpa/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRepositoryTest.java?rev=1352182&r1=1352181&r2=1352182&view=diff
==============================================================================
--- rave/branches/model_interfaces/rave-components/rave-jpa/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRepositoryTest.java (original)
+++ rave/branches/model_interfaces/rave-components/rave-jpa/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetRepositoryTest.java Wed Jun 20 15:59:58 2012
@@ -20,10 +20,8 @@
package org.apache.rave.portal.repository.impl;
import org.apache.rave.portal.model.*;
-import org.apache.rave.portal.model.impl.CategoryImpl;
import org.apache.rave.portal.model.util.WidgetStatistics;
import org.apache.rave.portal.repository.WidgetRepository;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@@ -155,7 +153,6 @@ public class JpaWidgetRepositoryTest {
}
@Test
- @Ignore //TODO Broke during interface migration
public void getByStatusAndTypeAndFreeText() {
final String searchTerm = "gAdGet";
final String type = "OpenSocial";
@@ -169,7 +166,6 @@ public class JpaWidgetRepositoryTest {
}
@Test
- @Ignore //TODO Broke during interface migration
public void countByStatusAndTypeAndFreeText() {
final String searchTerm = "gAdGet";
final String type = "OpenSocial";
@@ -392,15 +388,14 @@ public class JpaWidgetRepositoryTest {
assertTrue(repository.getCountByTag("NEWS") == 1);
}
- // TODO: remove expected IllegalArgumentException once Widget has been refactored
- @Test(expected = IllegalArgumentException.class)
+ @Test
@Transactional(readOnly = false)
@Rollback
public void addWidgetCategory() {
final long WIDGET_ID = 1L;
final User user = new JpaUser(1L);
- Category category = new CategoryImpl();
+ Category category = new JpaCategory();
category.setId(1L);
category.setText("Sample Category");
category.setCreatedUser(user);
Modified: rave/branches/model_interfaces/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/admin/UserController.java
URL: http://svn.apache.org/viewvc/rave/branches/model_interfaces/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/admin/UserController.java?rev=1352182&r1=1352181&r2=1352182&view=diff
==============================================================================
--- rave/branches/model_interfaces/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/admin/UserController.java (original)
+++ rave/branches/model_interfaces/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/admin/UserController.java Wed Jun 20 15:59:58 2012
@@ -19,7 +19,9 @@
package org.apache.rave.portal.web.controller.admin;
-import org.apache.rave.portal.model.*;
+import org.apache.rave.portal.model.Authority;
+import org.apache.rave.portal.model.PortalPreference;
+import org.apache.rave.portal.model.User;
import org.apache.rave.portal.model.impl.UserImpl;
import org.apache.rave.portal.model.util.SearchResult;
import org.apache.rave.portal.service.AuthorityService;
@@ -126,6 +128,13 @@ public class UserController {
return ViewNames.ADMIN_USERDETAIL;
}
+ /* TODO - Fix binding of Authorities
+ * When the model was converted to interfaces, the authorities no longer bind correctly to the object that is
+ * stuffed into the session by spring form. This means the JpaUser that was added to the model in the method above
+ * cannot get updated properly when the form is parsed by the sping data binder. No errors are noted though, so the
+ * process proceeds. If we use the UserForm class here, we need to pull the user out of the database and update its values
+ *
+ */
@RequestMapping(value = "/admin/userdetail/update", method = RequestMethod.POST)
public String updateUserDetail(@ModelAttribute User user, BindingResult result,
@ModelAttribute(ModelKeys.TOKENCHECK) String sessionToken,
Modified: rave/branches/model_interfaces/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/util/ModelUtils.java
URL: http://svn.apache.org/viewvc/rave/branches/model_interfaces/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/util/ModelUtils.java?rev=1352182&r1=1352181&r2=1352182&view=diff
==============================================================================
--- rave/branches/model_interfaces/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/util/ModelUtils.java (original)
+++ rave/branches/model_interfaces/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/util/ModelUtils.java Wed Jun 20 15:59:58 2012
@@ -1,8 +1,10 @@
package org.apache.rave.portal.web.controller.util;
+import org.apache.rave.portal.model.Authority;
import org.apache.rave.portal.model.User;
import org.apache.rave.portal.model.impl.UserImpl;
import org.apache.rave.portal.web.model.UserForm;
+import org.apache.rave.util.CollectionUtils;
/**
*/
@@ -13,7 +15,7 @@ public class ModelUtils {
public static User convert(UserForm form) {
User newUser = new UserImpl(form.getId(), form.getUsername());
- newUser.setAuthorities(form.getAuthorities());
+ newUser.setAuthorities(CollectionUtils.<Authority>toBaseTypedCollection(form.getAuthorities()));
newUser.setPassword(form.getPassword());
newUser.setConfirmPassword(form.getConfirmPassword());
newUser.setForgotPasswordHash(form.getForgotPasswordHash());
Modified: rave/branches/model_interfaces/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/model/UserForm.java
URL: http://svn.apache.org/viewvc/rave/branches/model_interfaces/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/model/UserForm.java?rev=1352182&r1=1352181&r2=1352182&view=diff
==============================================================================
--- rave/branches/model_interfaces/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/model/UserForm.java (original)
+++ rave/branches/model_interfaces/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/model/UserForm.java Wed Jun 20 15:59:58 2012
@@ -1,6 +1,6 @@
package org.apache.rave.portal.web.model;
-import org.apache.rave.portal.model.Authority;
+import org.apache.rave.portal.model.impl.AuthorityImpl;
import java.util.ArrayList;
import java.util.Collection;
@@ -11,7 +11,7 @@ import java.util.Collection;
public class UserForm {
private Long id;
- private Collection<Authority> authorities;
+ private Collection<AuthorityImpl> authorities;
private String password;
private String username;
private String confirmPassword;
@@ -36,7 +36,7 @@ public class UserForm {
}
public UserForm() {
- this.authorities = new ArrayList<Authority>();
+ this.authorities = new ArrayList<AuthorityImpl>();
}
@@ -48,11 +48,11 @@ public class UserForm {
this.id = id;
}
- public Collection<Authority> getAuthorities() {
+ public Collection<AuthorityImpl> getAuthorities() {
return authorities;
}
- public void setAuthorities(Collection<Authority> authorities) {
+ public void setAuthorities(Collection<AuthorityImpl> authorities) {
this.authorities = authorities;
}
Modified: rave/branches/model_interfaces/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/tag/RegionWidgetTagTest.java
URL: http://svn.apache.org/viewvc/rave/branches/model_interfaces/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/tag/RegionWidgetTagTest.java?rev=1352182&r1=1352181&r2=1352182&view=diff
==============================================================================
--- rave/branches/model_interfaces/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/tag/RegionWidgetTagTest.java (original)
+++ rave/branches/model_interfaces/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/tag/RegionWidgetTagTest.java Wed Jun 20 15:59:58 2012
@@ -30,7 +30,6 @@ import org.apache.rave.portal.web.render
import org.apache.rave.portal.web.renderer.ScriptManager;
import org.apache.rave.portal.web.renderer.model.RenderContext;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.context.WebApplicationContext;
@@ -143,7 +142,6 @@ public class RegionWidgetTagTest {
}
@Test(expected = JspException.class)
- @Ignore // TODO Broken with interface migration
public void doStartTag_unsupportedWidget() throws JspException {
replay(pageContext);
@@ -165,7 +163,6 @@ public class RegionWidgetTagTest {
}
@Test
- @Ignore // TODO Broken with interface migration
public void doStartTag_disabledWidget() throws IOException, JspException {
final String DISABLED_WIDGET_MESSAGE = "THIS IS DISABLED";