mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -19,7 +19,6 @@
|
||||
package org.alfresco.repo.subscriptions;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
@@ -32,12 +31,11 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.subscriptions.PagingFollowingResults;
|
||||
import org.alfresco.service.cmr.subscriptions.PagingFollowingResultsImpl;
|
||||
import org.alfresco.service.cmr.subscriptions.PagingSubscriptionResults;
|
||||
import org.alfresco.service.cmr.subscriptions.PagingSubscriptionResultsImpl;
|
||||
import org.alfresco.service.cmr.subscriptions.PrivateSubscriptionListException;
|
||||
import org.alfresco.service.cmr.subscriptions.SubscriptionItemTypeEnum;
|
||||
import org.alfresco.service.cmr.subscriptions.SubscriptionService;
|
||||
import org.alfresco.service.cmr.subscriptions.SubscriptionsDisabledException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONException;
|
||||
@@ -93,16 +91,11 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
||||
this.activityService = activictyService;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public PagingSubscriptionResults getSubscriptions(String userId, SubscriptionItemTypeEnum type,
|
||||
PagingRequest pagingRequest)
|
||||
{
|
||||
if (!subscriptionsEnabled())
|
||||
{
|
||||
return new PagingSubscriptionResultsImpl(Collections.EMPTY_LIST, false, 0);
|
||||
}
|
||||
|
||||
checkEnabled();
|
||||
checkRead(userId);
|
||||
return subscriptionsDAO.selectSubscriptions(userId, type, pagingRequest);
|
||||
}
|
||||
@@ -110,22 +103,15 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
||||
@Override
|
||||
public int getSubscriptionCount(String userId, SubscriptionItemTypeEnum type)
|
||||
{
|
||||
if (!subscriptionsEnabled())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
checkEnabled();
|
||||
checkRead(userId);
|
||||
return subscriptionsDAO.countSubscriptions(userId, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribe(String userId, NodeRef node)
|
||||
{
|
||||
if (!subscriptionsEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
checkEnabled();
|
||||
checkWrite(userId);
|
||||
checkUserNode(node);
|
||||
subscriptionsDAO.insertSubscription(userId, node);
|
||||
@@ -152,11 +138,7 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
||||
@Override
|
||||
public void unsubscribe(String userId, NodeRef node)
|
||||
{
|
||||
if (!subscriptionsEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
checkEnabled();
|
||||
checkWrite(userId);
|
||||
subscriptionsDAO.deleteSubscription(userId, node);
|
||||
}
|
||||
@@ -164,75 +146,47 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
||||
@Override
|
||||
public boolean hasSubscribed(String userId, NodeRef node)
|
||||
{
|
||||
if (!subscriptionsEnabled())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
checkEnabled();
|
||||
checkRead(userId);
|
||||
return subscriptionsDAO.hasSubscribed(userId, node);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public PagingFollowingResults getFollowing(String userId, PagingRequest pagingRequest)
|
||||
{
|
||||
if (!subscriptionsEnabled())
|
||||
{
|
||||
return new PagingFollowingResultsImpl(Collections.EMPTY_LIST, false, 0);
|
||||
}
|
||||
|
||||
checkEnabled();
|
||||
checkRead(userId);
|
||||
return subscriptionsDAO.selectFollowing(userId, pagingRequest);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public PagingFollowingResults getFollowers(String userId, PagingRequest pagingRequest)
|
||||
{
|
||||
if (!subscriptionsEnabled())
|
||||
{
|
||||
return new PagingFollowingResultsImpl(Collections.EMPTY_LIST, false, 0);
|
||||
}
|
||||
|
||||
if (userId == null)
|
||||
{
|
||||
throw new IllegalArgumentException("User Id may not be null!");
|
||||
}
|
||||
|
||||
checkEnabled();
|
||||
checkRead(userId);
|
||||
return subscriptionsDAO.selectFollowers(userId, pagingRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFollowersCount(String userId)
|
||||
{
|
||||
if (!subscriptionsEnabled())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
checkEnabled();
|
||||
checkRead(userId);
|
||||
return subscriptionsDAO.countFollowers(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFollowingCount(String userId)
|
||||
{
|
||||
if (!subscriptionsEnabled())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
checkEnabled();
|
||||
checkRead(userId);
|
||||
return getSubscriptionCount(userId, SubscriptionItemTypeEnum.USER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void follow(String userId, String userToFollow)
|
||||
{
|
||||
if (!subscriptionsEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
checkEnabled();
|
||||
checkWrite(userId);
|
||||
subscriptionsDAO.insertSubscription(userId, getUserNodeRef(userToFollow));
|
||||
|
||||
@@ -258,11 +212,7 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
||||
@Override
|
||||
public void unfollow(String userId, String userToUnfollow)
|
||||
{
|
||||
if (!subscriptionsEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
checkEnabled();
|
||||
checkWrite(userId);
|
||||
subscriptionsDAO.deleteSubscription(userId, getUserNodeRef(userToUnfollow));
|
||||
}
|
||||
@@ -270,11 +220,7 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
||||
@Override
|
||||
public boolean follows(String userId, String userToFollow)
|
||||
{
|
||||
if (!subscriptionsEnabled())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
checkEnabled();
|
||||
checkRead(userId);
|
||||
return subscriptionsDAO.hasSubscribed(userId, getUserNodeRef(userToFollow));
|
||||
}
|
||||
@@ -282,6 +228,7 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
||||
@Override
|
||||
public void setSubscriptionListPrivate(String userId, boolean isPrivate)
|
||||
{
|
||||
checkEnabled();
|
||||
checkWrite(userId);
|
||||
nodeService.setProperty(getUserNodeRef(userId), ContentModel.PROP_SUBSCRIPTIONS_PRIVATE, isPrivate);
|
||||
}
|
||||
@@ -289,6 +236,8 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
||||
@Override
|
||||
public boolean isSubscriptionListPrivate(String userId)
|
||||
{
|
||||
checkEnabled();
|
||||
|
||||
if (userId == null)
|
||||
{
|
||||
throw new IllegalArgumentException("User Id may not be null!");
|
||||
@@ -309,11 +258,23 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean subscriptionsEnabled()
|
||||
@Override
|
||||
public boolean subscriptionsEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the subscription service is enabled.
|
||||
*/
|
||||
protected void checkEnabled()
|
||||
{
|
||||
if (!subscriptionsEnabled())
|
||||
{
|
||||
throw new SubscriptionsDisabledException("subscription_service.err.disabled");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current user is allowed to get subscription data.
|
||||
*/
|
||||
|
@@ -144,7 +144,7 @@ public interface SubscriptionService
|
||||
int getFollowersCount(String userId);
|
||||
|
||||
/**
|
||||
* Follows another
|
||||
* Follows a user.
|
||||
*
|
||||
* @param userId
|
||||
* the id of the user
|
||||
@@ -154,6 +154,14 @@ public interface SubscriptionService
|
||||
@Auditable(parameters = { "userId", "userToFollow" })
|
||||
void follow(String userId, String userToFollow);
|
||||
|
||||
/**
|
||||
* Unfollows a user.
|
||||
*
|
||||
* @param userId
|
||||
* the id of the user
|
||||
* @param userToUnfollow
|
||||
* the id of the user to unfollow
|
||||
*/
|
||||
@Auditable(parameters = { "userId", "userToUnfollow" })
|
||||
void unfollow(String userId, String userToUnfollow);
|
||||
|
||||
@@ -191,4 +199,10 @@ public interface SubscriptionService
|
||||
*/
|
||||
@NotAuditable
|
||||
boolean isSubscriptionListPrivate(String userId);
|
||||
|
||||
/**
|
||||
* Returns if subscription are enabled for this system.
|
||||
*/
|
||||
@NotAuditable
|
||||
boolean subscriptionsEnabled();
|
||||
}
|
||||
|
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.service.cmr.subscriptions;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
|
||||
/**
|
||||
* This exception is thrown if subscriptions are disabled.
|
||||
*
|
||||
* @author Florian Mueller
|
||||
* @since 4.0
|
||||
*/
|
||||
public class SubscriptionsDisabledException extends AlfrescoRuntimeException
|
||||
{
|
||||
private static final long serialVersionUID = 6971869799749343887L;
|
||||
|
||||
public SubscriptionsDisabledException(String msg)
|
||||
{
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public SubscriptionsDisabledException(String msg, Throwable cause)
|
||||
{
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user