View Javadoc

1   /**
2    * 
3    */
4   package net.smartlab.web.auth.handlers;
5   
6   import java.util.Map;
7   
8   import org.apache.commons.beanutils.BeanUtils;
9   
10  import net.smartlab.web.BusinessException;
11  import net.smartlab.web.auth.User;
12  import net.smartlab.web.auth.User.Status;
13  
14  /**
15   * @author svetrini
16   */
17  public class BusinessObjectAssociationRegistrationHandler extends AbstractAssociationRegistrationHandler {
18  
19  	public static final String BUSINESS_OBJECT_ASSOCIATION_KEY = "BUSINESS_OBJECT_ASSOCIATION_KEY";
20  
21  
22  	/*
23  	 * (non-Javadoc)
24  	 * 
25  	 * @see net.smartlab.web.auth.handlers.AbstractAssociationRegistrationHandler#associate(java.util.Map,
26  	 *      net.smartlab.web.auth.User)
27  	 */
28  	protected User associate(Map parameters, User user) throws BusinessException {
29  		user.setProperty(BUSINESS_OBJECT_ASSOCIATION_KEY, (String)parameters.get(BUSINESS_OBJECT_ASSOCIATION_KEY));
30  		// update user infos in db
31  		domain.updateUser(user);
32  		return user;
33  	}
34  
35  	/**
36  	 * @param parameters
37  	 * @param user
38  	 * @return
39  	 * @throws BusinessException
40  	 */
41  	protected User updateUser(Map parameters, User user) throws BusinessException {
42  		if (user == null || user.getId() == 0) {
43  			// insert new user in db
44  			user = new User();
45  			try {
46  				BeanUtils.populate(user, parameters);
47  			} catch (Exception e) {
48  				throw new BusinessException("Error inserting user", e);
49  			}
50  		}
51  		user.setStatus(Status.PENDING);
52  		// update user infos in db
53  		domain.updateUser(user);
54  		return user;
55  	}
56  
57  	/*
58  	 * (non-Javadoc)
59  	 * 
60  	 * @see net.smartlab.web.auth.Handler#destroy()
61  	 */
62  	public void destroy() throws Exception {
63  		// TODO Auto-generated method stub
64  	}
65  
66  	/*
67  	 * (non-Javadoc)
68  	 * 
69  	 * @see net.smartlab.web.auth.Handler#init(java.util.Map)
70  	 */
71  	public void init(Map parameters) throws Exception {
72  		// TODO Auto-generated method stub
73  	}
74  }