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;
|
package org.alfresco.repo.subscriptions;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.query.PagingRequest;
|
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.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.security.PersonService;
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
import org.alfresco.service.cmr.subscriptions.PagingFollowingResults;
|
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.PagingSubscriptionResults;
|
||||||
import org.alfresco.service.cmr.subscriptions.PagingSubscriptionResultsImpl;
|
|
||||||
import org.alfresco.service.cmr.subscriptions.PrivateSubscriptionListException;
|
import org.alfresco.service.cmr.subscriptions.PrivateSubscriptionListException;
|
||||||
import org.alfresco.service.cmr.subscriptions.SubscriptionItemTypeEnum;
|
import org.alfresco.service.cmr.subscriptions.SubscriptionItemTypeEnum;
|
||||||
import org.alfresco.service.cmr.subscriptions.SubscriptionService;
|
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.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@@ -93,16 +91,11 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
|||||||
this.activityService = activictyService;
|
this.activityService = activictyService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public PagingSubscriptionResults getSubscriptions(String userId, SubscriptionItemTypeEnum type,
|
public PagingSubscriptionResults getSubscriptions(String userId, SubscriptionItemTypeEnum type,
|
||||||
PagingRequest pagingRequest)
|
PagingRequest pagingRequest)
|
||||||
{
|
{
|
||||||
if (!subscriptionsEnabled())
|
checkEnabled();
|
||||||
{
|
|
||||||
return new PagingSubscriptionResultsImpl(Collections.EMPTY_LIST, false, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
checkRead(userId);
|
checkRead(userId);
|
||||||
return subscriptionsDAO.selectSubscriptions(userId, type, pagingRequest);
|
return subscriptionsDAO.selectSubscriptions(userId, type, pagingRequest);
|
||||||
}
|
}
|
||||||
@@ -110,22 +103,15 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
|||||||
@Override
|
@Override
|
||||||
public int getSubscriptionCount(String userId, SubscriptionItemTypeEnum type)
|
public int getSubscriptionCount(String userId, SubscriptionItemTypeEnum type)
|
||||||
{
|
{
|
||||||
if (!subscriptionsEnabled())
|
checkEnabled();
|
||||||
{
|
checkRead(userId);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return subscriptionsDAO.countSubscriptions(userId, type);
|
return subscriptionsDAO.countSubscriptions(userId, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void subscribe(String userId, NodeRef node)
|
public void subscribe(String userId, NodeRef node)
|
||||||
{
|
{
|
||||||
if (!subscriptionsEnabled())
|
checkEnabled();
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkWrite(userId);
|
checkWrite(userId);
|
||||||
checkUserNode(node);
|
checkUserNode(node);
|
||||||
subscriptionsDAO.insertSubscription(userId, node);
|
subscriptionsDAO.insertSubscription(userId, node);
|
||||||
@@ -152,11 +138,7 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
|||||||
@Override
|
@Override
|
||||||
public void unsubscribe(String userId, NodeRef node)
|
public void unsubscribe(String userId, NodeRef node)
|
||||||
{
|
{
|
||||||
if (!subscriptionsEnabled())
|
checkEnabled();
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkWrite(userId);
|
checkWrite(userId);
|
||||||
subscriptionsDAO.deleteSubscription(userId, node);
|
subscriptionsDAO.deleteSubscription(userId, node);
|
||||||
}
|
}
|
||||||
@@ -164,75 +146,47 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
|||||||
@Override
|
@Override
|
||||||
public boolean hasSubscribed(String userId, NodeRef node)
|
public boolean hasSubscribed(String userId, NodeRef node)
|
||||||
{
|
{
|
||||||
if (!subscriptionsEnabled())
|
checkEnabled();
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkRead(userId);
|
checkRead(userId);
|
||||||
return subscriptionsDAO.hasSubscribed(userId, node);
|
return subscriptionsDAO.hasSubscribed(userId, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public PagingFollowingResults getFollowing(String userId, PagingRequest pagingRequest)
|
public PagingFollowingResults getFollowing(String userId, PagingRequest pagingRequest)
|
||||||
{
|
{
|
||||||
if (!subscriptionsEnabled())
|
checkEnabled();
|
||||||
{
|
|
||||||
return new PagingFollowingResultsImpl(Collections.EMPTY_LIST, false, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
checkRead(userId);
|
checkRead(userId);
|
||||||
return subscriptionsDAO.selectFollowing(userId, pagingRequest);
|
return subscriptionsDAO.selectFollowing(userId, pagingRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public PagingFollowingResults getFollowers(String userId, PagingRequest pagingRequest)
|
public PagingFollowingResults getFollowers(String userId, PagingRequest pagingRequest)
|
||||||
{
|
{
|
||||||
if (!subscriptionsEnabled())
|
checkEnabled();
|
||||||
{
|
checkRead(userId);
|
||||||
return new PagingFollowingResultsImpl(Collections.EMPTY_LIST, false, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userId == null)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("User Id may not be null!");
|
|
||||||
}
|
|
||||||
|
|
||||||
return subscriptionsDAO.selectFollowers(userId, pagingRequest);
|
return subscriptionsDAO.selectFollowers(userId, pagingRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getFollowersCount(String userId)
|
public int getFollowersCount(String userId)
|
||||||
{
|
{
|
||||||
if (!subscriptionsEnabled())
|
checkEnabled();
|
||||||
{
|
checkRead(userId);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return subscriptionsDAO.countFollowers(userId);
|
return subscriptionsDAO.countFollowers(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getFollowingCount(String userId)
|
public int getFollowingCount(String userId)
|
||||||
{
|
{
|
||||||
if (!subscriptionsEnabled())
|
checkEnabled();
|
||||||
{
|
checkRead(userId);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return getSubscriptionCount(userId, SubscriptionItemTypeEnum.USER);
|
return getSubscriptionCount(userId, SubscriptionItemTypeEnum.USER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void follow(String userId, String userToFollow)
|
public void follow(String userId, String userToFollow)
|
||||||
{
|
{
|
||||||
if (!subscriptionsEnabled())
|
checkEnabled();
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkWrite(userId);
|
checkWrite(userId);
|
||||||
subscriptionsDAO.insertSubscription(userId, getUserNodeRef(userToFollow));
|
subscriptionsDAO.insertSubscription(userId, getUserNodeRef(userToFollow));
|
||||||
|
|
||||||
@@ -258,11 +212,7 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
|||||||
@Override
|
@Override
|
||||||
public void unfollow(String userId, String userToUnfollow)
|
public void unfollow(String userId, String userToUnfollow)
|
||||||
{
|
{
|
||||||
if (!subscriptionsEnabled())
|
checkEnabled();
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkWrite(userId);
|
checkWrite(userId);
|
||||||
subscriptionsDAO.deleteSubscription(userId, getUserNodeRef(userToUnfollow));
|
subscriptionsDAO.deleteSubscription(userId, getUserNodeRef(userToUnfollow));
|
||||||
}
|
}
|
||||||
@@ -270,11 +220,7 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
|||||||
@Override
|
@Override
|
||||||
public boolean follows(String userId, String userToFollow)
|
public boolean follows(String userId, String userToFollow)
|
||||||
{
|
{
|
||||||
if (!subscriptionsEnabled())
|
checkEnabled();
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkRead(userId);
|
checkRead(userId);
|
||||||
return subscriptionsDAO.hasSubscribed(userId, getUserNodeRef(userToFollow));
|
return subscriptionsDAO.hasSubscribed(userId, getUserNodeRef(userToFollow));
|
||||||
}
|
}
|
||||||
@@ -282,6 +228,7 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
|||||||
@Override
|
@Override
|
||||||
public void setSubscriptionListPrivate(String userId, boolean isPrivate)
|
public void setSubscriptionListPrivate(String userId, boolean isPrivate)
|
||||||
{
|
{
|
||||||
|
checkEnabled();
|
||||||
checkWrite(userId);
|
checkWrite(userId);
|
||||||
nodeService.setProperty(getUserNodeRef(userId), ContentModel.PROP_SUBSCRIPTIONS_PRIVATE, isPrivate);
|
nodeService.setProperty(getUserNodeRef(userId), ContentModel.PROP_SUBSCRIPTIONS_PRIVATE, isPrivate);
|
||||||
}
|
}
|
||||||
@@ -289,6 +236,8 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
|||||||
@Override
|
@Override
|
||||||
public boolean isSubscriptionListPrivate(String userId)
|
public boolean isSubscriptionListPrivate(String userId)
|
||||||
{
|
{
|
||||||
|
checkEnabled();
|
||||||
|
|
||||||
if (userId == null)
|
if (userId == null)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("User Id may not be null!");
|
throw new IllegalArgumentException("User Id may not be null!");
|
||||||
@@ -309,11 +258,23 @@ public class SubscriptionServiceImpl implements SubscriptionService
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean subscriptionsEnabled()
|
@Override
|
||||||
|
public boolean subscriptionsEnabled()
|
||||||
{
|
{
|
||||||
return true;
|
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.
|
* Checks if the current user is allowed to get subscription data.
|
||||||
*/
|
*/
|
||||||
|
@@ -144,7 +144,7 @@ public interface SubscriptionService
|
|||||||
int getFollowersCount(String userId);
|
int getFollowersCount(String userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Follows another
|
* Follows a user.
|
||||||
*
|
*
|
||||||
* @param userId
|
* @param userId
|
||||||
* the id of the user
|
* the id of the user
|
||||||
@@ -154,6 +154,14 @@ public interface SubscriptionService
|
|||||||
@Auditable(parameters = { "userId", "userToFollow" })
|
@Auditable(parameters = { "userId", "userToFollow" })
|
||||||
void follow(String userId, String 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" })
|
@Auditable(parameters = { "userId", "userToUnfollow" })
|
||||||
void unfollow(String userId, String userToUnfollow);
|
void unfollow(String userId, String userToUnfollow);
|
||||||
|
|
||||||
@@ -191,4 +199,10 @@ public interface SubscriptionService
|
|||||||
*/
|
*/
|
||||||
@NotAuditable
|
@NotAuditable
|
||||||
boolean isSubscriptionListPrivate(String userId);
|
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