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

@@ -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;
}
}