Completed subscriptions REST API and added a bit more UI logic

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28488 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Florian Mü
2011-06-20 18:08:36 +00:00
parent 5daf79d986
commit f0acf43970
13 changed files with 250 additions and 29 deletions

View File

@@ -1,7 +1,7 @@
<webscript>
<shortname>Follow</shortname>
<description>Follow a user</description>
<url>/api/subscriptions/{userid}/follow/{otheruserid}</url>
<url>/api/subscriptions/{userid}/follow</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>

View File

@@ -0,0 +1,8 @@
<webscript>
<shortname>Follows</shortname>
<description>Returns if people follow a person</description>
<url>/api/subscriptions/{userid}/follows</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,8 @@
<webscript>
<shortname>Private Following List</shortname>
<description>Returns (or sets) if a following list is private</description>
<url>/api/subscriptions/{userid}/private</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,8 @@
<webscript>
<shortname>Private Following List</shortname>
<description>Sets if a following list is private</description>
<url>/api/subscriptions/{userid}/private</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -1,8 +0,0 @@
<webscript>
<shortname>Follow</shortname>
<description>Follow a user</description>
<url>/api/subscriptions/{userid}/unfollow/{otheruserid}</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,8 @@
<webscript>
<shortname>Unfollow</shortname>
<description>Unfollow a user</description>
<url>/api/subscriptions/{userid}/unfollow</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -611,6 +611,12 @@
<property name="personService" ref="PersonService"/>
</bean>
<bean id="webscript.org.alfresco.repository.subscriptions.follows.post" class="org.alfresco.repo.web.scripts.subscriptions.SubscriptionServiceFollowsPost" parent="webscript">
<property name="subscriptionService" ref="SubscriptionService"/>
<property name="nodeService" ref="NodeService"/>
<property name="personService" ref="PersonService"/>
</bean>
<bean id="webscript.org.alfresco.repository.subscriptions.following.get" class="org.alfresco.repo.web.scripts.subscriptions.SubscriptionServiceFollowingGet" parent="webscript">
<property name="subscriptionService" ref="SubscriptionService"/>
<property name="nodeService" ref="NodeService"/>
@@ -623,18 +629,31 @@
<property name="personService" ref="PersonService"/>
</bean>
<bean id="webscript.org.alfresco.repository.subscriptions.follow.get" class="org.alfresco.repo.web.scripts.subscriptions.SubscriptionServiceFollowGet" parent="webscript">
<bean id="webscript.org.alfresco.repository.subscriptions.follow.post" class="org.alfresco.repo.web.scripts.subscriptions.SubscriptionServiceFollowPost" parent="webscript">
<property name="subscriptionService" ref="SubscriptionService"/>
<property name="nodeService" ref="NodeService"/>
<property name="personService" ref="PersonService"/>
</bean>
<bean id="webscript.org.alfresco.repository.subscriptions.unfollow.get" class="org.alfresco.repo.web.scripts.subscriptions.SubscriptionServiceUnfollowGet" parent="webscript">
<bean id="webscript.org.alfresco.repository.subscriptions.unfollow.post" class="org.alfresco.repo.web.scripts.subscriptions.SubscriptionServiceUnfollowPost" parent="webscript">
<property name="subscriptionService" ref="SubscriptionService"/>
<property name="nodeService" ref="NodeService"/>
<property name="personService" ref="PersonService"/>
</bean>
<bean id="webscript.org.alfresco.repository.subscriptions.private.get" class="org.alfresco.repo.web.scripts.subscriptions.SubscriptionServicePrivateListGet" parent="webscript">
<property name="subscriptionService" ref="SubscriptionService"/>
<property name="nodeService" ref="NodeService"/>
<property name="personService" ref="PersonService"/>
</bean>
<bean id="webscript.org.alfresco.repository.subscriptions.private.put" class="org.alfresco.repo.web.scripts.subscriptions.SubscriptionServicePrivateListPut" parent="webscript">
<property name="subscriptionService" ref="SubscriptionService"/>
<property name="nodeService" ref="NodeService"/>
<property name="personService" ref="PersonService"/>
</bean>
<!-- -->
<!-- Invite Service REST API -->
<!-- -->

View File

@@ -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)
{

View File

@@ -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<String> users = new ArrayList<String>(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;
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<String> users = new ArrayList<String>(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;
}
}

View File

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

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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);
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<String> users = new ArrayList<String>(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;
}
}