Author: cgeer
Date: Thu May 31 03:13:44 2012
New Revision: 1344550

URL: http://svn.apache.org/viewvc?rev=1344550&view=rev
Log:
RAVE-635 Initial cutover of Group to be interface based.

Added:
    
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/GroupImpl.java
    
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/JpaGroup.java
      - copied, changed from r1344517, 
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/Group.java
    
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/conversion/JpaGroupConverter.java
    
rave/branches/model_interfaces/rave-components/rave-core/src/test/java/org/apache/rave/portal/model/conversion/JpaGroupConverterTest.java
Removed:
    
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/Group.java
Modified:
    
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/JpaPerson.java
    
rave/branches/model_interfaces/rave-providers/rave-opensocial-provider/rave-opensocial-core/src/main/java/org/apache/rave/opensocial/repository/impl/JpaPersonRepository.java
    
rave/branches/model_interfaces/rave-providers/rave-opensocial-provider/rave-opensocial-core/src/main/resources/META-INF/persistence.xml

Added: 
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/GroupImpl.java
URL: 
http://svn.apache.org/viewvc/rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/GroupImpl.java?rev=1344550&view=auto
==============================================================================
--- 
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/GroupImpl.java
 (added)
+++ 
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/GroupImpl.java
 Thu May 31 03:13:44 2012
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.rave.portal.model;
+
+import java.util.List;
+
+public class GroupImpl implements Group {
+
+    protected String description;
+    protected Long entityId;
+    protected Person owner;
+    protected String title;
+    protected List<Person> members;
+
+    @Override
+    public Person getOwner() {
+        return owner;
+    }
+
+    @Override
+    public void setOwner(Person owner) {
+        this.owner = owner;
+    }
+
+    @Override
+    public String getDescription() {
+        return description;
+    }
+
+    @Override
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    @Override
+    public List<Person> getMembers() {
+        return members;
+    }
+
+    @Override
+    public void setMembers(List<Person> members) {
+        this.members = members;
+    }
+
+    @Override
+    public String getTitle() {
+        return this.title;
+    }
+
+    @Override
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    @Override
+    public Long getEntityId() {
+        return this.entityId;
+    }
+
+    @Override
+    public void setEntityId(Long entityId) {
+        this.entityId = entityId;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = description != null ? description.hashCode() : 0;
+        result = 31 * result + (entityId != null ? entityId.hashCode() : 0);
+        result = 31 * result + (owner != null ? owner.hashCode() : 0);
+        result = 31 * result + (title != null ? title.hashCode() : 0);
+        result = 31 * result + (members != null ? members.hashCode() : 0);
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof GroupImpl)) return false;
+
+        GroupImpl group = (GroupImpl) o;
+
+        if (description != null ? !description.equals(group.description) : 
group.description != null) return false;
+        if (entityId != null ? !entityId.equals(group.entityId) : 
group.entityId != null) return false;
+        if (owner != null ? !owner.equals(group.owner) : group.owner != null) 
return false;
+        if (members != null ? !members.equals(group.members) : group.members 
!= null) return false;
+        if (title != null ? !title.equals(group.title) : group.title != null) 
return false;
+
+        return true;
+    }
+}

Copied: 
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/JpaGroup.java
 (from r1344517, 
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/Group.java)
URL: 
http://svn.apache.org/viewvc/rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/JpaGroup.java?p2=rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/JpaGroup.java&p1=rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/Group.java&r1=1344517&r2=1344550&rev=1344550&view=diff
==============================================================================
--- 
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/Group.java
 (original)
+++ 
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/JpaGroup.java
 Thu May 31 03:13:44 2012
@@ -19,8 +19,13 @@
 package org.apache.rave.portal.model;
 
 import org.apache.rave.persistence.BasicEntity;
