Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPD-44885 - Update the way we store objects deletion events in SystemEvents #158589

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6cbed13
LPD-45734 service.xml
DaniSzimko Jan 9, 2025
602b2c5
LPD-45734 serviceBuilder
DaniSzimko Jan 9, 2025
6579aaa
LPD-45734 add externalReferenceCode to SystemEventLocalServiceImpl ad…
DaniSzimko Jan 15, 2025
34087b6
LPD-45734 serviceBuilder
DaniSzimko Jan 15, 2025
72a965e
LPD-45734 fix interfaces
DaniSzimko Jan 15, 2025
4fc2e20
LPD-45734 fix method calls
DaniSzimko Jan 20, 2025
aac56e4
LPD-45734 set externalReferenceCode to systemEvents
DaniSzimko Jan 20, 2025
2a3913b
LPD-45734 set modelClassName for Custom ObjectDefinitions
DaniSzimko Jan 23, 2025
ef8e202
LPD-45734 SF
DaniSzimko Jan 23, 2025
02749c6
LPD-45734 add IntegrationTest
DaniSzimko Jan 23, 2025
1b8ca2c
LPD-45734 service.xml Rename column to avoid misunderstanding
DaniSzimko Jan 24, 2025
a4a7241
LPD-45734 serviceBuilder
DaniSzimko Jan 24, 2025
b197aea
LPD-45734 rename externalReferenceCode param to classExternalReferenc…
DaniSzimko Jan 24, 2025
9abbb8d
LPD-45734 serviceBuilder
DaniSzimko Jan 24, 2025
1d5c6dc
LPD-45734 override getStagedModelType method
DaniSzimko Jan 24, 2025
395facd
LPD-45734 rename + first use ExternalReferenceCodeModel to retrieve ERC
DaniSzimko Jan 24, 2025
44f53f3
LPD-45734 SF
DaniSzimko Jan 24, 2025
bf7a5e8
LPD-45734 first param should be the expected one + avoid using stream
DaniSzimko Jan 24, 2025
03e3554
LPD-45734 baseline
DaniSzimko Jan 27, 2025
f3d68a2
LPD-45734 upgradeDB
DaniSzimko Jan 27, 2025
f70d11c
LPD-45734 Simplify. If a NullPointerException is thrown, the test wil…
ccorreagg Jan 27, 2025
f5c9e4d
LPD-45734 Sort
ccorreagg Jan 27, 2025
1dabb55
LPD-45734 include assertion inside testDeleteObjectEntry
DaniSzimko Jan 27, 2025
c1b00be
LPD-45734 remove reflection
DaniSzimko Feb 4, 2025
16ac1b6
LPD-45734 sort
DaniSzimko Feb 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,8 @@ private void _addDeletionSystemEvent(AssetLink assetLink) {
_systemEventLocalService.addSystemEvent(
0, assetEntry.getGroupId(), stagedModelType.getClassName(),
stagedAssetLink.getPrimaryKey(), stagedAssetLink.getUuid(),
null, SystemEventConstants.TYPE_DELETE, StringPool.BLANK);
StringPool.BLANK, null, SystemEventConstants.TYPE_DELETE,
StringPool.BLANK);
}
catch (PortalException portalException) {
throw new RuntimeException(portalException);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ public CalendarBooking updateCalendarBooking(
userId, calendarBooking.getGroupId(),
CalendarBooking.class.getName(),
calendarBooking.getCalendarBookingId(),
calendarBooking.getUuid(), null,
calendarBooking.getUuid(), StringPool.BLANK, null,
SystemEventConstants.TYPE_DELETE, StringPool.BLANK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public void deleteStagedModel(DummyFolder dummyFolder)
systemEventLocalService.addSystemEvent(
0, dummyFolder.getGroupId(), dummyFolder.getModelClassName(),
dummyFolder.getPrimaryKey(), dummyFolder.getUuid(),
StringPool.BLANK, SystemEventConstants.TYPE_DELETE,
StringPool.BLANK);
StringPool.BLANK, StringPool.BLANK,
SystemEventConstants.TYPE_DELETE, StringPool.BLANK);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public void deleteStagedModel(DummyReference dummyReference)
0, dummyReference.getGroupId(),
dummyReference.getModelClassName(),
dummyReference.getPrimaryKey(), dummyReference.getUuid(),
StringPool.BLANK, SystemEventConstants.TYPE_DELETE,
StringPool.BLANK);
StringPool.BLANK, StringPool.BLANK,
SystemEventConstants.TYPE_DELETE, StringPool.BLANK);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public void deleteStagedModel(Dummy dummy) throws PortalException {
systemEventLocalService.addSystemEvent(
0, dummy.getGroupId(), dummy.getModelClassName(),
dummy.getPrimaryKey(), dummy.getUuid(), StringPool.BLANK,
SystemEventConstants.TYPE_DELETE, StringPool.BLANK);
StringPool.BLANK, SystemEventConstants.TYPE_DELETE,
StringPool.BLANK);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected CTModel<?> addCTModel() throws Exception {
return _systemEventLocalService.addSystemEvent(
TestPropsValues.getUserId(), TestPropsValues.getGroupId(),
Group.class.getName(), RandomTestUtil.nextLong(),
PortalUUIDUtil.generate(), StringPool.BLANK,
PortalUUIDUtil.generate(), StringPool.BLANK, StringPool.BLANK,
SystemEventConstants.TYPE_DELETE, StringPool.BLANK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected SystemEvent addSystemEvent() throws Exception {
return SystemEventLocalServiceUtil.addSystemEvent(
TestPropsValues.getUserId(), _group.getGroupId(),
Group.class.getName(), RandomTestUtil.nextLong(),
PortalUUIDUtil.generate(), StringPool.BLANK,
PortalUUIDUtil.generate(), StringPool.BLANK, StringPool.BLANK,
SystemEventConstants.TYPE_DELETE, StringPool.BLANK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.liferay.journal.service.JournalArticleResourceLocalService;
import com.liferay.journal.service.JournalFolderLocalService;
import com.liferay.journal.util.JournalHelper;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.json.JSONUtil;
Expand Down Expand Up @@ -80,8 +81,8 @@ public SystemEvent addDeletionSystemEvent(

return _systemEventLocalService.addSystemEvent(
userId, groupId, getSystemEventClassName(), classPK, classUuid,
referrerClassName, SystemEventConstants.TYPE_DELETE,
extraDataJSONObject.toString());
StringPool.BLANK, referrerClassName,
SystemEventConstants.TYPE_DELETE, extraDataJSONObject.toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1383,8 +1383,8 @@ public JournalArticle deleteArticle(
if (articleResource != null) {
_systemEventLocalService.addSystemEvent(
0, article.getGroupId(), article.getModelClassName(),
article.getPrimaryKey(), articleResource.getUuid(), null,
SystemEventConstants.TYPE_DELETE,
article.getPrimaryKey(), articleResource.getUuid(),
StringPool.BLANK, null, SystemEventConstants.TYPE_DELETE,
JSONUtil.put(
"assetTitle",
article.getTitle(article.getDefaultLanguageId())
Expand Down Expand Up @@ -1471,7 +1471,7 @@ public void deleteArticle(
_systemEventLocalService.addSystemEvent(
0, groupId, JournalArticle.class.getName(),
articleResource.getResourcePrimKey(), articleResource.getUuid(),
null, SystemEventConstants.TYPE_DELETE,
StringPool.BLANK, null, SystemEventConstants.TYPE_DELETE,
JSONUtil.put(
"assetTitle", assetTitle
).toString());
Expand Down Expand Up @@ -1528,7 +1528,8 @@ public void deleteArticles(long groupId) throws PortalException {
_systemEventLocalService.addSystemEvent(
0, groupId, JournalArticle.class.getName(),
articleResource.getResourcePrimKey(), articleResource.getUuid(),
null, SystemEventConstants.TYPE_DELETE, StringPool.BLANK);
StringPool.BLANK, null, SystemEventConstants.TYPE_DELETE,
StringPool.BLANK);
}
}

Expand Down Expand Up @@ -1602,7 +1603,8 @@ public void deleteArticles(
_systemEventLocalService.addSystemEvent(
0, groupId, JournalArticle.class.getName(),
articleResource.getResourcePrimKey(), articleResource.getUuid(),
null, SystemEventConstants.TYPE_DELETE, StringPool.BLANK);
StringPool.BLANK, null, SystemEventConstants.TYPE_DELETE,
StringPool.BLANK);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package com.liferay.object.model.impl;

import com.liferay.exportimport.kernel.lar.StagedModelType;
import com.liferay.friendly.url.model.FriendlyURLEntry;
import com.liferay.friendly.url.service.FriendlyURLEntryLocalServiceUtil;
import com.liferay.object.constants.ObjectEntryFolderConstants;
Expand All @@ -27,6 +28,7 @@
import com.liferay.portal.kernel.service.ClassNameLocalServiceUtil;
import com.liferay.portal.kernel.service.CompanyLocalServiceUtil;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.Validator;

import java.io.Serializable;
Expand Down Expand Up @@ -98,6 +100,12 @@ public long getNonzeroGroupId() throws PortalException {
return groupId;
}

@Override
public StagedModelType getStagedModelType() {
return new StagedModelType(
PortalUtil.getClassNameId(getModelClassName()));
}

@Override
public String getTitleValue() throws PortalException {
ObjectDefinition objectDefinition =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
import com.liferay.portal.kernel.model.ModelListener;
import com.liferay.portal.kernel.model.ResourceConstants;
import com.liferay.portal.kernel.model.Role;
import com.liferay.portal.kernel.model.SystemEvent;
import com.liferay.portal.kernel.model.SystemEventConstants;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.model.role.RoleConstants;
import com.liferay.portal.kernel.repository.model.FileEntry;
Expand All @@ -127,6 +129,7 @@
import com.liferay.portal.kernel.service.ResourcePermissionLocalService;
import com.liferay.portal.kernel.service.RoleLocalService;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.service.SystemEventLocalService;
import com.liferay.portal.kernel.service.UserLocalService;
import com.liferay.portal.kernel.service.WorkflowDefinitionLinkLocalService;
import com.liferay.portal.kernel.test.AssertUtils;
Expand Down Expand Up @@ -155,6 +158,7 @@
import com.liferay.portal.kernel.util.LocaleThreadLocal;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.MapUtil;
import com.liferay.portal.kernel.util.Portal;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringUtil;
Expand Down Expand Up @@ -3119,15 +3123,26 @@ public void testDeleteObjectEntry() throws Exception {
_objectEntryLocalService.deleteObjectEntry(
objectEntry1.getObjectEntryId());

List<SystemEvent> systemEvents =
_systemEventLocalService.getSystemEvents(
0, _portal.getClassNameId(objectEntry1.getModelClassName()),
objectEntry1.getPrimaryKey());

SystemEvent systemEvent = systemEvents.get(0);

Assert.assertEquals(
objectEntry1.getExternalReferenceCode(),
systemEvent.getClassExternalReferenceCode());
Assert.assertEquals(
SystemEventConstants.TYPE_DELETE, systemEvent.getType());

AssertUtils.assertFailure(
NoSuchObjectEntryException.class,
"No ObjectEntry exists with the primary key " +
objectEntry1.getObjectEntryId(),
() -> _objectEntryLocalService.deleteObjectEntry(
objectEntry1.getObjectEntryId()));

_objectEntryLocalService.deleteObjectEntry(objectEntry1);

AssertUtils.assertFailure(
NoSuchObjectEntryException.class,
"No ObjectEntry exists with the primary key " +
Expand Down Expand Up @@ -5708,6 +5723,9 @@ private ObjectValidationRule _updateObjectValidationRule(
@Inject
private ObjectValidationRuleLocalService _objectValidationRuleLocalService;

@Inject
private Portal _portal;

@Inject
private ResourceActions _resourceActions;

Expand All @@ -5717,6 +5735,9 @@ private ObjectValidationRule _updateObjectValidationRule(
@Inject
private RoleLocalService _roleLocalService;

@Inject
private SystemEventLocalService _systemEventLocalService;

@Inject
private UserLocalService _userLocalService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ protected SystemEvent addBaseModel(long userId, boolean deleteAfterTestRun)
SystemEvent systemEvent = _systemEventLocalService.addSystemEvent(
userId, TestPropsValues.getGroupId(), Group.class.getName(),
RandomTestUtil.nextLong(), PortalUUIDUtil.generate(),
StringPool.BLANK, SystemEventConstants.TYPE_DELETE,
StringPool.BLANK);
StringPool.BLANK, StringPool.BLANK,
SystemEventConstants.TYPE_DELETE, StringPool.BLANK);

if (deleteAfterTestRun) {
_systemEvents.add(systemEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ protected SystemEvent addBaseModel(long userId) throws Exception {
SystemEvent systemEvent = _systemEventLocalService.addSystemEvent(
userId, TestPropsValues.getGroupId(), Group.class.getName(),
RandomTestUtil.nextLong(), PortalUUIDUtil.generate(),
StringPool.BLANK, SystemEventConstants.TYPE_DELETE,
StringPool.BLANK);
StringPool.BLANK, StringPool.BLANK,
SystemEventConstants.TYPE_DELETE, StringPool.BLANK);

_systemEvents.add(systemEvent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ protected void doDeleteLayout(

_systemEventLocalService.addSystemEvent(
0, layout.getGroupId(), Layout.class.getName(),
layout.getPlid(), layout.getUuid(), null,
layout.getPlid(), layout.getUuid(), null, null,
SystemEventConstants.TYPE_DELETE,
systemEventHierarchyEntry.getExtraData());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public SystemEvent addDeletionSystemEvent(

return SystemEventLocalServiceUtil.addSystemEvent(
userId, groupId, getSystemEventClassName(), classPK, classUuid,
referrerClassName, SystemEventConstants.TYPE_DELETE,
extraDataJSONObject.toString());
StringPool.BLANK, referrerClassName,
SystemEventConstants.TYPE_DELETE, extraDataJSONObject.toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,8 @@ public void deletePage(WikiPage page) throws PortalException {
if (pageResource != null) {
_systemEventLocalService.addSystemEvent(
0, page.getGroupId(), page.getModelClassName(),
page.getPrimaryKey(), pageResource.getUuid(), null,
SystemEventConstants.TYPE_DELETE, StringPool.BLANK);
page.getPrimaryKey(), pageResource.getUuid(), StringPool.BLANK,
null, SystemEventConstants.TYPE_DELETE, StringPool.BLANK);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public void testUpdateExisting() throws Exception {

newSystemEvent.setClassUuid(RandomTestUtil.randomString());

newSystemEvent.setClassExternalReferenceCode(
RandomTestUtil.randomString());

newSystemEvent.setReferrerClassNameId(RandomTestUtil.nextLong());

newSystemEvent.setParentSystemEventId(RandomTestUtil.nextLong());
Expand Down Expand Up @@ -174,6 +177,9 @@ public void testUpdateExisting() throws Exception {
existingSystemEvent.getClassPK(), newSystemEvent.getClassPK());
Assert.assertEquals(
existingSystemEvent.getClassUuid(), newSystemEvent.getClassUuid());
Assert.assertEquals(
existingSystemEvent.getClassExternalReferenceCode(),
newSystemEvent.getClassExternalReferenceCode());
Assert.assertEquals(
existingSystemEvent.getReferrerClassNameId(),
newSystemEvent.getReferrerClassNameId());
Expand Down Expand Up @@ -250,9 +256,9 @@ protected OrderByComparator<SystemEvent> getOrderByComparator() {
"SystemEvent", "mvccVersion", true, "ctCollectionId", true,
"systemEventId", true, "groupId", true, "companyId", true, "userId",
true, "userName", true, "createDate", true, "classNameId", true,
"classPK", true, "classUuid", true, "referrerClassNameId", true,
"parentSystemEventId", true, "systemEventSetKey", true, "type",
true);
"classPK", true, "classUuid", true, "classExternalReferenceCode",
true, "referrerClassNameId", true, "parentSystemEventId", true,
"systemEventSetKey", true, "type", true);
}

@Test
Expand Down Expand Up @@ -489,6 +495,9 @@ protected SystemEvent addSystemEvent() throws Exception {

systemEvent.setClassUuid(RandomTestUtil.randomString());

systemEvent.setClassExternalReferenceCode(
RandomTestUtil.randomString());

systemEvent.setReferrerClassNameId(RandomTestUtil.nextLong());

systemEvent.setParentSystemEventId(RandomTestUtil.nextLong());
Expand Down
1 change: 1 addition & 0 deletions portal-impl/src/META-INF/portal-hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@
<property access="com.liferay.portal.dao.orm.hibernate.MethodPropertyAccessor" name="classNameId" type="com.liferay.portal.dao.orm.hibernate.LongType" />
<property access="com.liferay.portal.dao.orm.hibernate.MethodPropertyAccessor" name="classPK" type="com.liferay.portal.dao.orm.hibernate.LongType" />
<property access="com.liferay.portal.dao.orm.hibernate.MethodPropertyAccessor" name="classUuid" type="com.liferay.portal.dao.orm.hibernate.StringType" />
<property access="com.liferay.portal.dao.orm.hibernate.MethodPropertyAccessor" name="classExternalReferenceCode" type="com.liferay.portal.dao.orm.hibernate.StringType" />
<property access="com.liferay.portal.dao.orm.hibernate.MethodPropertyAccessor" name="referrerClassNameId" type="com.liferay.portal.dao.orm.hibernate.LongType" />
<property access="com.liferay.portal.dao.orm.hibernate.MethodPropertyAccessor" name="parentSystemEventId" type="com.liferay.portal.dao.orm.hibernate.LongType" />
<property access="com.liferay.portal.dao.orm.hibernate.MethodPropertyAccessor" name="systemEventSetKey" type="com.liferay.portal.dao.orm.hibernate.LongType" />
Expand Down
1 change: 1 addition & 0 deletions portal-impl/src/META-INF/portal-model-hints.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,7 @@
<field name="classNameId" type="long" />
<field name="classPK" type="long" />
<field name="classUuid" type="String" />
<field name="classExternalReferenceCode" type="String" />
<field name="referrerClassNameId" type="long" />
<field name="parentSystemEventId" type="long" />
<field name="systemEventSetKey" type="long" />
Expand Down
Loading