mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged 5.2.N (5.2.1) to HEAD (5.2)
125783 rmunteanu: Merged 5.1.N (5.1.2) to 5.2.N (5.2.1) 125605 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2) 125498 slanglois: MNT-16155 Update source headers - remove svn:eol-style property on Java and JSP source files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127809 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,119 +1,119 @@
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.extensions.surf.util.AbstractLifecycleBean;
|
||||
|
||||
public abstract class AbstractActivitySummaryProcessor extends AbstractLifecycleBean implements ActivitySummaryProcessor
|
||||
{
|
||||
protected static Log logger = LogFactory.getLog(ActivitySummaryProcessor.class);
|
||||
|
||||
protected ActivitySummaryProcessorRegistry registry;
|
||||
private List<String> eventTypes;
|
||||
|
||||
public void setEventTypes(List<String> eventTypes)
|
||||
{
|
||||
this.eventTypes = eventTypes;
|
||||
}
|
||||
|
||||
public void setRegistry(ActivitySummaryProcessorRegistry registry)
|
||||
{
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
public void setCustomRenditions(List<String> eventTypes)
|
||||
{
|
||||
this.eventTypes = eventTypes;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.extensions.surf.util.AbstractLifecycleBean#onBootstrap(org.springframework.context.ApplicationEvent)
|
||||
*/
|
||||
protected void onBootstrap(ApplicationEvent event)
|
||||
{
|
||||
register();
|
||||
}
|
||||
|
||||
protected void onShutdown(ApplicationEvent event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> process(Map<String, Object> entries)
|
||||
{
|
||||
List<Change> changes = new LinkedList<Change>();
|
||||
Map<String, Object> ret = new HashMap<String, Object>(entries.size());
|
||||
for(Map.Entry<String, Object> entry : entries.entrySet())
|
||||
{
|
||||
String key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
Change change = processEntry(key, value);
|
||||
if(change != null)
|
||||
{
|
||||
changes.add(change);
|
||||
}
|
||||
}
|
||||
|
||||
for(Change change : changes)
|
||||
{
|
||||
if(change != null)
|
||||
{
|
||||
change.process(entries);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected abstract Change processEntry(String key, Object value);
|
||||
|
||||
protected void register()
|
||||
{
|
||||
for(String eventType : eventTypes)
|
||||
{
|
||||
registry.register(eventType, this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ChangeKey implements Change
|
||||
{
|
||||
private String oldKey;
|
||||
private String newKey;
|
||||
|
||||
public ChangeKey(String oldKey, String newKey) {
|
||||
super();
|
||||
this.oldKey = oldKey;
|
||||
this.newKey = newKey;
|
||||
}
|
||||
|
||||
public void process(Map<String, Object> entries)
|
||||
{
|
||||
Object value = entries.remove(oldKey);
|
||||
entries.put(newKey, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static class RemoveKey implements Change
|
||||
{
|
||||
private String key;
|
||||
|
||||
public RemoveKey(String key) {
|
||||
super();
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public void process(Map<String, Object> entries)
|
||||
{
|
||||
entries.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.extensions.surf.util.AbstractLifecycleBean;
|
||||
|
||||
public abstract class AbstractActivitySummaryProcessor extends AbstractLifecycleBean implements ActivitySummaryProcessor
|
||||
{
|
||||
protected static Log logger = LogFactory.getLog(ActivitySummaryProcessor.class);
|
||||
|
||||
protected ActivitySummaryProcessorRegistry registry;
|
||||
private List<String> eventTypes;
|
||||
|
||||
public void setEventTypes(List<String> eventTypes)
|
||||
{
|
||||
this.eventTypes = eventTypes;
|
||||
}
|
||||
|
||||
public void setRegistry(ActivitySummaryProcessorRegistry registry)
|
||||
{
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
public void setCustomRenditions(List<String> eventTypes)
|
||||
{
|
||||
this.eventTypes = eventTypes;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.extensions.surf.util.AbstractLifecycleBean#onBootstrap(org.springframework.context.ApplicationEvent)
|
||||
*/
|
||||
protected void onBootstrap(ApplicationEvent event)
|
||||
{
|
||||
register();
|
||||
}
|
||||
|
||||
protected void onShutdown(ApplicationEvent event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> process(Map<String, Object> entries)
|
||||
{
|
||||
List<Change> changes = new LinkedList<Change>();
|
||||
Map<String, Object> ret = new HashMap<String, Object>(entries.size());
|
||||
for(Map.Entry<String, Object> entry : entries.entrySet())
|
||||
{
|
||||
String key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
Change change = processEntry(key, value);
|
||||
if(change != null)
|
||||
{
|
||||
changes.add(change);
|
||||
}
|
||||
}
|
||||
|
||||
for(Change change : changes)
|
||||
{
|
||||
if(change != null)
|
||||
{
|
||||
change.process(entries);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected abstract Change processEntry(String key, Object value);
|
||||
|
||||
protected void register()
|
||||
{
|
||||
for(String eventType : eventTypes)
|
||||
{
|
||||
registry.register(eventType, this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ChangeKey implements Change
|
||||
{
|
||||
private String oldKey;
|
||||
private String newKey;
|
||||
|
||||
public ChangeKey(String oldKey, String newKey) {
|
||||
super();
|
||||
this.oldKey = oldKey;
|
||||
this.newKey = newKey;
|
||||
}
|
||||
|
||||
public void process(Map<String, Object> entries)
|
||||
{
|
||||
Object value = entries.remove(oldKey);
|
||||
entries.put(newKey, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static class RemoveKey implements Change
|
||||
{
|
||||
private String key;
|
||||
|
||||
public RemoveKey(String key) {
|
||||
super();
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public void process(Map<String, Object> entries)
|
||||
{
|
||||
entries.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,168 +1,168 @@
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.util.registry.NamedObjectRegistry;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONException;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.springframework.extensions.surf.util.ISO8601DateFormat;
|
||||
|
||||
/*
|
||||
* Adapted from JSONtoFmModel
|
||||
*/
|
||||
public class ActivitySummaryParser implements ActivitySummaryProcessorRegistry
|
||||
{
|
||||
private final Log logger = LogFactory.getLog(ActivitySummaryParser.class);
|
||||
|
||||
// note: current format is dependent on ISO8601DateFormat.parser, eg. YYYY-MM-DDThh:mm:ss.sssTZD
|
||||
private static String REGEXP_ISO8061 = "^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(.([0-9]){3})?(Z|[\\+\\-]([0-9]{2}):([0-9]{2}))$";
|
||||
private static Pattern matcherISO8601 = Pattern.compile(REGEXP_ISO8061);
|
||||
private static final Pattern nodeRefPattern = Pattern.compile("^[a-zA-Z]+://.+/.+");
|
||||
|
||||
private NamedObjectRegistry<ActivitySummaryProcessor> processors;
|
||||
|
||||
private boolean autoConvertISO8601 = true;
|
||||
|
||||
public ActivitySummaryParser()
|
||||
{
|
||||
}
|
||||
|
||||
public void setProcessors(NamedObjectRegistry<ActivitySummaryProcessor> processors)
|
||||
{
|
||||
this.processors = processors;
|
||||
}
|
||||
|
||||
public void register(String activityType, ActivitySummaryProcessor processor)
|
||||
{
|
||||
ActivitySummaryProcessor existingProcessor = processors.getNamedObject(activityType);
|
||||
if(existingProcessor != null)
|
||||
{
|
||||
logger.warn("Activity summary processor " + existingProcessor + " is being overridden by " + processor + " for activity type " + activityType);
|
||||
}
|
||||
|
||||
processors.register(activityType, processor);
|
||||
}
|
||||
|
||||
private void processActivitySummary(String activityType, Map<String, Object> entries)
|
||||
{
|
||||
ActivitySummaryProcessor processor = processors.getNamedObject(activityType);
|
||||
if(processor == null)
|
||||
{
|
||||
processor = new BaseActivitySummaryProcessor();
|
||||
}
|
||||
|
||||
processor.process(entries);
|
||||
}
|
||||
|
||||
public Map<String, Object> parse(String activityType, String activitySummary) throws JSONException
|
||||
{
|
||||
JSONObject json = (JSONObject)JSONValue.parse(activitySummary);
|
||||
Map<String, Object> map = convertJSONObjectToMap(json);
|
||||
processActivitySummary(activityType, map);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if passed string conforms to the pattern of a node reference
|
||||
*
|
||||
* @param nodeRef the node reference as a string
|
||||
* @return true => it matches the pattern of a node reference
|
||||
*/
|
||||
private boolean isNodeRef(String nodeRef)
|
||||
{
|
||||
Matcher matcher = nodeRefPattern.matcher(nodeRef);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
Map<String, Object> convertJSONObjectToMap(JSONObject jo) throws JSONException
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
|
||||
for(Object key : jo.keySet())
|
||||
{
|
||||
Object value = jo.get(key);
|
||||
if (value instanceof JSONObject)
|
||||
{
|
||||
model.put((String)key, convertJSONObjectToMap((JSONObject)value));
|
||||
}
|
||||
else if (value instanceof JSONArray)
|
||||
{
|
||||
model.put((String)key, convertJSONArrayToList((JSONArray)value));
|
||||
}
|
||||
else if (value == null)
|
||||
{
|
||||
model.put((String)key, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((value instanceof String) && autoConvertISO8601 && (matcherISO8601.matcher((String)value).matches()))
|
||||
{
|
||||
value = ISO8601DateFormat.parse((String)value);
|
||||
}
|
||||
|
||||
if ((value instanceof String) && isNodeRef((String)value))
|
||||
{
|
||||
try
|
||||
{
|
||||
value = new NodeRef((String)value);
|
||||
}
|
||||
catch(AlfrescoRuntimeException e)
|
||||
{
|
||||
// cannot convert to a nodeRef, just keep as a string
|
||||
logger.warn("Cannot convert activity summary NodeRef string " + value + " to a NodeRef");
|
||||
}
|
||||
}
|
||||
|
||||
model.put((String)key, value);
|
||||
}
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
List<Object> convertJSONArrayToList(JSONArray ja) throws JSONException
|
||||
{
|
||||
List<Object> model = new ArrayList<Object>();
|
||||
|
||||
for (int i = 0; i < ja.size(); i++)
|
||||
{
|
||||
Object o = ja.get(i);
|
||||
|
||||
if (o instanceof JSONArray)
|
||||
{
|
||||
model.add(convertJSONArrayToList((JSONArray)o));
|
||||
}
|
||||
else if (o instanceof JSONObject)
|
||||
{
|
||||
model.add(convertJSONObjectToMap((JSONObject)o));
|
||||
}
|
||||
else if (o == null)
|
||||
{
|
||||
model.add(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((o instanceof String) && autoConvertISO8601 && (matcherISO8601.matcher((String)o).matches()))
|
||||
{
|
||||
o = ISO8601DateFormat.parse((String)o);
|
||||
}
|
||||
|
||||
model.add(o);
|
||||
}
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.util.registry.NamedObjectRegistry;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONException;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.springframework.extensions.surf.util.ISO8601DateFormat;
|
||||
|
||||
/*
|
||||
* Adapted from JSONtoFmModel
|
||||
*/
|
||||
public class ActivitySummaryParser implements ActivitySummaryProcessorRegistry
|
||||
{
|
||||
private final Log logger = LogFactory.getLog(ActivitySummaryParser.class);
|
||||
|
||||
// note: current format is dependent on ISO8601DateFormat.parser, eg. YYYY-MM-DDThh:mm:ss.sssTZD
|
||||
private static String REGEXP_ISO8061 = "^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(.([0-9]){3})?(Z|[\\+\\-]([0-9]{2}):([0-9]{2}))$";
|
||||
private static Pattern matcherISO8601 = Pattern.compile(REGEXP_ISO8061);
|
||||
private static final Pattern nodeRefPattern = Pattern.compile("^[a-zA-Z]+://.+/.+");
|
||||
|
||||
private NamedObjectRegistry<ActivitySummaryProcessor> processors;
|
||||
|
||||
private boolean autoConvertISO8601 = true;
|
||||
|
||||
public ActivitySummaryParser()
|
||||
{
|
||||
}
|
||||
|
||||
public void setProcessors(NamedObjectRegistry<ActivitySummaryProcessor> processors)
|
||||
{
|
||||
this.processors = processors;
|
||||
}
|
||||
|
||||
public void register(String activityType, ActivitySummaryProcessor processor)
|
||||
{
|
||||
ActivitySummaryProcessor existingProcessor = processors.getNamedObject(activityType);
|
||||
if(existingProcessor != null)
|
||||
{
|
||||
logger.warn("Activity summary processor " + existingProcessor + " is being overridden by " + processor + " for activity type " + activityType);
|
||||
}
|
||||
|
||||
processors.register(activityType, processor);
|
||||
}
|
||||
|
||||
private void processActivitySummary(String activityType, Map<String, Object> entries)
|
||||
{
|
||||
ActivitySummaryProcessor processor = processors.getNamedObject(activityType);
|
||||
if(processor == null)
|
||||
{
|
||||
processor = new BaseActivitySummaryProcessor();
|
||||
}
|
||||
|
||||
processor.process(entries);
|
||||
}
|
||||
|
||||
public Map<String, Object> parse(String activityType, String activitySummary) throws JSONException
|
||||
{
|
||||
JSONObject json = (JSONObject)JSONValue.parse(activitySummary);
|
||||
Map<String, Object> map = convertJSONObjectToMap(json);
|
||||
processActivitySummary(activityType, map);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if passed string conforms to the pattern of a node reference
|
||||
*
|
||||
* @param nodeRef the node reference as a string
|
||||
* @return true => it matches the pattern of a node reference
|
||||
*/
|
||||
private boolean isNodeRef(String nodeRef)
|
||||
{
|
||||
Matcher matcher = nodeRefPattern.matcher(nodeRef);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
Map<String, Object> convertJSONObjectToMap(JSONObject jo) throws JSONException
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
|
||||
for(Object key : jo.keySet())
|
||||
{
|
||||
Object value = jo.get(key);
|
||||
if (value instanceof JSONObject)
|
||||
{
|
||||
model.put((String)key, convertJSONObjectToMap((JSONObject)value));
|
||||
}
|
||||
else if (value instanceof JSONArray)
|
||||
{
|
||||
model.put((String)key, convertJSONArrayToList((JSONArray)value));
|
||||
}
|
||||
else if (value == null)
|
||||
{
|
||||
model.put((String)key, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((value instanceof String) && autoConvertISO8601 && (matcherISO8601.matcher((String)value).matches()))
|
||||
{
|
||||
value = ISO8601DateFormat.parse((String)value);
|
||||
}
|
||||
|
||||
if ((value instanceof String) && isNodeRef((String)value))
|
||||
{
|
||||
try
|
||||
{
|
||||
value = new NodeRef((String)value);
|
||||
}
|
||||
catch(AlfrescoRuntimeException e)
|
||||
{
|
||||
// cannot convert to a nodeRef, just keep as a string
|
||||
logger.warn("Cannot convert activity summary NodeRef string " + value + " to a NodeRef");
|
||||
}
|
||||
}
|
||||
|
||||
model.put((String)key, value);
|
||||
}
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
List<Object> convertJSONArrayToList(JSONArray ja) throws JSONException
|
||||
{
|
||||
List<Object> model = new ArrayList<Object>();
|
||||
|
||||
for (int i = 0; i < ja.size(); i++)
|
||||
{
|
||||
Object o = ja.get(i);
|
||||
|
||||
if (o instanceof JSONArray)
|
||||
{
|
||||
model.add(convertJSONArrayToList((JSONArray)o));
|
||||
}
|
||||
else if (o instanceof JSONObject)
|
||||
{
|
||||
model.add(convertJSONObjectToMap((JSONObject)o));
|
||||
}
|
||||
else if (o == null)
|
||||
{
|
||||
model.add(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((o instanceof String) && autoConvertISO8601 && (matcherISO8601.matcher((String)o).matches()))
|
||||
{
|
||||
o = ISO8601DateFormat.parse((String)o);
|
||||
}
|
||||
|
||||
model.add(o);
|
||||
}
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,13 +1,13 @@
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface ActivitySummaryProcessor
|
||||
{
|
||||
public interface Change
|
||||
{
|
||||
void process(Map<String, Object> entries);
|
||||
}
|
||||
|
||||
public Map<String, Object> process(Map<String, Object> entries);
|
||||
}
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface ActivitySummaryProcessor
|
||||
{
|
||||
public interface Change
|
||||
{
|
||||
void process(Map<String, Object> entries);
|
||||
}
|
||||
|
||||
public Map<String, Object> process(Map<String, Object> entries);
|
||||
}
|
||||
|
@@ -1,12 +1,12 @@
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
/**
|
||||
* A registry for activity summary parsers/post processors.
|
||||
*
|
||||
* @author steveglover
|
||||
*
|
||||
*/
|
||||
public interface ActivitySummaryProcessorRegistry
|
||||
{
|
||||
public void register(String activityType, ActivitySummaryProcessor processor);
|
||||
}
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
/**
|
||||
* A registry for activity summary parsers/post processors.
|
||||
*
|
||||
* @author steveglover
|
||||
*
|
||||
*/
|
||||
public interface ActivitySummaryProcessorRegistry
|
||||
{
|
||||
public void register(String activityType, ActivitySummaryProcessor processor);
|
||||
}
|
||||
|
@@ -1,96 +1,96 @@
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.alfresco.rest.api.impl.activities.AbstractActivitySummaryProcessor.RemoveKey;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
public class BaseActivitySummaryProcessor extends AbstractActivitySummaryProcessor
|
||||
{
|
||||
@Override
|
||||
protected Change processEntry(String key, Object value)
|
||||
{
|
||||
Change change = null;
|
||||
|
||||
if(key.equals("page"))
|
||||
{
|
||||
change = new ChangePageValue(key);
|
||||
}
|
||||
|
||||
if(key.equals("tenantDomain"))
|
||||
{
|
||||
change = new RemoveKey(key);
|
||||
}
|
||||
|
||||
if(key.equals("nodeRef"))
|
||||
{
|
||||
change = new ChangeKey(key, "objectId");
|
||||
}
|
||||
|
||||
if(key.equals("parentNodeRef"))
|
||||
{
|
||||
change = new ChangeKey(key, "parentObjectId");
|
||||
}
|
||||
|
||||
// remove null or empty properties
|
||||
if(value == null || value.equals(""))
|
||||
{
|
||||
change = new RemoveKey(key);
|
||||
}
|
||||
|
||||
return change;
|
||||
}
|
||||
|
||||
public static class ChangePageValue implements Change
|
||||
{
|
||||
private String key;
|
||||
private static final String regex = Pattern.quote("document-details?nodeRef=") + "(.*)";
|
||||
private static final Pattern pattern = Pattern.compile(regex);
|
||||
|
||||
public ChangePageValue(String key) {
|
||||
super();
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract and output the node id from input that looks like this: document-details?nodeRef=workspace%3A%2F%2FSpacesStore%2Fd4c1a75e-a17e-4033-94f4-988cca39a357 (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.rest.api.impl.activities.ActivitySummaryProcessor.Change#process(java.util.Map)
|
||||
*/
|
||||
public void process(Map<String, Object> entries)
|
||||
{
|
||||
String value = (String)entries.remove(key);
|
||||
try
|
||||
{
|
||||
value = URLDecoder.decode(value, "UTF-8");
|
||||
Matcher matcher = pattern.matcher(value);
|
||||
if(matcher.matches())
|
||||
{
|
||||
String nodeRefStr = matcher.group(1);
|
||||
boolean isNodeRef = NodeRef.isNodeRef(nodeRefStr);
|
||||
if(isNodeRef)
|
||||
{
|
||||
NodeRef nodeRef = new NodeRef(nodeRefStr);
|
||||
entries.put("objectId", nodeRef.getId());
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("Activity page url contains an invalid NodeRef " + value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("Failed to match activity page url for objectId extraction " + value);
|
||||
}
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
logger.warn("Unable to decode activity page url " + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.alfresco.rest.api.impl.activities.AbstractActivitySummaryProcessor.RemoveKey;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
public class BaseActivitySummaryProcessor extends AbstractActivitySummaryProcessor
|
||||
{
|
||||
@Override
|
||||
protected Change processEntry(String key, Object value)
|
||||
{
|
||||
Change change = null;
|
||||
|
||||
if(key.equals("page"))
|
||||
{
|
||||
change = new ChangePageValue(key);
|
||||
}
|
||||
|
||||
if(key.equals("tenantDomain"))
|
||||
{
|
||||
change = new RemoveKey(key);
|
||||
}
|
||||
|
||||
if(key.equals("nodeRef"))
|
||||
{
|
||||
change = new ChangeKey(key, "objectId");
|
||||
}
|
||||
|
||||
if(key.equals("parentNodeRef"))
|
||||
{
|
||||
change = new ChangeKey(key, "parentObjectId");
|
||||
}
|
||||
|
||||
// remove null or empty properties
|
||||
if(value == null || value.equals(""))
|
||||
{
|
||||
change = new RemoveKey(key);
|
||||
}
|
||||
|
||||
return change;
|
||||
}
|
||||
|
||||
public static class ChangePageValue implements Change
|
||||
{
|
||||
private String key;
|
||||
private static final String regex = Pattern.quote("document-details?nodeRef=") + "(.*)";
|
||||
private static final Pattern pattern = Pattern.compile(regex);
|
||||
|
||||
public ChangePageValue(String key) {
|
||||
super();
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract and output the node id from input that looks like this: document-details?nodeRef=workspace%3A%2F%2FSpacesStore%2Fd4c1a75e-a17e-4033-94f4-988cca39a357 (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.rest.api.impl.activities.ActivitySummaryProcessor.Change#process(java.util.Map)
|
||||
*/
|
||||
public void process(Map<String, Object> entries)
|
||||
{
|
||||
String value = (String)entries.remove(key);
|
||||
try
|
||||
{
|
||||
value = URLDecoder.decode(value, "UTF-8");
|
||||
Matcher matcher = pattern.matcher(value);
|
||||
if(matcher.matches())
|
||||
{
|
||||
String nodeRefStr = matcher.group(1);
|
||||
boolean isNodeRef = NodeRef.isNodeRef(nodeRefStr);
|
||||
if(isNodeRef)
|
||||
{
|
||||
NodeRef nodeRef = new NodeRef(nodeRefStr);
|
||||
entries.put("objectId", nodeRef.getId());
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("Activity page url contains an invalid NodeRef " + value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("Failed to match activity page url for objectId extraction " + value);
|
||||
}
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
logger.warn("Unable to decode activity page url " + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
public class CommentsActivitySummaryProcessor extends BaseActivitySummaryProcessor
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
public class CommentsActivitySummaryProcessor extends BaseActivitySummaryProcessor
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,17 +1,17 @@
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
public class DiscussionsActivitySummaryProcessor extends BaseActivitySummaryProcessor
|
||||
{
|
||||
@Override
|
||||
protected Change processEntry(String key, Object value)
|
||||
{
|
||||
Change change = null;
|
||||
|
||||
if(key.equals("params"))
|
||||
{
|
||||
change = new RemoveKey(key);
|
||||
}
|
||||
|
||||
return change;
|
||||
}
|
||||
}
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
public class DiscussionsActivitySummaryProcessor extends BaseActivitySummaryProcessor
|
||||
{
|
||||
@Override
|
||||
protected Change processEntry(String key, Object value)
|
||||
{
|
||||
Change change = null;
|
||||
|
||||
if(key.equals("params"))
|
||||
{
|
||||
change = new RemoveKey(key);
|
||||
}
|
||||
|
||||
return change;
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
public class DocumentLibraryActivitySummaryProcessor extends BaseActivitySummaryProcessor
|
||||
{
|
||||
|
||||
}
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
public class DocumentLibraryActivitySummaryProcessor extends BaseActivitySummaryProcessor
|
||||
{
|
||||
|
||||
}
|
||||
|
@@ -1,18 +1,18 @@
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
public class SiteActivitySummaryProcessor extends BaseActivitySummaryProcessor
|
||||
{
|
||||
@Override
|
||||
protected Change processEntry(String key, Object value)
|
||||
{
|
||||
Change change = super.processEntry(key, value);
|
||||
|
||||
if(key.equals("memberUserName"))
|
||||
{
|
||||
change = new ChangeKey(key, "memberPersonId");
|
||||
}
|
||||
|
||||
return change;
|
||||
}
|
||||
|
||||
}
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
public class SiteActivitySummaryProcessor extends BaseActivitySummaryProcessor
|
||||
{
|
||||
@Override
|
||||
protected Change processEntry(String key, Object value)
|
||||
{
|
||||
Change change = super.processEntry(key, value);
|
||||
|
||||
if(key.equals("memberUserName"))
|
||||
{
|
||||
change = new ChangeKey(key, "memberPersonId");
|
||||
}
|
||||
|
||||
return change;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,26 +1,26 @@
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
public class SubscriptionsActivitySummaryProcessor extends BaseActivitySummaryProcessor
|
||||
{
|
||||
//{"lastName":"Glover","userFirstName":"David","followerLastName":"Glover","userUserName":"david.bowie@alfresco.com","followerFirstName":"Steve",
|
||||
// "userLastName":"Bowie","followerUserName":"steven.glover@alfresco.com","firstName":"Steve","tenantDomain":"alfresco.com"}
|
||||
|
||||
@Override
|
||||
protected Change processEntry(String key, Object value)
|
||||
{
|
||||
Change change = super.processEntry(key, value);
|
||||
|
||||
if(key.equals("userUserName"))
|
||||
{
|
||||
change = new ChangeKey(key, "userPersonId");
|
||||
}
|
||||
|
||||
if(key.equals("followerUserName"))
|
||||
{
|
||||
change = new ChangeKey(key, "followerPersonId");
|
||||
}
|
||||
|
||||
return change;
|
||||
}
|
||||
|
||||
}
|
||||
package org.alfresco.rest.api.impl.activities;
|
||||
|
||||
public class SubscriptionsActivitySummaryProcessor extends BaseActivitySummaryProcessor
|
||||
{
|
||||
//{"lastName":"Glover","userFirstName":"David","followerLastName":"Glover","userUserName":"david.bowie@alfresco.com","followerFirstName":"Steve",
|
||||
// "userLastName":"Bowie","followerUserName":"steven.glover@alfresco.com","firstName":"Steve","tenantDomain":"alfresco.com"}
|
||||
|
||||
@Override
|
||||
protected Change processEntry(String key, Object value)
|
||||
{
|
||||
Change change = super.processEntry(key, value);
|
||||
|
||||
if(key.equals("userUserName"))
|
||||
{
|
||||
change = new ChangeKey(key, "userPersonId");
|
||||
}
|
||||
|
||||
if(key.equals("followerUserName"))
|
||||
{
|
||||
change = new ChangeKey(key, "followerPersonId");
|
||||
}
|
||||
|
||||
return change;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user