Skip to content

Commit

Permalink
SAK-25801 changed based on code reviews
Browse files Browse the repository at this point in the history
git-svn-id: https://source.sakaiproject.org/svn/user/trunk@307559 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
zqian committed Mar 27, 2014
1 parent 80c1dbf commit 15af685
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
5 changes: 5 additions & 0 deletions user/user-tool-prefs/tool/src/bundle/userPrefs.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# EntityProvider properties
userPrefs=User Preference Values
userPrefs.action.key=Retrieve user preference property settings given user id and property key name. Here is the request URL pattern: /direct/userPrefs/key/{user_id}/{key_name}.{format}
userPrefs.action.updateKey= Update the key property values. Here is the request URL pattern: /direct/userPrefs/updateKey/{user_id}/{key_name}/{name=val&name1=val1...}
userPrefs.action.saveDivState= Save key-value pair as current user preferences. Here is the request url pattern: /direct/userPrefs/saveDivState/{key_name}/{state_value}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.entitybroker.EntityReference;
import org.sakaiproject.entitybroker.EntityView;
import org.sakaiproject.entitybroker.exception.EntityException;
import org.sakaiproject.entitybroker.entityprovider.CoreEntityProvider;
import org.sakaiproject.entitybroker.entityprovider.annotations.EntityCustomAction;
import org.sakaiproject.entitybroker.entityprovider.capabilities.RESTful;
Expand All @@ -52,6 +53,7 @@
import org.sakaiproject.user.api.PreferencesService;
import org.sakaiproject.user.api.UserNotDefinedException;
import org.sakaiproject.user.tool.UserPrefsTool;
import org.sakaiproject.util.ResourceLoader;
import org.sakaiproject.exception.InUseException;
import org.sakaiproject.exception.PermissionException;

Expand All @@ -63,6 +65,8 @@ public class UserPrefsEntityProvider extends AbstractEntityProvider implements C
private PreferencesService preferencesService;
private SessionManager sessionManager;
private RequestStorage requestStorage;
/** * Resource bundle messages */
ResourceLoader msgs = new ResourceLoader("user-tool-prefs");

public void init() {
log.info("init()");
Expand All @@ -72,13 +76,13 @@ public String getEntityPrefix() {
return PREFIX;
}
public boolean entityExists(String id) {
log.debug(this + " entityExists() " + id);
boolean rv = false;
Preferences p = preferencesService.getPreferences(id);
if (p != null)
{
rv = true;
}
log.debug(this + " entityExists() " + id + " " + rv);
return rv;
}

Expand Down Expand Up @@ -157,24 +161,28 @@ public Object getEntity(EntityReference ref) {
*/
public void deleteEntity(EntityReference ref, Map<String, Object> params) {
log.debug(this + ".deleteEntity of user " + ref);
String refId = ref.getId();
try
{
PreferencesEdit edit = preferencesService.edit(ref.getId());
PreferencesEdit edit = preferencesService.edit(refId);

// now remove the preference
preferencesService.remove(edit);
}
catch (IdUnusedException e)
{
log.warn(this + ".deleteEntity of user " + ref + " " + e.getMessage());
throw new EntityException("UserPrefsEntityProvider get UserPreference not found for ", refId, 404);
}
catch (PermissionException e)
{
log.warn(this + ".deleteEntity of user " + ref + " " + e.getMessage());
throw new EntityException("UserPrefsEntityProvider get UserPreference not permitted for ", refId, 403);
}
catch (InUseException e)
{
log.warn(this + ".deleteEntity of user " + ref + " " + e.getMessage());
throw new EntityException("UserPrefsEntityProvider get UserPreference not found for", refId, 404);
}

}
Expand Down Expand Up @@ -212,6 +220,11 @@ public void setSessionManager(SessionManager sessionManager) {
this.sessionManager = sessionManager;
}

/**
* Save key-value pair as current user preferences.
* Here is the request url pattern: /direct/userPrefs/saveDivState/{key_name}/{state_value}
* @param view
*/
@EntityCustomAction(action="saveDivState", viewKey=EntityView.VIEW_EDIT)
public void doSaveDivState(EntityView view) {

Expand Down Expand Up @@ -310,11 +323,11 @@ public Map<String, Object> getKeyProperties(EntityView view) {
}

/**
*
* update the key-ed property values
*
* use the following format to invoke this function:
*"/direct/userPrefs/updateKey/[user_id]/[key_name]/[name=val&name1=val1...]"
*"/direct/userPrefs/updateKey/[user_id]/[key_name]/[name=val&name1=val1...]
* @param view
*/
@EntityCustomAction(action = "updateKey", viewKey = EntityView.VIEW_EDIT)
public void updateKeyProperties(EntityView view) {
Expand Down

0 comments on commit 15af685

Please sign in to comment.