mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Coding standards and consistency sweep across new services code in remote-api project.
Covers spacing, trailing {, @since tags, tabs and copyright headers. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30216 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -45,7 +45,6 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONException;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.JSONTokener;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
@@ -101,7 +100,7 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
protected Date parseDate(String date)
|
||||
{
|
||||
// Is there one at all?
|
||||
if(date == null || date.length() == 0)
|
||||
if (date == null || date.length() == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -111,7 +110,7 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
{
|
||||
return ISO8601DateFormat.parse(date);
|
||||
}
|
||||
catch(Exception e) {}
|
||||
catch (Exception e) {}
|
||||
|
||||
// Try YYYY/MM/DD
|
||||
SimpleDateFormat slashtime = new SimpleDateFormat("yyyy/MM/dd HH:mm");
|
||||
@@ -120,12 +119,12 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
{
|
||||
return slashtime.parse(date);
|
||||
}
|
||||
catch(ParseException e) {}
|
||||
catch (ParseException e) {}
|
||||
try
|
||||
{
|
||||
return slash.parse(date);
|
||||
}
|
||||
catch(ParseException e) {}
|
||||
catch (ParseException e) {}
|
||||
|
||||
// Try YYYY-MM-DD
|
||||
SimpleDateFormat dashtime = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
@@ -134,12 +133,12 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
{
|
||||
return dashtime.parse(date);
|
||||
}
|
||||
catch(ParseException e) {}
|
||||
catch (ParseException e) {}
|
||||
try
|
||||
{
|
||||
return dash.parse(date);
|
||||
}
|
||||
catch(ParseException e) {}
|
||||
catch (ParseException e) {}
|
||||
|
||||
// We don't know what it is, object
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid date '" + date + "'");
|
||||
@@ -153,18 +152,18 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
{
|
||||
boolean isAllDay = false;
|
||||
|
||||
if(json.containsKey("startAt") && json.containsKey("endAt"))
|
||||
if (json.containsKey("startAt") && json.containsKey("endAt"))
|
||||
{
|
||||
// New style ISO8601 dates
|
||||
entry.setStart(parseDate((String)json.get("startAt")));
|
||||
entry.setEnd(parseDate((String)json.get("endAt")));
|
||||
if(json.containsKey("allday"))
|
||||
if (json.containsKey("allday"))
|
||||
{
|
||||
// TODO Handle All Day events properly, including timezones
|
||||
isAllDay = true;
|
||||
}
|
||||
}
|
||||
else if(json.containsKey("allday"))
|
||||
else if (json.containsKey("allday"))
|
||||
{
|
||||
// Old style all-day event
|
||||
entry.setStart(parseDate(getOrNull(json, "from")));
|
||||
@@ -183,7 +182,7 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
|
||||
protected String getOrNull(JSONObject json, String key) throws JSONException
|
||||
{
|
||||
if(json.containsKey(key))
|
||||
if (json.containsKey(key))
|
||||
{
|
||||
return (String)json.get(key);
|
||||
}
|
||||
@@ -238,14 +237,14 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
|
||||
// What page is this for?
|
||||
String page = req.getParameter("page");
|
||||
if(page == null && json != null)
|
||||
if (page == null && json != null)
|
||||
{
|
||||
if(json.containsKey("page"))
|
||||
if (json.containsKey("page"))
|
||||
{
|
||||
page = (String)json.get("page");
|
||||
}
|
||||
}
|
||||
if(page == null)
|
||||
if (page == null)
|
||||
{
|
||||
// Default
|
||||
page = "calendar";
|
||||
@@ -264,10 +263,9 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
"org.alfresco.calendar.event-" + event,
|
||||
site.getShortName(),
|
||||
CALENDAR_SERVICE_ACTIVITY_APP_NAME,
|
||||
activityJson.toString()
|
||||
);
|
||||
activityJson.toString());
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
// Warn, but carry on
|
||||
logger.warn("Error adding event " + event + " to activities feed", e);
|
||||
@@ -303,10 +301,10 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
Status status, Cache cache)
|
||||
{
|
||||
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||
if(templateVars == null)
|
||||
if (templateVars == null)
|
||||
{
|
||||
String error = "No parameters supplied";
|
||||
if(useJSONErrors())
|
||||
if (useJSONErrors())
|
||||
{
|
||||
return buildError(error);
|
||||
}
|
||||
@@ -320,22 +318,22 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
// Parse the JSON, if supplied
|
||||
JSONObject json = null;
|
||||
String contentType = req.getContentType();
|
||||
if(contentType != null && contentType.indexOf(';') != -1)
|
||||
if (contentType != null && contentType.indexOf(';') != -1)
|
||||
{
|
||||
contentType = contentType.substring(0, contentType.indexOf(';'));
|
||||
}
|
||||
if(MimetypeMap.MIMETYPE_JSON.equals(contentType))
|
||||
if (MimetypeMap.MIMETYPE_JSON.equals(contentType))
|
||||
{
|
||||
JSONParser parser = new JSONParser();
|
||||
try
|
||||
{
|
||||
json = (JSONObject)parser.parse(req.getContent().getContent());
|
||||
}
|
||||
catch(IOException io)
|
||||
catch (IOException io)
|
||||
{
|
||||
return buildError("Invalid JSON: " + io.getMessage());
|
||||
}
|
||||
catch(org.json.simple.parser.ParseException je)
|
||||
catch (org.json.simple.parser.ParseException je)
|
||||
{
|
||||
return buildError("Invalid JSON: " + je.getMessage());
|
||||
}
|
||||
@@ -344,29 +342,29 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
|
||||
// Get the site short name. Try quite hard to do so...
|
||||
String siteName = templateVars.get("siteid");
|
||||
if(siteName == null)
|
||||
if (siteName == null)
|
||||
{
|
||||
siteName = templateVars.get("site");
|
||||
}
|
||||
if(siteName == null)
|
||||
if (siteName == null)
|
||||
{
|
||||
siteName = req.getParameter("site");
|
||||
}
|
||||
if(siteName == null && json != null)
|
||||
if (siteName == null && json != null)
|
||||
{
|
||||
if(json.containsKey("siteid"))
|
||||
if (json.containsKey("siteid"))
|
||||
{
|
||||
siteName = (String)json.get("siteid");
|
||||
}
|
||||
else if(json.containsKey("site"))
|
||||
else if (json.containsKey("site"))
|
||||
{
|
||||
siteName = (String)json.get("site");
|
||||
}
|
||||
}
|
||||
if(siteName == null)
|
||||
if (siteName == null)
|
||||
{
|
||||
String error = "No site given";
|
||||
if(useJSONErrors())
|
||||
if (useJSONErrors())
|
||||
{
|
||||
return buildError("No site given");
|
||||
}
|
||||
@@ -378,10 +376,10 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
|
||||
// Grab the requested site
|
||||
SiteInfo site = siteService.getSite(siteName);
|
||||
if(site == null)
|
||||
if (site == null)
|
||||
{
|
||||
String error = "Could not find site: " + siteName;
|
||||
if(useJSONErrors())
|
||||
if (useJSONErrors())
|
||||
{
|
||||
return buildError(error);
|
||||
}
|
||||
@@ -401,5 +399,4 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
protected abstract Map<String, Object> executeImpl(SiteInfo site,
|
||||
String eventName, WebScriptRequest req, JSONObject json,
|
||||
Status status, Cache cache);
|
||||
|
||||
}
|
||||
|
@@ -49,7 +49,8 @@ public class CalendarEntriesListGet extends AbstractCalendarWebScript
|
||||
{
|
||||
@Override
|
||||
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)
|
||||
{
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); // Evil...
|
||||
|
||||
// Get the entries for the list
|
||||
@@ -68,8 +69,8 @@ public class CalendarEntriesListGet extends AbstractCalendarWebScript
|
||||
|
||||
List<ChildAssociationRef> ignores = nodeService.getChildAssocs(
|
||||
entry.getNodeRef(), CalendarModel.TYPE_IGNORE_EVENT,
|
||||
ContentModel.ASSOC_CONTAINS, true
|
||||
);
|
||||
ContentModel.ASSOC_CONTAINS, true);
|
||||
|
||||
List<String> ignoreEvents = new ArrayList<String>();
|
||||
List<Date> ignoreEventDates = new ArrayList<Date>();
|
||||
for (ChildAssociationRef ref : ignores)
|
||||
|
@@ -39,25 +39,26 @@ public class CalendarEntryDelete extends AbstractCalendarWebScript
|
||||
* This WebScript uses HTTP status codes for errors
|
||||
*/
|
||||
@Override
|
||||
protected boolean useJSONErrors() {
|
||||
protected boolean useJSONErrors()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
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)
|
||||
{
|
||||
CalendarEntry entry = calendarService.getCalendarEntry(
|
||||
site.getShortName(), eventName
|
||||
);
|
||||
site.getShortName(), eventName);
|
||||
|
||||
if(entry == null)
|
||||
if (entry == null)
|
||||
{
|
||||
status.setCode(Status.STATUS_NOT_FOUND);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Special case for "deleting" an instance of a recurring event
|
||||
if(req.getParameter("date") != null && entry.getRecurrenceRule() != null)
|
||||
if (req.getParameter("date") != null && entry.getRecurrenceRule() != null)
|
||||
{
|
||||
// Have an ignored event generated
|
||||
createIgnoreEvent(req, entry);
|
||||
|
@@ -47,12 +47,12 @@ public class CalendarEntryGet extends AbstractCalendarWebScript
|
||||
|
||||
@Override
|
||||
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)
|
||||
{
|
||||
CalendarEntry entry = calendarService.getCalendarEntry(
|
||||
site.getShortName(), eventName
|
||||
);
|
||||
site.getShortName(), eventName);
|
||||
|
||||
if(entry == null)
|
||||
if (entry == null)
|
||||
{
|
||||
return buildError("Could not find event: " + eventName);
|
||||
}
|
||||
@@ -73,9 +73,9 @@ public class CalendarEntryGet extends AbstractCalendarWebScript
|
||||
result.put("recurrence", buildRecurrenceString(entry));
|
||||
|
||||
// Replace nulls with blank strings for the JSON
|
||||
for(String key : result.keySet())
|
||||
for (String key : result.keySet())
|
||||
{
|
||||
if(result.get(key) == null)
|
||||
if (result.get(key) == null)
|
||||
{
|
||||
result.put(key, "");
|
||||
}
|
||||
@@ -98,7 +98,7 @@ public class CalendarEntryGet extends AbstractCalendarWebScript
|
||||
{
|
||||
// If there's no recurrence rules, then there's nothing to do
|
||||
String recurrence = event.getRecurrenceRule();
|
||||
if(recurrence == null || recurrence.trim().length() == 0)
|
||||
if (recurrence == null || recurrence.trim().length() == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -114,11 +114,11 @@ public class CalendarEntryGet extends AbstractCalendarWebScript
|
||||
StringBuffer text = new StringBuffer();
|
||||
|
||||
// Handle the different frequencies
|
||||
if(params.containsKey("FREQ"))
|
||||
if (params.containsKey("FREQ"))
|
||||
{
|
||||
String freq = params.get("FREQ");
|
||||
String interval = params.get("INTERVAL");
|
||||
if(interval == null)
|
||||
if (interval == null)
|
||||
{
|
||||
interval = "1";
|
||||
}
|
||||
@@ -134,7 +134,7 @@ public class CalendarEntryGet extends AbstractCalendarWebScript
|
||||
text.append("Occurs every " + interval + " weeks on ");
|
||||
}
|
||||
|
||||
for(String day : params.get("BYDAY").split(","))
|
||||
for (String day : params.get("BYDAY").split(","))
|
||||
{
|
||||
text.append(days.get(day));
|
||||
text.append(", ");
|
||||
@@ -179,11 +179,11 @@ public class CalendarEntryGet extends AbstractCalendarWebScript
|
||||
|
||||
// And the rest
|
||||
DateFormat dFormat = SimpleDateFormat.getDateInstance(
|
||||
SimpleDateFormat.MEDIUM, I18NUtil.getLocale()
|
||||
);
|
||||
SimpleDateFormat.MEDIUM, I18NUtil.getLocale());
|
||||
|
||||
DateFormat tFormat = SimpleDateFormat.getTimeInstance(
|
||||
SimpleDateFormat.SHORT, I18NUtil.getLocale()
|
||||
);
|
||||
SimpleDateFormat.SHORT, I18NUtil.getLocale());
|
||||
|
||||
text.append("effective " + dFormat.format(event.getStart()));
|
||||
|
||||
if (params.containsKey("COUNT"))
|
||||
|
@@ -41,7 +41,8 @@ public class CalendarEntryPost extends AbstractCalendarWebScript
|
||||
{
|
||||
@Override
|
||||
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)
|
||||
{
|
||||
CalendarEntry entry = new CalendarEntryDTO();
|
||||
|
||||
// TODO Handle All Day events properly, including timezones
|
||||
@@ -59,26 +60,20 @@ public class CalendarEntryPost extends AbstractCalendarWebScript
|
||||
isAllDay = extractDates(entry, json);
|
||||
|
||||
// Handle tags
|
||||
if(json.containsKey("tags"))
|
||||
if (json.containsKey("tags"))
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer((String)json.get("tags"), " ");
|
||||
while(st.hasMoreTokens())
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
entry.getTags().add(st.nextToken());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(JSONException je)
|
||||
catch (JSONException je)
|
||||
{
|
||||
return buildError("Invalid JSON: " + je.getMessage());
|
||||
}
|
||||
|
||||
if(entry == null)
|
||||
{
|
||||
return buildError("Could not find event: " + eventName);
|
||||
}
|
||||
|
||||
|
||||
// Have it added
|
||||
entry = calendarService.createCalendarEntry(site.getShortName(), entry);
|
||||
|
||||
@@ -102,9 +97,9 @@ public class CalendarEntryPost extends AbstractCalendarWebScript
|
||||
result.put("docfolder", entry.getSharePointDocFolder());
|
||||
|
||||
// Replace nulls with blank strings for the JSON
|
||||
for(String key : result.keySet())
|
||||
for (String key : result.keySet())
|
||||
{
|
||||
if(result.get(key) == null)
|
||||
if (result.get(key) == null)
|
||||
{
|
||||
result.put(key, "");
|
||||
}
|
||||
|
@@ -41,12 +41,12 @@ public class CalendarEntryPut extends AbstractCalendarWebScript
|
||||
{
|
||||
@Override
|
||||
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)
|
||||
{
|
||||
CalendarEntry entry = calendarService.getCalendarEntry(
|
||||
site.getShortName(), eventName
|
||||
);
|
||||
site.getShortName(), eventName);
|
||||
|
||||
if(entry == null)
|
||||
if (entry == null)
|
||||
{
|
||||
return buildError("Could not find event: " + eventName);
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public class CalendarEntryPut extends AbstractCalendarWebScript
|
||||
String docFolder = (String)json.get("docfolder");
|
||||
|
||||
// Editing recurring events is special and a little bit odd...
|
||||
if(entry.getRecurrenceRule() != null && !json.containsKey("recurrenceRule"))
|
||||
if (entry.getRecurrenceRule() != null && !json.containsKey("recurrenceRule"))
|
||||
{
|
||||
// Have an ignored event generated
|
||||
// Will allow us to override this one instance
|
||||
@@ -70,7 +70,7 @@ public class CalendarEntryPut extends AbstractCalendarWebScript
|
||||
CalendarEntry newEntry = new CalendarEntryDTO();
|
||||
newEntry.setOutlook(true);
|
||||
|
||||
if("*NOT_CHANGE*".equals(docFolder))
|
||||
if ("*NOT_CHANGE*".equals(docFolder))
|
||||
{
|
||||
newEntry.setSharePointDocFolder(entry.getSharePointDocFolder());
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class CalendarEntryPut extends AbstractCalendarWebScript
|
||||
}
|
||||
|
||||
// Doc folder is a bit special
|
||||
if("*NOT_CHANGE*".equals(docFolder))
|
||||
if ("*NOT_CHANGE*".equals(docFolder))
|
||||
{
|
||||
// Nothing to change
|
||||
}
|
||||
@@ -119,34 +119,27 @@ public class CalendarEntryPut extends AbstractCalendarWebScript
|
||||
else
|
||||
{
|
||||
entry.setLastRecurrence(
|
||||
parseDate((String)json.get("recurrenceLastMeeting"))
|
||||
);
|
||||
parseDate((String)json.get("recurrenceLastMeeting")));
|
||||
}
|
||||
}
|
||||
|
||||
// Handle tags
|
||||
if(json.containsKey("tags"))
|
||||
if (json.containsKey("tags"))
|
||||
{
|
||||
entry.getTags().clear();
|
||||
|
||||
StringTokenizer st = new StringTokenizer((String)json.get("tags"), " ");
|
||||
while(st.hasMoreTokens())
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
entry.getTags().add(st.nextToken());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(JSONException je)
|
||||
catch (JSONException je)
|
||||
{
|
||||
return buildError("Invalid JSON: " + je.getMessage());
|
||||
}
|
||||
|
||||
if(entry == null)
|
||||
{
|
||||
return buildError("Could not find event: " + eventName);
|
||||
}
|
||||
|
||||
|
||||
// Have it edited
|
||||
entry = calendarService.updateCalendarEntry(entry);
|
||||
|
||||
@@ -170,9 +163,9 @@ public class CalendarEntryPut extends AbstractCalendarWebScript
|
||||
result.put("docfolder", entry.getSharePointDocFolder());
|
||||
|
||||
// Replace nulls with blank strings for the JSON
|
||||
for(String key : result.keySet())
|
||||
for (String key : result.keySet())
|
||||
{
|
||||
if(result.get(key) == null)
|
||||
if (result.get(key) == null)
|
||||
{
|
||||
result.put(key, "");
|
||||
}
|
||||
@@ -192,11 +185,11 @@ public class CalendarEntryPut extends AbstractCalendarWebScript
|
||||
protected String generateTagString(CalendarEntry entry)
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if(entry.getTags() != null)
|
||||
if (entry.getTags() != null)
|
||||
{
|
||||
for(String tag : entry.getTags())
|
||||
for (String tag : entry.getTags())
|
||||
{
|
||||
if(sb.length() > 0) sb.append(' ');
|
||||
if (sb.length() > 0) sb.append(' ');
|
||||
sb.append(tag);
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -45,12 +45,13 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
||||
* Unit Test to test the Calendaring Web Script API
|
||||
*
|
||||
* @author Nick Burch
|
||||
* @since 4.0
|
||||
*/
|
||||
public class CalendarRestApiTest extends BaseWebScriptTest
|
||||
{
|
||||
@SuppressWarnings("unused")
|
||||
@SuppressWarnings("unused")
|
||||
private static Log logger = LogFactory.getLog(CalendarRestApiTest.class);
|
||||
|
||||
|
||||
private MutableAuthenticationService authenticationService;
|
||||
private AuthenticationComponent authenticationComponent;
|
||||
private PersonService personService;
|
||||
@@ -99,7 +100,7 @@ public class CalendarRestApiTest extends BaseWebScriptTest
|
||||
}
|
||||
|
||||
// Ensure the calendar container is there
|
||||
if(!siteService.hasContainer(SITE_SHORT_NAME_CALENDAR, "calendar"))
|
||||
if (!siteService.hasContainer(SITE_SHORT_NAME_CALENDAR, "calendar"))
|
||||
{
|
||||
siteService.createContainer(SITE_SHORT_NAME_CALENDAR, "calendar", null, null);
|
||||
}
|
||||
@@ -125,13 +126,13 @@ public class CalendarRestApiTest extends BaseWebScriptTest
|
||||
|
||||
// delete the users
|
||||
personService.deletePerson(USER_ONE);
|
||||
if(this.authenticationService.authenticationExists(USER_ONE))
|
||||
if (this.authenticationService.authenticationExists(USER_ONE))
|
||||
{
|
||||
this.authenticationService.deleteAuthentication(USER_ONE);
|
||||
}
|
||||
|
||||
personService.deletePerson(USER_TWO);
|
||||
if(this.authenticationService.authenticationExists(USER_TWO))
|
||||
if (this.authenticationService.authenticationExists(USER_TWO))
|
||||
{
|
||||
this.authenticationService.deleteAuthentication(USER_TWO);
|
||||
}
|
||||
@@ -168,13 +169,13 @@ public class CalendarRestApiTest extends BaseWebScriptTest
|
||||
private JSONObject getEntries(String username, String from) throws Exception
|
||||
{
|
||||
String url = URL_EVENTS_LIST + "?site=" + SITE_SHORT_NAME_CALENDAR;
|
||||
if(username != null)
|
||||
if (username != null)
|
||||
{
|
||||
url = URL_USER_SITE_EVENTS_LIST;
|
||||
}
|
||||
if(from != null)
|
||||
if (from != null)
|
||||
{
|
||||
if(url.indexOf('/') > 0)
|
||||
if (url.indexOf('/') > 0)
|
||||
{
|
||||
url += "&";
|
||||
}
|
||||
@@ -208,8 +209,7 @@ public class CalendarRestApiTest extends BaseWebScriptTest
|
||||
* Creates a 1 hour, non-all day event on the 29th of June
|
||||
*/
|
||||
private JSONObject createEntry(String name, String where, String description,
|
||||
int expectedStatus)
|
||||
throws Exception
|
||||
int expectedStatus) throws Exception
|
||||
{
|
||||
String date = "2011/06/29"; // A wednesday
|
||||
String start = "12:00";
|
||||
@@ -234,7 +234,7 @@ public class CalendarRestApiTest extends BaseWebScriptTest
|
||||
if (expectedStatus == Status.STATUS_OK)
|
||||
{
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
if(result.has("event"))
|
||||
if (result.has("event"))
|
||||
{
|
||||
return result.getJSONObject("event");
|
||||
}
|
||||
@@ -270,7 +270,7 @@ public class CalendarRestApiTest extends BaseWebScriptTest
|
||||
json.put("docfolder", "");
|
||||
json.put("page", "calendar");
|
||||
|
||||
if(withRecurrence)
|
||||
if (withRecurrence)
|
||||
{
|
||||
json.put("recurrenceRule", "FREQ=WEEKLY;INTERVAL=2;BYDAY=WE,FR");
|
||||
json.put("recurrenceLastMeeting", "2011-09-11");
|
||||
@@ -280,11 +280,11 @@ public class CalendarRestApiTest extends BaseWebScriptTest
|
||||
if (expectedStatus == Status.STATUS_OK)
|
||||
{
|
||||
JSONObject result = new JSONObject(response.getContentAsString());
|
||||
if(result.has("event"))
|
||||
if (result.has("event"))
|
||||
{
|
||||
return result.getJSONObject("event");
|
||||
}
|
||||
if(result.has("data"))
|
||||
if (result.has("data"))
|
||||
{
|
||||
return result.getJSONObject("data");
|
||||
}
|
||||
@@ -301,17 +301,16 @@ public class CalendarRestApiTest extends BaseWebScriptTest
|
||||
*/
|
||||
private String getNameFromEntry(JSONObject entry) throws Exception
|
||||
{
|
||||
if(! entry.has("uri"))
|
||||
if (! entry.has("uri"))
|
||||
{
|
||||
throw new IllegalArgumentException("No uri in " + entry.toString());
|
||||
}
|
||||
|
||||
String uri = entry.getString("uri");
|
||||
String name = uri.substring(
|
||||
uri.indexOf(SITE_SHORT_NAME_CALENDAR) + SITE_SHORT_NAME_CALENDAR.length() + 1
|
||||
);
|
||||
uri.indexOf(SITE_SHORT_NAME_CALENDAR) + SITE_SHORT_NAME_CALENDAR.length() + 1);
|
||||
|
||||
if(name.indexOf('?') > 0)
|
||||
if (name.indexOf('?') > 0)
|
||||
{
|
||||
return name.substring(0, name.indexOf('?'));
|
||||
}
|
||||
@@ -433,9 +432,7 @@ public class CalendarRestApiTest extends BaseWebScriptTest
|
||||
assertEquals(
|
||||
"Occurs every 2 weeks on Wednesday, Friday, effective " +
|
||||
"28-Jun-2011 until 11-Sep-2011 from 11:30 to 13:30",
|
||||
entry.getString("recurrence")
|
||||
);
|
||||
|
||||
entry.getString("recurrence"));
|
||||
|
||||
// Delete
|
||||
sendRequest(new DeleteRequest(URL_EVENT_BASE + name), Status.STATUS_NO_CONTENT);
|
||||
|
@@ -64,7 +64,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
// Site is optional
|
||||
SiteInfo site = null;
|
||||
String siteName = templateVars.get("site");
|
||||
if(siteName != null)
|
||||
if (siteName != null)
|
||||
{
|
||||
site = siteService.getSite(siteName);
|
||||
}
|
||||
@@ -74,7 +74,8 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(SiteInfo singleSite, String eventName,
|
||||
WebScriptRequest req, JSONObject json, Status status, Cache cache) {
|
||||
WebScriptRequest req, JSONObject json, Status status, Cache cache)
|
||||
{
|
||||
// Did they restrict by date?
|
||||
Date fromDate = parseDate(req.getParameter("from"));
|
||||
Date toDate = parseDate(req.getParameter("to"));
|
||||
@@ -82,13 +83,13 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
// What should we do about repeating events? First or all?
|
||||
boolean repeatingFirstOnly = true;
|
||||
String repeatingEvents = req.getParameter("repeating");
|
||||
if(repeatingEvents != null)
|
||||
if (repeatingEvents != null)
|
||||
{
|
||||
if("first".equals(repeatingEvents))
|
||||
if ("first".equals(repeatingEvents))
|
||||
{
|
||||
repeatingFirstOnly = true;
|
||||
}
|
||||
else if("all".equals(repeatingEvents))
|
||||
else if ("all".equals(repeatingEvents))
|
||||
{
|
||||
repeatingFirstOnly = false;
|
||||
}
|
||||
@@ -97,15 +98,15 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
{
|
||||
// Fall back to the icky old way of guessing it from
|
||||
// the format of the from date, which differs between uses!
|
||||
if(fromDate != null)
|
||||
if (fromDate != null)
|
||||
{
|
||||
String fromDateS = req.getParameter("from");
|
||||
if(fromDateS.indexOf('-') != -1)
|
||||
if (fromDateS.indexOf('-') != -1)
|
||||
{
|
||||
// Apparently this is the site calendar dashlet...
|
||||
repeatingFirstOnly = true;
|
||||
}
|
||||
if(fromDateS.indexOf('/') != -1)
|
||||
if (fromDateS.indexOf('/') != -1)
|
||||
{
|
||||
// This is something else, wants all events in range
|
||||
repeatingFirstOnly = false;
|
||||
@@ -115,7 +116,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
|
||||
// One site, or all the user's ones?
|
||||
List<SiteInfo> sites = new ArrayList<SiteInfo>();
|
||||
if(singleSite != null)
|
||||
if (singleSite != null)
|
||||
{
|
||||
// Just one
|
||||
sites.add(singleSite);
|
||||
@@ -129,7 +130,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
// We need to know the Site Names, and the NodeRefs of the calendar containers
|
||||
String[] siteShortNames = new String[sites.size()];
|
||||
Map<NodeRef, SiteInfo> containerLookup = new HashMap<NodeRef, SiteInfo>();
|
||||
for(int i=0; i<sites.size(); i++)
|
||||
for (int i=0; i<sites.size(); i++)
|
||||
{
|
||||
SiteInfo site = sites.get(i);
|
||||
siteShortNames[i] = site.getShortName();
|
||||
@@ -138,10 +139,9 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
{
|
||||
containerLookup.put(
|
||||
siteService.getContainer(site.getShortName(), CalendarServiceImpl.CALENDAR_COMPONENT),
|
||||
site
|
||||
);
|
||||
site);
|
||||
}
|
||||
catch(AccessDeniedException e)
|
||||
catch (AccessDeniedException e)
|
||||
{
|
||||
// You can see the site, but not the calendar, so skip it
|
||||
// This means you won't have any events in it anyway
|
||||
@@ -156,7 +156,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
|
||||
boolean resortNeeded = false;
|
||||
List<Map<String, Object>> results = new ArrayList<Map<String,Object>>();
|
||||
for(CalendarEntry entry : entries.getPage())
|
||||
for (CalendarEntry entry : entries.getPage())
|
||||
{
|
||||
// Build the object
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
@@ -178,9 +178,9 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
result.put("siteTitle", site.getTitle());
|
||||
|
||||
// Replace nulls with blank strings for the JSON
|
||||
for(String key : result.keySet())
|
||||
for (String key : result.keySet())
|
||||
{
|
||||
if(result.get(key) == null)
|
||||
if (result.get(key) == null)
|
||||
{
|
||||
result.put(key, "");
|
||||
}
|
||||
@@ -191,28 +191,30 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
|
||||
// Handle recurring as needed
|
||||
boolean orderChanged = handleRecurring(entry, result, results, fromDate, repeatingFirstOnly);
|
||||
if(orderChanged)
|
||||
if (orderChanged)
|
||||
{
|
||||
resortNeeded = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If the recurring events meant dates changed, re-sort
|
||||
if(resortNeeded)
|
||||
if (resortNeeded)
|
||||
{
|
||||
Collections.sort(results, new Comparator<Map<String, Object>>() {
|
||||
Collections.sort(results, new Comparator<Map<String, Object>>()
|
||||
{
|
||||
public int compare(Map<String, Object> resultA,
|
||||
Map<String, Object> resultB) {
|
||||
Map<String, Object> resultB)
|
||||
{
|
||||
Date startA = (Date)resultA.get(RESULT_START);
|
||||
Date startB = (Date)resultB.get(RESULT_START);
|
||||
|
||||
int cmp = startA.compareTo(startB);
|
||||
if(cmp == 0)
|
||||
if (cmp == 0)
|
||||
{
|
||||
Date endA = (Date)resultA.get(RESULT_END);
|
||||
Date endB = (Date)resultB.get(RESULT_END);
|
||||
cmp = endA.compareTo(endB);
|
||||
if(cmp == 0)
|
||||
if (cmp == 0)
|
||||
{
|
||||
String nameA = (String)resultA.get(RESULT_NAME);
|
||||
String nameB = (String)resultB.get(RESULT_NAME);
|
||||
@@ -248,7 +250,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
long timeDiff = entry.getEnd().getTime() - entry.getStart().getTime();
|
||||
|
||||
int weeks = (int)Math.floor(timeDiff / DURATION_WEEK);
|
||||
if(weeks > 0)
|
||||
if (weeks > 0)
|
||||
{
|
||||
duration.append(weeks);
|
||||
duration.append("W");
|
||||
@@ -256,7 +258,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
}
|
||||
|
||||
int days = (int)Math.floor(timeDiff / DURATION_DAY);
|
||||
if(days > 0)
|
||||
if (days > 0)
|
||||
{
|
||||
duration.append(days);
|
||||
duration.append("D");
|
||||
@@ -266,7 +268,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
duration.append("T");
|
||||
|
||||
int hours = (int)Math.floor(timeDiff / DURATION_HOUR);
|
||||
if(hours > 0)
|
||||
if (hours > 0)
|
||||
{
|
||||
duration.append(hours);
|
||||
duration.append("H");
|
||||
@@ -274,7 +276,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
}
|
||||
|
||||
int minutes = (int)Math.floor(timeDiff / DURATION_MINUTE);
|
||||
if(minutes > 0)
|
||||
if (minutes > 0)
|
||||
{
|
||||
duration.append(minutes);
|
||||
duration.append("M");
|
||||
@@ -282,7 +284,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
}
|
||||
|
||||
int seconds = (int)Math.floor(timeDiff / DURATION_SECOND);
|
||||
if(seconds > 0)
|
||||
if (seconds > 0)
|
||||
{
|
||||
duration.append(seconds);
|
||||
timeDiff -= minutes * DURATION_MINUTE;
|
||||
@@ -299,21 +301,21 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
private boolean handleRecurring(CalendarEntry entry, Map<String, Object> entryResult,
|
||||
List<Map<String, Object>> allResults, Date from, boolean repeatingFirstOnly)
|
||||
{
|
||||
if(entry.getRecurrenceRule() == null)
|
||||
if (entry.getRecurrenceRule() == null)
|
||||
{
|
||||
// Nothing to do
|
||||
return false;
|
||||
}
|
||||
|
||||
// If no date is given, start looking for occurrences from the event itself
|
||||
if(from == null)
|
||||
if (from == null)
|
||||
{
|
||||
from = entry.getStart();
|
||||
}
|
||||
|
||||
// Should we limit ourselves?
|
||||
Date until = null;
|
||||
if(!repeatingFirstOnly)
|
||||
if (!repeatingFirstOnly)
|
||||
{
|
||||
// Only repeating instances for the next 60 days, to keep the list sane
|
||||
// (It's normally only used for a month view anyway)
|
||||
@@ -329,15 +331,15 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
// Get it's recurring instances
|
||||
List<Date> dates = CalendarRecurrenceHelper.getRecurrencesOnOrAfter(
|
||||
entry, from, until, repeatingFirstOnly);
|
||||
if(dates == null)
|
||||
if (dates == null)
|
||||
{
|
||||
dates = new ArrayList<Date>();
|
||||
}
|
||||
|
||||
// Add on the original event time itself if needed
|
||||
if(entry.getStart().getTime() >= from.getTime())
|
||||
if (entry.getStart().getTime() >= from.getTime())
|
||||
{
|
||||
if(dates.size() == 0 || dates.get(0).getTime() != entry.getStart().getTime())
|
||||
if (dates.size() == 0 || dates.get(0).getTime() != entry.getStart().getTime())
|
||||
{
|
||||
// Original event is after the start time, and not on the recurring list
|
||||
dates.add(0, entry.getStart());
|
||||
@@ -345,7 +347,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
}
|
||||
|
||||
// If we got no dates, then no recurrences in the period so zap
|
||||
if(dates.size() == 0)
|
||||
if (dates.size() == 0)
|
||||
{
|
||||
allResults.remove(entryResult);
|
||||
return false; // Remains sorted despite delete
|
||||
@@ -355,14 +357,14 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript
|
||||
updateRepeatingStartEnd(dates.get(0), duration, entryResult);
|
||||
|
||||
// If first result only, alter title and finish
|
||||
if(repeatingFirstOnly)
|
||||
if (repeatingFirstOnly)
|
||||
{
|
||||
entryResult.put(RESULT_TITLE, entry.getTitle() + " (Repeating)");
|
||||
return true; // Date has been changed
|
||||
}
|
||||
|
||||
// Otherwise generate one entry per extra date
|
||||
for(int i=1; i<dates.size(); i++)
|
||||
for (int i=1; i<dates.size(); i++)
|
||||
{
|
||||
// Clone the properties
|
||||
Map<String, Object> newResult = new HashMap<String, Object>(entryResult);
|
||||
|
Reference in New Issue
Block a user