[jboss-svn-commits] JBL Code SVN: r33541 - in labs/jbosslabs/labs-3.0-build/integration/sbs-nukesauthentication/trunk/src/main: java/org/jboss/labs/sbs/plugin/nukesauth/struts and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jun 18 05:18:02 EDT 2010
Author: lkrzyzanek
Date: 2010-06-18 05:18:01 -0400 (Fri, 18 Jun 2010)
New Revision: 33541
Modified:
labs/jbosslabs/labs-3.0-build/integration/sbs-nukesauthentication/trunk/src/main/java/org/jboss/labs/sbs/plugin/nukesauth/SbsAccountManager.java
labs/jbosslabs/labs-3.0-build/integration/sbs-nukesauthentication/trunk/src/main/java/org/jboss/labs/sbs/plugin/nukesauth/SbsAccountManagerImpl.java
labs/jbosslabs/labs-3.0-build/integration/sbs-nukesauthentication/trunk/src/main/java/org/jboss/labs/sbs/plugin/nukesauth/struts/UpdateMasterAccountAction.java
labs/jbosslabs/labs-3.0-build/integration/sbs-nukesauthentication/trunk/src/main/plugin/resources/templates/update-master-account.ftl
Log:
Implemented updating master account profile fields
Modified: labs/jbosslabs/labs-3.0-build/integration/sbs-nukesauthentication/trunk/src/main/java/org/jboss/labs/sbs/plugin/nukesauth/SbsAccountManager.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs-nukesauthentication/trunk/src/main/java/org/jboss/labs/sbs/plugin/nukesauth/SbsAccountManager.java 2010-06-18 09:16:13 UTC (rev 33540)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs-nukesauthentication/trunk/src/main/java/org/jboss/labs/sbs/plugin/nukesauth/SbsAccountManager.java 2010-06-18 09:18:01 UTC (rev 33541)
@@ -50,13 +50,6 @@
EmailAlreadyExistsException;
/**
- * Update account based on data from nukes
- *
- * @param nukesUser
- */
- public void updateAccount(NukesUser nukesUser);
-
- /**
* Update password.
*
* @param username
Modified: labs/jbosslabs/labs-3.0-build/integration/sbs-nukesauthentication/trunk/src/main/java/org/jboss/labs/sbs/plugin/nukesauth/SbsAccountManagerImpl.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs-nukesauthentication/trunk/src/main/java/org/jboss/labs/sbs/plugin/nukesauth/SbsAccountManagerImpl.java 2010-06-18 09:16:13 UTC (rev 33540)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs-nukesauthentication/trunk/src/main/java/org/jboss/labs/sbs/plugin/nukesauth/SbsAccountManagerImpl.java 2010-06-18 09:18:01 UTC (rev 33541)
@@ -137,13 +137,6 @@
}
@Override
- public void updateAccount(NukesUser nukesUser) {
- if (log.isDebugEnabled()) {
- log.debug("Update account: " + nukesUser);
- }
- }
-
- @Override
public void updatePassword(String username, String password) throws UserNotFoundException {
User user = userManager.getUser(username);
UserTemplate userTemplate = new UserTemplate(user);
Modified: labs/jbosslabs/labs-3.0-build/integration/sbs-nukesauthentication/trunk/src/main/java/org/jboss/labs/sbs/plugin/nukesauth/struts/UpdateMasterAccountAction.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs-nukesauthentication/trunk/src/main/java/org/jboss/labs/sbs/plugin/nukesauth/struts/UpdateMasterAccountAction.java 2010-06-18 09:16:13 UTC (rev 33540)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs-nukesauthentication/trunk/src/main/java/org/jboss/labs/sbs/plugin/nukesauth/struts/UpdateMasterAccountAction.java 2010-06-18 09:18:01 UTC (rev 33541)
@@ -21,14 +21,22 @@
*/
package org.jboss.labs.sbs.plugin.nukesauth.struts;
+import java.util.Date;
import java.util.List;
+import java.util.Map;
import org.jboss.labs.sbs.plugin.nukesauth.NukesAccountManager;
import org.jboss.labs.sbs.plugin.nukesauth.SbsAccountManager;
import org.jboss.labs.sbs.plugin.nukesauth.dao.NukesUser;
import org.jboss.labs.sbs.plugin.nukesauth.dao.NukesUserMapper;
-import com.jivesoftware.community.action.JiveActionSupport;
+import com.jivesoftware.base.UnauthorizedException;
+import com.jivesoftware.base.UserAlreadyExistsException;
+import com.jivesoftware.base.UserNotFoundException;
+import com.jivesoftware.base.UserTemplate;
+import com.jivesoftware.community.JiveRuntimeException;
+import com.jivesoftware.community.action.EditProfileAction;
+import com.jivesoftware.community.user.profile.ProfileFieldValue;
import com.jivesoftware.community.web.struts.SetReferer;
/**
@@ -38,8 +46,10 @@
* @author <a href="mailto:lkrzyzan at redhat.com">Libor Krzyzanek</a>
*/
@SetReferer(false)
-public class UpdateMasterAccountAction extends JiveActionSupport {
+public class UpdateMasterAccountAction extends EditProfileAction {
+ public static final String MASTER_ACCOUNT_SELECTED = "MASTER-ACCOUNT-SELECTED";
+
private List<NukesUser> accounts;
private NukesUser masterAccount;
@@ -49,6 +59,11 @@
private SbsAccountManager sbsAccountManager;
@Override
+ protected UserTemplate getTargetUser() {
+ return new UserTemplate(getUser());
+ }
+
+ @Override
public String input() {
if (isGuest()) {
return UNAUTHENTICATED;
@@ -83,11 +98,88 @@
if (isGuest()) {
return UNAUTHENTICATED;
}
- sbsAccountManager.updateAccount(masterAccount);
+ UserTemplate user = getTargetUser();
+ if (isFieldChanged(masterAccount.getFirstName())) {
+ user.setFirstName(masterAccount.getFirstName());
+ }
+ if (isFieldChanged(masterAccount.getLastName())) {
+ user.setLastName(masterAccount.getLastName());
+ }
+ Map<Long, String> profile = masterAccount.getProfile();
+ // Map<String, String> targetProfile = user.getProperties();
+ Map<Long, ProfileFieldValue> targetProfile = profileManager.getProfile(user);
+
+ // TODO address
+ // updateProfileField(NukesUserMapper.ADDRESS, profile, targetProfile);
+ updateProfileField(NukesUserMapper.PHONE_NUMBER, profile, targetProfile);
+ updateProfileField(NukesUserMapper.ALTERNATE_EMAIL, profile, targetProfile);
+ updateProfileField(NukesUserMapper.YOUR_ICQ_NUMBER, profile, targetProfile);
+ updateProfileField(NukesUserMapper.YOUR_AIM_ADDRESS, profile, targetProfile);
+ updateProfileField(NukesUserMapper.YOUR_YIM_NUMBER, profile, targetProfile);
+
+ // TODO address
+ // updateProfileField(NukesUserMapper.HOME_ADDRESS, profile, targetProfile);
+ updateProfileField(NukesUserMapper.OCCUPATION, profile, targetProfile);
+ updateProfileField(NukesUserMapper.EXPERTISE, profile, targetProfile);
+ updateProfileField(NukesUserMapper.COMPANY_NAME, profile, targetProfile);
+ updateProfileField(NukesUserMapper.TITLE, profile, targetProfile);
+ updateProfileField(NukesUserMapper.URL, profile, targetProfile);
+ updateProfileField(NukesUserMapper.TYPE_OF_COMPANY, profile, targetProfile);
+ updateProfileField(NukesUserMapper.BIOGRAPHY, profile, targetProfile);
+
+ profileManager.setProfile(user, targetProfile.values());
+
+ try {
+ user.setLastProfileUpdate(new Date());
+ userManager.updateUser(user);
+
+ // need to update the user's authentication object at this point
+ if (getUser() != null && getUser().getID() == getTargetUser().getID()) {
+ this.reAuthenticateUser(user);
+ }
+ } catch (UnauthorizedException e) {
+ return UNAUTHORIZED;
+ } catch (UserNotFoundException e) {
+ log.error("Error occured during updating The Master Account. (UserNotFoundException)");
+ throw new JiveRuntimeException(e);
+ } catch (UserAlreadyExistsException e) {
+ log.error("Error occured during updating The Master Account. (UserAlreadyExistsException)");
+ throw new JiveRuntimeException(e);
+ }
+
return SUCCESS;
}
+ private void updateProfileField(long fieldId, Map<Long, String> profile, Map<Long, ProfileFieldValue> targetProfile) {
+ if (isFieldChanged(profile.get(fieldId))) {
+ String value = profile.get(fieldId);
+
+ ProfileFieldValue field = targetProfile.get(fieldId);
+ if (value != null && value.trim().length() > 0) {
+
+ if (field == null) {
+ field = new ProfileFieldValue(profileFieldManager.getProfileField(fieldId));
+ targetProfile.put(fieldId, field);
+ }
+
+ field.setValue(profile.get(fieldId));
+ } else {
+ if (field != null) {
+ targetProfile.remove(field);
+ }
+ }
+
+ }
+ }
+
+ private boolean isFieldChanged(String value) {
+ if (MASTER_ACCOUNT_SELECTED.equals(value)) {
+ return false;
+ }
+ return true;
+ }
+
public String accountUpdated() {
if (isGuest()) {
return UNAUTHENTICATED;
@@ -103,6 +195,10 @@
return parameterName.contains("masterAccount.");
}
+ public String getMasterAccountSelected() {
+ return MASTER_ACCOUNT_SELECTED;
+ }
+
public List<NukesUser> getAccounts() {
return accounts;
}
Modified: labs/jbosslabs/labs-3.0-build/integration/sbs-nukesauthentication/trunk/src/main/plugin/resources/templates/update-master-account.ftl
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs-nukesauthentication/trunk/src/main/plugin/resources/templates/update-master-account.ftl 2010-06-18 09:16:13 UTC (rev 33540)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs-nukesauthentication/trunk/src/main/plugin/resources/templates/update-master-account.ftl 2010-06-18 09:18:01 UTC (rev 33541)
@@ -49,7 +49,7 @@
<td><@s.text name="plugin.nukesauth.masteraccount.account.firstname" />:</td>
<@s.iterator value="accounts" status="index">
<td>
-<input type="radio" value="<@s.property value="#index.count" />" id="firstname-<@s.property value="#index.count" />" name="masterAccount.firstName" <@s.if test="#index.count == 1">checked="checked"</@s.if>>
+<input type="radio" id="firstname-<@s.property value="#index.count" />" name="masterAccount.firstName" <@s.if test="#index.count == 1">value="<@s.property value="masterAccountSelected" />" checked="checked"</@s.if><@s.else>value="<@s.property value="firstName" />"</@s.else>>
<label for="firstname-<@s.property value="#index.count" />"><@s.property value="firstName" /></label>
</td>
</@s.iterator>
@@ -58,7 +58,7 @@
<td><@s.text name="plugin.nukesauth.masteraccount.account.lastname" />:</td>
<@s.iterator value="accounts" status="index">
<td>
-<input type="radio" value="<@s.property value="#index.count" />" id="lastName-<@s.property value="#index.count" />" name="masterAccount.lastName" <@s.if test="#index.count == 1">checked="checked"</@s.if>>
+<input type="radio" id="lastName-<@s.property value="#index.count" />" name="masterAccount.lastName" <@s.if test="#index.count == 1">value="<@s.property value="masterAccountSelected" />" checked="checked"</@s.if><@s.else>value="<@s.property value="lastName" />"</@s.else>>
<label for="lastName-<@s.property value="#index.count" />"><@s.property value="lastName" /></label>
</td>
</@s.iterator>
@@ -67,7 +67,7 @@
<td><@s.text name="plugin.nukesauth.masteraccount.account.address" />:</td>
<@s.iterator value="accounts" status="index">
<td>
-<input type="radio" value="<@s.property value="#index.count" />" id="address-<@s.property value="#index.count" />" name="masterAccount.profile[3]" <@s.if test="#index.count == 1">checked="checked"</@s.if>>
+<input type="radio" id="address-<@s.property value="#index.count" />" name="masterAccount.profile[3]" <@s.if test="#index.count == 1">value="<@s.property value="masterAccountSelected" />" checked="checked"</@s.if><@s.else>value="<@s.property value="profile[3]" />"</@s.else>>
<label for="address-<@s.property value="#index.count" />"><@s.property value="profile[3]" /></label>
</td>
</@s.iterator>
@@ -84,7 +84,7 @@
<td><@s.text name="plugin.nukesauth.masteraccount.account.phone" />:</td>
<@s.iterator value="accounts" status="index">
<td>
-<input type="radio" value="<@s.property value="#index.count" />" id="phone-<@s.property value="#index.count" />" name="masterAccount.profile[4]" <@s.if test="#index.count == 1">checked="checked"</@s.if>>
+<input type="radio" id="phone-<@s.property value="#index.count" />" name="masterAccount.profile[4]" <@s.if test="#index.count == 1">value="<@s.property value="masterAccountSelected" />" checked="checked"</@s.if><@s.else>value="<@s.property value="profile[4]" />"</@s.else>>
<label for="phone-<@s.property value="#index.count" />"><@s.property value="profile[4]" /></label>
</td>
</@s.iterator>
@@ -93,7 +93,7 @@
<td><@s.text name="plugin.nukesauth.masteraccount.account.alternateemail" />:</td>
<@s.iterator value="accounts" status="index">
<td>
-<input type="radio" value="<@s.property value="#index.count" />" id="alternateemail-<@s.property value="#index.count" />" name="masterAccount.profile[13]" <@s.if test="#index.count == 1">checked="checked"</@s.if>>
+<input type="radio" id="alternateemail-<@s.property value="#index.count" />" name="masterAccount.profile[13]" <@s.if test="#index.count == 1">value="<@s.property value="masterAccountSelected" />" checked="checked"</@s.if><@s.else>value="<@s.property value="profile[13]" />"</@s.else>>
<label for="alternateemail-<@s.property value="#index.count" />"><@s.property value="profile[13]" /></label>
</td>
</@s.iterator>
@@ -102,7 +102,7 @@
<td><@s.text name="plugin.nukesauth.masteraccount.account.icq" />:</td>
<@s.iterator value="accounts" status="index">
<td>
-<input type="radio" value="<@s.property value="#index.count" />" id="icq-<@s.property value="#index.count" />" name="masterAccount.profile[5004]" <@s.if test="#index.count == 1">checked="checked"</@s.if>>
+<input type="radio" id="icq-<@s.property value="#index.count" />" name="masterAccount.profile[5004]" <@s.if test="#index.count == 1">value="<@s.property value="masterAccountSelected" />" checked="checked"</@s.if><@s.else>value="<@s.property value="profile[5004]" />"</@s.else>>
<label for="icq-<@s.property value="#index.count" />"><@s.property value="profile[5004]" /></label>
</td>
</@s.iterator>
@@ -111,7 +111,7 @@
<td><@s.text name="plugin.nukesauth.masteraccount.account.aim" />:</td>
<@s.iterator value="accounts" status="index">
<td>
-<input type="radio" value="<@s.property value="#index.count" />" id="aim-<@s.property value="#index.count" />" name="masterAccount.profile[5012]" <@s.if test="#index.count == 1">checked="checked"</@s.if>>
+<input type="radio" id="aim-<@s.property value="#index.count" />" name="masterAccount.profile[5012]" <@s.if test="#index.count == 1">value="<@s.property value="masterAccountSelected" />" checked="checked"</@s.if><@s.else>value="<@s.property value="profile[5012]" />"</@s.else>>
<label for="aim-<@s.property value="#index.count" />"><@s.property value="profile[5012]" /></label>
</td>
</@s.iterator>
@@ -120,7 +120,7 @@
<td><@s.text name="plugin.nukesauth.masteraccount.account.yim" />:</td>
<@s.iterator value="accounts" status="index">
<td>
-<input type="radio" value="<@s.property value="#index.count" />" id="yim-<@s.property value="#index.count" />" name="masterAccount.profile[5015]" <@s.if test="#index.count == 1">checked="checked"</@s.if>>
+<input type="radio" id="yim-<@s.property value="#index.count" />" name="masterAccount.profile[5015]" <@s.if test="#index.count == 1">value="<@s.property value="masterAccountSelected" />" checked="checked"</@s.if><@s.else>value="<@s.property value="profile[5015]" />"</@s.else>>
<label for="yim-<@s.property value="#index.count" />"><@s.property value="profile[5015]" /></label>
</td>
</@s.iterator>
@@ -129,7 +129,7 @@
<td><@s.text name="plugin.nukesauth.masteraccount.account.homeaddress" />:</td>
<@s.iterator value="accounts" status="index">
<td>
-<input type="radio" value="<@s.property value="#index.count" />" id="homeaddress-<@s.property value="#index.count" />" name="masterAccount.profile[14]" <@s.if test="#index.count == 1">checked="checked"</@s.if>>
+<input type="radio" id="homeaddress-<@s.property value="#index.count" />" name="masterAccount.profile[14]" <@s.if test="#index.count == 1">value="<@s.property value="masterAccountSelected" />" checked="checked"</@s.if><@s.else>value="<@s.property value="profile[14]" />"</@s.else>>
<label for="homeaddress-<@s.property value="#index.count" />"><@s.property value="profile[14]" /></label>
</td>
</@s.iterator>
@@ -138,7 +138,7 @@
<td><@s.text name="plugin.nukesauth.masteraccount.account.occupation" />:</td>
<@s.iterator value="accounts" status="index">
<td>
-<input type="radio" value="<@s.property value="#index.count" />" id="occupation-<@s.property value="#index.count" />" name="masterAccount.profile[5009]" <@s.if test="#index.count == 1">checked="checked"</@s.if>>
+<input type="radio" id="occupation-<@s.property value="#index.count" />" name="masterAccount.profile[5009]" <@s.if test="#index.count == 1">value="<@s.property value="masterAccountSelected" />" checked="checked"</@s.if><@s.else>value="<@s.property value="profile[5009]" />"</@s.else>>
<label for="occupation-<@s.property value="#index.count" />"><@s.property value="profile[5009]" /></label>
</td>
</@s.iterator>
@@ -147,7 +147,7 @@
<td><@s.text name="plugin.nukesauth.masteraccount.account.expertise" />:</td>
<@s.iterator value="accounts" status="index">
<td>
-<input type="radio" value="<@s.property value="#index.count" />" id="expertise-<@s.property value="#index.count" />" name="masterAccount.profile[12]" <@s.if test="#index.count == 1">checked="checked"</@s.if>>
+<input type="radio" id="expertise-<@s.property value="#index.count" />" name="masterAccount.profile[12]" <@s.if test="#index.count == 1">value="<@s.property value="masterAccountSelected" />" checked="checked"</@s.if><@s.else>value="<@s.property value="profile[12]" />"</@s.else>>
<label for="expertise-<@s.property value="#index.count" />"><@s.property value="profile[12]" /></label>
</td>
</@s.iterator>
@@ -156,7 +156,7 @@
<td><@s.text name="plugin.nukesauth.masteraccount.account.companyname" />:</td>
<@s.iterator value="accounts" status="index">
<td>
-<input type="radio" value="<@s.property value="#index.count" />" id="companyname-<@s.property value="#index.count" />" name="masterAccount.profile[5001]" <@s.if test="#index.count == 1">checked="checked"</@s.if>>
+<input type="radio" id="companyname-<@s.property value="#index.count" />" name="masterAccount.profile[5001]" <@s.if test="#index.count == 1">value="<@s.property value="masterAccountSelected" />" checked="checked"</@s.if><@s.else>value="<@s.property value="profile[5001]" />"</@s.else>>
<label for="companyname-<@s.property value="#index.count" />"><@s.property value="profile[5001]" /></label>
</td>
</@s.iterator>
@@ -165,7 +165,7 @@
<td><@s.text name="plugin.nukesauth.masteraccount.account.title" />:</td>
<@s.iterator value="accounts" status="index">
<td>
-<input type="radio" value="<@s.property value="#index.count" />" id="title-<@s.property value="#index.count" />" name="masterAccount.profile[1]" <@s.if test="#index.count == 1">checked="checked"</@s.if>>
+<input type="radio" id="title-<@s.property value="#index.count" />" name="masterAccount.profile[1]" <@s.if test="#index.count == 1">value="<@s.property value="masterAccountSelected" />" checked="checked"</@s.if><@s.else>value="<@s.property value="profile[1]" />"</@s.else>>
<label for="title-<@s.property value="#index.count" />"><@s.property value="profile[1]" /></label>
</td>
</@s.iterator>
@@ -174,7 +174,7 @@
<td><@s.text name="plugin.nukesauth.masteraccount.account.url" />:</td>
<@s.iterator value="accounts" status="index">
<td>
-<input type="radio" value="<@s.property value="#index.count" />" id="url-<@s.property value="#index.count" />" name="masterAccount.profile[9]" <@s.if test="#index.count == 1">checked="checked"</@s.if>>
+<input type="radio" id="url-<@s.property value="#index.count" />" name="masterAccount.profile[9]" <@s.if test="#index.count == 1">value="<@s.property value="masterAccountSelected" />" checked="checked"</@s.if><@s.else>value="<@s.property value="profile[9]" />"</@s.else>>
<label for="url-<@s.property value="#index.count" />"><@s.property value="profile[9]" /></label>
</td>
</@s.iterator>
@@ -183,7 +183,7 @@
<td nowrap="nowrap"><@s.text name="plugin.nukesauth.masteraccount.account.typeofcompany" />:</td>
<@s.iterator value="accounts" status="index">
<td>
-<input type="radio" value="<@s.property value="#index.count" />" id="typeofcompany-<@s.property value="#index.count" />" name="masterAccount.profile[5029]" <@s.if test="#index.count == 1">checked="checked"</@s.if>>
+<input type="radio" id="typeofcompany-<@s.property value="#index.count" />" name="masterAccount.profile[5029]" <@s.if test="#index.count == 1">value="<@s.property value="masterAccountSelected" />" checked="checked"</@s.if><@s.else>value="<@s.property value="profile[5029]" />"</@s.else>>
<label for="typeofcompany-<@s.property value="#index.count" />"><@s.property value="profile[5029]" /></label>
</td>
</@s.iterator>
@@ -192,7 +192,7 @@
<td><@s.text name="plugin.nukesauth.masteraccount.account.bio" />:</td>
<@s.iterator value="accounts" status="index">
<td>
-<input type="radio" value="<@s.property value="#index.count" />" id="bio-<@s.property value="#index.count" />" name="masterAccount.profile[11]" <@s.if test="#index.count == 1">checked="checked"</@s.if>>
+<input type="radio" id="bio-<@s.property value="#index.count" />" name="masterAccount.profile[11]" <@s.if test="#index.count == 1">value="<@s.property value="masterAccountSelected" />" checked="checked"</@s.if><@s.else>value="<@s.property value="profile[11]" />"</@s.else>>
<label for="bio-<@s.property value="#index.count" />"><@s.property value="profile[11]" /></label>
</td>
</@s.iterator>
More information about the jboss-svn-commits
mailing list