mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
ALF-9156 Refactor the calendar webscript activity generation to the abstract base class
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29079 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -39,6 +39,8 @@ import org.alfresco.service.cmr.site.SiteService;
|
|||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.util.GUID;
|
import org.alfresco.util.GUID;
|
||||||
import org.alfresco.util.ISO8601DateFormat;
|
import org.alfresco.util.ISO8601DateFormat;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONTokener;
|
import org.json.JSONTokener;
|
||||||
@@ -56,6 +58,8 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
|||||||
{
|
{
|
||||||
public static final String CALENDAR_SERVICE_ACTIVITY_APP_NAME = "calendar";
|
public static final String CALENDAR_SERVICE_ACTIVITY_APP_NAME = "calendar";
|
||||||
|
|
||||||
|
private static Log logger = LogFactory.getLog(AbstractCalendarWebScript.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When no maximum or paging info is given, what should we use?
|
* When no maximum or paging info is given, what should we use?
|
||||||
*/
|
*/
|
||||||
@@ -220,6 +224,57 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
|||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates an activity entry for the entry
|
||||||
|
*/
|
||||||
|
protected String addActivityEntry(String event, CalendarEntry entry, SiteInfo site,
|
||||||
|
WebScriptRequest req, JSONObject json)
|
||||||
|
{
|
||||||
|
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
String dateOpt = "?date=" + fmt.format(entry.getStart());
|
||||||
|
|
||||||
|
// What page is this for?
|
||||||
|
String page = req.getParameter("page");
|
||||||
|
if(page == null && json != null)
|
||||||
|
{
|
||||||
|
if(json.has("page"))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
page = json.getString("page");
|
||||||
|
}
|
||||||
|
catch(JSONException e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(page == null)
|
||||||
|
{
|
||||||
|
// Default
|
||||||
|
page = "calendar";
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
JSONObject activity = new JSONObject();
|
||||||
|
activity.put("title", entry.getTitle());
|
||||||
|
activity.put("page", page + dateOpt);
|
||||||
|
|
||||||
|
activityService.postActivity(
|
||||||
|
"org.alfresco.calendar.event-" + event,
|
||||||
|
site.getShortName(),
|
||||||
|
CALENDAR_SERVICE_ACTIVITY_APP_NAME,
|
||||||
|
activity.toString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
// Warn, but carry on
|
||||||
|
logger.warn("Error adding event " + event + " to activities feed", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the date we used
|
||||||
|
return dateOpt;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For an event that is a recurring event, have an ignored child event
|
* For an event that is a recurring event, have an ignored child event
|
||||||
* generated for it
|
* generated for it
|
||||||
|
@@ -22,8 +22,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.alfresco.service.cmr.calendar.CalendarEntry;
|
import org.alfresco.service.cmr.calendar.CalendarEntry;
|
||||||
import org.alfresco.service.cmr.site.SiteInfo;
|
import org.alfresco.service.cmr.site.SiteInfo;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.springframework.extensions.webscripts.Cache;
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
import org.springframework.extensions.webscripts.Status;
|
import org.springframework.extensions.webscripts.Status;
|
||||||
@@ -37,8 +35,6 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
|||||||
*/
|
*/
|
||||||
public class CalendarEntryDelete extends AbstractCalendarWebScript
|
public class CalendarEntryDelete extends AbstractCalendarWebScript
|
||||||
{
|
{
|
||||||
private static Log logger = LogFactory.getLog(CalendarEntryDelete.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This WebScript uses HTTP status codes for errors
|
* This WebScript uses HTTP status codes for errors
|
||||||
*/
|
*/
|
||||||
@@ -75,24 +71,7 @@ public class CalendarEntryDelete extends AbstractCalendarWebScript
|
|||||||
calendarService.deleteCalendarEntry(entry);
|
calendarService.deleteCalendarEntry(entry);
|
||||||
|
|
||||||
// Record this in the activity feed
|
// Record this in the activity feed
|
||||||
try
|
addActivityEntry("deleted", entry, site, req, json);
|
||||||
{
|
|
||||||
JSONObject activity = new JSONObject();
|
|
||||||
activity.put("title", entry.getTitle());
|
|
||||||
activity.put("page", req.getParameter("page"));
|
|
||||||
|
|
||||||
activityService.postActivity(
|
|
||||||
"org.alfresco.calendar.event-deleted",
|
|
||||||
site.getShortName(),
|
|
||||||
CALENDAR_SERVICE_ACTIVITY_APP_NAME,
|
|
||||||
activity.toString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
// Warn, but carry on
|
|
||||||
logger.warn("Error adding event deletion to activities feed", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// All done
|
// All done
|
||||||
status.setCode(Status.STATUS_NO_CONTENT, "Entry deleted");
|
status.setCode(Status.STATUS_NO_CONTENT, "Entry deleted");
|
||||||
|
@@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.web.scripts.calendar;
|
package org.alfresco.repo.web.scripts.calendar;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
@@ -26,8 +25,6 @@ import java.util.StringTokenizer;
|
|||||||
import org.alfresco.service.cmr.calendar.CalendarEntry;
|
import org.alfresco.service.cmr.calendar.CalendarEntry;
|
||||||
import org.alfresco.service.cmr.calendar.CalendarEntryDTO;
|
import org.alfresco.service.cmr.calendar.CalendarEntryDTO;
|
||||||
import org.alfresco.service.cmr.site.SiteInfo;
|
import org.alfresco.service.cmr.site.SiteInfo;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.springframework.extensions.webscripts.Cache;
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
@@ -42,8 +39,6 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
|||||||
*/
|
*/
|
||||||
public class CalendarEntryPost extends AbstractCalendarWebScript
|
public class CalendarEntryPost extends AbstractCalendarWebScript
|
||||||
{
|
{
|
||||||
private static Log logger = LogFactory.getLog(CalendarEntryPost.class);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, Object> executeImpl(SiteInfo site, String eventName,
|
protected Map<String, Object> executeImpl(SiteInfo site, String eventName,
|
||||||
WebScriptRequest req, JSONObject json, Status status, Cache cache) {
|
WebScriptRequest req, JSONObject json, Status status, Cache cache) {
|
||||||
@@ -89,26 +84,7 @@ public class CalendarEntryPost extends AbstractCalendarWebScript
|
|||||||
|
|
||||||
|
|
||||||
// Generate the activity feed for this
|
// Generate the activity feed for this
|
||||||
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
|
String dateOpt = addActivityEntry("created", entry, site, req, json);
|
||||||
String dateOpt = "?date=" + fmt.format(entry.getStart());
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JSONObject activity = new JSONObject();
|
|
||||||
activity.put("title", entry.getTitle());
|
|
||||||
activity.put("page", req.getParameter("page") + dateOpt);
|
|
||||||
|
|
||||||
activityService.postActivity(
|
|
||||||
"org.alfresco.calendar.event-created",
|
|
||||||
site.getShortName(),
|
|
||||||
CALENDAR_SERVICE_ACTIVITY_APP_NAME,
|
|
||||||
activity.toString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
// Warn, but carry on
|
|
||||||
logger.warn("Error adding event deletion to activities feed", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Build the return object
|
// Build the return object
|
||||||
|
@@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.web.scripts.calendar;
|
package org.alfresco.repo.web.scripts.calendar;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
@@ -26,8 +25,6 @@ import java.util.StringTokenizer;
|
|||||||
import org.alfresco.service.cmr.calendar.CalendarEntry;
|
import org.alfresco.service.cmr.calendar.CalendarEntry;
|
||||||
import org.alfresco.service.cmr.calendar.CalendarEntryDTO;
|
import org.alfresco.service.cmr.calendar.CalendarEntryDTO;
|
||||||
import org.alfresco.service.cmr.site.SiteInfo;
|
import org.alfresco.service.cmr.site.SiteInfo;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.springframework.extensions.webscripts.Cache;
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
@@ -42,8 +39,6 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
|||||||
*/
|
*/
|
||||||
public class CalendarEntryPut extends AbstractCalendarWebScript
|
public class CalendarEntryPut extends AbstractCalendarWebScript
|
||||||
{
|
{
|
||||||
private static Log logger = LogFactory.getLog(CalendarEntryPut.class);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, Object> executeImpl(SiteInfo site, String eventName,
|
protected Map<String, Object> executeImpl(SiteInfo site, String eventName,
|
||||||
WebScriptRequest req, JSONObject json, Status status, Cache cache) {
|
WebScriptRequest req, JSONObject json, Status status, Cache cache) {
|
||||||
@@ -157,26 +152,7 @@ public class CalendarEntryPut extends AbstractCalendarWebScript
|
|||||||
|
|
||||||
|
|
||||||
// Generate the activity feed for this
|
// Generate the activity feed for this
|
||||||
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
|
String dateOpt = addActivityEntry("updated", entry, site, req, json);
|
||||||
String dateOpt = "?date=" + fmt.format(entry.getStart());
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JSONObject activity = new JSONObject();
|
|
||||||
activity.put("title", entry.getTitle());
|
|
||||||
activity.put("page", req.getParameter("page") + dateOpt);
|
|
||||||
|
|
||||||
activityService.postActivity(
|
|
||||||
"org.alfresco.calendar.event-updated",
|
|
||||||
site.getShortName(),
|
|
||||||
CALENDAR_SERVICE_ACTIVITY_APP_NAME,
|
|
||||||
activity.toString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
// Warn, but carry on
|
|
||||||
logger.warn("Error adding event deletion to activities feed", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Build the return object
|
// Build the return object
|
||||||
|
Reference in New Issue
Block a user