Update of 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/person
In directory 
james.mmbase.org:/tmp/cvs-serv10025/community/src/java/com/finalist/cmsc/services/community/person

Modified Files:
        PersonService.java PersonHibernateService.java Person.java 
Log Message:
CMSC-617 Personal Pages module
Synced branch 1.4 fixes to head


See also: 
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/person
See also: http://www.mmbase.org/jira/browse/CMSC-617


Index: PersonService.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/person/PersonService.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- PersonService.java  29 Jan 2008 09:59:40 -0000      1.2
+++ PersonService.java  31 Mar 2008 19:49:02 -0000      1.3
@@ -6,9 +6,11 @@
 The license (Mozilla version 1.0) can be read at the MMBase site.
 See http://www.MMBase.org/license
 
-*/
+ */
 package com.finalist.cmsc.services.community.person;
 
+import java.util.List;
+
 /**
  * This service encapsulates the management of people and groups.
  * 
@@ -23,8 +25,25 @@
 
     Person getPersonByUserId(String userId);
     
-    void createPerson(String firstName, String infix, String lastName, String 
userId);
+   /**
+    * Get a list of matching persons that match the given example. The fields
+    * that are set on the example Person are the criteria for the search.
+    *
+    * @param example
+    *           the example person
+    * @return a list of persons that match the given example.
+    */
+   List<Person> getPersons(Person example);
+
+   Person getPersonByAuthenticationId(Long authenticationId);
+
+   Person createPerson(String firstName, String infix, String lastName, Long 
authenticationId);
+
+   /*
+    * Save or update the person to the database
+    */
+   void updatePerson(Person person);
 
-    void deletePersonByUserId(String userId);
+   boolean deletePersonByAuthenticationId(Long userId);
 
 }


Index: PersonHibernateService.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/person/PersonHibernateService.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- PersonHibernateService.java 22 Feb 2008 12:39:37 -0000      1.3
+++ PersonHibernateService.java 31 Mar 2008 19:49:02 -0000      1.4
@@ -9,11 +9,12 @@
  */
 package com.finalist.cmsc.services.community.person;
 
+import java.util.Collections;
 import java.util.List;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.StringUtils;
 import org.hibernate.Criteria;
+import org.hibernate.criterion.Example;
 import org.hibernate.criterion.Restrictions;
 import org.springframework.beans.factory.annotation.Required;
 import org.springframework.transaction.annotation.Transactional;
@@ -26,50 +27,78 @@
  */
 public class PersonHibernateService extends HibernateService implements 
PersonService {
 
-       private static Log log = 
LogFactory.getLog(PersonHibernateService.class);
-
        private AuthenticationService authenticationService;
 
        /** [EMAIL PROTECTED] */
        @Transactional(readOnly = true)
        public Person getPersonByUserId(String userId) {
+      if (StringUtils.isBlank(userId)) {
+         throw new IllegalArgumentException("UserId is not filled in. ");
+      }
                return findPersonByUserId(userId);
        }
 
        /** [EMAIL PROTECTED] */
        @Transactional
-       public void createPerson(String firstName, String infix, String 
lastName, String userId) {
-               Long authenticationId = 
authenticationService.getAuthenticationIdForUserId(userId);
+   @SuppressWarnings("unchecked")
+   public List<Person> getPersons(Person example) {
+      if (example == null) {
+         return Collections.emptyList();
+      }
+
+      List personList = 
getSession().createCriteria(Person.class).add(Example.create(example)).list();
+      return personList;
+
+   }
+
+   /** [EMAIL PROTECTED] */
+   @Transactional
+   public Person createPerson(String firstName, String infix, String lastName, 
Long authenticationId) {
+      if (firstName == null) {
+         throw new IllegalArgumentException("Firstname is null. ");
+      }
+      if (lastName == null) {
+         throw new IllegalArgumentException("Lastname is null. ");
+      }
+      if (authenticationId == null) {
+         throw new IllegalArgumentException("authenticationId is not filled 
in. ");
+      }
+
                if (authenticationId != null) {
                        Person person = new Person();
                        person.setFirstName(firstName);
                        person.setInfix(infix);
                        person.setLastName(lastName);
-                       person.setAuthenticationId(authenticationId);
+         person.setAuthenticationId(authenticationId); // used to find account
                        getSession().save(person);
+         return person;
                }
+      return null;
+   }
+
+   /** [EMAIL PROTECTED] */
+   @Transactional
+   public void updatePerson(Person person) {
+      getSession().saveOrUpdate(person);
+      getSession().flush();
        }
 
        /** [EMAIL PROTECTED] */
        @Transactional
-       public void deletePersonByUserId(String userId) {
-               if (userId != null) {
-                       Person person = findPersonByUserId(userId);
+   public boolean deletePersonByAuthenticationId(Long authenticationId) {
+      if (authenticationId != null) {
+         Person person = getPersonByAuthenticationId(authenticationId);
                        if (person != null) {
                                getSession().delete(person);
+            return true;
                        }
                }
+      return false;
        }
 
        private Person findPersonByUserId(String userId) {
                Long authenticationId = 
authenticationService.getAuthenticationIdForUserId(userId);
-               Person person = null;
-               if (authenticationId != null) {
-                       Criteria criteria = 
getSession().createCriteria(Person.class).add(
-                                       Restrictions.eq("authenticationId", 
authenticationId));
-                       person = findPersonByCriteria(criteria);
-               }
-               return person;
+      return getPersonByAuthenticationId(authenticationId);
        }
 
        @SuppressWarnings("unchecked")
@@ -82,4 +111,16 @@
        public void setAuthenticationService(AuthenticationService 
authenticationService) {
                this.authenticationService = authenticationService;
        }
+
+   /** [EMAIL PROTECTED] */
+   @Transactional(readOnly = true)
+   public Person getPersonByAuthenticationId(Long authenticationId) {
+      Person person = null;
+      if (authenticationId != null) {
+         Criteria criteria = 
getSession().createCriteria(Person.class).add(Restrictions.eq("authenticationId",
 authenticationId));
+         person = findPersonByCriteria(criteria);
+      }
+      return person;
+   }
+
 }


Index: Person.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/person/Person.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- Person.java 29 Jan 2008 09:59:40 -0000      1.2
+++ Person.java 31 Mar 2008 19:49:02 -0000      1.3
@@ -25,7 +25,7 @@
     @GeneratedValue
     private Long id;
 
-    private Long authenticationId; // his/her credentials (usually an e-mail 
adress and password)
+   private Long authenticationId; // his/her credentials (usually an e-mail 
address and password)
 
     private String firstName;
     private String lastName;
@@ -121,6 +121,4 @@
                return true;
        }
        
-       
-
 }
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to