First-cut Activity Service (SLNG-20)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9128 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2008-05-15 16:34:11 +00:00
parent 9c50e9b4e2
commit bebf7778b6
20 changed files with 551 additions and 1 deletions

View File

@@ -0,0 +1,17 @@
<entry xmlns='http://www.w3.org/2005/Atom'>
<title>${name!""}</title>
<link rel="alternate" type="text/html"
<#if nodeRef?? && nodeRef != "">
href="${repoEndPoint}/d/d/${nodeRef?replace("://","/")}/${name!""}"
<#else>
href="${repoEndPoint}"
</#if>
/>
<icon></icon>
<id>${id}</id>
<updated>${xmldate(date)}</updated>
<summary>${userId!""} ${activityType!""} ${displayPath!""} <#if siteNetwork?? && siteNetwork != "">(${siteNetwork} site)</#if></summary>
<author>
<name>${userId!""}</name>
</author>
</entry>

View File

@@ -0,0 +1,2 @@
<#-- default JSON rendering is to pass-through - assumes activityData is posted in JSON format -->
${activityData!""}

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<generator version="0.1">Alfresco (0.1)</generator>
<link rel="self" href=""/>
<title>Alfresco Activities Site Feed for ${siteId}</title>
<#if feedEntries??>
<#list feedEntries as feedEntry>
${feedEntry.activitySummary}
</#list>

View File

@@ -0,0 +1,10 @@
<webscript>
<shortname>Activities Site Feed Web Script</shortname>
<description>Allow currently logged in user to get feed for specified site (if private site then user must be a member or an admin user)</description>
<url>/api/activities/feed/site/{siteId}</url>
<url>/api/activities/feed/site/{siteId}?format=atomfeed</url>
<url>/api/activities/feed/site/{siteId}?format=json</url>
<format default="atomfeed"></format>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,9 @@
<webscript>
<shortname>Activity Type Template</shortname>
<description>Get the activity type template.</description>
<url>/api/activities/template?p={path}</url>
<url>/api/activities/template?p={path}&amp;format=text</url>
<format default="text"/>
<authentication>admin</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,2 @@
<#if template??>
${template}

View File

