mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Fix for ALF-20023 Recent Sites and Favourite Sites in copy/move pickers empty
So the bug was caused by 2 problems: one in ScriptPreferenceService and one in person.sites.get.js The first problem was that ScriptPreferenceService constructs raw Mozilla NativeObjects - a very unusual practice in itself - and it does not provide a default value as required by ECMA 9.1 from the ECMA standard. I've added this code to the NativeObject (can't change the type to ScriptableHashMap<K, V> or similar as the API is published). I've also fixed the same bug (unreported, possibly never apparent) in a jbpm class. The second problem was that person.sites.get.js simply could never return preferences data if the caller provided a filter (favourites or recents) and did not also provide a page size. There was a logic error in the algorithm such that the size defaulted to 0 thus providing a 'page' of zero results as a default. I assume this is a merge error from cloud, but I don't know. I added tests for the JavaScript API's favourites/recents filter calls and logging here and there. Also deleted some dead code. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@55474 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -21,11 +21,9 @@ package org.alfresco.repo.preference;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
@@ -50,6 +48,8 @@ import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.util.ISO8601DateFormat;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -60,7 +60,9 @@ import org.json.JSONObject;
|
||||
*/
|
||||
public class PreferenceServiceImpl implements PreferenceService
|
||||
{
|
||||
private static final String SHARE_SITES_PREFERENCE_KEY = "org.alfresco.share.sites.favourites.";
|
||||
private static final Log log = LogFactory.getLog(PreferenceServiceImpl.class);
|
||||
|
||||
private static final String SHARE_SITES_PREFERENCE_KEY = "org.alfresco.share.sites.favourites.";
|
||||
private static final int SHARE_SITES_PREFERENCE_KEY_LEN = SHARE_SITES_PREFERENCE_KEY.length();
|
||||
private static final String EXT_SITES_PREFERENCE_KEY = "org.alfresco.ext.sites.favourites.";
|
||||
|
||||
@@ -192,12 +194,12 @@ public class PreferenceServiceImpl implements PreferenceService
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public Map<String, Serializable> getPreferences(String userName, String preferenceFilter)
|
||||
{
|
||||
if (log.isTraceEnabled()) { log.trace("getPreferences(" + userName + ", " + preferenceFilter + ")"); }
|
||||
|
||||
Map<String, Serializable> preferences = new TreeMap<String, Serializable>();
|
||||
|
||||
try
|
||||
{
|
||||
Set<String> siteIds = new HashSet<String>();
|
||||
|
||||
JSONObject jsonPrefs = getPreferencesObject(userName);
|
||||
if(jsonPrefs != null)
|
||||
{
|
||||
@@ -220,7 +222,6 @@ public class PreferenceServiceImpl implements PreferenceService
|
||||
String siteId = key.substring(SHARE_SITES_PREFERENCE_KEY_LEN, idx);
|
||||
StringBuilder sb = new StringBuilder(SHARE_SITES_PREFERENCE_KEY);
|
||||
sb.append(siteId);
|
||||
siteIds.add(siteId);
|
||||
key = sb.toString();
|
||||
}
|
||||
|
||||
@@ -231,7 +232,6 @@ public class PreferenceServiceImpl implements PreferenceService
|
||||
StringBuilder sb = new StringBuilder(EXT_SITES_PREFERENCE_KEY);
|
||||
sb.append(siteId);
|
||||
sb.append(".createdAt");
|
||||
siteIds.add(siteId);
|
||||
key = sb.toString();
|
||||
}
|
||||
else if(preferences.containsKey(key))
|
||||
@@ -254,9 +254,11 @@ public class PreferenceServiceImpl implements PreferenceService
|
||||
}
|
||||
catch (JSONException exception)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Can not get preferences for " + userName + " because there was an error pasing the JSON data.", exception);
|
||||
throw new AlfrescoRuntimeException("Can not get preferences for " + userName + " because there was an error parsing the JSON data.", exception);
|
||||
}
|
||||
|
||||
if (log.isTraceEnabled()) { log.trace("result = " + preferences); }
|
||||
|
||||
return preferences;
|
||||
}
|
||||
|
||||
|
@@ -68,8 +68,10 @@ public class ScriptPreferenceService extends BaseScopableProcessorExtension
|
||||
|
||||
public NativeObject getPreferences(String userName, String preferenceFilter)
|
||||
{
|
||||
// It's a tad unusual to return a NativeObject like this - at least within Alfresco.
|
||||
// But we can't change it to e.g. a ScriptableHashMap as the API is published.
|
||||
Map<String, Serializable> prefs = this.preferenceService.getPreferences(userName, preferenceFilter);
|
||||
NativeObject result = new NativeObject();
|
||||
NativeObject result = new NativeObjectDV();
|
||||
|
||||
for (Map.Entry<String, Serializable> entry : prefs.entrySet())
|
||||
{
|
||||
@@ -80,6 +82,16 @@ public class ScriptPreferenceService extends BaseScopableProcessorExtension
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This extension of NativeObject adds a default value. See ALF-20023 for some background.
|
||||
*/
|
||||
private static class NativeObjectDV extends NativeObject
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override public Object getDefaultValue(@SuppressWarnings("rawtypes") Class typeHint) { return toString(); }
|
||||
}
|
||||
|
||||
private void setPrefValue(String[] keys, Serializable value, NativeObject object)
|
||||
{
|
||||
NativeObject currentObject = object;
|
||||
@@ -96,7 +108,7 @@ public class ScriptPreferenceService extends BaseScopableProcessorExtension
|
||||
Object temp = currentObject.get(key, currentObject);
|
||||
if (temp == null || temp instanceof NativeObject == false)
|
||||
{
|
||||
newObject = new NativeObject();
|
||||
newObject = new NativeObjectDV();
|
||||
currentObject.put(key, currentObject, newObject);
|
||||
}
|
||||
else
|
||||
|
Reference in New Issue
Block a user