Line-endings only

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14164 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2009-05-01 12:59:21 +00:00
parent 6c00f407db
commit ee6b8d2c7c
2 changed files with 303 additions and 303 deletions

View File

@@ -1,136 +1,136 @@
/* /*
* Copyright (C) 2005-2009 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 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 * 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 * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing * http://www.alfresco.com/legal/licensing
*/ */
package org.alfresco.repo.web.scripts.activities.feed; package org.alfresco.repo.web.scripts.activities.feed;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.activities.ActivityService; import org.alfresco.service.cmr.activities.ActivityService;
import org.alfresco.util.JSONtoFmModel; import org.alfresco.util.JSONtoFmModel;
import org.alfresco.web.scripts.DeclarativeWebScript; import org.alfresco.web.scripts.DeclarativeWebScript;
import org.alfresco.web.scripts.Status; import org.alfresco.web.scripts.Status;
import org.alfresco.web.scripts.WebScriptRequest; import org.alfresco.web.scripts.WebScriptRequest;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.json.JSONException; import org.json.JSONException;
/** /**
* Java-backed WebScript to retrieve Activity Site Feed * Java-backed WebScript to retrieve Activity Site Feed
*/ */
public class SiteFeedRetrieverWebScript extends DeclarativeWebScript public class SiteFeedRetrieverWebScript extends DeclarativeWebScript
{ {
private static final Log logger = LogFactory.getLog(SiteFeedRetrieverWebScript.class); private static final Log logger = LogFactory.getLog(SiteFeedRetrieverWebScript.class);
private ActivityService activityService; private ActivityService activityService;
public void setActivityService(ActivityService activityService) public void setActivityService(ActivityService activityService)
{ {
this.activityService = activityService; this.activityService = activityService;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse) * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse)
*/ */
@Override @Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)
{ {
// retrieve requested format // retrieve requested format
String format = req.getFormat(); String format = req.getFormat();
if (format == null || format.length() == 0) if (format == null || format.length() == 0)
{ {
format = getDescription().getDefaultFormat(); format = getDescription().getDefaultFormat();
} }
String extensionPath = req.getExtensionPath(); String extensionPath = req.getExtensionPath();
String[] extParts = extensionPath == null ? new String[1] : extensionPath.split("/"); String[] extParts = extensionPath == null ? new String[1] : extensionPath.split("/");
String siteId = null; String siteId = null;
if (extParts.length == 1) if (extParts.length == 1)
{ {
siteId = extParts[0]; siteId = extParts[0];
} }
else else
{ {
throw new AlfrescoRuntimeException("Unexpected extension: " + extensionPath); throw new AlfrescoRuntimeException("Unexpected extension: " + extensionPath);
} }
// map feed collection format to feed entry format (if not the same), eg. // map feed collection format to feed entry format (if not the same), eg.
// atomfeed -> atomentry // atomfeed -> atomentry
// atom -> atomentry // atom -> atomentry
if (format.equals("atomfeed") || format.equals("atom")) if (format.equals("atomfeed") || format.equals("atom"))
{ {
format = "atomentry"; format = "atomentry";
} }
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
try try
{ {
List<String> feedEntries = activityService.getSiteFeedEntries(siteId, format); List<String> feedEntries = activityService.getSiteFeedEntries(siteId, format);
if (format.equals("json")) if (format.equals("json"))
{ {
model.put("feedEntries", feedEntries); model.put("feedEntries", feedEntries);
model.put("siteId", siteId); model.put("siteId", siteId);
} }
else else
{ {
List<Map<String, Object>> activityFeedModels = new ArrayList<Map<String, Object>>(); List<Map<String, Object>> activityFeedModels = new ArrayList<Map<String, Object>>();
try try
{ {
for (String feedEntry : feedEntries) for (String feedEntry : feedEntries)
{ {
activityFeedModels.add(JSONtoFmModel.convertJSONObjectToMap(feedEntry)); activityFeedModels.add(JSONtoFmModel.convertJSONObjectToMap(feedEntry));
} }
} }
catch (JSONException je) catch (JSONException je)
{ {
throw new AlfrescoRuntimeException("Unable to get user feed entries: " + je.getMessage()); throw new AlfrescoRuntimeException("Unable to get user feed entries: " + je.getMessage());
} }
model.put("feedEntries", activityFeedModels); model.put("feedEntries", activityFeedModels);
model.put("siteId", siteId); model.put("siteId", siteId);
} }
} }
catch (AccessDeniedException ade) catch (AccessDeniedException ade)
{ {
// implies that site either does not exist or is private (and current user is not admin or a member) - hence return 401 (unauthorised) // implies that site either does not exist or is private (and current user is not admin or a member) - hence return 401 (unauthorised)
String currentUser = AuthenticationUtil.getFullyAuthenticatedUser(); String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
status.setCode(Status.STATUS_UNAUTHORIZED); status.setCode(Status.STATUS_UNAUTHORIZED);
logger.warn("Unable to get site feed entries for '" + siteId + "' (site does not exist or is private) - currently logged in as '" + currentUser +"'"); logger.warn("Unable to get site feed entries for '" + siteId + "' (site does not exist or is private) - currently logged in as '" + currentUser +"'");
model.put("feedEntries", null); model.put("feedEntries", null);
model.put("siteId", ""); model.put("siteId", "");
} }
return model; return model;
} }
} }

