mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
ALF-10204 Support the new calendar start and end date format which mirrors the display format
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30489 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -61,6 +61,11 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
{
|
||||
public static final String CALENDAR_SERVICE_ACTIVITY_APP_NAME = "calendar";
|
||||
|
||||
protected static final String PARAM_TIMEZONE = "timeZone";
|
||||
protected static final String PARAM_START_AT = "startAt";
|
||||
protected static final String PARAM_END_AT = "endAt";
|
||||
protected static final String PARAM_ISO8601 = "iso8601";
|
||||
|
||||
private static Log logger = LogFactory.getLog(AbstractCalendarWebScript.class);
|
||||
|
||||
/**
|
||||
@@ -157,11 +162,48 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
isAllDay = true;
|
||||
}
|
||||
|
||||
if (json.containsKey("startAt") && json.containsKey("endAt"))
|
||||
if (json.containsKey(PARAM_START_AT) && json.containsKey(PARAM_END_AT))
|
||||
{
|
||||
// New style ISO8601 based dates and times
|
||||
String startAt = ((String)json.get("startAt"));
|
||||
String endAt = ((String)json.get("endAt"));
|
||||
Object startAtO = json.get(PARAM_START_AT);
|
||||
Object endAtO = json.get(PARAM_END_AT);
|
||||
|
||||
// Grab the details
|
||||
String startAt;
|
||||
String endAt;
|
||||
String timezoneName = null;
|
||||
if(startAtO instanceof JSONObject)
|
||||
{
|
||||
// "startAt": { "iso8601":"2011-...." }
|
||||
JSONObject startAtJSON = (JSONObject)startAtO;
|
||||
JSONObject endAtJSON = (JSONObject)endAtO;
|
||||
startAt = (String)startAtJSON.get(PARAM_ISO8601);
|
||||
endAt = (String)endAtJSON.get(PARAM_ISO8601);
|
||||
|
||||
if(startAtJSON.containsKey(PARAM_TIMEZONE))
|
||||
{
|
||||
timezoneName = (String)startAtJSON.get(PARAM_TIMEZONE);
|
||||
if(endAtJSON.containsKey(PARAM_TIMEZONE))
|
||||
{
|
||||
String endTZ = (String)endAtJSON.get(PARAM_TIMEZONE);
|
||||
if(! endTZ.equals(timezoneName))
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Timezones must match");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// "startAt": "2011-...."
|
||||
startAt = (String)json.get(PARAM_START_AT);
|
||||
endAt = (String)json.get(PARAM_END_AT);
|
||||
}
|
||||
if(json.containsKey(PARAM_TIMEZONE))
|
||||
{
|
||||
timezoneName = (String)json.get(PARAM_TIMEZONE);
|
||||
}
|
||||
|
||||
|
||||
// Is this an all day event?
|
||||
if (json.containsKey("allday"))
|
||||
@@ -179,10 +221,10 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
// Regular event start and end rules
|
||||
|
||||
// Do we have explicit timezone information?
|
||||
if (json.containsKey("timeZone"))
|
||||
if (timezoneName != null)
|
||||
{
|
||||
// Get the specified timezone
|
||||
TimeZone tz = TimeZone.getTimeZone((String)json.get("timeZone"));
|
||||
TimeZone tz = TimeZone.getTimeZone(timezoneName);
|
||||
|
||||
// Grab the dates and times in the specified timezone
|
||||
entry.setStart(ISO8601DateFormat.parse(startAt, tz));
|
||||
|
@@ -168,6 +168,13 @@ public class CalendarRestApiTest extends BaseWebScriptTest
|
||||
|
||||
// Test helper methods
|
||||
|
||||
private JSONObject validateAndParseJSON(String json) throws Exception
|
||||
{
|
||||
// TODO Do full validation, rather than just the basic bits
|
||||
// that the JSONObject constructor provides
|
||||
return new JSONObject(json);
|
||||
}
|
||||
|
||||
private JSONObject getEntries(String username, String from) throws Exception
|
||||
{
|
||||
String url = URL_EVENTS_LIST + "?site=" + SITE_SHORT_NAME_CALENDAR;
|
||||
@@ -189,7 +196,7 @@ public class CalendarRestApiTest extends BaseWebScriptTest
|
||||
}
|
||||
|
||||
Response response = sendRequest(new GetRequest(url), 200);
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
JSONObject result = validateAndParseJSON(response.getContentAsString());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -198,7 +205,7 @@ public class CalendarRestApiTest extends BaseWebScriptTest
|
||||
Response response = sendRequest(new GetRequest(URL_EVENT_BASE + name), expectedStatus);
|
||||
if (expectedStatus == Status.STATUS_OK)
|
||||
{
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
JSONObject result = validateAndParseJSON(response.getContentAsString());
|
||||
return result;
|
||||
}
|
||||
else
|
||||
@@ -257,7 +264,7 @@ public class CalendarRestApiTest extends BaseWebScriptTest
|
||||
Response response = sendRequest(new PostRequest(URL_EVENT_CREATE, json.toString(), "application/json"), expectedStatus);
|
||||
if (expectedStatus == Status.STATUS_OK)
|
||||
{
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
JSONObject result = validateAndParseJSON(response.getContentAsString());
|
||||
if (result.has("event"))
|
||||
{
|
||||
return result.getJSONObject("event");
|
||||
@@ -303,7 +310,7 @@ public class CalendarRestApiTest extends BaseWebScriptTest
|
||||
Response response = sendRequest(new PutRequest(URL_EVENT_BASE + name, json.toString(), "application/json"), expectedStatus);
|
||||
if (expectedStatus == Status.STATUS_OK)
|
||||
{
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
JSONObject result = validateAndParseJSON(response.getContentAsString());
|
||||
if (result.has("event"))
|
||||
{
|
||||
return result.getJSONObject("event");
|
||||
@@ -554,6 +561,30 @@ public class CalendarRestApiTest extends BaseWebScriptTest
|
||||
assertEquals("2011-06-22T12:45:25.000+01:00", entry.getJSONObject("endAt").getString("iso8601"));
|
||||
|
||||
|
||||
// ISO8601 in get style, with timezone
|
||||
json = new JSONObject();
|
||||
JSONObject startAt = new JSONObject();
|
||||
JSONObject endAt = new JSONObject();
|
||||
startAt.put("iso8601", "2011-06-24T09:30:05");
|
||||
startAt.put("timeZone", "Europe/London");
|
||||
endAt.put("iso8601", "2011-06-24T10:45:25");
|
||||
endAt.put("timeZone", "Europe/London");
|
||||
json.put("startAt", startAt);
|
||||
json.put("endAt", endAt);
|
||||
entry = createEntry(EVENT_TITLE_ONE, "Where", "Thing", json, Status.STATUS_OK);
|
||||
|
||||
// Check old style dates and times
|
||||
assertEquals("2011-06-24", entry.getString("from"));
|
||||
assertEquals("2011-06-24", entry.getString("to"));
|
||||
assertEquals("09:30", entry.getString("start"));
|
||||
assertEquals("10:45", entry.getString("end"));
|
||||
assertEquals("false", entry.getString("allday"));
|
||||
|
||||
// Check new style dates and times
|
||||
assertEquals("2011-06-24T09:30:05.000+01:00", entry.getJSONObject("startAt").getString("iso8601"));
|
||||
assertEquals("2011-06-24T10:45:25.000+01:00", entry.getJSONObject("endAt").getString("iso8601"));
|
||||
|
||||
|
||||
// All-day old-style
|
||||
json = new JSONObject();
|
||||
json.put("from", "2011/06/21");
|
||||
|
Reference in New Issue
Block a user