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

Modified Files:
        PreferenceHibernateService.java 
Log Message:
CMSC-947, Improve the newletter import/export into a generic community 
import/export,cheched the code


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


Index: PreferenceHibernateService.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/preferences/PreferenceHibernateService.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- PreferenceHibernateService.java     15 Jul 2008 04:39:16 -0000      1.8
+++ PreferenceHibernateService.java     15 Jul 2008 12:30:31 -0000      1.9
@@ -241,6 +241,7 @@
    public void createPreference(PreferenceVO preference) {      
       
createPreference(preference.getModule(),preference.getUserId(),preference.getKey(),preference.getValue());
    }
+    
     @Transactional
     public void createPreference(Preference preference,String userId) {      
        
createPreference(preference.getModule(),userId,preference.getKey(),preference.getValue());
@@ -249,7 +250,8 @@
     @Transactional
    public void updatePreference(PreferenceVO preferenceVO) {
       try {
-         Preference preference = 
(Preference)getSession().load(Preference.class, 
Long.parseLong(preferenceVO.getId()));
+                       Preference preference = (Preference) getSession().load(
+                                       Preference.class, 
Long.parseLong(preferenceVO.getId()));
          preference.setKey(preferenceVO.getKey());
          preference.setValue(preferenceVO.getValue());
          getSession().saveOrUpdate(preference);
@@ -260,19 +262,23 @@
     
     @Transactional
    public void deletePreference(String number) {
-      Preference preference = (Preference)getSession().get(Preference.class, 
Long.parseLong(number));
+               Preference preference = (Preference) 
getSession().get(Preference.class,
+                               Long.parseLong(number));
       getSession().delete(preference);
   }
+
     public void deletePreference(long number) {
-        Preference preference = (Preference)getSession().get(Preference.class, 
number);
+               Preference preference = (Preference) 
getSession().get(Preference.class,
+                               number);
       getSession().delete(preference);
   }
     
     @Transactional(readOnly = true)
    public List<String> getAllUserIds() {
-      List<Authentication> authentications = 
authenticationService.findAuthentications();
+               List<Authentication> authentications = authenticationService
+                               .findAuthentications();
       List<String> userIds = new ArrayList<String>();
-      for(Authentication authentication : authentications) {
+               for (Authentication authentication : authentications) {
          userIds.add(authentication.getUserId());
       }
       return userIds;
@@ -281,34 +287,39 @@
     @Transactional(readOnly = true)
     public int getTotalCount(PreferenceVO preference) {
        Criteria criteria = getSession().createCriteria(Preference.class);
-       if(preference != null) {
+               if (preference != null) {
 
-          if(StringUtils.isNotBlank(preference.getUserId())) {
-             Criteria authentication = 
getSession().createCriteria(Authentication.class);
-             authentication.add(Restrictions.ilike("userId", 
"%"+preference.getUserId()+"%"));
+                       if (StringUtils.isNotBlank(preference.getUserId())) {
+                               Criteria authentication = 
getSession().createCriteria(
+                                               Authentication.class);
+                               authentication.add(Restrictions.ilike("userId", 
"%"
+                                               + preference.getUserId() + 
"%"));
              List<Authentication>  authentications = authentication.list();
              List<Long> authenticationIds = new ArrayList<Long>();
-             for(Authentication authe : authentications) {
+                               for (Authentication authe : authentications) {
                 authenticationIds.add(authe.getId());
              }
-             if(authenticationIds.size() > 0) {
-                criteria.add(Restrictions.in("authenticationId", 
authenticationIds));
-             }
-
-          }
-          
-          if(StringUtils.isNotBlank(preference.getModule())) {
-             criteria.add(Restrictions.ilike("module", 
"%"+preference.getModule()+"%"));
-          }
-          if(StringUtils.isNotBlank(preference.getKey())) {
-             criteria.add(Restrictions.ilike("key", 
"%"+preference.getKey()+"%"));
-          }
-          if(StringUtils.isNotBlank(preference.getValue())) {
-             criteria.add(Restrictions.ilike("value", 
"%"+preference.getValue()+"%"));
+                               if (authenticationIds.size() > 0) {
+                                       
criteria.add(Restrictions.in("authenticationId",
+                                                       authenticationIds));
+                               }
+                       }
+                       if (StringUtils.isNotBlank(preference.getModule())) {
+                               criteria.add(Restrictions.ilike("module", "%"
+                                               + preference.getModule() + 
"%"));
+                       }
+                       if (StringUtils.isNotBlank(preference.getKey())) {
+                               criteria.add(Restrictions.ilike("key", "%"
+                                               + preference.getKey() + "%"));
+                       }
+                       if (StringUtils.isNotBlank(preference.getValue())) {
+                               criteria.add(Restrictions.ilike("value", "%"
+                                               + preference.getValue() + "%"));
           }
        }
        return criteria.list().size();
     }
+    
    private void copyPropertiesToVO(List<PreferenceVO> dest,List<Preference> 
src) {
       if(src == null || src.size() == 0) {
          return;
@@ -324,11 +335,13 @@
          dest.add(preferenceVO);
       }
    }
+   
    @Transactional  
    private String getUserIdByAuthenticationId(Long authenticationId){
       Authentication authentication = 
authenticationService.getAuthenticationById(authenticationId);
       return authentication.getUserId();
    }
+   
    @Transactional 
        public void batchCleanByAuthenticationId(long authenticationId) {
                String hqlDelete = "delete Preference where authenticationid 
=:authenticationId";
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to