From b6ce6f3aa01f07e9ae60de58a5c7177423746769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20P=C3=A9rez=20=C3=81lvarez?= Date: Wed, 10 Jan 2024 12:48:11 +0100 Subject: [PATCH] LPS-204267 Use model listener instead of service wrapper --- .../BlogsEntryReadingTimeModelListener.java | 55 +++++++++++ ...gsReadingTimeEntryLocalServiceWrapper.java | 93 ------------------- 2 files changed, 55 insertions(+), 93 deletions(-) create mode 100644 modules/apps/blogs/blogs-reading-time/src/main/java/com/liferay/blogs/reading/time/internal/model/listener/BlogsEntryReadingTimeModelListener.java delete mode 100644 modules/apps/blogs/blogs-reading-time/src/main/java/com/liferay/blogs/reading/time/internal/service/BlogsReadingTimeEntryLocalServiceWrapper.java diff --git a/modules/apps/blogs/blogs-reading-time/src/main/java/com/liferay/blogs/reading/time/internal/model/listener/BlogsEntryReadingTimeModelListener.java b/modules/apps/blogs/blogs-reading-time/src/main/java/com/liferay/blogs/reading/time/internal/model/listener/BlogsEntryReadingTimeModelListener.java new file mode 100644 index 00000000000000..4ca4c4646e624d --- /dev/null +++ b/modules/apps/blogs/blogs-reading-time/src/main/java/com/liferay/blogs/reading/time/internal/model/listener/BlogsEntryReadingTimeModelListener.java @@ -0,0 +1,55 @@ +/** + * SPDX-FileCopyrightText: (c) 2024 Liferay, Inc. https://liferay.com + * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 + */ + +package com.liferay.blogs.reading.time.internal.model.listener; + +import com.liferay.blogs.model.BlogsEntry; +import com.liferay.portal.kernel.exception.ModelListenerException; +import com.liferay.portal.kernel.model.BaseModelListener; +import com.liferay.portal.kernel.model.ModelListener; +import com.liferay.reading.time.service.ReadingTimeEntryLocalService; + +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; + +/** + * @author Adolfo Pérez + */ +@Component(service = ModelListener.class) +public class BlogsEntryReadingTimeModelListener + extends BaseModelListener { + + @Override + public void onAfterCreate(BlogsEntry blogsEntry) + throws ModelListenerException { + + super.onAfterCreate(blogsEntry); + + _readingTimeEntryLocalService.updateReadingTimeEntry(blogsEntry); + } + + @Override + public void onAfterUpdate( + BlogsEntry originalBlogsEntry, BlogsEntry blogsEntry) + throws ModelListenerException { + + super.onAfterUpdate(originalBlogsEntry, blogsEntry); + + _readingTimeEntryLocalService.updateReadingTimeEntry(blogsEntry); + } + + @Override + public void onBeforeRemove(BlogsEntry blogsEntry) + throws ModelListenerException { + + super.onBeforeRemove(blogsEntry); + + _readingTimeEntryLocalService.deleteReadingTimeEntry(blogsEntry); + } + + @Reference + private ReadingTimeEntryLocalService _readingTimeEntryLocalService; + +} \ No newline at end of file diff --git a/modules/apps/blogs/blogs-reading-time/src/main/java/com/liferay/blogs/reading/time/internal/service/BlogsReadingTimeEntryLocalServiceWrapper.java b/modules/apps/blogs/blogs-reading-time/src/main/java/com/liferay/blogs/reading/time/internal/service/BlogsReadingTimeEntryLocalServiceWrapper.java deleted file mode 100644 index 8aa069dd01551b..00000000000000 --- a/modules/apps/blogs/blogs-reading-time/src/main/java/com/liferay/blogs/reading/time/internal/service/BlogsReadingTimeEntryLocalServiceWrapper.java +++ /dev/null @@ -1,93 +0,0 @@ -/** - * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com - * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 - */ - -package com.liferay.blogs.reading.time.internal.service; - -import com.liferay.blogs.model.BlogsEntry; -import com.liferay.blogs.service.BlogsEntryLocalService; -import com.liferay.blogs.service.BlogsEntryLocalServiceWrapper; -import com.liferay.portal.kernel.exception.PortalException; -import com.liferay.portal.kernel.service.ServiceContext; -import com.liferay.portal.kernel.service.ServiceWrapper; -import com.liferay.portal.kernel.servlet.taglib.ui.ImageSelector; -import com.liferay.reading.time.service.ReadingTimeEntryLocalService; - -import java.util.Date; - -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Reference; - -/** - * @author Alejandro Tardín - */ -@Component(service = ServiceWrapper.class) -public class BlogsReadingTimeEntryLocalServiceWrapper - extends BlogsEntryLocalServiceWrapper { - - @Override - public BlogsEntry addEntry( - String externalReferenceCode, long userId, String title, - String subtitle, String urlTitle, String description, - String content, Date displayDate, boolean allowPingbacks, - boolean allowTrackbacks, String[] trackbacks, - String coverImageCaption, ImageSelector coverImageImageSelector, - ImageSelector smallImageImageSelector, - ServiceContext serviceContext) - throws PortalException { - - BlogsEntry blogsEntry = super.addEntry( - externalReferenceCode, userId, title, subtitle, urlTitle, - description, content, displayDate, allowPingbacks, allowTrackbacks, - trackbacks, coverImageCaption, coverImageImageSelector, - smallImageImageSelector, serviceContext); - - _readingTimeEntryLocalService.updateReadingTimeEntry(blogsEntry); - - return blogsEntry; - } - - @Override - public BlogsEntry deleteEntry(BlogsEntry blogsEntry) - throws PortalException { - - blogsEntry = super.deleteEntry(blogsEntry); - - _readingTimeEntryLocalService.deleteReadingTimeEntry(blogsEntry); - - return blogsEntry; - } - - @Override - public BlogsEntry updateEntry( - long userId, long entryId, String title, String subtitle, - String urlTitle, String description, String content, - Date displayDate, boolean allowPingbacks, boolean allowTrackbacks, - String[] trackbacks, String coverImageCaption, - ImageSelector coverImageImageSelector, - ImageSelector smallImageImageSelector, - ServiceContext serviceContext) - throws PortalException { - - BlogsEntry blogsEntry = super.updateEntry( - userId, entryId, title, subtitle, urlTitle, description, content, - displayDate, allowPingbacks, allowTrackbacks, trackbacks, - coverImageCaption, coverImageImageSelector, smallImageImageSelector, - serviceContext); - - _readingTimeEntryLocalService.updateReadingTimeEntry(blogsEntry); - - return blogsEntry; - } - - /** - * See LPS-204267. The BlogsEntryLocalService service must be available. - */ - @Reference - private BlogsEntryLocalService _blogsEntryLocalService; - - @Reference - private ReadingTimeEntryLocalService _readingTimeEntryLocalService; - -} \ No newline at end of file