ALF-9156 - Begin to use the Calendar Service for a replacement java backed calendar webscript

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28802 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2011-07-04 19:05:19 +00:00
parent f4f15adf14
commit 45f6179b19
3 changed files with 170 additions and 0 deletions

View File

@@ -18,10 +18,18 @@
*/ */
package org.alfresco.repo.web.scripts.calendar; package org.alfresco.repo.web.scripts.calendar;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.repo.model.Repository; import org.alfresco.repo.model.Repository;
import org.alfresco.service.cmr.calendar.CalendarService;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService; import org.alfresco.service.cmr.site.SiteService;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript; import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/** /**
* @author Nick Burch * @author Nick Burch
@@ -33,6 +41,7 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
protected Repository repository; protected Repository repository;
protected NodeService nodeService; protected NodeService nodeService;
protected SiteService siteService; protected SiteService siteService;
protected CalendarService calendarService;
public void setRepository(Repository repository) public void setRepository(Repository repository)
{ {
@@ -48,4 +57,55 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
{ {
this.siteService = siteService; this.siteService = siteService;
} }
public void setCalendarService(CalendarService calendarService)
{
this.calendarService = calendarService;
}
/**
* Equivalent of <i>jsonError</i> in the old JavaScript controllers
*/
protected Map<String,Object> buildError(String message)
{
HashMap<String, Object> model = new HashMap<String, Object>();
model.put("error", message);
return model;
}
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req,
Status status, Cache cache)
{
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
if(templateVars == null)
{
return buildError("No parameters supplied");
}
String siteName = templateVars.get("site");
if(siteName == null)
{
siteName = req.getParameter("site");
}
if(siteName == null)
{
return buildError("No site given");
}
SiteInfo site = siteService.getSite(siteName);
if(site == null)
{
return buildError("Could not find site: " + siteName);
}
// Event name is optional
String eventName = templateVars.get("eventname");
// Have the real work done
return executeImpl(site, eventName, req, status, cache);
}
protected abstract Map<String, Object> executeImpl(SiteInfo site,
String eventName, WebScriptRequest req, Status status, Cache cache);
} }

View File

@@ -0,0 +1,42 @@
/*
* 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 org.alfresco.repo.calendar.CalendarServiceImplTest;
import org.alfresco.service.cmr.calendar.CalendarService;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
/**
* This class is a holder for the various test classes associated with the {@link CalendarService}.
* It is not (at the time of writing) intended to be incorporated into the automatic build
* which will find the various test classes and run them individually.
*
* @author Nick Burch
* @since 4.0
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
CalendarServiceImplTest.class,
CalendarRestApiTest.class
})
public class AllCalendarTests
{
// Intentionally empty
}

View File

@@ -0,0 +1,68 @@
/*
* 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.util.HashMap;
import java.util.Map;
import org.alfresco.repo.model.Repository;
import org.alfresco.service.cmr.calendar.CalendarEntry;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* This class is the controller for the slingshot calendar event.get webscript.
*
* @author Nick Burch
* @since 4.0
*/
public class CalendarEntryGet extends AbstractCalendarWebScript
{
@Override
protected Map<String, Object> executeImpl(SiteInfo site, String eventName,
WebScriptRequest req, Status status, Cache cache) {
CalendarEntry entry = calendarService.getCalendarEntry(
site.getShortName(), eventName
);
if(entry == null)
{
return buildError("Could not find event: " + eventName);
}
Map<String, Object> model = new HashMap<String, Object>();
model.put("name", entry.getSystemName());
model.put("what", entry.getTitle());
model.put("description", entry.getDescription());
model.put("location", entry.getLocation());
model.put("from", entry.getStart());
model.put("to", entry.getEnd());
model.put("tags", entry.getTags());
model.put("allday", null); // TODO
model.put("docfolder", null); // TODO
model.put("recurrence", null); // TODO
model.put("isoutlook", null); // TODO
return model;
}
}