diff --git a/config/alfresco/templates/activities/org/alfresco/generic.atomentry.ftl b/config/alfresco/templates/activities/org/alfresco/generic.atomentry.ftl new file mode 100644 index 0000000000..dbae100e98 --- /dev/null +++ b/config/alfresco/templates/activities/org/alfresco/generic.atomentry.ftl @@ -0,0 +1,17 @@ + + ${name!""} + + href="${repoEndPoint}/d/d/${nodeRef?replace("://","/")}/${name!""}" + <#else> + href="${repoEndPoint}" + + /> + + ${id} + ${xmldate(date)} + ${userId!""} ${activityType!""} ${displayPath!""} <#if siteNetwork?? && siteNetwork != "">(${siteNetwork} site) + + ${userId!""} + + \ No newline at end of file diff --git a/config/alfresco/templates/activities/org/alfresco/generic.json.ftl b/config/alfresco/templates/activities/org/alfresco/generic.json.ftl new file mode 100644 index 0000000000..46ecb90319 --- /dev/null +++ b/config/alfresco/templates/activities/org/alfresco/generic.json.ftl @@ -0,0 +1,2 @@ +<#-- default JSON rendering is to pass-through - assumes activityData is posted in JSON format --> +${activityData!""} \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/activities/sitefeed.get.atomfeed.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/sitefeed.get.atomfeed.ftl new file mode 100644 index 0000000000..3ceda2a791 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/sitefeed.get.atomfeed.ftl @@ -0,0 +1,9 @@ + + +Alfresco (0.1) + +Alfresco Activities Site Feed for ${siteId} +<#if feedEntries??> +<#list feedEntries as feedEntry> ${feedEntry.activitySummary} +<#else> + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/activities/sitefeed.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/sitefeed.get.desc.xml new file mode 100644 index 0000000000..cae93abce6 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/sitefeed.get.desc.xml @@ -0,0 +1,10 @@ + + Activities Site Feed Web Script + Allow currently logged in user to get feed for specified site (if private site then user must be a member or an admin user) + /api/activities/feed/site/{siteId} + /api/activities/feed/site/{siteId}?format=atomfeed + /api/activities/feed/site/{siteId}?format=json + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/activities/template.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/template.get.desc.xml new file mode 100644 index 0000000000..ffe6402e50 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/template.get.desc.xml @@ -0,0 +1,9 @@ + + Activity Type Template + Get the activity type template. + /api/activities/template?p={path} + /api/activities/template?p={path}&format=text + + admin + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/activities/template.get.text.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/template.get.text.ftl new file mode 100644 index 0000000000..ed575c13dd --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/template.get.text.ftl @@ -0,0 +1,2 @@ +<#if template??> +${template} \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/activities/templates.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/templates.get.desc.xml new file mode 100644 index 0000000000..fa03049684 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/templates.get.desc.xml @@ -0,0 +1,11 @@ + + Activity Template Paths + Get a collection of the template paths. + /api/activities/templates + /api/activities/templates?p={path}&format=json + /api/activities/templates?p={path} + /api/activities/templates?p={path}&format=json + + admin + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/activities/templates.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/templates.get.json.ftl new file mode 100644 index 0000000000..0473d35cac --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/templates.get.json.ftl @@ -0,0 +1,4 @@ +[ +<#if paths??> +<#list paths as path> "${path}"<#if path_has_next>, +] \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed-admin.get.atomfeed.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed-admin.get.atomfeed.ftl new file mode 100644 index 0000000000..aa716367d7 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed-admin.get.atomfeed.ftl @@ -0,0 +1,9 @@ + + +Alfresco (0.1) + +Alfresco Activities User Feed for ${feedUserId} +<#if feedEntries??> +<#list feedEntries as feedEntry> ${feedEntry.activitySummary} +<#else> + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed-admin.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed-admin.get.desc.xml new file mode 100644 index 0000000000..39321d87a2 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed-admin.get.desc.xml @@ -0,0 +1,13 @@ + + Activities Admin User Feed Web Script + Allow admin to get feed for a specified user + /api/activities/feed/user/{userId} + /api/activities/feed/user/{userId}?format=atomfeed + /api/activities/feed/user/{userId}?format=json + /api/activities/feed/user/{userId}?s={siteId} + /api/activities/feed/user/{userId}?s={siteId}&format=atomfeed + /api/activities/feed/user/{userId}?s={siteId}&format=json + + admin + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed-admin.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed-admin.get.json.ftl new file mode 100644 index 0000000000..e6f2c5868a --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed-admin.get.json.ftl @@ -0,0 +1,5 @@ +{ +<#if feedEntries??> +<#list feedEntries as feedEntry> ${feedEntry.activitySummary} +<#else> +} \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed.get.atomfeed.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed.get.atomfeed.ftl new file mode 100644 index 0000000000..aa716367d7 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed.get.atomfeed.ftl @@ -0,0 +1,9 @@ + + +Alfresco (0.1) + +Alfresco Activities User Feed for ${feedUserId} +<#if feedEntries??> +<#list feedEntries as feedEntry> ${feedEntry.activitySummary} +<#else> + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed.get.desc.xml new file mode 100644 index 0000000000..1560a38f35 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed.get.desc.xml @@ -0,0 +1,13 @@ + + Activities User Feed Web Script + Allow currently logged in user to get their feed + /api/activities/feed/user + /api/activities/feed/user?format=atomfeed + /api/activities/feed/user?format=json + /api/activities/feed/user?s={siteId} + /api/activities/feed/user?s={siteId}&format=atomfeed + /api/activities/feed/user?s={siteId}&format=json + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed.get.json.ftl new file mode 100644 index 0000000000..e6f2c5868a --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/activities/userfeed.get.json.ftl @@ -0,0 +1,5 @@ +{ +<#if feedEntries??> +<#list feedEntries as feedEntry> ${feedEntry.activitySummary} +<#else> +} \ No newline at end of file diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index 4e28829727..ad0d5583d2 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -222,4 +222,55 @@ sitestore + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + alfresco/extension/templates/activities + + + + true + alfresco/templates/activities + + + + + + + + + + + diff --git a/source/java/org/alfresco/repo/web/scripts/RepositoryContainer.java b/source/java/org/alfresco/repo/web/scripts/RepositoryContainer.java index 87dce7d53b..56f2600386 100644 --- a/source/java/org/alfresco/repo/web/scripts/RepositoryContainer.java +++ b/source/java/org/alfresco/repo/web/scripts/RepositoryContainer.java @@ -257,7 +257,7 @@ public class RepositoryContainer extends AbstractRuntimeContainer implements Ten // if (auth == null || auth.authenticate(required, isGuest)) { - if (required == RequiredAuthentication.admin && !authorityService.hasAdminAuthority()) + if (required == RequiredAuthentication.admin && !(authorityService.hasAdminAuthority() || AuthenticationUtil.getCurrentUserName().equals(AuthenticationUtil.getSystemUserName()))) { throw new WebScriptException(HttpServletResponse.SC_UNAUTHORIZED, "Web Script " + desc.getId() + " requires admin authentication; however, a non-admin has attempted access."); } diff --git a/source/java/org/alfresco/repo/web/scripts/activities/SiteFeedRetrieverWebScript.java b/source/java/org/alfresco/repo/web/scripts/activities/SiteFeedRetrieverWebScript.java new file mode 100644 index 0000000000..3188099326 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/activities/SiteFeedRetrieverWebScript.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2005-2008 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ +package org.alfresco.repo.web.scripts.activities; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.service.cmr.activities.ActivityService; +import org.alfresco.web.scripts.DeclarativeWebScript; +import org.alfresco.web.scripts.Status; +import org.alfresco.web.scripts.WebScriptRequest; + +/** + * Java-backed WebScript to retrieve Activity Site Feed + */ +public class SiteFeedRetrieverWebScript extends DeclarativeWebScript +{ + private ActivityService activityService; + + public void setActivityService(ActivityService activityService) + { + this.activityService = activityService; + } + + /* (non-Javadoc) + * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse) + */ + @Override + protected Map executeImpl(WebScriptRequest req, Status status) + { + // retrieve requested format + String format = req.getFormat(); + if (format == null || format.length() == 0) + { + format = getDescription().getDefaultFormat(); + } + + String extensionPath = req.getExtensionPath(); + String[] extParts = extensionPath == null ? new String[1] : extensionPath.split("/"); + + String siteId = null; + if (extParts.length == 1) + { + siteId = extParts[0]; + } + else + { + throw new AlfrescoRuntimeException("Unexpected extension: " + extensionPath); + } + + // map feed collection format to feed entry format (if not the same), eg. + // atomfeed -> atomentry + // atom -> atomentry + if (format.equals("atomfeed") || format.equals("atom")) + { + format = "atomentry"; + } + + // TODO - check if site is public or private + // if private and user is not a member or not an admin then throw 401 (unauthorised) + + List> feedEntries = activityService.getSiteFeedEntries(siteId, format); + + Map model = new HashMap(); + model.put("feedEntries", feedEntries); + model.put("siteId", siteId); + return model; + } +} diff --git a/source/java/org/alfresco/repo/web/scripts/activities/TemplateWebScript.java b/source/java/org/alfresco/repo/web/scripts/activities/TemplateWebScript.java new file mode 100644 index 0000000000..88087c04a9 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/activities/TemplateWebScript.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2005-2008 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.web.scripts.activities; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.web.scripts.DeclarativeWebScript; +import org.alfresco.web.scripts.SearchPath; +import org.alfresco.web.scripts.Status; +import org.alfresco.web.scripts.WebScriptRequest; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Java-backed WebScript to get a Template from a Template Store + */ +public class TemplateWebScript extends DeclarativeWebScript +{ + // Logger + protected static final Log logger = LogFactory.getLog(TemplateWebScript.class); + + private SearchPath searchPath; + + public void setSearchPath(SearchPath searchPath) + { + this.searchPath = searchPath; + } + + /* (non-Javadoc) + * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse) + */ + @Override + protected Map executeImpl(WebScriptRequest req, Status status) + { + Map model = new HashMap(); + + // process arguments + String path = req.getParameter("p"); // required + + if ((path != null) && (path.length() != 0)) + { + if (path.endsWith(".ftl")) + { + try + { + InputStream is = searchPath.getDocument(path); + if (is != null) + { + BufferedReader br = null; + try + { + br = new BufferedReader(new InputStreamReader(is)); + String line = null; + StringBuffer sb = new StringBuffer(); + while(((line = br.readLine()) !=null)) + { + sb.append(line); + } + + model.put("template", sb.toString()); + } + finally + { + if (br != null) { br.close(); }; + } + } + } + catch (IOException ioe) + { + logger.error("Failed to getTemplate: " + ioe); + } + } + } + return model; + } +} diff --git a/source/java/org/alfresco/repo/web/scripts/activities/TemplatesWebScript.java b/source/java/org/alfresco/repo/web/scripts/activities/TemplatesWebScript.java new file mode 100644 index 0000000000..226706b4bd --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/activities/TemplatesWebScript.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2005-2008 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.web.scripts.activities; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.alfresco.web.scripts.DeclarativeWebScript; +import org.alfresco.web.scripts.SearchPath; +import org.alfresco.web.scripts.Status; +import org.alfresco.web.scripts.Store; +import org.alfresco.web.scripts.WebScriptRequest; + +/** + * Java-backed WebScript to get list of Activity Templates from a Template Store + */ +public class TemplatesWebScript extends DeclarativeWebScript +{ + private SearchPath searchPath; + + public void setSearchPath(SearchPath searchPath) + { + this.searchPath = searchPath; + } + + /* (non-Javadoc) + * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse) + */ + @Override + protected Map executeImpl(WebScriptRequest req, Status status) + { + // process arguments + String p = req.getParameter("p"); // optional + + String path = "/"; + String templatePattern = "*.ftl"; + + if ((p != null) && (p.length() > 0)) + { + int idx = p.lastIndexOf("/"); + if (idx != -1) + { + path = p.substring(0, idx); + templatePattern = p.substring(idx+1) + ".ftl"; + } + } + + Set templatePaths = new HashSet(); + for (Store apiStore : searchPath.getStores()) + { + for(String templatePath : apiStore.getDocumentPaths(path, false, templatePattern)) + { + templatePaths.add(templatePath); + } + } + + Map model = new HashMap(); + model.put("paths", templatePaths); + return model; + } +} diff --git a/source/java/org/alfresco/repo/web/scripts/activities/UserFeedRetrieverWebScript.java b/source/java/org/alfresco/repo/web/scripts/activities/UserFeedRetrieverWebScript.java new file mode 100644 index 0000000000..ff7b91b97e --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/activities/UserFeedRetrieverWebScript.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2005-2008 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ +package org.alfresco.repo.web.scripts.activities; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.service.cmr.activities.ActivityService; +import org.alfresco.web.scripts.DeclarativeWebScript; +import org.alfresco.web.scripts.Status; +import org.alfresco.web.scripts.WebScriptRequest; + +/** + * Java-backed WebScript to retrieve Activity User Feed + */ +public class UserFeedRetrieverWebScript extends DeclarativeWebScript +{ + private ActivityService activityService; + + public void setActivityService(ActivityService activityService) + { + this.activityService = activityService; + } + + /* (non-Javadoc) + * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse) + */ + @Override + protected Map executeImpl(WebScriptRequest req, Status status) + { + // retrieve requested format + String format = req.getFormat(); + if (format == null || format.length() == 0) + { + format = getDescription().getDefaultFormat(); + } + + // process extension + String extensionPath = req.getExtensionPath(); + String[] extParts = extensionPath == null ? new String[1] : extensionPath.split("/"); + + String feedUserId = null; + if (extParts.length == 1) + { + feedUserId = extParts[0]; + } + else if (extParts.length > 1) + { + throw new AlfrescoRuntimeException("Unexpected extension: " + extensionPath); + } + + // process arguments + String siteId = req.getParameter("s"); // optional + + if ((feedUserId == null) || (feedUserId.length() == 0)) + { + feedUserId = AuthenticationUtil.getCurrentUserName(); + } + + // map feed collection format to feed entry format (if not the same), eg. + // atomfeed -> atomentry + // atom -> atomentry + if (format.equals("atomfeed") || format.equals("atom")) + { + format = "atomentry"; + } + + List> feedEntries = activityService.getUserFeedEntries(feedUserId, format, siteId); + + Map model = new HashMap(); + model.put("feedEntries", feedEntries); + model.put("feedUserId", feedUserId); + return model; + } +}