Clover coverage report - Prayer Portlets - 0.1-rc4-SNAPSHOT
Coverage timestamp: Thu Aug 19 2004 18:34:34 EDT
file stats: LOC: 121   Methods: 8
NCLOC: 89   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
LiferayUserManager.java 0% 25% 62.5% 29.2%
coverage coverage
 1   
 package org.marketchangers.liferay;
 2   
 
 3   
 import java.rmi.RemoteException;
 4   
 import java.util.ArrayList;
 5   
 import java.util.Collections;
 6   
 import java.util.Iterator;
 7   
 import java.util.List;
 8   
 
 9   
 import org.marketchangers.PortalUser;
 10   
 import org.marketchangers.PortalUserManager;
 11   
 
 12   
 import com.liferay.portal.PortalException;
 13   
 import com.liferay.portal.SystemException;
 14   
 import com.liferay.portal.ejb.RoleManager;
 15   
 import com.liferay.portal.ejb.UserRemoteManager;
 16   
 import com.liferay.portal.model.Address;
 17   
 import com.liferay.portal.model.Role;
 18   
 import com.liferay.portal.model.User;
 19   
 
 20   
 /**
 21   
  * @author <a href="mailto:mtodd@wc-group.com">Matthew Todd</a>
 22   
  */
 23   
 public class LiferayUserManager implements PortalUserManager {
 24   
     private UserRemoteManager userManager;
 25   
     private RoleManager roleManager;
 26   
 
 27   
     // ------------------------------------------------------------ Constructor
 28  12
     public LiferayUserManager(
 29   
         UserRemoteManager userManager,
 30   
         RoleManager roleManager) {
 31   
 
 32  12
         this.userManager = userManager;
 33  12
         this.roleManager = roleManager;
 34   
     }
 35   
 
 36   
     // ---------------------------------------------------- UserRoleManager API
 37  2
     public boolean addRole(String user, String role) {
 38  2
         try {
 39  2
             return userManager.addRole(user, getRole(role));
 40   
         } catch (Exception e) {
 41   
             // TODO need fancier exception handling
 42  0
             throw new RuntimeException(e);
 43   
         }
 44   
     }
 45   
 
 46  4
     public boolean isUserInRole(String user, String role) {
 47  4
         try {
 48  4
             return userManager.getRoles(user).contains(getRole(role));
 49   
         } catch (Exception e) {
 50   
             // TODO need fancier exception handling
 51  0
             throw new RuntimeException(e);
 52   
         }
 53   
     }
 54   
 
 55  2
     public boolean removeRole(String user, String role) {
 56  2
         try {
 57  2
             return userManager.deleteRole(user, getRole(role));
 58   
         } catch (Exception e) {
 59   
             // TODO need fancier exception handling
 60  0
             throw new RuntimeException(e);
 61   
         }
 62   
     }
 63   
 
 64  0
     public PortalUser lookupUserById(String userid) {
 65  0
         PortalUser user = null;
 66  0
         try {
 67  0
             User liferayUser = userManager.getUserById(userid);
 68   
 
 69  0
             user = convertLiferayUser(liferayUser);
 70   
         } catch (Exception e) {
 71   
             // TODO need fancier exception handling
 72  0
             throw new RuntimeException(e);
 73   
         }
 74   
 
 75  0
         return user;
 76   
     }
 77   
 
 78  0
     public List lookupUsersByRole(String roleName) {
 79  0
         List users = new ArrayList();
 80  0
         List liferayUsers = Collections.EMPTY_LIST;
 81   
 
 82  0
         try {
 83  0
             liferayUsers =
 84   
                 roleManager.getUsers(
 85   
                     roleManager.getRoleByName(roleName).getRoleId());
 86  0
             Iterator iUsers = (liferayUsers).iterator();
 87  0
             while (iUsers.hasNext()) {
 88  0
                 users.add(convertLiferayUser((User)iUsers.next()));
 89   
             }
 90   
         } catch (Exception e) {
 91  0
             users = Collections.EMPTY_LIST;
 92   
             // TODO need fancier exception handling
 93  0
             e.printStackTrace();
 94   
         }
 95   
 
 96  0
         return users;
 97   
     }
 98   
 
 99   
     // -------------------------------------------------------- Private Methods
 100  8
     private Role getRole(String role)
 101   
         throws PortalException, SystemException, RemoteException {
 102  8
         return roleManager.getRoleByName(role);
 103   
     }
 104   
 
 105  0
     private PortalUser convertLiferayUser(User liferayUser)
 106   
         throws PortalException, SystemException {
 107  0
         PortalUser user;
 108  0
         user = new PortalUser();
 109  0
         user.setUserId(liferayUser.getUserId());
 110  0
         user.setFullName(liferayUser.getFullName());
 111   
 
 112   
         //TODO - not sure if address description is right place for organization name
 113  0
         List addresses = liferayUser.getAddresses();
 114  0
         if ((addresses != null) && (!addresses.isEmpty())) {
 115  0
             user.setOrganization(((Address)addresses.get(0)).getDescription());
 116   
         }
 117  0
         return user;
 118   
     }
 119   
 
 120   
 }
 121