@@ -0,0 +1,11 @@
<webscript>
<shortname>Activity Template Paths</shortname>
<description>Get a collection of the template paths.</description>
<url>/api/activities/templates</url>
<url>/api/activities/templates?p={path}&amp;format=json</url>
<url>/api/activities/templates?p={path}</url>
<url>/api/activities/templates?p={path}&amp;format=json</url>
<format default="json"/>
<authentication>admin</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,4 @@
[
<#if paths??>
<#list paths as path>
"${path}"<#if path_has_next>,</#if>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<generator version="0.1">Alfresco (0.1)</generator>
<link rel="self" href=""/>
<title>Alfresco Activities User Feed for ${feedUserId}</title>
<#if feedEntries??>
<#list feedEntries as feedEntry>
${feedEntry.activitySummary}
</#list>

View File

@@ -0,0 +1,13 @@
<webscript>
<shortname>Activities Admin User Feed Web Script</shortname>
<description>Allow admin to get feed for a specified user</description>
<url>/api/activities/feed/user/{userId}</url>
<url>/api/activities/feed/user/{userId}?format=atomfeed</url>
<url>/api/activities/feed/user/{userId}?format=json</url>
<url>/api/activities/feed/user/{userId}?s={siteId}</url>
<url>/api/activities/feed/user/{userId}?s={siteId}&amp;format=atomfeed</url>
<url>/api/activities/feed/user/{userId}?s={siteId}&amp;format=json</url>
<format default="atomfeed"></format>
<authentication>admin</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,5 @@
{
<#if feedEntries??>
<#list feedEntries as feedEntry>
${feedEntry.activitySummary}
</#list>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<generator version="0.1">Alfresco (0.1)</generator>
<link rel="self" href=""/>
<title>Alfresco Activities User Feed for ${feedUserId}</title>
<#if feedEntries??>
<#list feedEntries as feedEntry>
${feedEntry.activitySummary}
</#list>

View File

@@ -0,0 +1,13 @@
<webscript>
<shortname>Activities User Feed Web Script</shortname>
<description>Allow currently logged in user to get their feed</description>
<url>/api/activities/feed/user</url>
<url>/api/activities/feed/user?format=atomfeed</url>
<url>/api/activities/feed/user?format=json</url>
<url>/api/activities/feed/user?s={siteId}</url>
<url>/api/activities/feed/user?s={siteId}&amp;format=atomfeed</url>
<url>/api/activities/feed/user?s={siteId}&amp;format=json</url>
<format default="atomfeed"></format>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,5 @@
{
<#if feedEntries??>
<#list feedEntries as feedEntry>
${feedEntry.activitySummary}
</#list>

View File

@@ -222,4 +222,55 @@
<property name="store"><value>sitestore</value></property>
</bean>
<!-- -->
<!-- Activity Feed Web Scripts -->
<!-- -->
<!-- Activity User Feed - to get activities feed for logged in user -->
<bean id="webscript.org.alfresco.repository.activities.userfeed.get" class="org.alfresco.repo.web.scripts.activities.UserFeedRetrieverWebScript" parent="webscript">
<property name="activityService" ref="activityService"/>
</bean>
<!-- Activity Admin Feed - to get activities feed for specified user -->
<bean id="webscript.org.alfresco.repository.activities.userfeed-admin.get" class="org.alfresco.repo.web.scripts.activities.UserFeedRetrieverWebScript" parent="webscript">
<property name="activityService" ref="activityService"/>
</bean>
<!-- Activity Site Feed - to get activities feed for given site, if private site then need to be a member or admin -->
<bean id="webscript.org.alfresco.repository.activities.sitefeed.get" class="org.alfresco.repo.web.scripts.activities.SiteFeedRetrieverWebScript" parent="webscript">
<property name="activityService" ref="activityService"/>
</bean>
<!-- -->
<!-- Activity Templates Storage -->
<!-- -->
<bean id="webscript.org.alfresco.repository.activities.templates.get" class="org.alfresco.repo.web.scripts.activities.TemplatesWebScript" parent="webscript">
<property name="searchPath" ref="activity.template.searchpath"/>
</bean>
<bean id="webscript.org.alfresco.repository.activities.template.get" class="org.alfresco.repo.web.scripts.activities.TemplateWebScript" parent="webscript">
<property name="searchPath" ref="activity.template.searchpath"/>
</bean>
<bean id="templates.classpathstore" class="org.alfresco.web.scripts.ClassPathStore" abstract="true" />
<bean id="activity.template.store.client.extension" parent="templates.classpathstore">
<property name="classPath"><value>alfresco/extension/templates/activities</value></property>
</bean>
<bean id="activity.template.store.client" parent="templates.classpathstore">
<property name="mustExist"><value>true</value></property>
<property name="classPath"><value>alfresco/templates/activities</value></property>
</bean>
<bean id="activity.template.searchpath" class="org.alfresco.web.scripts.SearchPath">
<property name="searchPath">
<list>
<ref bean="activity.template.store.client.extension" />
<ref bean="activity.template.store.client" />
</list>
</property>
</bean>
</beans>

View File

@@ -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.");
}

View File

@@ -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<String, Object> 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<Map<String, Object>> feedEntries = activityService.getSiteFeedEntries(siteId, format);
Map<String, Object> model = new HashMap<String, Object>();
model.put("feedEntries", feedEntries);
model.put("siteId", siteId);
return model;
}
}

View File

@@ -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<String, Object> executeImpl(WebScriptRequest req, Status status)
{
Map<String, Object> model = new HashMap<String, Object>();
// 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;
}
}

View File

@@ -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<String, Object> 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<String> templatePaths = new HashSet<String>();
for (Store apiStore : searchPath.getStores())
{
for(String templatePath : apiStore.getDocumentPaths(path, false, templatePattern))
{
templatePaths.add(templatePath);
}
}
Map<String, Object> model = new HashMap<String, Object>();
model.put("paths", templatePaths);
return model;
}
}

View File

@@ -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<String, Object> 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<Map<String, Object>> feedEntries = activityService.getUserFeedEntries(feedUserId, format, siteId);
Map<String, Object> model = new HashMap<String, Object>();
model.put("feedEntries", feedEntries);
model.put("feedUserId", feedUserId);
return model;
}
}