Update of /var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/person In directory james.mmbase.org:/tmp/cvs-serv5044/src/java/com/finalist/cmsc/services/community/person
Modified Files: PersonHibernateService.java PersonService.java Log Message: CMSC-1265 - Community: improve import and export options of community users 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-1265 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.25 retrieving revision 1.26 diff -u -b -r1.25 -r1.26 --- PersonHibernateService.java 2 Dec 2008 06:39:34 -0000 1.25 +++ PersonHibernateService.java 23 Feb 2009 09:11:50 -0000 1.26 @@ -8,7 +8,14 @@ */ package com.finalist.cmsc.services.community.person; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + import org.apache.commons.lang.StringUtils; import org.hibernate.Criteria; import org.hibernate.Query; @@ -19,6 +26,7 @@ import org.springframework.beans.factory.annotation.Required; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; + import com.finalist.cmsc.paging.PagingStatusHolder; import com.finalist.cmsc.paging.PagingUtils; import com.finalist.cmsc.services.HibernateService; @@ -27,6 +35,7 @@ import com.finalist.cmsc.services.community.preferences.PreferenceService; import com.finalist.cmsc.services.community.security.Authentication; import com.finalist.cmsc.services.community.security.AuthenticationService; +import com.finalist.cmsc.services.community.security.Authority; /** * @author Remco Bos @@ -210,10 +219,26 @@ @SuppressWarnings("unchecked") public void creatRelationRecord(PersonExportImportVO xperson) { Authentication authentication = xperson.getAuthentication(); + if(authenticationService.authenticationExists(authentication.getUserId()) && xperson.getAuthorityId()>0 ){ + Authority authority = this.getAuthorityById(xperson.getAuthorityId()); + if(null!=authority){ + authentication = authenticationService.getAuthenticationById(authenticationService.getAuthenticationIdForUserId(authentication.getUserId())); + authentication.getAuthorities().add(authority); + getSession().saveOrUpdate(authentication); + } + } + else if(!authenticationService.authenticationExists(authentication.getUserId())){ authentication = authenticationService.createAuthentication(authentication); + if(xperson.getAuthorityId()>0 ){ + Authority authority = this.getAuthorityById(xperson.getAuthorityId()); + if (null!=authentication.getAuthorities()) { + authentication.getAuthorities().add(authority); + } + } Person person = new Person(); converPersonPropertis(xperson, person); person.setAuthenticationId(authentication.getId()); + getSession().saveOrUpdate(authentication); updatePerson(person); String userId = xperson.getAuthentication().getUserId(); List < Preference > preferences = xperson.getPreferences(); @@ -223,6 +248,7 @@ } } } + } @Transactional(readOnly = true) public List < PersonExportImportVO > getPersonExportImportVO() { @@ -237,6 +263,19 @@ } return XPersons; } + @Transactional(readOnly = true) + public List < PersonExportImportVO > getPersonExportImportVO(String group) { + List < PersonExportImportVO > XPersons = new ArrayList < PersonExportImportVO >(); + List < Person > persons = getPersonsByGroup(group); + if (null == persons) { + return null; + } + for (Person tempPerson : persons) { + PersonExportImportVO o = transformToPersonExportImportVO(tempPerson); + XPersons.add(o); + } + return XPersons; + } private void converPersonPropertis(Person t, Person o) { o.setFirstName(t.getFirstName()); @@ -245,6 +284,8 @@ o.setLastName(t.getLastName()); o.setEmail(t.getEmail()); o.setUri(t.getUri()); + o.setActive(t.getActive()); + o.setRegisterDate(t.getRegisterDate()); } private PersonExportImportVO transformToPersonExportImportVO(Person tempPerson) { @@ -261,6 +302,14 @@ o.setPreferences(preferences); return o; } + private List<Person> getPersonsByGroup(String groupId){ + String sql = "select distinct person from Person person , Authentication authentication " + + "left join authentication.authorities authority " + + "where person.authenticationId = authentication.id"+ + " and authority.id = "+Integer.parseInt(groupId); + Query q = getSession().createQuery(sql); + return q.list(); + } @Transactional(readOnly = true) public List < Person > getAssociatedPersons(Map conditions) { @@ -378,11 +427,20 @@ private void updateRelationRecord(Person oldDataPerson, PersonExportImportVO importPerson) { Session session = getSession(); Authentication activedAuthentication = importPerson.getAuthentication(); + if(importPerson.getAuthorityId()>0){ + Authority authority = this.getAuthorityById(importPerson.getAuthorityId()); + activedAuthentication.getAuthorities().add(authority); + } Authentication dbAuthentication = (Authentication) session.load(Authentication.class, oldDataPerson.getId()); converPersonPropertis(importPerson, oldDataPerson); converAuthenticationPropertis(activedAuthentication, dbAuthentication); parsePreferences(importPerson, session, activedAuthentication, dbAuthentication); } + private Authority getAuthorityById(Long authorityId){ + Criteria criteria = getSession().createCriteria(Authority.class).add( + Restrictions.eq("id", authorityId)); + return (Authority)criteria.list().get(0); + } private void parsePreferences(PersonExportImportVO importPerson, Session session, Authentication activedAuthentication, Authentication dbAuthentication) { @@ -423,13 +481,14 @@ @Transactional public void addRelationRecord(String level, PersonExportImportVO importPerson) { Person p = getPersonByUserId(importPerson.getAuthentication().getUserId()); - if (null != p && "over".equals(level)) { + if ("over".equals(level)) { updateRelationRecord(p, importPerson); } - if (null == p) { - // only add new users + else{ + // add new users or put user to another group creatRelationRecord(importPerson); } + } @Transactional public void changeStateByAuthenticationId(Long authenticationId, String active) { @@ -437,4 +496,10 @@ per.setActive(active); updatePerson(per); } + @Transactional + public List<Authority> getAllAuthorities() { + Criteria criteria = getSession().createCriteria(Authority.class); + criteria = criteria.setResultTransformer(criteria.DISTINCT_ROOT_ENTITY); + return criteria.list(); + } } 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.18 retrieving revision 1.19 diff -u -b -r1.18 -r1.19 --- PersonService.java 2 Dec 2008 06:39:34 -0000 1.18 +++ PersonService.java 23 Feb 2009 09:11:50 -0000 1.19 @@ -13,6 +13,7 @@ import java.util.Map; import java.util.Set; import com.finalist.cmsc.services.community.domain.PersonExportImportVO; +import com.finalist.cmsc.services.community.security.Authority; /** * This service encapsulates the management of people and groups. @@ -83,4 +84,8 @@ public void addRelationRecord(String level, PersonExportImportVO importPerson); void changeStateByAuthenticationId(Long authenticationId, String active); + + public List<PersonExportImportVO> getPersonExportImportVO(String group); + + public List<Authority> getAllAuthorities(); } _______________________________________________ Cvs mailing list Cvs@lists.mmbase.org http://lists.mmbase.org/mailman/listinfo/cvs