+import org.apache.rave.portal.model.conversion.ConvertingListProxyFactory;
+import org.apache.rave.portal.model.conversion.JpaConverter;
+import org.apache.rave.portal.model.conversion.JpaGroupConverter;
+import org.apache.rave.portal.model.conversion.JpaPersonConverter;
 
 import javax.persistence.*;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -30,9 +35,9 @@ import java.util.List;
 @Entity
 @Table(name = "groups")
 @NamedQueries(
-        @NamedQuery(name = Group.FIND_BY_TITLE, query="select g from Group g 
where g.title = :groupId")
+        @NamedQuery(name = JpaGroup.FIND_BY_TITLE, query="select g from 
JpaGroup g where g.title = :groupId")
 )
-public class Group implements BasicEntity {
+public class JpaGroup implements BasicEntity, Group {
 
     public static final String FIND_BY_TITLE = "Group.findById";
     public static final String GROUP_ID_PARAM = "groupId";
@@ -73,8 +78,9 @@ public class Group implements BasicEntit
         return owner;
     }
 
-    public void setOwner(JpaPerson owner) {
-        this.owner = owner;
+    public void setOwner(Person owner) {
+        JpaPersonConverter converter = new JpaPersonConverter();
+        this.owner = converter.convert(owner);
     }
 
     public String getDescription() {
@@ -85,12 +91,16 @@ public class Group implements BasicEntit
         this.description = description;
     }
 
-    public List<JpaPerson> getMembers() {
-        return members;
+    public List<Person> getMembers() {
+        return ConvertingListProxyFactory.createProxyList(Person.class, 
members);
     }
 
-    public void setMembers(List<JpaPerson> members) {
-        this.members = members;
+    public void setMembers(List<Person> members) {
+        if(this.members == null) {
+            this.members = new ArrayList<JpaPerson>();
+        }
+        this.getMembers().clear();
+        this.getMembers().addAll(members);
     }
 
     public String getTitle() {

Modified: 
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/JpaPerson.java
URL: 
http://svn.apache.org/viewvc/rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/JpaPerson.java?rev=1344550&r1=1344549&r2=1344550&view=diff
==============================================================================
--- 
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/JpaPerson.java
 (original)
+++ 
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/JpaPerson.java
 Thu May 31 03:13:44 2012
@@ -33,7 +33,7 @@ import java.util.List;
 @NamedQueries(value = {
     @NamedQuery(name = JpaPerson.FIND_BY_USERNAME, query = "select p from 
JpaPerson p where p.username like :username"),
     @NamedQuery(name = JpaPerson.FIND_FRIENDS_BY_USERNAME, query = "select 
a.followed from PersonAssociation a where a.follower.username = :username"),
-    @NamedQuery(name = JpaPerson.FIND_BY_GROUP_MEMBERSHIP, query = "select m 
from Group g join g.members m where exists " +
+    @NamedQuery(name = JpaPerson.FIND_BY_GROUP_MEMBERSHIP, query = "select m 
from JpaGroup g join g.members m where exists " +
             "(select 'found' from g.members b where b.username = :username) 
and m.username <> :username")
 })
 public class JpaPerson implements BasicEntity, Person {

Added: 
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/conversion/JpaGroupConverter.java
URL: 
http://svn.apache.org/viewvc/rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/conversion/JpaGroupConverter.java?rev=1344550&view=auto
==============================================================================
--- 
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/conversion/JpaGroupConverter.java
 (added)
+++ 
rave/branches/model_interfaces/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/conversion/JpaGroupConverter.java
 Thu May 31 03:13:44 2012
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.rave.portal.model.conversion;
+
+import org.apache.rave.model.ModelConverter;
+import org.apache.rave.portal.model.Group;
+import org.apache.rave.portal.model.JpaGroup;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.TypedQuery;
+import java.util.List;
+
+import static org.apache.rave.persistence.jpa.util.JpaUtil.getSingleResult;
+
+public class JpaGroupConverter implements ModelConverter<Group, JpaGroup> {
+    @PersistenceContext(unitName = "ravePersistenceUnit")
+    private EntityManager manager;
+
+    @Override
+    public Class<Group> getSourceType() {
+        return Group.class;
+    }
+
+    @Override
+    public JpaGroup convert(Group source) {
+        return source instanceof JpaGroup ? (JpaGroup)source : 
createEntity(source);
+    }
+
+    private JpaGroup createEntity(Group source) {
+        JpaGroup converted;
+        TypedQuery<JpaGroup> query = 
manager.createNamedQuery(JpaGroup.FIND_BY_TITLE, JpaGroup.class);
+        query.setParameter(JpaGroup.GROUP_ID_PARAM, source.getEntityId());
+        converted = getSingleResult(query.getResultList());
+
+        if(converted == null) {
+            converted = new JpaGroup();
+        }
+        updateProperties(source, converted);
+        return converted;
+    }
+
+    private void updateProperties(Group source, JpaGroup converted) {
+        converted.setDescription(source.getDescription());
+        converted.setTitle(source.getTitle());
+        converted.setEntityId(source.getEntityId());
+        converted.setOwner(source.getOwner());
+        converted.setMembers(source.getMembers());
+    }
+}

Added: 
rave/branches/model_interfaces/rave-components/rave-core/src/test/java/org/apache/rave/portal/model/conversion/JpaGroupConverterTest.java
URL: 
http://svn.apache.org/viewvc/rave/branches/model_interfaces/rave-components/rave-core/src/test/java/org/apache/rave/portal/model/conversion/JpaGroupConverterTest.java?rev=1344550&view=auto
==============================================================================
--- 
rave/branches/model_interfaces/rave-components/rave-core/src/test/java/org/apache/rave/portal/model/conversion/JpaGroupConverterTest.java
 (added)
+++ 
rave/branches/model_interfaces/rave-components/rave-core/src/test/java/org/apache/rave/portal/model/conversion/JpaGroupConverterTest.java
 Thu May 31 03:13:44 2012
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.rave.portal.model.conversion;
+
+import static org.junit.Assert.*;
+
+import org.apache.rave.portal.model.*;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.util.ArrayList;
+import java.util.List;
+
+//@RunWith(SpringJUnit4ClassRunner.class)
+//@ContextConfiguration(locations={"classpath:test-applicationContext.xml","classpath:test-dataContext.xml"}
 )
+public class JpaGroupConverterTest {
+
+//    private Group group;
+//
+//    private String description = "Test Group";
+//    private Long entityId = Long.valueOf(400);
+//    private String title = "GroupTitle";
+//    private Person owner = null;
+//    private List<Person> members = null;
+//
+//    private String ownerDisplayName = "Bob";
+//    private String ownerGivenName = "Smith";
+//
+//    public void setup() {
+//        members = new ArrayList<Person>();
+//        owner = new PersonImpl();
+//        owner.setDisplayName(ownerDisplayName);
+//        owner.setGivenName(ownerGivenName);
+//        members.add(owner);
+//
+//        group = new GroupImpl();
+//        group.setDescription(description);
+//        group.setEntityId(entityId);
+//        group.setTitle(title);
+//        group.setOwner(owner);
+//        group.setMembers(members);
+//    }
+//
+//    @Test
+//    public void testConvertGroupToJpaGroup() {
+//        JpaGroupConverter converter = new JpaGroupConverter();
+//
+//        JpaGroup jpaGroup = converter.convert(group);
+//
+//        assertEquals(description, jpaGroup.getDescription());
+//        assertEquals(entityId, jpaGroup.getEntityId());
+//        assertEquals(title, jpaGroup.getTitle());
+//        assertEquals(owner, jpaGroup.getOwner());
+//        assertEquals(members.size(), jpaGroup.getMembers().size());
+//    }
+
+}

Modified: 
rave/branches/model_interfaces/rave-providers/rave-opensocial-provider/rave-opensocial-core/src/main/java/org/apache/rave/opensocial/repository/impl/JpaPersonRepository.java
URL: 
http://svn.apache.org/viewvc/rave/branches/model_interfaces/rave-providers/rave-opensocial-provider/rave-opensocial-core/src/main/java/org/apache/rave/opensocial/repository/impl/JpaPersonRepository.java?rev=1344550&r1=1344549&r2=1344550&view=diff
==============================================================================
--- 
rave/branches/model_interfaces/rave-providers/rave-opensocial-provider/rave-opensocial-core/src/main/java/org/apache/rave/opensocial/repository/impl/JpaPersonRepository.java
 (original)
+++ 
rave/branches/model_interfaces/rave-providers/rave-opensocial-provider/rave-opensocial-core/src/main/java/org/apache/rave/opensocial/repository/impl/JpaPersonRepository.java
 Thu May 31 03:13:44 2012
@@ -20,11 +20,10 @@
 package org.apache.rave.opensocial.repository.impl;
 
 import org.apache.rave.exception.NotSupportedException;
-import org.apache.rave.portal.model.Group;
+import org.apache.rave.portal.model.JpaGroup;
 import org.apache.rave.portal.model.JpaPerson;
 import org.apache.rave.portal.model.Person;
 import org.apache.rave.opensocial.repository.PersonRepository;
-import org.apache.rave.persistence.jpa.AbstractJpaRepository;
 import org.apache.rave.portal.model.conversion.JpaPersonConverter;
 import org.apache.rave.util.CollectionUtils;
 import org.apache.shindig.protocol.model.FilterOperation;
@@ -108,9 +107,9 @@ public class JpaPersonRepository impleme
 
     @Override
     public List<Person> findByGroup(String groupId) {
-        TypedQuery<Group> query = 
manager.createNamedQuery(Group.FIND_BY_TITLE, Group.class);
-        query.setParameter(Group.GROUP_ID_PARAM, groupId);
-        Group result = getSingleResult(query.getResultList());
+        TypedQuery<JpaGroup> query = 
manager.createNamedQuery(JpaGroup.FIND_BY_TITLE, JpaGroup.class);
+        query.setParameter(JpaGroup.GROUP_ID_PARAM, groupId);
+        JpaGroup result = getSingleResult(query.getResultList());
         return result == null ? new ArrayList<Person>() : 
CollectionUtils.<Person>toBaseTypedList(result.getMembers());
     }
 

Modified: 
rave/branches/model_interfaces/rave-providers/rave-opensocial-provider/rave-opensocial-core/src/main/resources/META-INF/persistence.xml
URL: 
http://svn.apache.org/viewvc/rave/branches/model_interfaces/rave-providers/rave-opensocial-provider/rave-opensocial-core/src/main/resources/META-INF/persistence.xml?rev=1344550&r1=1344549&r2=1344550&view=diff
==============================================================================
--- 
rave/branches/model_interfaces/rave-providers/rave-opensocial-provider/rave-opensocial-core/src/main/resources/META-INF/persistence.xml
 (original)
+++ 
rave/branches/model_interfaces/rave-providers/rave-opensocial-provider/rave-opensocial-core/src/main/resources/META-INF/persistence.xml
 Thu May 31 03:13:44 2012
@@ -24,7 +24,7 @@
   <persistence-unit name="raveShindigPersistenceUnit" 
transaction-type="RESOURCE_LOCAL">
       
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
       <class>org.apache.rave.portal.model.JpaPerson</class>
-      <class>org.apache.rave.portal.model.Group</class>
+      <class>org.apache.rave.portal.model.JpaGroup</class>
       <class>org.apache.rave.portal.model.PersonAssociation</class>
       <class>org.apache.rave.portal.model.JpaPersonProperty</class>
       <class>org.apache.rave.portal.model.JpaAddress</class>


Reply via email to