diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/follow.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/follow.post.desc.xml similarity index 76% rename from config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/follow.get.desc.xml rename to config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/follow.post.desc.xml index 321348a2a8..d7c9c710cb 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/follow.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/follow.post.desc.xml @@ -1,7 +1,7 @@ Follow Follow a user - /api/subscriptions/{userid}/follow/{otheruserid} + /api/subscriptions/{userid}/follow user required diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/follows.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/follows.post.desc.xml new file mode 100644 index 0000000000..f0a8501104 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/follows.post.desc.xml @@ -0,0 +1,8 @@ + + Follows + Returns if people follow a person + /api/subscriptions/{userid}/follows + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/private.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/private.get.desc.xml new file mode 100644 index 0000000000..e46fa16b78 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/private.get.desc.xml @@ -0,0 +1,8 @@ + + Private Following List + Returns (or sets) if a following list is private + /api/subscriptions/{userid}/private + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/private.put.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/private.put.desc.xml new file mode 100644 index 0000000000..7c705b9cf5 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/private.put.desc.xml @@ -0,0 +1,8 @@ + + Private Following List + Sets if a following list is private + /api/subscriptions/{userid}/private + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/unfollow.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/unfollow.get.desc.xml deleted file mode 100644 index 8d1da74dd6..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/unfollow.get.desc.xml +++ /dev/null @@ -1,8 +0,0 @@ - - Follow - Follow a user - /api/subscriptions/{userid}/unfollow/{otheruserid} - - user - required - \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/unfollow.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/unfollow.post.desc.xml new file mode 100644 index 0000000000..8000acbb14 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/subscriptions/unfollow.post.desc.xml @@ -0,0 +1,8 @@ + + Unfollow + Unfollow a user + /api/subscriptions/{userid}/unfollow + + user + required + \ 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 5d1f971082..230a01aeea 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -611,6 +611,12 @@ + + + + + + @@ -623,18 +629,31 @@ - + - + + + + + + + + + + + + + + diff --git a/source/java/org/alfresco/repo/web/scripts/subscriptions/AbstractSubscriptionServiceWebScript.java b/source/java/org/alfresco/repo/web/scripts/subscriptions/AbstractSubscriptionServiceWebScript.java index 6ac6acf066..193b95b5b2 100644 --- a/source/java/org/alfresco/repo/web/scripts/subscriptions/AbstractSubscriptionServiceWebScript.java +++ b/source/java/org/alfresco/repo/web/scripts/subscriptions/AbstractSubscriptionServiceWebScript.java @@ -31,6 +31,7 @@ import org.alfresco.service.cmr.security.NoSuchPersonException; import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.subscriptions.PrivateSubscriptionListException; import org.alfresco.service.cmr.subscriptions.SubscriptionService; +import org.alfresco.service.cmr.subscriptions.SubscriptionsDisabledException; import org.alfresco.util.ISO8601DateFormat; import org.json.JSONArray; import org.json.JSONException; @@ -66,17 +67,28 @@ public abstract class AbstractSubscriptionServiceWebScript extends AbstractWebSc try { String userId = req.getServiceMatch().getTemplateVars().get("userid"); - JSONObject obj = executeImpl(userId, req, res); + Object obj = executeImpl(userId, req, res); - if (obj == null) + if (obj instanceof JSONObject || obj instanceof JSONArray) { - res.setStatus(204); + res.setContentEncoding("UTF-8"); + + Writer writer = res.getWriter(); + if (obj instanceof JSONObject) + { + ((JSONObject) obj).write(writer); + } else + { + ((JSONArray) obj).write(writer); + } + writer.flush(); } else { - Writer writer = res.getWriter(); - obj.write(writer); - writer.flush(); + res.setStatus(204); } + } catch (SubscriptionsDisabledException sde) + { + throw new WebScriptException(400, "Subscription service is disabled!", sde); } catch (NoSuchPersonException nspe) { throw new WebScriptException(400, "Unknown user '" + nspe.getUserName() + "'!", nspe); @@ -85,12 +97,12 @@ public abstract class AbstractSubscriptionServiceWebScript extends AbstractWebSc throw new WebScriptException(403, "Subscription list is private!", psle); } catch (JSONException je) { - throw new WebScriptException(500, "Unable to serialize JSON!", je); + throw new WebScriptException(500, "Unable to parse or serialize JSON!", je); } } - public abstract JSONObject executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) - throws IOException, JSONException; + public abstract Object executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException, + JSONException; protected int parseNumber(String name, String number, int def) { @@ -141,7 +153,7 @@ public abstract class AbstractSubscriptionServiceWebScript extends AbstractWebSc if (statusTime != null) { JSONObject statusTimeJson = new JSONObject(); - statusTimeJson.put("iso8601", ISO8601DateFormat.format(statusTime)); + statusTimeJson.put("iso8601", ISO8601DateFormat.format(statusTime)); result.put("userStatusTime", statusTimeJson); } diff --git a/source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServiceUnfollowGet.java b/source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServiceFollowPost.java similarity index 69% rename from source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServiceUnfollowGet.java rename to source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServiceFollowPost.java index 780fefe993..b0dc413143 100644 --- a/source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServiceUnfollowGet.java +++ b/source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServiceFollowPost.java @@ -19,20 +19,32 @@ package org.alfresco.repo.web.scripts.subscriptions; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.springframework.extensions.webscripts.WebScriptRequest; import org.springframework.extensions.webscripts.WebScriptResponse; -public class SubscriptionServiceUnfollowGet extends AbstractSubscriptionServiceWebScript +public class SubscriptionServiceFollowPost extends AbstractSubscriptionServiceWebScript { public JSONObject executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException, JSONException { - String otherUser = req.getServiceMatch().getTemplateVars().get("otheruserid"); + JSONArray jsonUsers = new JSONArray(req.getContent().getContent()); - subscriptionService.unfollow(userId, otherUser); + List users = new ArrayList(jsonUsers.length()); + for (int i = 0; i < jsonUsers.length(); i++) + { + users.add(jsonUsers.getString(i)); + } + + for (String user : users) + { + subscriptionService.follow(userId, user); + } return null; } diff --git a/source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServiceFollowsPost.java b/source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServiceFollowsPost.java new file mode 100644 index 0000000000..699f4dbbc2 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServiceFollowsPost.java @@ -0,0 +1,54 @@ +/* + * 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 . + */ +package org.alfresco.repo.web.scripts.subscriptions; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.springframework.extensions.webscripts.WebScriptRequest; +import org.springframework.extensions.webscripts.WebScriptResponse; + +public class SubscriptionServiceFollowsPost extends AbstractSubscriptionServiceWebScript +{ + public JSONArray executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException, + JSONException + { + JSONArray jsonUsers = new JSONArray(req.getContent().getContent()); + + List users = new ArrayList(jsonUsers.length()); + for (int i = 0; i < jsonUsers.length(); i++) + { + users.add(jsonUsers.getString(i)); + } + + JSONArray result = new JSONArray(); + for (String user : users) + { + JSONObject item = new JSONObject(); + item.put(user, subscriptionService.follows(userId, user)); + result.put(item); + } + + return result; + } +} diff --git a/source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServiceFollowGet.java b/source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServicePrivateListGet.java similarity index 82% rename from source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServiceFollowGet.java rename to source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServicePrivateListGet.java index e6342e9603..821eb0f927 100644 --- a/source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServiceFollowGet.java +++ b/source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServicePrivateListGet.java @@ -25,15 +25,14 @@ import org.json.JSONObject; import org.springframework.extensions.webscripts.WebScriptRequest; import org.springframework.extensions.webscripts.WebScriptResponse; -public class SubscriptionServiceFollowGet extends AbstractSubscriptionServiceWebScript +public class SubscriptionServicePrivateListGet extends AbstractSubscriptionServiceWebScript { public JSONObject executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException, JSONException { - String otherUser = req.getServiceMatch().getTemplateVars().get("otheruserid"); + JSONObject obj = new JSONObject(); + obj.put("private", subscriptionService.isSubscriptionListPrivate(userId)); - subscriptionService.follow(userId, otherUser); - - return null; + return obj; } } diff --git a/source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServicePrivateListPut.java b/source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServicePrivateListPut.java new file mode 100644 index 0000000000..42a7a1f7a6 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServicePrivateListPut.java @@ -0,0 +1,50 @@ +/* + * 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 . + */ +package org.alfresco.repo.web.scripts.subscriptions; + +import java.io.IOException; + +import org.json.JSONException; +import org.json.JSONObject; +import org.springframework.extensions.webscripts.WebScriptRequest; +import org.springframework.extensions.webscripts.WebScriptResponse; + +public class SubscriptionServicePrivateListPut extends SubscriptionServicePrivateListGet +{ + public JSONObject executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException, + JSONException + { + JSONObject obj = new JSONObject(req.getContent().getContent()); + + String setPrivate = obj.getString("private"); + + if (setPrivate != null) + { + if (setPrivate.equalsIgnoreCase("true")) + { + subscriptionService.setSubscriptionListPrivate(userId, true); + } else if (setPrivate.equalsIgnoreCase("false")) + { + subscriptionService.setSubscriptionListPrivate(userId, false); + } + } + + return super.executeImpl(userId, req, res); + } +} diff --git a/source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServiceUnfollowPost.java b/source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServiceUnfollowPost.java new file mode 100644 index 0000000000..4e979cbed1 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/subscriptions/SubscriptionServiceUnfollowPost.java @@ -0,0 +1,51 @@ +/* + * 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 . + */ +package org.alfresco.repo.web.scripts.subscriptions; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.springframework.extensions.webscripts.WebScriptRequest; +import org.springframework.extensions.webscripts.WebScriptResponse; + +public class SubscriptionServiceUnfollowPost extends AbstractSubscriptionServiceWebScript +{ + public JSONObject executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException, + JSONException + { + JSONArray jsonUsers = new JSONArray(req.getContent().getContent()); + + List users = new ArrayList(jsonUsers.length()); + for (int i = 0; i < jsonUsers.length(); i++) + { + users.add(jsonUsers.getString(i)); + } + + for (String user : users) + { + subscriptionService.unfollow(userId, user); + } + + return null; + } +}