/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library 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 2.1 of the License, or (at your option) * any later version. * * This library 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. */ package com.liferay.my.subscriptions.web.internal.portlet; import com.liferay.my.subscriptions.web.internal.constants.MySubscriptionsPortletKeys; import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet; import com.liferay.portal.kernel.security.auth.PrincipalException; import com.liferay.portal.kernel.theme.ThemeDisplay; import com.liferay.portal.kernel.util.ParamUtil; import com.liferay.portal.kernel.util.StringUtil; import com.liferay.portal.kernel.util.WebKeys; import com.liferay.subscription.model.Subscription; import com.liferay.subscription.service.SubscriptionLocalService; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.Portlet; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** * @author Peter Shin * @author Jonathan Lee * @author Peter Fellwock */ @Component( enabled = false, immediate = true, property = { "com.liferay.portlet.css-class-wrapper=my-subscriptions-portlet", "com.liferay.portlet.display-category=category.collaboration", "com.liferay.portlet.icon=/icons/my_subscriptions.png", "com.liferay.portlet.preferences-owned-by-group=true", "com.liferay.portlet.private-request-attributes=false", "com.liferay.portlet.private-session-attributes=false", "com.liferay.portlet.remoteable=true", "com.liferay.portlet.render-weight=0", "javax.portlet.display-name=My Subscriptions", "javax.portlet.expiration-cache=0", "javax.portlet.init-param.copy-request-parameters=true", "javax.portlet.init-param.template-path=/", "javax.portlet.init-param.view-template=/view.jsp", "javax.portlet.name=" + MySubscriptionsPortletKeys.MY_SUBSCRIPTIONS, "javax.portlet.portlet-info.keywords=My Subscriptions", "javax.portlet.portlet-info.short-title=My Subscriptions", "javax.portlet.portlet-info.title=My Subscriptions", "javax.portlet.resource-bundle=content.Language", "javax.portlet.security-role-ref=power-user,user" }, service = Portlet.class ) public class MySubscriptionsPortlet extends MVCPortlet { public void unsubscribe( ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute( WebKeys.THEME_DISPLAY); if (!themeDisplay.isSignedIn()) { return; } long[] subscriptionIds = StringUtil.split( ParamUtil.getString(actionRequest, "subscriptionIds"), 0L); for (long subscriptionId : subscriptionIds) { if (subscriptionId <= 0) { continue; } Subscription subscription = _subscriptionLocalService.getSubscription(subscriptionId); if (themeDisplay.getUserId() != subscription.getUserId()) { throw new PrincipalException(); } _subscriptionLocalService.deleteSubscription(subscription); } } @Reference private SubscriptionLocalService _subscriptionLocalService; }