mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
ALF-9156 First pass of converting the whole-site calendar listing webscript to Java with some de-luceneing
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28959 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/lib/calendar.lib.js">
|
||||
|
||||
var siteId = args["site"];
|
||||
|
||||
model.events = getEvents(siteId);
|
||||
model.siteId = siteId;
|
||||
|
||||
function getEvents(siteId)
|
||||
{
|
||||
var site = siteService.getSite(siteId);
|
||||
if (site === null)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
var calendar = getCalendarContainer(site);
|
||||
if (calendar === null)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
var query = "+PATH:\"/app:company_home/st:sites/cm:" + search.ISO9075Encode(site.shortName) + "/cm:calendar/*\" " +
|
||||
"+TYPE:\"{http\://www.alfresco.org/model/calendar}calendarEvent\"";
|
||||
|
||||
var results = search.luceneSearch(query, "ia:fromDate", true);
|
||||
var e, events = [];
|
||||
|
||||
for (var i=0; i < results.length; i++)
|
||||
{
|
||||
e = results[i];
|
||||
var ignoreEvents = [];
|
||||
if (e.children != null)
|
||||
{
|
||||
var childrenEvents = e.children;
|
||||
for (var j=0; j<childrenEvents.length; j++)
|
||||
{
|
||||
var fullDate = childrenEvents[j].properties["ia:date"];
|
||||
ignoreEvents.push((fullDate.getMonth() + 1) + "/" + fullDate.getDate() + "/" + fullDate.getFullYear());
|
||||
}
|
||||
}
|
||||
|
||||
events.push(
|
||||
{
|
||||
"event": e,
|
||||
"fromDate": e.properties["ia:fromDate"],
|
||||
"tags": e.tags,
|
||||
"ignoreEvents": ignoreEvents
|
||||
});
|
||||
}
|
||||
|
||||
return events;
|
||||
}
|
@@ -1,11 +1,10 @@
|
||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||
<#-- <#escape x as jsonUtils.encodeJSONString(x)> -->
|
||||
{
|
||||
<#if events?exists && events?size > 0>
|
||||
<#assign prev = "">
|
||||
<#-- We do the sort here as the sort in the JavaScript doesn't seem to work as expected! -->
|
||||
<#list events?sort_by(["fromDate"]) as item>
|
||||
<#list events as item>
|
||||
<#assign event = item.event>
|
||||
<#assign date = event.properties["ia:fromDate"]?string("M/d/yyyy")>
|
||||
<#assign date = event.start?string("M/d/yyyy")>
|
||||
<#if date != prev>
|
||||
<#assign counter = 0>
|
||||
<#if item_index > 0>],</#if>
|
||||
@@ -13,18 +12,18 @@
|
||||
</#if>
|
||||
<#if counter > 0>,</#if>
|
||||
{
|
||||
"name": "${event.properties["ia:whatEvent"]}",
|
||||
"from": "${event.properties["ia:fromDate"]?string("M/d/yyyy")}",
|
||||
"start": "${event.properties["ia:fromDate"]?string("HH:mm")}",
|
||||
"to": "${event.properties["ia:toDate"]?string("M/d/yyyy")}",
|
||||
"end": "${event.properties["ia:toDate"]?string("HH:mm")}",
|
||||
"uri": "calendar/event/${siteId}/${event.name}",
|
||||
"name": "${event.title}",
|
||||
"from": "${event.start?string("M/d/yyyy")}",
|
||||
"start": "${event.start?string("HH:mm")}",
|
||||
"to": "${event.end?string("M/d/yyyy")}",
|
||||
"end": "${event.end?string("HH:mm")}",
|
||||
"uri": "calendar/event/${siteId}/${event.systemName}",
|
||||
"tags": [<#list item.tags as tag>"${tag}"<#if tag_has_next>,</#if></#list>],
|
||||
<#if event.properties["ia:recurrenceRule"]??>
|
||||
"recurrenceRule": "${event.properties["ia:recurrenceRule"]}",
|
||||
<#if event.recurrenceRule??>
|
||||
"recurrenceRule": "${event.recurrenceRule}",
|
||||
</#if>
|
||||
<#if event.properties["ia:recurrenceLastMeeting"]??>
|
||||
"recurrenceLastMeeting": "${event.properties["ia:recurrenceLastMeeting"]?string("M/d/yyyy")}",
|
||||
<#if event.lastRecurrence??>
|
||||
"recurrenceLastMeeting": "${event.lastRecurrence?string("M/d/yyyy")}",
|
||||
</#if>
|
||||
"ignoreEvents": [<#list item.ignoreEvents as ignoreEvent>"${ignoreEvent}"<#if ignoreEvent_has_next>,</#if></#list>]
|
||||
}
|
||||
@@ -34,4 +33,4 @@
|
||||
</#list>
|
||||
</#if>
|
||||
}
|
||||
</#escape>
|
||||
<#-- </#escape> -->
|
||||
|
@@ -1511,4 +1511,10 @@
|
||||
parent="abstractCalendarWebScript">
|
||||
</bean>
|
||||
|
||||
<!-- Lists the Calendar Events for a site calendar -->
|
||||
<bean id="webscript.org.alfresco.slingshot.calendar.eventList.get"
|
||||
class="org.alfresco.repo.web.scripts.calendar.CalendarEntriesListGet"
|
||||
parent="abstractCalendarWebScript">
|
||||
</bean>
|
||||
|
||||
</beans>
|
@@ -26,6 +26,7 @@ import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.repo.calendar.CalendarModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.service.cmr.activities.ActivityService;
|
||||
@@ -55,6 +56,11 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
{
|
||||
public static final String CALENDAR_SERVICE_ACTIVITY_APP_NAME = "calendar";
|
||||
|
||||
/**
|
||||
* When no maximum or paging info is given, what should we use?
|
||||
*/
|
||||
protected static final int MAX_QUERY_ENTRY_COUNT = 1000;
|
||||
|
||||
// Injected services
|
||||
protected NodeService nodeService;
|
||||
protected SiteService siteService;
|
||||
@@ -177,6 +183,18 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds up a listing Paging request, either using the defaults or
|
||||
* the paging options specified
|
||||
*/
|
||||
protected PagingRequest buildPagingRequest(WebScriptRequest req)
|
||||
{
|
||||
// TODO Check the request for standard paging options
|
||||
PagingRequest paging = new PagingRequest(MAX_QUERY_ENTRY_COUNT);
|
||||
paging.setRequestTotalCountMax(MAX_QUERY_ENTRY_COUNT);
|
||||
return paging;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normally the Calendar webscripts return a 200 with JSON
|
||||
* containing the error message. Override this to switch to
|
||||
|
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.calendar;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.calendar.CalendarModel;
|
||||
import org.alfresco.service.cmr.calendar.CalendarEntry;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
* This class is the controller for the slingshot calendar eventList.get webscript.
|
||||
*
|
||||
* TODO Improve what we give to the FTL, and have the FTL include iso8601 dates too
|
||||
*
|
||||
* @author Nick Burch
|
||||
* @since 4.0
|
||||
*/
|
||||
public class CalendarEntriesListGet extends AbstractCalendarWebScript
|
||||
{
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(SiteInfo site, String eventName,
|
||||
WebScriptRequest req, JSONObject json, Status status, Cache cache) {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); // Evil...
|
||||
|
||||
// Get the entries for the list
|
||||
PagingRequest paging = buildPagingRequest(req);
|
||||
PagingResults<CalendarEntry> entries =
|
||||
calendarService.listCalendarEntries(site.getShortName(), paging);
|
||||
|
||||
// For each one in our page, grab details of any ignored instances
|
||||
List<Map<String,Object>> results = new ArrayList<Map<String,Object>>();
|
||||
for (CalendarEntry entry : entries.getPage())
|
||||
{
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
result.put("event", entry);
|
||||
result.put("fromDate", entry.getStart());
|
||||
result.put("tags", entry.getTags());
|
||||
|
||||
List<ChildAssociationRef> ignores = nodeService.getChildAssocs(
|
||||
entry.getNodeRef(), CalendarModel.TYPE_IGNORE_EVENT,
|
||||
ContentModel.ASSOC_CONTAINS, true
|
||||
);
|
||||
List<String> ignoreEvents = new ArrayList<String>();
|
||||
List<Date> ignoreEventDates = new ArrayList<Date>();
|
||||
for (ChildAssociationRef ref : ignores)
|
||||
{
|
||||
Date date = (Date)nodeService.getProperty(ref.getChildRef(), CalendarModel.PROP_IGNORE_EVENT_DATE);
|
||||
if (date != null)
|
||||
{
|
||||
ignoreEventDates.add(date);
|
||||
ignoreEvents.add(formatter.format(date));
|
||||
}
|
||||
}
|
||||
result.put("ignoreEvents", ignoreEvents);
|
||||
result.put("ignoreEventDates", ignoreEventDates);
|
||||
|
||||
results.add(result);
|
||||
}
|
||||
|
||||
// All done
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("events", results);
|
||||
model.put("siteId", site.getShortName());
|
||||
model.put("site", site);
|
||||
return model;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user