View File

@@ -1,167 +1,167 @@
/* /*
* Copyright (C) 2005-2009 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 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 * 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 * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing * http://www.alfresco.com/legal/licensing
*/ */
package org.alfresco.repo.web.scripts.activities.feed; package org.alfresco.repo.web.scripts.activities.feed;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.activities.ActivityService; import org.alfresco.service.cmr.activities.ActivityService;
import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.util.JSONtoFmModel; import org.alfresco.util.JSONtoFmModel;
import org.alfresco.web.scripts.DeclarativeWebScript; import org.alfresco.web.scripts.DeclarativeWebScript;
import org.alfresco.web.scripts.Status; import org.alfresco.web.scripts.Status;
import org.alfresco.web.scripts.WebScriptRequest; import org.alfresco.web.scripts.WebScriptRequest;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.json.JSONException; import org.json.JSONException;
/** /**
* Java-backed WebScript to retrieve Activity User Feed * Java-backed WebScript to retrieve Activity User Feed
*/ */
public class UserFeedRetrieverWebScript extends DeclarativeWebScript public class UserFeedRetrieverWebScript extends DeclarativeWebScript
{ {
private static final Log logger = LogFactory.getLog(UserFeedRetrieverWebScript.class); private static final Log logger = LogFactory.getLog(UserFeedRetrieverWebScript.class);
// URL request parameter names // URL request parameter names
public static final String PARAM_SITE_ID = "s"; public static final String PARAM_SITE_ID = "s";
public static final String PARAM_EXCLUDE_THIS_USER = "exclUser"; public static final String PARAM_EXCLUDE_THIS_USER = "exclUser";
public static final String PARAM_EXCLUDE_OTHER_USERS = "exclOthers"; public static final String PARAM_EXCLUDE_OTHER_USERS = "exclOthers";
private ActivityService activityService; private ActivityService activityService;
private AuthorityService authorityService; private AuthorityService authorityService;
public void setActivityService(ActivityService activityService) public void setActivityService(ActivityService activityService)
{ {
this.activityService = activityService; this.activityService = activityService;
} }
public void setAuthorityService(AuthorityService authorityService) public void setAuthorityService(AuthorityService authorityService)
{ {
this.authorityService = authorityService; this.authorityService = authorityService;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse) * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse)
*/ */
@Override @Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)
{ {
// retrieve requested format // retrieve requested format
String format = req.getFormat(); String format = req.getFormat();
if (format == null || format.length() == 0) if (format == null || format.length() == 0)
{ {
format = getDescription().getDefaultFormat(); format = getDescription().getDefaultFormat();
} }
// process extension // process extension
String extensionPath = req.getExtensionPath(); String extensionPath = req.getExtensionPath();
String[] extParts = extensionPath == null ? new String[1] : extensionPath.split("/"); String[] extParts = extensionPath == null ? new String[1] : extensionPath.split("/");
String feedUserId = null; String feedUserId = null;
if (extParts.length == 1) if (extParts.length == 1)
{ {
feedUserId = extParts[0]; feedUserId = extParts[0];
} }
else if (extParts.length > 1) else if (extParts.length > 1)
{ {
throw new AlfrescoRuntimeException("Unexpected extension: " + extensionPath); throw new AlfrescoRuntimeException("Unexpected extension: " + extensionPath);
} }
// process arguments // process arguments
String siteId = req.getParameter(PARAM_SITE_ID); // optional String siteId = req.getParameter(PARAM_SITE_ID); // optional
String exclThisUserStr = req.getParameter(PARAM_EXCLUDE_THIS_USER); // optional String exclThisUserStr = req.getParameter(PARAM_EXCLUDE_THIS_USER); // optional
String exclOtherUsersStr = req.getParameter(PARAM_EXCLUDE_OTHER_USERS); // optional String exclOtherUsersStr = req.getParameter(PARAM_EXCLUDE_OTHER_USERS); // optional
boolean exclThisUser = false; boolean exclThisUser = false;
if ((exclThisUserStr != null) && (exclThisUserStr.equalsIgnoreCase("true") || exclThisUserStr.equalsIgnoreCase("t"))) if ((exclThisUserStr != null) && (exclThisUserStr.equalsIgnoreCase("true") || exclThisUserStr.equalsIgnoreCase("t")))
{ {
exclThisUser = true; exclThisUser = true;
} }
boolean exclOtherUsers = false; boolean exclOtherUsers = false;
if ((exclOtherUsersStr != null) && (exclOtherUsersStr.equalsIgnoreCase("true") || exclOtherUsersStr.equalsIgnoreCase("t"))) if ((exclOtherUsersStr != null) && (exclOtherUsersStr.equalsIgnoreCase("true") || exclOtherUsersStr.equalsIgnoreCase("t")))
{ {
exclOtherUsers = true; exclOtherUsers = true;
} }
if ((feedUserId == null) || (feedUserId.length() == 0)) if ((feedUserId == null) || (feedUserId.length() == 0))
{ {
feedUserId = AuthenticationUtil.getFullyAuthenticatedUser(); feedUserId = AuthenticationUtil.getFullyAuthenticatedUser();
} }
// map feed collection format to feed entry format (if not the same), eg. // map feed collection format to feed entry format (if not the same), eg.
// atomfeed -> atomentry // atomfeed -> atomentry
// atom -> atomentry // atom -> atomentry
if (format.equals("atomfeed") || format.equals("atom")) if (format.equals("atomfeed") || format.equals("atom"))
{ {
format = "atomentry"; format = "atomentry";
} }
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
try try
{ {
List<String> feedEntries = activityService.getUserFeedEntries(feedUserId, format, siteId, exclThisUser, exclOtherUsers); List<String> feedEntries = activityService.getUserFeedEntries(feedUserId, format, siteId, exclThisUser, exclOtherUsers);
if (format.equals("json")) if (format.equals("json"))
{ {
model.put("feedEntries", feedEntries); model.put("feedEntries", feedEntries);
model.put("siteId", siteId); model.put("siteId", siteId);
} }
else else
{ {
List<Map<String, Object>> activityFeedModels = new ArrayList<Map<String, Object>>(); List<Map<String, Object>> activityFeedModels = new ArrayList<Map<String, Object>>();
try try
{ {
for (String feedEntry : feedEntries) for (String feedEntry : feedEntries)
{ {
activityFeedModels.add(JSONtoFmModel.convertJSONObjectToMap(feedEntry)); activityFeedModels.add(JSONtoFmModel.convertJSONObjectToMap(feedEntry));
} }
} }
catch (JSONException je) catch (JSONException je)
{ {
throw new AlfrescoRuntimeException("Unable to get user feed entries: " + je.getMessage()); throw new AlfrescoRuntimeException("Unable to get user feed entries: " + je.getMessage());
} }
model.put("feedEntries", activityFeedModels); model.put("feedEntries", activityFeedModels);
model.put("feedUserId", feedUserId); model.put("feedUserId", feedUserId);
} }
} }
catch (AccessDeniedException ade) catch (AccessDeniedException ade)
{ {
status.setCode(Status.STATUS_UNAUTHORIZED); status.setCode(Status.STATUS_UNAUTHORIZED);
logger.warn("Unable to get user feed entries for '" + feedUserId + "' - currently logged in as '" + AuthenticationUtil.getFullyAuthenticatedUser() +"'"); logger.warn("Unable to get user feed entries for '" + feedUserId + "' - currently logged in as '" + AuthenticationUtil.getFullyAuthenticatedUser() +"'");
return null; return null;
} }
return model; return model;
} }
} }