Skip to content

Commit

Permalink
LPS-56048 Make Actions components and inject deps
Browse files Browse the repository at this point in the history
  • Loading branch information
adolfopa authored and brianchandotcom committed Aug 5, 2015
1 parent 8f0816a commit 20ae830
Show file tree
Hide file tree
Showing 25 changed files with 267 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@
import com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.spring.osgi.OSGiBeanProperties;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.security.auth.PrincipalException;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.ServiceContextFactory;
import com.liferay.portal.util.PortletKeys;
import com.liferay.portlet.messageboards.model.MBBan;
import com.liferay.portlet.messageboards.service.MBBanServiceUtil;
import com.liferay.portlet.messageboards.service.MBBanService;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
* @author Michael Young
*/
@OSGiBeanProperties(
@Component(
property = {
"javax.portlet.name=" + PortletKeys.MESSAGE_BOARDS,
"javax.portlet.name=" + PortletKeys.MESSAGE_BOARDS_ADMIN,
Expand All @@ -49,7 +51,7 @@ protected void banUser(ActionRequest actionRequest) throws Exception {
ServiceContext serviceContext = ServiceContextFactory.getInstance(
MBBan.class.getName(), actionRequest);

MBBanServiceUtil.addBan(banUserId, serviceContext);
_mbBanService.addBan(banUserId, serviceContext);
}

@Override
Expand All @@ -75,13 +77,20 @@ else if (cmd.equals("unban")) {
}
}

@Reference(unbind = "-")
protected void setMBBanService(MBBanService mbBanService) {
_mbBanService = mbBanService;
}

protected void unbanUser(ActionRequest actionRequest) throws Exception {
long banUserId = ParamUtil.getLong(actionRequest, "banUserId");

ServiceContext serviceContext = ServiceContextFactory.getInstance(
MBBan.class.getName(), actionRequest);

MBBanServiceUtil.deleteBan(banUserId, serviceContext);
_mbBanService.deleteBan(banUserId, serviceContext);
}

private MBBanService _mbBanService;

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCResourceCommand;
import com.liferay.portal.kernel.spring.osgi.OSGiBeanProperties;
import com.liferay.portal.util.PortletKeys;

import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;

import org.osgi.service.component.annotations.Component;

/**
* @author Adolfo Pérez
*/
@OSGiBeanProperties(
@Component(
property = {
"javax.portlet.name=" + PortletKeys.MESSAGE_BOARDS,
"javax.portlet.name=" + PortletKeys.MESSAGE_BOARDS_ADMIN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.spring.osgi.OSGiBeanProperties;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.StringUtil;
Expand All @@ -26,7 +25,7 @@
import com.liferay.portal.util.PortletKeys;
import com.liferay.portlet.messageboards.LockedThreadException;
import com.liferay.portlet.messageboards.model.MBThread;
import com.liferay.portlet.messageboards.service.MBThreadServiceUtil;
import com.liferay.portlet.messageboards.service.MBThreadService;
import com.liferay.portlet.trash.util.TrashUtil;

import java.util.ArrayList;
Expand All @@ -35,12 +34,15 @@
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
* @author Deepak Gothe
* @author Sergio González
* @author Zsolt Berentey
*/
@OSGiBeanProperties(
@Component(
property = {
"javax.portlet.name=" + PortletKeys.MESSAGE_BOARDS,
"javax.portlet.name=" + PortletKeys.MESSAGE_BOARDS_ADMIN,
Expand Down Expand Up @@ -70,13 +72,13 @@ protected void deleteThreads(

for (long deleteThreadId : deleteThreadIds) {
if (moveToTrash) {
MBThread thread = MBThreadServiceUtil.moveThreadToTrash(
MBThread thread = _mbThreadService.moveThreadToTrash(
deleteThreadId);

trashedModels.add(thread);
}
else {
MBThreadServiceUtil.deleteThread(deleteThreadId);
_mbThreadService.deleteThread(deleteThreadId);
}
}

Expand Down Expand Up @@ -110,4 +112,11 @@ else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
}
}

@Reference(unbind = "-")
protected void setMBThreadService(MBThreadService mbThreadService) {
_mbThreadService = mbThreadService;
}

private MBThreadService _mbThreadService;

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.spring.osgi.OSGiBeanProperties;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.StringUtil;
Expand All @@ -42,8 +41,8 @@
import com.liferay.portlet.messageboards.MailingListOutUserNameException;
import com.liferay.portlet.messageboards.NoSuchCategoryException;
import com.liferay.portlet.messageboards.model.MBCategory;
import com.liferay.portlet.messageboards.service.MBCategoryServiceUtil;
import com.liferay.portlet.trash.service.TrashEntryServiceUtil;
import com.liferay.portlet.messageboards.service.MBCategoryService;
import com.liferay.portlet.trash.service.TrashEntryService;
import com.liferay.portlet.trash.util.TrashUtil;

import java.util.ArrayList;
Expand All @@ -52,11 +51,14 @@
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
* @author Brian Wing Shun Chan
* @author Daniel Sanz
*/
@OSGiBeanProperties(
@Component(
property = {
"javax.portlet.name=" + PortletKeys.MESSAGE_BOARDS,
"javax.portlet.name=" + PortletKeys.MESSAGE_BOARDS_ADMIN,
Expand Down Expand Up @@ -89,13 +91,13 @@ protected void deleteCategories(

for (long deleteCategoryId : deleteCategoryIds) {
if (moveToTrash) {
MBCategory category = MBCategoryServiceUtil.moveCategoryToTrash(
MBCategory category = _mbCategoryService.moveCategoryToTrash(
deleteCategoryId);

trashedModels.add(category);
}
else {
MBCategoryServiceUtil.deleteCategory(
_mbCategoryService.deleteCategory(
themeDisplay.getScopeGroupId(), deleteCategoryId);
}
}
Expand Down Expand Up @@ -160,10 +162,20 @@ protected void restoreTrashEntries(ActionRequest actionRequest)
ParamUtil.getString(actionRequest, "restoreTrashEntryIds"), 0L);

for (long restoreTrashEntryId : restoreTrashEntryIds) {
TrashEntryServiceUtil.restoreEntry(restoreTrashEntryId);
_trashEntryService.restoreEntry(restoreTrashEntryId);
}
}

@Reference(unbind = "-")
protected void setMBCategoryService(MBCategoryService mbCategoryService) {
_mbCategoryService = mbCategoryService;
}

@Reference(unbind = "-")
protected void setTrashEntryService(TrashEntryService trashEntryService) {
_trashEntryService = trashEntryService;
}

protected void subscribeCategory(ActionRequest actionRequest)
throws Exception {

Expand All @@ -172,7 +184,7 @@ protected void subscribeCategory(ActionRequest actionRequest)

long categoryId = ParamUtil.getLong(actionRequest, "mbCategoryId");

MBCategoryServiceUtil.subscribeCategory(
_mbCategoryService.subscribeCategory(
themeDisplay.getScopeGroupId(), categoryId);
}

Expand All @@ -184,7 +196,7 @@ protected void unsubscribeCategory(ActionRequest actionRequest)

long categoryId = ParamUtil.getLong(actionRequest, "mbCategoryId");

MBCategoryServiceUtil.unsubscribeCategory(
_mbCategoryService.unsubscribeCategory(
themeDisplay.getScopeGroupId(), categoryId);
}

Expand Down Expand Up @@ -241,7 +253,7 @@ protected void updateCategory(ActionRequest actionRequest)

// Add category

MBCategoryServiceUtil.addCategory(
_mbCategoryService.addCategory(
parentCategoryId, name, description, displayStyle, emailAddress,
inProtocol, inServerName, inServerPort, inUseSSL, inUserName,
inPassword, inReadInterval, outEmailAddress, outCustom,
Expand All @@ -252,7 +264,7 @@ protected void updateCategory(ActionRequest actionRequest)

// Update category

MBCategoryServiceUtil.updateCategory(
_mbCategoryService.updateCategory(
categoryId, parentCategoryId, name, description, displayStyle,
emailAddress, inProtocol, inServerName, inServerPort, inUseSSL,
inUserName, inPassword, inReadInterval, outEmailAddress,
Expand All @@ -262,4 +274,7 @@ protected void updateCategory(ActionRequest actionRequest)
}
}

private MBCategoryService _mbCategoryService;
private TrashEntryService _trashEntryService;

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import com.liferay.portal.kernel.portlet.bridges.mvc.MVCRenderCommand;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.spring.osgi.OSGiBeanProperties;
import com.liferay.portal.security.auth.PrincipalException;
import com.liferay.portal.util.PortletKeys;
import com.liferay.portlet.messageboards.NoSuchCategoryException;
Expand All @@ -25,10 +24,12 @@
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.osgi.service.component.annotations.Component;

/**
* @author Adolfo Pérez
*/
@OSGiBeanProperties(
@Component(
property = {
"javax.portlet.name=" + PortletKeys.MESSAGE_BOARDS,
"javax.portlet.name=" + PortletKeys.MESSAGE_BOARDS_ADMIN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.spring.osgi.OSGiBeanProperties;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.StringUtil;
Expand All @@ -29,19 +28,22 @@
import com.liferay.portal.security.auth.PrincipalException;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortletKeys;
import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
import com.liferay.portlet.trash.service.TrashEntryServiceUtil;
import com.liferay.portlet.messageboards.service.MBMessageLocalService;
import com.liferay.portlet.messageboards.service.MBMessageService;
import com.liferay.portlet.trash.service.TrashEntryService;
import com.liferay.portlet.trash.util.TrashUtil;
import com.liferay.taglib.util.RestoreEntryUtil;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
* @author Eudaldo Alonso
*/
@OSGiBeanProperties(
@Component(
property = {
"javax.portlet.name=" + PortletKeys.MESSAGE_BOARDS,
"javax.portlet.name=" + PortletKeys.MESSAGE_BOARDS_ADMIN,
Expand All @@ -59,7 +61,7 @@ protected void deleteAttachment(ActionRequest actionRequest)

String fileName = ParamUtil.getString(actionRequest, "fileName");

MBMessageLocalServiceUtil.deleteMessageAttachment(messageId, fileName);
_mbMessageLocalService.deleteMessageAttachment(messageId, fileName);
}

@Override
Expand Down Expand Up @@ -113,7 +115,7 @@ else if (cmd.equals(Constants.OVERRIDE)) {
protected void emptyTrash(ActionRequest actionRequest) throws Exception {
long messageId = ParamUtil.getLong(actionRequest, "messageId");

MBMessageServiceUtil.emptyMessageAttachments(messageId);
_mbMessageService.emptyMessageAttachments(messageId);
}

protected void restoreEntries(ActionRequest actionRequest)
Expand All @@ -122,7 +124,7 @@ protected void restoreEntries(ActionRequest actionRequest)
long trashEntryId = ParamUtil.getLong(actionRequest, "trashEntryId");

if (trashEntryId > 0) {
TrashEntryServiceUtil.restoreEntry(trashEntryId);
_trashEntryService.restoreEntry(trashEntryId);

return;
}
Expand All @@ -131,7 +133,7 @@ protected void restoreEntries(ActionRequest actionRequest)
ParamUtil.getString(actionRequest, "restoreTrashEntryIds"), 0L);

for (long restoreEntryId : restoreEntryIds) {
TrashEntryServiceUtil.restoreEntry(restoreEntryId);
_trashEntryService.restoreEntry(restoreEntryId);
}
}

Expand All @@ -143,8 +145,7 @@ protected void restoreOverride(ActionRequest actionRequest)
long duplicateEntryId = ParamUtil.getLong(
actionRequest, "duplicateEntryId");

TrashEntryServiceUtil.restoreEntry(
trashEntryId, duplicateEntryId, null);
_trashEntryService.restoreEntry(trashEntryId, duplicateEntryId, null);
}

protected void restoreRename(ActionRequest actionRequest) throws Exception {
Expand All @@ -161,7 +162,28 @@ protected void restoreRename(ActionRequest actionRequest) throws Exception {
newName = TrashUtil.getNewName(themeDisplay, null, 0, oldName);
}

TrashEntryServiceUtil.restoreEntry(trashEntryId, 0, newName);
_trashEntryService.restoreEntry(trashEntryId, 0, newName);
}

@Reference(unbind = "-")
protected void setMBMessageLocalService(
MBMessageLocalService mbMessageLocalService) {

_mbMessageLocalService = mbMessageLocalService;
}

@Reference(unbind = "-")
protected void setMBMessageService(MBMessageService mbMessageService) {
_mbMessageService = mbMessageService;
}

@Reference(unbind = "-")
protected void setTrashEntryService(TrashEntryService trashEntryService) {
_trashEntryService = trashEntryService;
}

private MBMessageLocalService _mbMessageLocalService;
private MBMessageService _mbMessageService;
private TrashEntryService _trashEntryService;

}
Loading

0 comments on commit 20ae830

Please sign in to comment.