summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSidharth Singh2012-05-09 09:31:43 (EDT)
committer Manik Kishore2012-06-19 07:29:16 (EDT)
commite7e3614ea4e668aacad373ee67b25fbb5e3b0e47 (patch)
tree5f27a7863939f35300c2ad8cc2cf12521b3fc2aa
parent82ad49a2073f9b80c7c70aba90e7c4b22f3be854 (diff)
downloadorg.eclipse.stardust.ui.web-e7e3614ea4e668aacad373ee67b25fbb5e3b0e47.zip
org.eclipse.stardust.ui.web-e7e3614ea4e668aacad373ee67b25fbb5e3b0e47.tar.gz
org.eclipse.stardust.ui.web-e7e3614ea4e668aacad373ee67b25fbb5e3b0e47.tar.bz2
Jira-ID: CRNT-23229
-Refactored the code in CreateOrModifyPreferenceBean.java -Made changes in code to retrieve User in PreferenceManagerBean.java removePreference() -Added setter methods for userId and realmId git-svn-id: http://emeafrazerg/svn/ipp/product/trunk/stardust/ui.web@56198 8100b5e0-4d52-466c-ae9c-bdeccbdeaf6b
-rw-r--r--admin-portal/src/main/java/org/eclipse/stardust/ui/web/admin/views/CreateOrModifyPreferenceBean.java123
-rw-r--r--admin-portal/src/main/java/org/eclipse/stardust/ui/web/admin/views/PreferenceBean.java11
-rw-r--r--admin-portal/src/main/java/org/eclipse/stardust/ui/web/admin/views/PreferenceManagerBean.java31
3 files changed, 102 insertions, 63 deletions
diff --git a/admin-portal/src/main/java/org/eclipse/stardust/ui/web/admin/views/CreateOrModifyPreferenceBean.java b/admin-portal/src/main/java/org/eclipse/stardust/ui/web/admin/views/CreateOrModifyPreferenceBean.java
index d014815..690abee 100644
--- a/admin-portal/src/main/java/org/eclipse/stardust/ui/web/admin/views/CreateOrModifyPreferenceBean.java
+++ b/admin-portal/src/main/java/org/eclipse/stardust/ui/web/admin/views/CreateOrModifyPreferenceBean.java
@@ -20,12 +20,14 @@ import javax.faces.component.UIComponent;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
+import org.eclipse.stardust.common.CollectionUtils;
+import org.eclipse.stardust.engine.api.query.PreferenceQuery;
import org.eclipse.stardust.engine.api.runtime.AdministrationService;
import org.eclipse.stardust.engine.api.runtime.User;
import org.eclipse.stardust.engine.core.preferences.PreferenceScope;
import org.eclipse.stardust.engine.core.preferences.Preferences;
import org.eclipse.stardust.ui.web.admin.messages.AdminMessagesPropertiesBean;
-import org.eclipse.stardust.ui.web.admin.views.PreferenceManagerBean.VIEW_TYPE;
+import org.eclipse.stardust.ui.web.admin.views.PreferenceManagerBean.PREF_VIEW_TYPE;
import org.eclipse.stardust.ui.web.common.PopupUIComponentBean;
import org.eclipse.stardust.ui.web.common.message.MessageDialog;
import org.eclipse.stardust.ui.web.common.message.MessageDialog.MessageType;
@@ -40,15 +42,14 @@ public class CreateOrModifyPreferenceBean extends PopupUIComponentBean
*
*/
private static final long serialVersionUID = 1L;
-
+ private final SelectItem[] viewSelection = new SelectItem[2];
private boolean modifyMode;
-
- private PreferenceBean preferenceBean;
private String selectedView;
- private final SelectItem[] viewSelection = new SelectItem[2];
- private AdminMessagesPropertiesBean propsBean;
private String userValidationMsg;
+ private AdminMessagesPropertiesBean propsBean;
+ private PreferenceBean preferenceBean;
private UserAutocompleteMultiSelector userSelector;
+ AdministrationService adminService;
public CreateOrModifyPreferenceBean()
{
@@ -79,11 +80,11 @@ public class CreateOrModifyPreferenceBean extends PopupUIComponentBean
{
this.preferenceBean = new PreferenceBean(row.getModuleId(), row.getPreferenceId(),
row.getPreferenceName(), row.getPreferenceValue(), row.getUserId(), row.getRealmId());
- selectedView = row.getScope().contains(VIEW_TYPE.PARTITION.name())
- ? VIEW_TYPE.PARTITION.name()
- : VIEW_TYPE.USER.name();
+ selectedView = row.getScope().contains(PREF_VIEW_TYPE.PARTITION.name()) ? PREF_VIEW_TYPE.PARTITION
+ .name() : PREF_VIEW_TYPE.USER.name();
}
}
+ // If no row is selected, show error message dialog
if (null == preferenceBean)
{
MessageDialog.addMessage(MessageType.ERROR, propsBean.getString("views.common.error.label"),
@@ -96,74 +97,90 @@ public class CreateOrModifyPreferenceBean extends PopupUIComponentBean
{
this.preferenceBean = new PreferenceBean();
this.modifyMode = false;
- viewSelection[0] = new SelectItem(VIEW_TYPE.PARTITION.name(),
+ viewSelection[0] = new SelectItem(PREF_VIEW_TYPE.PARTITION.name(),
propsBean.getString("views.prefManagerBean.modifyPreference.tenant.label"));
- viewSelection[1] = new SelectItem(VIEW_TYPE.USER.name(),
+ viewSelection[1] = new SelectItem(PREF_VIEW_TYPE.USER.name(),
propsBean.getString("views.prefManagerBean.modifyPreference.user.label"));
- selectedView = VIEW_TYPE.PARTITION.name();
- userSelector = new UserAutocompleteMultiSelector(false, true);
- userSelector.setShowOnlineIndicator(false);
+ selectedView = PREF_VIEW_TYPE.PARTITION.name();
}
+ userSelector = new UserAutocompleteMultiSelector(false, true);
+ userSelector.setShowOnlineIndicator(false);
super.openPopup();
}
public void apply()
{
- AdministrationService adminService = SessionContext.findSessionContext().getServiceFactory()
- .getAdministrationService();
- Map<String, Serializable> preferenceMap = new HashMap<String, Serializable>();
+ adminService = SessionContext.findSessionContext().getServiceFactory().getAdministrationService();
Preferences prefs = null;
userValidationMsg = null;
- preferenceMap.put(preferenceBean.getPreferenceName(), preferenceBean.getPreferenceValue());
- if (VIEW_TYPE.PARTITION.name().equals(selectedView))
+ if (PREF_VIEW_TYPE.PARTITION.name().equals(selectedView))
{
- // If Preference for current Preference Id already exist,set Preference Map
- prefs = adminService.getPreferences(PreferenceScope.PARTITION, preferenceBean.getModuleId(),
- preferenceBean.getPreferenceId());
- if (null != prefs)
- {
- prefs.getPreferences().put(preferenceBean.getPreferenceName(), preferenceBean.getPreferenceValue());
- }
- else
- {
- prefs = new Preferences(PreferenceScope.PARTITION, preferenceBean.getModuleId(),
- preferenceBean.getPreferenceId(), preferenceMap);
- }
+ prefs = updatePreference(PreferenceScope.PARTITION, true);
}
else
{
- prefs = adminService.getPreferences(PreferenceScope.USER, preferenceBean.getModuleId(),
- preferenceBean.getPreferenceId());
+ prefs = updatePreference(PreferenceScope.USER, false);
+ }
+ if (null == prefs)
+ return;
+ else
+ adminService.savePreferences(prefs);
+ PreferenceManagerBean.getCurrent().update();
+ closePopup();
+ }
- if (null != prefs)
- {
- prefs.getPreferences().put(preferenceBean.getPreferenceName(), preferenceBean.getPreferenceValue());
- prefs.setUserId(preferenceBean.getUserId());
- prefs.setRealmId(preferenceBean.getRealmId());
- }
- else
- {
- prefs = new Preferences(PreferenceScope.USER, preferenceBean.getModuleId(),
- preferenceBean.getPreferenceId(), preferenceMap);
- }
- UserWrapper userWrapper = getUserSelector().getSelectedValue();
+ private Preferences updatePreference(PreferenceScope prefScope, boolean partitionPrefSelected)
+ {
+ Preferences prefs = null;
+ Map<String, Serializable> preferenceMap = new HashMap<String, Serializable>();
+ preferenceMap.put(preferenceBean.getPreferenceName(), preferenceBean.getPreferenceValue());
+ UserWrapper userWrapper = getUserSelector().getSelectedValue();
+
+ if (partitionPrefSelected)
+ prefs = adminService.getPreferences(prefScope, preferenceBean.getModuleId(), preferenceBean.getPreferenceId());
+ else
+ {
+ // Add Preference with User selection
if (!modifyMode && null != userWrapper)
{
User u = userWrapper.getUser();
- prefs.setUserId(u.getId());
- prefs.setRealmId(u.getRealm().getId());
+ preferenceBean.setUserId(u.getId());
+ preferenceBean.setRealmId(u.getRealm().getId());
}
- // If Add Preference with User is selected and User entry is empty add error
- // message
else if (!modifyMode && null == userWrapper)
{
+ // When no user selection is made in 'Add' for User Preference Scope , return
+ // null with error msg
userValidationMsg = propsBean.getString("views.prefManagerBean.modifyPreference.confirmAddPref.error");
- return;
+ return null;
+ }
+ List<Preferences> userPrefList = CollectionUtils.newArrayList();
+ // AdminServiceImpl does not have method to retrieve specific preference for User
+ // , we use QueryService call to get preference for User selected
+ userPrefList = SessionContext
+ .findSessionContext()
+ .getServiceFactory()
+ .getQueryService()
+ .getAllPreferences(
+ PreferenceQuery.findPreferencesForUsers(preferenceBean.getRealmId(), preferenceBean.getUserId(),
+ preferenceBean.getModuleId(), preferenceBean.getPreferenceId()));
+ if (CollectionUtils.isNotEmpty(userPrefList))
+ {
+ prefs = userPrefList.get(0);
}
}
- adminService.savePreferences(prefs);
- PreferenceManagerBean.getCurrent().update();
- closePopup();
+ if (null == prefs)
+ {
+ prefs = new Preferences(prefScope, preferenceBean.getModuleId(), preferenceBean.getPreferenceId(),
+ preferenceMap);
+ }
+ else
+ {
+ prefs.getPreferences().put(preferenceBean.getPreferenceName(), preferenceBean.getPreferenceValue());
+ }
+ prefs.setUserId(preferenceBean.getUserId());
+ prefs.setRealmId(preferenceBean.getRealmId());
+ return prefs;
}
@Override
diff --git a/admin-portal/src/main/java/org/eclipse/stardust/ui/web/admin/views/PreferenceBean.java b/admin-portal/src/main/java/org/eclipse/stardust/ui/web/admin/views/PreferenceBean.java
index f3e8937..1d22c2b 100644
--- a/admin-portal/src/main/java/org/eclipse/stardust/ui/web/admin/views/PreferenceBean.java
+++ b/admin-portal/src/main/java/org/eclipse/stardust/ui/web/admin/views/PreferenceBean.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.stardust.ui.web.admin.views;
-
/**
*
* @author Sidharth.Singh
@@ -88,9 +87,19 @@ public class PreferenceBean
return userId;
}
+ public void setUserId(String userId)
+ {
+ this.userId = userId;
+ }
+
public String getRealmId()
{
return realmId;
}
+ public void setRealmId(String realmId)
+ {
+ this.realmId = realmId;
+ }
+
}
diff --git a/admin-portal/src/main/java/org/eclipse/stardust/ui/web/admin/views/PreferenceManagerBean.java b/admin-portal/src/main/java/org/eclipse/stardust/ui/web/admin/views/PreferenceManagerBean.java
index fd4d0a7..11ed238 100644
--- a/admin-portal/src/main/java/org/eclipse/stardust/ui/web/admin/views/PreferenceManagerBean.java
+++ b/admin-portal/src/main/java/org/eclipse/stardust/ui/web/admin/views/PreferenceManagerBean.java
@@ -76,6 +76,7 @@ public class PreferenceManagerBean extends UIComponentBean implements ViewEventH
private List<PreferenceManagerTableEntry> prefList;
private ConfirmationDialog prefMngrConfirmationDialog;
private PreferenceManagerTableEntry selectedPrefMngrObj;
+ private QueryService qService;
public PreferenceManagerBean()
{
@@ -104,9 +105,9 @@ public class PreferenceManagerBean extends UIComponentBean implements ViewEventH
{
userSelector = new UserAutocompleteMultiSelector(false, true);
userSelector.setShowOnlineIndicator(false);
- viewSelection[0] = new SelectItem(VIEW_TYPE.PARTITION.name(), getMessages().getString("tenant.label"));
- viewSelection[1] = new SelectItem(VIEW_TYPE.USER.name(), getMessages().getString("user.label"));
- selectedView = VIEW_TYPE.PARTITION.name();
+ viewSelection[0] = new SelectItem(PREF_VIEW_TYPE.PARTITION.name(), getMessages().getString("tenant.label"));
+ viewSelection[1] = new SelectItem(PREF_VIEW_TYPE.USER.name(), getMessages().getString("user.label"));
+ selectedView = PREF_VIEW_TYPE.PARTITION.name();
prefList = CollectionUtils.newArrayList();
createTable();
update();
@@ -130,11 +131,11 @@ public class PreferenceManagerBean extends UIComponentBean implements ViewEventH
private void fetchPreferences()
{
- QueryService qService = SessionContext.findSessionContext().getServiceFactory().getQueryService();
+ qService = SessionContext.findSessionContext().getServiceFactory().getQueryService();
List<Preferences> prefs = new ArrayList<Preferences>();
prefList.clear();
String userFullName = null;
- if (VIEW_TYPE.PARTITION.name().equals(selectedView))
+ if (PREF_VIEW_TYPE.PARTITION.name().equals(selectedView))
{
// fetch all the Partition preferences
prefs = qService.getAllPreferences(PreferenceQuery.findAll(PreferenceScope.PARTITION));
@@ -309,14 +310,21 @@ public class PreferenceManagerBean extends UIComponentBean implements ViewEventH
AdministrationService adminService = SessionContext.findSessionContext().getServiceFactory()
.getAdministrationService();
Preferences selPreference = null;
- if (VIEW_TYPE.PARTITION.name().equals(selectedView))
+ if (PREF_VIEW_TYPE.PARTITION.name().equals(selectedView))
{
selPreference = adminService.getPreferences(PreferenceScope.PARTITION, selectedPrefMngrObj.getModuleId(),
selectedPrefMngrObj.getPreferenceId());
}
else
- selPreference = adminService.getPreferences(PreferenceScope.USER, selectedPrefMngrObj.getModuleId(),
- selectedPrefMngrObj.getPreferenceId());
+ {
+ // Specific User Preference is retrieved from QueryService method to remove the
+ // Map entry for Preference Name-Value pair
+ selPreference = qService.getAllPreferences(
+ PreferenceQuery.findPreferencesForUsers(selectedPrefMngrObj.getRealmId(),
+ selectedPrefMngrObj.getUserId(), selectedPrefMngrObj.getModuleId(),
+ selectedPrefMngrObj.getPreferenceId())).get(0);
+ }
+
selPreference.getPreferences().remove(selectedPrefMngrObj.getPreferenceName());
adminService.savePreferences(selPreference);
update();
@@ -333,7 +341,7 @@ public class PreferenceManagerBean extends UIComponentBean implements ViewEventH
/**
*
*/
- public static enum VIEW_TYPE {
+ public static enum PREF_VIEW_TYPE {
PARTITION, USER;
}
@@ -392,4 +400,9 @@ public class PreferenceManagerBean extends UIComponentBean implements ViewEventH
this.selectedPrefMngrObj = selectedPrefMngrObj;
}
+ public QueryService getqService()
+ {
+ return qService;
+ }
+
}