From 55f2df335d2b2dcd6ceac6311d341710c33f9297 Mon Sep 17 00:00:00 2001 From: Stefano Motta <117469730+smottal@users.noreply.github.com> Date: Wed, 26 Feb 2025 10:11:28 +0100 Subject: [PATCH 01/16] LPD-50006 New ThreadLocal --- .../kernel/LazyReferencingThreadLocal.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 portal-kernel/src/com/liferay/lazy/referencing/kernel/LazyReferencingThreadLocal.java diff --git a/portal-kernel/src/com/liferay/lazy/referencing/kernel/LazyReferencingThreadLocal.java b/portal-kernel/src/com/liferay/lazy/referencing/kernel/LazyReferencingThreadLocal.java new file mode 100644 index 00000000000000..4beec70a7fd1a2 --- /dev/null +++ b/portal-kernel/src/com/liferay/lazy/referencing/kernel/LazyReferencingThreadLocal.java @@ -0,0 +1,42 @@ +/** + * SPDX-FileCopyrightText: (c) 2025 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.lazy.referencing.kernel; + +import com.liferay.petra.lang.CentralizedThreadLocal; + +/** + * @author Stefano Motta + */ +public class LazyReferencingThreadLocal { + + public static boolean isIncompleteModel() { + return _incompleteModel.get(); + } + + public static boolean isLazyReferencingEnabled() { + return _lazyReferencingEnabled.get(); + } + + public static void setIncompleteModel(boolean incompleteModel) { + _incompleteModel.set(incompleteModel); + } + + public static void setLazyReferencingEnabled( + boolean lazyReferencingEnabled) { + + _lazyReferencingEnabled.set(lazyReferencingEnabled); + } + + private static final ThreadLocal _incompleteModel = + new CentralizedThreadLocal<>( + LazyReferencingThreadLocal.class + "._incompleteModel", + () -> Boolean.FALSE); + private static final ThreadLocal _lazyReferencingEnabled = + new CentralizedThreadLocal<>( + LazyReferencingThreadLocal.class + "._lazyReferencingEnabled", + () -> Boolean.FALSE); + +} \ No newline at end of file From 3d6393c65de0905ed5d0604ba5fae596f10f040a Mon Sep 17 00:00:00 2001 From: Stefano Motta <117469730+smottal@users.noreply.github.com> Date: Wed, 26 Feb 2025 10:11:59 +0100 Subject: [PATCH 02/16] LPD-50006 Semantic Versioning (portal-kernel) --- .../src/com/liferay/lazy/referencing/kernel/packageinfo | 1 + 1 file changed, 1 insertion(+) create mode 100644 portal-kernel/src/com/liferay/lazy/referencing/kernel/packageinfo diff --git a/portal-kernel/src/com/liferay/lazy/referencing/kernel/packageinfo b/portal-kernel/src/com/liferay/lazy/referencing/kernel/packageinfo new file mode 100644 index 00000000000000..e2525561ab2e7b --- /dev/null +++ b/portal-kernel/src/com/liferay/lazy/referencing/kernel/packageinfo @@ -0,0 +1 @@ +version 1.0.0 \ No newline at end of file From 8510b5bd9736b022d71ca10a8f0d71b3a1af2b0d Mon Sep 17 00:00:00 2001 From: Stefano Motta <117469730+smottal@users.noreply.github.com> Date: Wed, 26 Feb 2025 10:12:56 +0100 Subject: [PATCH 03/16] LPD-50006 Add workflow to roles (service.xml) --- portal-impl/src/com/liferay/portal/service.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/portal-impl/src/com/liferay/portal/service.xml b/portal-impl/src/com/liferay/portal/service.xml index 937510222608c5..6f0e974d13e6a6 100644 --- a/portal-impl/src/com/liferay/portal/service.xml +++ b/portal-impl/src/com/liferay/portal/service.xml @@ -2198,6 +2198,10 @@ + + + + From 66ba36011d509e8397f064df14eae7b80f55335a Mon Sep 17 00:00:00 2001 From: Stefano Motta <117469730+smottal@users.noreply.github.com> Date: Wed, 26 Feb 2025 10:13:47 +0100 Subject: [PATCH 04/16] LPD-50006 Role service updates --- .../workflow/RoleWorkflowHandler.java | 79 ++++++++++++++ .../service/impl/RoleLocalServiceImpl.java | 100 +++++++++++++++++- 2 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 modules/apps/roles/roles-admin-impl/src/main/java/com/liferay/roles/admin/internal/workflow/RoleWorkflowHandler.java diff --git a/modules/apps/roles/roles-admin-impl/src/main/java/com/liferay/roles/admin/internal/workflow/RoleWorkflowHandler.java b/modules/apps/roles/roles-admin-impl/src/main/java/com/liferay/roles/admin/internal/workflow/RoleWorkflowHandler.java new file mode 100644 index 00000000000000..6717640da9bf74 --- /dev/null +++ b/modules/apps/roles/roles-admin-impl/src/main/java/com/liferay/roles/admin/internal/workflow/RoleWorkflowHandler.java @@ -0,0 +1,79 @@ +/** + * SPDX-FileCopyrightText: (c) 2025 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.roles.admin.internal.workflow; + +import com.liferay.portal.kernel.exception.PortalException; +import com.liferay.portal.kernel.language.Language; +import com.liferay.portal.kernel.model.Role; +import com.liferay.portal.kernel.service.RoleLocalService; +import com.liferay.portal.kernel.service.ServiceContext; +import com.liferay.portal.kernel.util.GetterUtil; +import com.liferay.portal.kernel.workflow.BaseWorkflowHandler; +import com.liferay.portal.kernel.workflow.WorkflowConstants; +import com.liferay.portal.kernel.workflow.WorkflowHandler; + +import java.io.Serializable; + +import java.util.Locale; +import java.util.Map; + +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; + +/** + * @author Stefano Motta + */ +@Component( + property = "model.class.name=com.liferay.portal.kernel.model.Role", + service = WorkflowHandler.class +) +public class RoleWorkflowHandler extends BaseWorkflowHandler { + + @Override + public String getClassName() { + return Role.class.getName(); + } + + @Override + public String getType(Locale locale) { + return _language.get(locale, "role"); + } + + @Override + public boolean isScopeable() { + return false; + } + + @Override + public boolean isVisible() { + return false; + } + + @Override + public Role updateStatus( + int status, Map workflowContext) + throws PortalException { + + long userId = GetterUtil.getLong( + (String)workflowContext.get(WorkflowConstants.CONTEXT_USER_ID)); + long classPK = GetterUtil.getLong( + (String)workflowContext.get( + WorkflowConstants.CONTEXT_ENTRY_CLASS_PK)); + + ServiceContext serviceContext = (ServiceContext)workflowContext.get( + "serviceContext"); + + return _roleLocalService.updateStatus( + userId, classPK, status, serviceContext, workflowContext); + } + + @Reference + private Language _language; + + @Reference + private RoleLocalService _roleLocalService; + +} \ No newline at end of file diff --git a/portal-impl/src/com/liferay/portal/service/impl/RoleLocalServiceImpl.java b/portal-impl/src/com/liferay/portal/service/impl/RoleLocalServiceImpl.java index 7ee8ecf1d6010c..4c3ae4408532f8 100644 --- a/portal-impl/src/com/liferay/portal/service/impl/RoleLocalServiceImpl.java +++ b/portal-impl/src/com/liferay/portal/service/impl/RoleLocalServiceImpl.java @@ -8,6 +8,7 @@ import com.liferay.admin.kernel.util.PortalMyAccountApplicationType; import com.liferay.expando.kernel.service.ExpandoRowLocalService; import com.liferay.exportimport.kernel.lar.ExportImportThreadLocal; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.sql.dsl.DSLFunctionFactoryUtil; import com.liferay.petra.sql.dsl.DSLQueryFactoryUtil; import com.liferay.petra.sql.dsl.expression.Predicate; @@ -106,10 +107,13 @@ import com.liferay.portal.util.PropsValues; import com.liferay.portlet.usersadmin.util.UsersAdminUtil; +import java.io.Serializable; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -129,6 +133,39 @@ */ public class RoleLocalServiceImpl extends RoleLocalServiceBaseImpl { + @Override + public Role addIncompleteRole( + String externalReferenceCode, long companyId, long userId, + String className, long classPK, String name, int type) + throws Exception { + + if (!LazyReferencingThreadLocal.isLazyReferencingEnabled()) { + throw new UnsupportedOperationException(); + } + + Role role = roleLocalService.fetchRoleByExternalReferenceCode( + externalReferenceCode, companyId); + + if (role != null) { + return role; + } + + if (roleLocalService.fetchRole(companyId, name) != null) { + name = externalReferenceCode; + } + + try { + LazyReferencingThreadLocal.setIncompleteModel(true); + + return roleLocalService.addRole( + externalReferenceCode, userId, className, classPK, name, null, + null, type, StringPool.BLANK, new ServiceContext()); + } + finally { + LazyReferencingThreadLocal.setIncompleteModel(false); + } + } + @Indexable(type = IndexableType.REINDEX) @Override public Role addRole( @@ -172,6 +209,24 @@ public Role addRole( role.setDescriptionMap(descriptionMap); role.setType(type); role.setSubtype(subtype); + + if (LazyReferencingThreadLocal.isIncompleteModel()) { + role.setStatus(WorkflowConstants.STATUS_INCOMPLETE); + } + else { + role.setStatus(WorkflowConstants.STATUS_APPROVED); + } + + role.setStatusByUserId(user.getUserId()); + role.setStatusByUserName(user.getFullName()); + + if (serviceContext != null) { + role.setStatusDate(serviceContext.getModifiedDate(new Date())); + } + else { + role.setStatusDate(new Date()); + } + role.setExpandoBridgeAttributes(serviceContext); role = rolePersistence.update(role); @@ -1918,7 +1973,50 @@ public Role updateRole( role.setSubtype(subtype); role.setExpandoBridgeAttributes(serviceContext); - return rolePersistence.update(role); + role = rolePersistence.update(role); + + if (role.getStatus() == WorkflowConstants.STATUS_INCOMPLETE) { + long userId = role.getUserId(); + + if (serviceContext != null) { + userId = serviceContext.getUserId(); + } + + role = updateStatus( + userId, role.getRoleId(), WorkflowConstants.STATUS_APPROVED, + serviceContext, Collections.emptyMap()); + } + + return role; + } + + @Indexable(type = IndexableType.REINDEX) + @Override + public Role updateStatus( + long userId, long roleId, int status, ServiceContext serviceContext, + Map workflowContext) + throws PortalException { + + Role role = getRole(roleId); + + if (role.getStatus() == status) { + return role; + } + + role.setStatus(status); + + User user = _userLocalService.getUser(userId); + + role.setStatusByUserId(user.getUserId()); + role.setStatusByUserName(user.getFullName()); + + if (serviceContext == null) { + serviceContext = new ServiceContext(); + } + + role.setStatusDate(serviceContext.getModifiedDate(new Date())); + + return updateRole(role); } @Override From df888fc184ffc328cbc58da6d48095b670c1551a Mon Sep 17 00:00:00 2001 From: Stefano Motta <117469730+smottal@users.noreply.github.com> Date: Thu, 27 Feb 2025 09:13:42 +0100 Subject: [PATCH 05/16] LPD-50006 Role service integration tests --- .../service/test/RoleLocalServiceTest.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/modules/apps/roles/roles-test/src/testIntegration/java/com/liferay/roles/service/test/RoleLocalServiceTest.java b/modules/apps/roles/roles-test/src/testIntegration/java/com/liferay/roles/service/test/RoleLocalServiceTest.java index 61ff0c5768c9c6..eb87a71a302249 100644 --- a/modules/apps/roles/roles-test/src/testIntegration/java/com/liferay/roles/service/test/RoleLocalServiceTest.java +++ b/modules/apps/roles/roles-test/src/testIntegration/java/com/liferay/roles/service/test/RoleLocalServiceTest.java @@ -7,6 +7,7 @@ import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian; import com.liferay.layout.test.util.LayoutTestUtil; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.string.StringPool; import com.liferay.portal.configuration.test.util.ConfigurationTemporarySwapper; import com.liferay.portal.kernel.dao.orm.QueryUtil; @@ -109,6 +110,32 @@ public static void tearDownClass() { _resourcePermission); } + @Test + public void testAddIncompleteRole() throws Exception { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); + + try { + _role = _roleLocalService.addIncompleteRole( + RandomTestUtil.randomString(), TestPropsValues.getCompanyId(), + TestPropsValues.getUserId(), Role.class.getName(), 0, + RandomTestUtil.randomString(), RoleConstants.TYPE_REGULAR); + + Assert.assertEquals( + WorkflowConstants.STATUS_INCOMPLETE, _role.getStatus()); + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); + } + } + + @Test(expected = UnsupportedOperationException.class) + public void testAddIncompleteRoleWithoutLazyReferencing() throws Exception { + _role = _roleLocalService.addIncompleteRole( + RandomTestUtil.randomString(), TestPropsValues.getCompanyId(), + TestPropsValues.getUserId(), Role.class.getName(), 0, + RandomTestUtil.randomString(), RoleConstants.TYPE_REGULAR); + } + @Test public void testAddRole() throws Exception { try { @@ -711,6 +738,31 @@ public void testLoggingAuditMessageProcessorConfigurationEnabled() } } + @Test + public void testUpdateRoleWithStatusIncomplete() throws Exception { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); + + try { + _role = _roleLocalService.addIncompleteRole( + RandomTestUtil.randomString(), TestPropsValues.getCompanyId(), + TestPropsValues.getUserId(), Role.class.getName(), 0, + RandomTestUtil.randomString(), RoleConstants.TYPE_REGULAR); + + Assert.assertEquals( + WorkflowConstants.STATUS_INCOMPLETE, _role.getStatus()); + + _role = _roleLocalService.updateRole( + _role.getRoleId(), _role.getName(), _role.getTitleMap(), + _role.getDescriptionMap(), _role.getSubtype(), null); + + Assert.assertEquals( + WorkflowConstants.STATUS_APPROVED, _role.getStatus()); + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); + } + } + protected void assertGetTeamRoleMap( Map teamRoleMap, Team team, boolean hasTeam) { From d3b0131d06d73008dab56ec153dfbdbd24d96125 Mon Sep 17 00:00:00 2001 From: Stefano Motta <117469730+smottal@users.noreply.github.com> Date: Wed, 26 Feb 2025 10:14:05 +0100 Subject: [PATCH 06/16] LPD-50006 Upgrade process --- .../upgrade/v7_4_x/PortalUpgradeProcessRegistryImpl.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/portal-impl/src/com/liferay/portal/upgrade/v7_4_x/PortalUpgradeProcessRegistryImpl.java b/portal-impl/src/com/liferay/portal/upgrade/v7_4_x/PortalUpgradeProcessRegistryImpl.java index 7546702371722e..489da81ce35712 100644 --- a/portal-impl/src/com/liferay/portal/upgrade/v7_4_x/PortalUpgradeProcessRegistryImpl.java +++ b/portal-impl/src/com/liferay/portal/upgrade/v7_4_x/PortalUpgradeProcessRegistryImpl.java @@ -575,6 +575,13 @@ protected String[][] getTableAndPrimaryKeyColumnNames() { new Version(31, 15, 1), new DBColumnSizeUpgradeProcess( DBType.ORACLE, "number", 30, 20, "DOUBLE")); + + upgradeVersionTreeMap.put( + new Version(31, 16, 0), + UpgradeProcessFactory.addColumns( + "Role_", "status INTEGER", "statusByUserId LONG", + "statusByUserName VARCHAR(75)", "statusDate DATE"), + UpgradeProcessFactory.runSQL("update Role_ set status = 0")); } } \ No newline at end of file From 22c54add3f4458a4532bc1a83667e02e33eed88d Mon Sep 17 00:00:00 2001 From: Stefano Motta <117469730+smottal@users.noreply.github.com> Date: Wed, 26 Feb 2025 10:16:06 +0100 Subject: [PATCH 07/16] LPD-50006 Autogenerated Code (build-service-portal) --- .../uad/anonymizer/BaseRoleUADAnonymizer.java | 5 + .../uad/constants/RolesUADConstants.java | 4 +- .../uad/exporter/BaseRoleUADExporter.java | 6 +- .../persistence/test/RolePersistenceTest.java | 28 ++- portal-impl/src/META-INF/portal-hbm.xml | 4 + .../src/META-INF/portal-model-hints.xml | 4 + .../portal/model/impl/RoleCacheModel.java | 50 +++- .../portal/model/impl/RoleModelImpl.java | 235 +++++++++++++++++- .../base/RoleLocalServiceBaseImpl.java | 44 +++- .../persistence/impl/RolePersistenceImpl.java | 4 + .../portal/kernel/model/RoleModel.java | 147 ++++++++++- .../portal/kernel/model/RoleTable.java | 8 + .../portal/kernel/model/RoleWrapper.java | 208 ++++++++++++++++ .../kernel/service/RoleLocalService.java | 11 + .../kernel/service/RoleLocalServiceUtil.java | 19 ++ .../service/RoleLocalServiceWrapper.java | 21 ++ sql/portal-tables.sql | 4 + 17 files changed, 793 insertions(+), 9 deletions(-) diff --git a/modules/apps/roles/roles-uad/src/main/java/com/liferay/roles/uad/anonymizer/BaseRoleUADAnonymizer.java b/modules/apps/roles/roles-uad/src/main/java/com/liferay/roles/uad/anonymizer/BaseRoleUADAnonymizer.java index b37d8066c6ee82..d54b0700f3c555 100644 --- a/modules/apps/roles/roles-uad/src/main/java/com/liferay/roles/uad/anonymizer/BaseRoleUADAnonymizer.java +++ b/modules/apps/roles/roles-uad/src/main/java/com/liferay/roles/uad/anonymizer/BaseRoleUADAnonymizer.java @@ -43,6 +43,11 @@ public void autoAnonymize(Role role, long userId, User anonymousUser) autoAnonymizeAssetEntry(role, anonymousUser); } + if (role.getStatusByUserId() == userId) { + role.setStatusByUserId(anonymousUser.getUserId()); + role.setStatusByUserName(anonymousUser.getFullName()); + } + roleLocalService.updateRole(role); } diff --git a/modules/apps/roles/roles-uad/src/main/java/com/liferay/roles/uad/constants/RolesUADConstants.java b/modules/apps/roles/roles-uad/src/main/java/com/liferay/roles/uad/constants/RolesUADConstants.java index f954ec0a88cb2d..d5cbf00dfb9f42 100644 --- a/modules/apps/roles/roles-uad/src/main/java/com/liferay/roles/uad/constants/RolesUADConstants.java +++ b/modules/apps/roles/roles-uad/src/main/java/com/liferay/roles/uad/constants/RolesUADConstants.java @@ -11,6 +11,8 @@ */ public class RolesUADConstants { - public static final String[] USER_ID_FIELD_NAMES_ROLE = {"userId"}; + public static final String[] USER_ID_FIELD_NAMES_ROLE = { + "userId", "statusByUserId" + }; } \ No newline at end of file diff --git a/modules/apps/roles/roles-uad/src/main/java/com/liferay/roles/uad/exporter/BaseRoleUADExporter.java b/modules/apps/roles/roles-uad/src/main/java/com/liferay/roles/uad/exporter/BaseRoleUADExporter.java index ec5fe68aa7757e..6cf3724437ca2b 100644 --- a/modules/apps/roles/roles-uad/src/main/java/com/liferay/roles/uad/exporter/BaseRoleUADExporter.java +++ b/modules/apps/roles/roles-uad/src/main/java/com/liferay/roles/uad/exporter/BaseRoleUADExporter.java @@ -46,12 +46,16 @@ protected String[] doGetUserIdFieldNames() { @Override protected String toXmlString(Role role) { - StringBundler sb = new StringBundler(13); + StringBundler sb = new StringBundler(19); sb.append(""); sb.append("com.liferay.portal.kernel.model.Role"); sb.append(""); + sb.append( + "statusByUserName"); sb.append( "userName getOrderByComparator() { "externalReferenceCode", true, "roleId", true, "companyId", true, "userId", true, "userName", true, "createDate", true, "modifiedDate", true, "classNameId", true, "classPK", true, "name", - true, "title", true, "type", true, "subtype", true); + true, "title", true, "type", true, "subtype", true, "status", true, + "statusByUserId", true, "statusByUserName", true, "statusDate", + true); } @Test @@ -701,6 +719,14 @@ protected Role addRole() throws Exception { role.setSubtype(RandomTestUtil.randomString()); + role.setStatus(RandomTestUtil.nextInt()); + + role.setStatusByUserId(RandomTestUtil.nextLong()); + + role.setStatusByUserName(RandomTestUtil.randomString()); + + role.setStatusDate(RandomTestUtil.nextDate()); + _roles.add(_persistence.update(role)); return role; diff --git a/portal-impl/src/META-INF/portal-hbm.xml b/portal-impl/src/META-INF/portal-hbm.xml index c23538acd00d61..9b93911baf6ce6 100644 --- a/portal-impl/src/META-INF/portal-hbm.xml +++ b/portal-impl/src/META-INF/portal-hbm.xml @@ -915,6 +915,10 @@ + + + + diff --git a/portal-impl/src/META-INF/portal-model-hints.xml b/portal-impl/src/META-INF/portal-model-hints.xml index 8aceb6dc921e58..5e6dba829562d2 100644 --- a/portal-impl/src/META-INF/portal-model-hints.xml +++ b/portal-impl/src/META-INF/portal-model-hints.xml @@ -1435,6 +1435,10 @@ + + + + diff --git a/portal-impl/src/com/liferay/portal/model/impl/RoleCacheModel.java b/portal-impl/src/com/liferay/portal/model/impl/RoleCacheModel.java index cb60cf619fc9ff..38d535c9b55db0 100644 --- a/portal-impl/src/com/liferay/portal/model/impl/RoleCacheModel.java +++ b/portal-impl/src/com/liferay/portal/model/impl/RoleCacheModel.java @@ -67,7 +67,7 @@ public void setMvccVersion(long mvccVersion) { @Override public String toString() { - StringBundler sb = new StringBundler(35); + StringBundler sb = new StringBundler(43); sb.append("{mvccVersion="); sb.append(mvccVersion); @@ -103,6 +103,14 @@ public String toString() { sb.append(type); sb.append(", subtype="); sb.append(subtype); + sb.append(", status="); + sb.append(status); + sb.append(", statusByUserId="); + sb.append(statusByUserId); + sb.append(", statusByUserName="); + sb.append(statusByUserName); + sb.append(", statusDate="); + sb.append(statusDate); sb.append("}"); return sb.toString(); @@ -187,6 +195,23 @@ public Role toEntityModel() { roleImpl.setSubtype(subtype); } + roleImpl.setStatus(status); + roleImpl.setStatusByUserId(statusByUserId); + + if (statusByUserName == null) { + roleImpl.setStatusByUserName(""); + } + else { + roleImpl.setStatusByUserName(statusByUserName); + } + + if (statusDate == Long.MIN_VALUE) { + roleImpl.setStatusDate(null); + } + else { + roleImpl.setStatusDate(new Date(statusDate)); + } + roleImpl.resetOriginalValues(); return roleImpl; @@ -220,6 +245,12 @@ public void readExternal(ObjectInput objectInput) type = objectInput.readInt(); subtype = objectInput.readUTF(); + + status = objectInput.readInt(); + + statusByUserId = objectInput.readLong(); + statusByUserName = objectInput.readUTF(); + statusDate = objectInput.readLong(); } @Override @@ -291,6 +322,19 @@ public void writeExternal(ObjectOutput objectOutput) throws IOException { else { objectOutput.writeUTF(subtype); } + + objectOutput.writeInt(status); + + objectOutput.writeLong(statusByUserId); + + if (statusByUserName == null) { + objectOutput.writeUTF(""); + } + else { + objectOutput.writeUTF(statusByUserName); + } + + objectOutput.writeLong(statusDate); } public long mvccVersion; @@ -310,5 +354,9 @@ public void writeExternal(ObjectOutput objectOutput) throws IOException { public String description; public int type; public String subtype; + public int status; + public long statusByUserId; + public String statusByUserName; + public long statusDate; } \ No newline at end of file diff --git a/portal-impl/src/com/liferay/portal/model/impl/RoleModelImpl.java b/portal-impl/src/com/liferay/portal/model/impl/RoleModelImpl.java index ac486a9c5f869a..888237dc7dbc34 100644 --- a/portal-impl/src/com/liferay/portal/model/impl/RoleModelImpl.java +++ b/portal-impl/src/com/liferay/portal/model/impl/RoleModelImpl.java @@ -28,6 +28,7 @@ import com.liferay.portal.kernel.util.ProxyUtil; import com.liferay.portal.kernel.util.StringUtil; import com.liferay.portal.kernel.util.Validator; +import com.liferay.portal.kernel.workflow.WorkflowConstants; import java.io.Serializable; @@ -78,7 +79,9 @@ public class RoleModelImpl extends BaseModelImpl implements RoleModel { {"classNameId", Types.BIGINT}, {"classPK", Types.BIGINT}, {"name", Types.VARCHAR}, {"title", Types.VARCHAR}, {"description", Types.CLOB}, {"type_", Types.INTEGER}, - {"subtype", Types.VARCHAR} + {"subtype", Types.VARCHAR}, {"status", Types.INTEGER}, + {"statusByUserId", Types.BIGINT}, {"statusByUserName", Types.VARCHAR}, + {"statusDate", Types.TIMESTAMP} }; public static final Map TABLE_COLUMNS_MAP = @@ -102,10 +105,14 @@ public class RoleModelImpl extends BaseModelImpl implements RoleModel { TABLE_COLUMNS_MAP.put("description", Types.CLOB); TABLE_COLUMNS_MAP.put("type_", Types.INTEGER); TABLE_COLUMNS_MAP.put("subtype", Types.VARCHAR); + TABLE_COLUMNS_MAP.put("status", Types.INTEGER); + TABLE_COLUMNS_MAP.put("statusByUserId", Types.BIGINT); + TABLE_COLUMNS_MAP.put("statusByUserName", Types.VARCHAR); + TABLE_COLUMNS_MAP.put("statusDate", Types.TIMESTAMP); } public static final String TABLE_SQL_CREATE = - "create table Role_ (mvccVersion LONG default 0 not null,ctCollectionId LONG default 0 not null,uuid_ VARCHAR(75) null,externalReferenceCode VARCHAR(75) null,roleId LONG not null,companyId LONG,userId LONG,userName VARCHAR(75) null,createDate DATE null,modifiedDate DATE null,classNameId LONG,classPK LONG,name VARCHAR(75) null,title STRING null,description TEXT null,type_ INTEGER,subtype VARCHAR(75) null,primary key (roleId, ctCollectionId))"; + "create table Role_ (mvccVersion LONG default 0 not null,ctCollectionId LONG default 0 not null,uuid_ VARCHAR(75) null,externalReferenceCode VARCHAR(75) null,roleId LONG not null,companyId LONG,userId LONG,userName VARCHAR(75) null,createDate DATE null,modifiedDate DATE null,classNameId LONG,classPK LONG,name VARCHAR(75) null,title STRING null,description TEXT null,type_ INTEGER,subtype VARCHAR(75) null,status INTEGER,statusByUserId LONG,statusByUserName VARCHAR(75) null,statusDate DATE null,primary key (roleId, ctCollectionId))"; public static final String TABLE_SQL_DROP = "drop table Role_"; @@ -332,6 +339,12 @@ private static class AttributeGetterFunctionsHolder { attributeGetterFunctions.put("description", Role::getDescription); attributeGetterFunctions.put("type", Role::getType); attributeGetterFunctions.put("subtype", Role::getSubtype); + attributeGetterFunctions.put("status", Role::getStatus); + attributeGetterFunctions.put( + "statusByUserId", Role::getStatusByUserId); + attributeGetterFunctions.put( + "statusByUserName", Role::getStatusByUserName); + attributeGetterFunctions.put("statusDate", Role::getStatusDate); _attributeGetterFunctions = Collections.unmodifiableMap( attributeGetterFunctions); @@ -384,6 +397,16 @@ private static class AttributeSetterBiConsumersHolder { "type", (BiConsumer)Role::setType); attributeSetterBiConsumers.put( "subtype", (BiConsumer)Role::setSubtype); + attributeSetterBiConsumers.put( + "status", (BiConsumer)Role::setStatus); + attributeSetterBiConsumers.put( + "statusByUserId", + (BiConsumer)Role::setStatusByUserId); + attributeSetterBiConsumers.put( + "statusByUserName", + (BiConsumer)Role::setStatusByUserName); + attributeSetterBiConsumers.put( + "statusDate", (BiConsumer)Role::setStatusDate); _attributeSetterBiConsumers = Collections.unmodifiableMap( (Map)attributeSetterBiConsumers); @@ -979,12 +1002,173 @@ public String getOriginalSubtype() { return getColumnOriginalValue("subtype"); } + @JSON + @Override + public int getStatus() { + return _status; + } + + @Override + public void setStatus(int status) { + if (_columnOriginalValues == Collections.EMPTY_MAP) { + _setColumnOriginalValues(); + } + + _status = status; + } + + @JSON + @Override + public long getStatusByUserId() { + return _statusByUserId; + } + + @Override + public void setStatusByUserId(long statusByUserId) { + if (_columnOriginalValues == Collections.EMPTY_MAP) { + _setColumnOriginalValues(); + } + + _statusByUserId = statusByUserId; + } + + @Override + public String getStatusByUserUuid() { + try { + User user = UserLocalServiceUtil.getUserById(getStatusByUserId()); + + return user.getUuid(); + } + catch (PortalException portalException) { + return ""; + } + } + + @Override + public void setStatusByUserUuid(String statusByUserUuid) { + } + + @JSON + @Override + public String getStatusByUserName() { + if (_statusByUserName == null) { + return ""; + } + else { + return _statusByUserName; + } + } + + @Override + public void setStatusByUserName(String statusByUserName) { + if (_columnOriginalValues == Collections.EMPTY_MAP) { + _setColumnOriginalValues(); + } + + _statusByUserName = statusByUserName; + } + + @JSON + @Override + public Date getStatusDate() { + return _statusDate; + } + + @Override + public void setStatusDate(Date statusDate) { + if (_columnOriginalValues == Collections.EMPTY_MAP) { + _setColumnOriginalValues(); + } + + _statusDate = statusDate; + } + @Override public StagedModelType getStagedModelType() { return new StagedModelType( PortalUtil.getClassNameId(Role.class.getName()), getClassNameId()); } + @Override + public boolean isApproved() { + if (getStatus() == WorkflowConstants.STATUS_APPROVED) { + return true; + } + else { + return false; + } + } + + @Override + public boolean isDenied() { + if (getStatus() == WorkflowConstants.STATUS_DENIED) { + return true; + } + else { + return false; + } + } + + @Override + public boolean isDraft() { + if (getStatus() == WorkflowConstants.STATUS_DRAFT) { + return true; + } + else { + return false; + } + } + + @Override + public boolean isExpired() { + if (getStatus() == WorkflowConstants.STATUS_EXPIRED) { + return true; + } + else { + return false; + } + } + + @Override + public boolean isInactive() { + if (getStatus() == WorkflowConstants.STATUS_INACTIVE) { + return true; + } + else { + return false; + } + } + + @Override + public boolean isIncomplete() { + if (getStatus() == WorkflowConstants.STATUS_INCOMPLETE) { + return true; + } + else { + return false; + } + } + + @Override + public boolean isPending() { + if (getStatus() == WorkflowConstants.STATUS_PENDING) { + return true; + } + else { + return false; + } + } + + @Override + public boolean isScheduled() { + if (getStatus() == WorkflowConstants.STATUS_SCHEDULED) { + return true; + } + else { + return false; + } + } + public long getColumnBitmask() { if (_columnBitmask > 0) { return _columnBitmask; @@ -1146,6 +1330,10 @@ public Object clone() { roleImpl.setDescription(getDescription()); roleImpl.setType(getType()); roleImpl.setSubtype(getSubtype()); + roleImpl.setStatus(getStatus()); + roleImpl.setStatusByUserId(getStatusByUserId()); + roleImpl.setStatusByUserName(getStatusByUserName()); + roleImpl.setStatusDate(getStatusDate()); roleImpl.resetOriginalValues(); @@ -1179,6 +1367,12 @@ public Role cloneWithOriginalValues() { this.getColumnOriginalValue("description")); roleImpl.setType(this.getColumnOriginalValue("type_")); roleImpl.setSubtype(this.getColumnOriginalValue("subtype")); + roleImpl.setStatus(this.getColumnOriginalValue("status")); + roleImpl.setStatusByUserId( + this.getColumnOriginalValue("statusByUserId")); + roleImpl.setStatusByUserName( + this.getColumnOriginalValue("statusByUserName")); + roleImpl.setStatusDate(this.getColumnOriginalValue("statusDate")); return roleImpl; } @@ -1346,6 +1540,27 @@ public CacheModel toCacheModel() { roleCacheModel.subtype = null; } + roleCacheModel.status = getStatus(); + + roleCacheModel.statusByUserId = getStatusByUserId(); + + roleCacheModel.statusByUserName = getStatusByUserName(); + + String statusByUserName = roleCacheModel.statusByUserName; + + if ((statusByUserName != null) && (statusByUserName.length() == 0)) { + roleCacheModel.statusByUserName = null; + } + + Date statusDate = getStatusDate(); + + if (statusDate != null) { + roleCacheModel.statusDate = statusDate.getTime(); + } + else { + roleCacheModel.statusDate = Long.MIN_VALUE; + } + return roleCacheModel; } @@ -1426,6 +1641,10 @@ private static class EscapedModelProxyProviderFunctionHolder { private String _descriptionCurrentLanguageId; private int _type; private String _subtype; + private int _status; + private long _statusByUserId; + private String _statusByUserName; + private Date _statusDate; public T getColumnValue(String columnName) { columnName = _attributeNames.getOrDefault(columnName, columnName); @@ -1475,6 +1694,10 @@ private void _setColumnOriginalValues() { _columnOriginalValues.put("description", _description); _columnOriginalValues.put("type_", _type); _columnOriginalValues.put("subtype", _subtype); + _columnOriginalValues.put("status", _status); + _columnOriginalValues.put("statusByUserId", _statusByUserId); + _columnOriginalValues.put("statusByUserName", _statusByUserName); + _columnOriginalValues.put("statusDate", _statusDate); } private static final Map _attributeNames; @@ -1534,6 +1757,14 @@ public static long getColumnBitmask(String columnName) { columnBitmasks.put("subtype", 65536L); + columnBitmasks.put("status", 131072L); + + columnBitmasks.put("statusByUserId", 262144L); + + columnBitmasks.put("statusByUserName", 524288L); + + columnBitmasks.put("statusDate", 1048576L); + _columnBitmasks = Collections.unmodifiableMap(columnBitmasks); } diff --git a/portal-impl/src/com/liferay/portal/service/base/RoleLocalServiceBaseImpl.java b/portal-impl/src/com/liferay/portal/service/base/RoleLocalServiceBaseImpl.java index c998a172f64c7a..ffd42b832a2654 100644 --- a/portal-impl/src/com/liferay/portal/service/base/RoleLocalServiceBaseImpl.java +++ b/portal-impl/src/com/liferay/portal/service/base/RoleLocalServiceBaseImpl.java @@ -8,6 +8,8 @@ import com.liferay.exportimport.kernel.lar.ExportImportHelperUtil; import com.liferay.exportimport.kernel.lar.ManifestSummary; import com.liferay.exportimport.kernel.lar.PortletDataContext; +import com.liferay.exportimport.kernel.lar.StagedModelDataHandler; +import com.liferay.exportimport.kernel.lar.StagedModelDataHandlerRegistryUtil; import com.liferay.exportimport.kernel.lar.StagedModelDataHandlerUtil; import com.liferay.exportimport.kernel.lar.StagedModelType; import com.liferay.petra.function.UnsafeFunction; @@ -17,7 +19,9 @@ import com.liferay.portal.kernel.dao.db.DBManagerUtil; import com.liferay.portal.kernel.dao.jdbc.CurrentConnectionUtil; import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery; +import com.liferay.portal.kernel.dao.orm.Criterion; import com.liferay.portal.kernel.dao.orm.DefaultActionableDynamicQuery; +import com.liferay.portal.kernel.dao.orm.Disjunction; import com.liferay.portal.kernel.dao.orm.DynamicQuery; import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil; import com.liferay.portal.kernel.dao.orm.ExportActionableDynamicQuery; @@ -25,6 +29,7 @@ import com.liferay.portal.kernel.dao.orm.Projection; import com.liferay.portal.kernel.dao.orm.Property; import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil; +import com.liferay.portal.kernel.dao.orm.RestrictionsFactoryUtil; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.log.Log; @@ -46,6 +51,7 @@ import com.liferay.portal.kernel.transaction.Transactional; import com.liferay.portal.kernel.util.OrderByComparator; import com.liferay.portal.kernel.util.PortalUtil; +import com.liferay.portal.kernel.workflow.WorkflowConstants; import java.io.Serializable; @@ -359,8 +365,23 @@ public long performCount() throws PortalException { @Override public void addCriteria(DynamicQuery dynamicQuery) { - portletDataContext.addDateRangeCriteria( - dynamicQuery, "modifiedDate"); + Criterion modifiedDateCriterion = + portletDataContext.getDateRangeCriteria("modifiedDate"); + + Criterion statusDateCriterion = + portletDataContext.getDateRangeCriteria("statusDate"); + + if ((modifiedDateCriterion != null) && + (statusDateCriterion != null)) { + + Disjunction disjunction = + RestrictionsFactoryUtil.disjunction(); + + disjunction.add(modifiedDateCriterion); + disjunction.add(statusDateCriterion); + + dynamicQuery.add(disjunction); + } StagedModelType stagedModelType = exportActionableDynamicQuery.getStagedModelType(); @@ -385,6 +406,25 @@ else if (referrerClassNameId == dynamicQuery.add(classNameIdProperty.isNotNull()); } + + Property workflowStatusProperty = + PropertyFactoryUtil.forName("status"); + + if (portletDataContext.isInitialPublication()) { + dynamicQuery.add( + workflowStatusProperty.ne( + WorkflowConstants.STATUS_IN_TRASH)); + } + else { + StagedModelDataHandler stagedModelDataHandler = + StagedModelDataHandlerRegistryUtil. + getStagedModelDataHandler(Role.class.getName()); + + dynamicQuery.add( + workflowStatusProperty.in( + stagedModelDataHandler. + getExportableStatuses())); + } } }); diff --git a/portal-impl/src/com/liferay/portal/service/persistence/impl/RolePersistenceImpl.java b/portal-impl/src/com/liferay/portal/service/persistence/impl/RolePersistenceImpl.java index b6dbc22b213460..099f42460eb0f6 100644 --- a/portal-impl/src/com/liferay/portal/service/persistence/impl/RolePersistenceImpl.java +++ b/portal-impl/src/com/liferay/portal/service/persistence/impl/RolePersistenceImpl.java @@ -11576,6 +11576,10 @@ public List getUniqueIndexColumnNames() { ctMergeColumnNames.add("description"); ctMergeColumnNames.add("type_"); ctMergeColumnNames.add("subtype"); + ctMergeColumnNames.add("status"); + ctMergeColumnNames.add("statusByUserId"); + ctMergeColumnNames.add("statusByUserName"); + ctMergeColumnNames.add("statusDate"); ctMergeColumnNames.add("groups_"); ctMergeColumnNames.add("users"); diff --git a/portal-kernel/src/com/liferay/portal/kernel/model/RoleModel.java b/portal-kernel/src/com/liferay/portal/kernel/model/RoleModel.java index 482f754ef7769f..abb9f58ea592ef 100644 --- a/portal-kernel/src/com/liferay/portal/kernel/model/RoleModel.java +++ b/portal-kernel/src/com/liferay/portal/kernel/model/RoleModel.java @@ -30,7 +30,7 @@ public interface RoleModel extends AttachedModel, BaseModel, CTModel, ExternalReferenceCodeModel, LocalizedModel, MVCCModel, ShardedModel, - StagedAuditedModel { + StagedAuditedModel, WorkflowedModel { /* * NOTE FOR DEVELOPERS: @@ -517,6 +517,151 @@ public void setDescriptionMap( */ public void setSubtype(String subtype); + /** + * Returns the status of this role. + * + * @return the status of this role + */ + @Override + public int getStatus(); + + /** + * Sets the status of this role. + * + * @param status the status of this role + */ + @Override + public void setStatus(int status); + + /** + * Returns the status by user ID of this role. + * + * @return the status by user ID of this role + */ + @Override + public long getStatusByUserId(); + + /** + * Sets the status by user ID of this role. + * + * @param statusByUserId the status by user ID of this role + */ + @Override + public void setStatusByUserId(long statusByUserId); + + /** + * Returns the status by user uuid of this role. + * + * @return the status by user uuid of this role + */ + @Override + public String getStatusByUserUuid(); + + /** + * Sets the status by user uuid of this role. + * + * @param statusByUserUuid the status by user uuid of this role + */ + @Override + public void setStatusByUserUuid(String statusByUserUuid); + + /** + * Returns the status by user name of this role. + * + * @return the status by user name of this role + */ + @AutoEscape + @Override + public String getStatusByUserName(); + + /** + * Sets the status by user name of this role. + * + * @param statusByUserName the status by user name of this role + */ + @Override + public void setStatusByUserName(String statusByUserName); + + /** + * Returns the status date of this role. + * + * @return the status date of this role + */ + @Override + public Date getStatusDate(); + + /** + * Sets the status date of this role. + * + * @param statusDate the status date of this role + */ + @Override + public void setStatusDate(Date statusDate); + + /** + * Returns true if this role is approved. + * + * @return true if this role is approved; false otherwise + */ + @Override + public boolean isApproved(); + + /** + * Returns true if this role is denied. + * + * @return true if this role is denied; false otherwise + */ + @Override + public boolean isDenied(); + + /** + * Returns true if this role is a draft. + * + * @return true if this role is a draft; false otherwise + */ + @Override + public boolean isDraft(); + + /** + * Returns true if this role is expired. + * + * @return true if this role is expired; false otherwise + */ + @Override + public boolean isExpired(); + + /** + * Returns true if this role is inactive. + * + * @return true if this role is inactive; false otherwise + */ + @Override + public boolean isInactive(); + + /** + * Returns true if this role is incomplete. + * + * @return true if this role is incomplete; false otherwise + */ + @Override + public boolean isIncomplete(); + + /** + * Returns true if this role is pending. + * + * @return true if this role is pending; false otherwise + */ + @Override + public boolean isPending(); + + /** + * Returns true if this role is scheduled. + * + * @return true if this role is scheduled; false otherwise + */ + @Override + public boolean isScheduled(); + @Override public String[] getAvailableLanguageIds(); diff --git a/portal-kernel/src/com/liferay/portal/kernel/model/RoleTable.java b/portal-kernel/src/com/liferay/portal/kernel/model/RoleTable.java index 69ef7ec8f11863..04a59f87d8b373 100644 --- a/portal-kernel/src/com/liferay/portal/kernel/model/RoleTable.java +++ b/portal-kernel/src/com/liferay/portal/kernel/model/RoleTable.java @@ -59,6 +59,14 @@ public class RoleTable extends BaseTable { "type_", Integer.class, Types.INTEGER, Column.FLAG_DEFAULT); public final Column subtype = createColumn( "subtype", String.class, Types.VARCHAR, Column.FLAG_DEFAULT); + public final Column status = createColumn( + "status", Integer.class, Types.INTEGER, Column.FLAG_DEFAULT); + public final Column statusByUserId = createColumn( + "statusByUserId", Long.class, Types.BIGINT, Column.FLAG_DEFAULT); + public final Column statusByUserName = createColumn( + "statusByUserName", String.class, Types.VARCHAR, Column.FLAG_DEFAULT); + public final Column statusDate = createColumn( + "statusDate", Date.class, Types.TIMESTAMP, Column.FLAG_DEFAULT); private RoleTable() { super("Role_", RoleTable::new); diff --git a/portal-kernel/src/com/liferay/portal/kernel/model/RoleWrapper.java b/portal-kernel/src/com/liferay/portal/kernel/model/RoleWrapper.java index decdc28139ebfb..080361a1a423b9 100644 --- a/portal-kernel/src/com/liferay/portal/kernel/model/RoleWrapper.java +++ b/portal-kernel/src/com/liferay/portal/kernel/model/RoleWrapper.java @@ -51,6 +51,10 @@ public Map getModelAttributes() { attributes.put("description", getDescription()); attributes.put("type", getType()); attributes.put("subtype", getSubtype()); + attributes.put("status", getStatus()); + attributes.put("statusByUserId", getStatusByUserId()); + attributes.put("statusByUserName", getStatusByUserName()); + attributes.put("statusDate", getStatusDate()); return attributes; } @@ -159,6 +163,30 @@ public void setModelAttributes(Map attributes) { if (subtype != null) { setSubtype(subtype); } + + Integer status = (Integer)attributes.get("status"); + + if (status != null) { + setStatus(status); + } + + Long statusByUserId = (Long)attributes.get("statusByUserId"); + + if (statusByUserId != null) { + setStatusByUserId(statusByUserId); + } + + String statusByUserName = (String)attributes.get("statusByUserName"); + + if (statusByUserName != null) { + setStatusByUserName(statusByUserName); + } + + Date statusDate = (Date)attributes.get("statusDate"); + + if (statusDate != null) { + setStatusDate(statusDate); + } } @Override @@ -384,6 +412,56 @@ public long getRoleId() { return model.getRoleId(); } + /** + * Returns the status of this role. + * + * @return the status of this role + */ + @Override + public int getStatus() { + return model.getStatus(); + } + + /** + * Returns the status by user ID of this role. + * + * @return the status by user ID of this role + */ + @Override + public long getStatusByUserId() { + return model.getStatusByUserId(); + } + + /** + * Returns the status by user name of this role. + * + * @return the status by user name of this role + */ + @Override + public String getStatusByUserName() { + return model.getStatusByUserName(); + } + + /** + * Returns the status by user uuid of this role. + * + * @return the status by user uuid of this role + */ + @Override + public String getStatusByUserUuid() { + return model.getStatusByUserUuid(); + } + + /** + * Returns the status date of this role. + * + * @return the status date of this role + */ + @Override + public Date getStatusDate() { + return model.getStatusDate(); + } + /** * Returns the subtype of this role. * @@ -525,6 +603,86 @@ public String getUuid() { return model.getUuid(); } + /** + * Returns true if this role is approved. + * + * @return true if this role is approved; false otherwise + */ + @Override + public boolean isApproved() { + return model.isApproved(); + } + + /** + * Returns true if this role is denied. + * + * @return true if this role is denied; false otherwise + */ + @Override + public boolean isDenied() { + return model.isDenied(); + } + + /** + * Returns true if this role is a draft. + * + * @return true if this role is a draft; false otherwise + */ + @Override + public boolean isDraft() { + return model.isDraft(); + } + + /** + * Returns true if this role is expired. + * + * @return true if this role is expired; false otherwise + */ + @Override + public boolean isExpired() { + return model.isExpired(); + } + + /** + * Returns true if this role is inactive. + * + * @return true if this role is inactive; false otherwise + */ + @Override + public boolean isInactive() { + return model.isInactive(); + } + + /** + * Returns true if this role is incomplete. + * + * @return true if this role is incomplete; false otherwise + */ + @Override + public boolean isIncomplete() { + return model.isIncomplete(); + } + + /** + * Returns true if this role is pending. + * + * @return true if this role is pending; false otherwise + */ + @Override + public boolean isPending() { + return model.isPending(); + } + + /** + * Returns true if this role is scheduled. + * + * @return true if this role is scheduled; false otherwise + */ + @Override + public boolean isScheduled() { + return model.isScheduled(); + } + @Override public boolean isSystem() { return model.isSystem(); @@ -737,6 +895,56 @@ public void setRoleId(long roleId) { model.setRoleId(roleId); } + /** + * Sets the status of this role. + * + * @param status the status of this role + */ + @Override + public void setStatus(int status) { + model.setStatus(status); + } + + /** + * Sets the status by user ID of this role. + * + * @param statusByUserId the status by user ID of this role + */ + @Override + public void setStatusByUserId(long statusByUserId) { + model.setStatusByUserId(statusByUserId); + } + + /** + * Sets the status by user name of this role. + * + * @param statusByUserName the status by user name of this role + */ + @Override + public void setStatusByUserName(String statusByUserName) { + model.setStatusByUserName(statusByUserName); + } + + /** + * Sets the status by user uuid of this role. + * + * @param statusByUserUuid the status by user uuid of this role + */ + @Override + public void setStatusByUserUuid(String statusByUserUuid) { + model.setStatusByUserUuid(statusByUserUuid); + } + + /** + * Sets the status date of this role. + * + * @param statusDate the status date of this role + */ + @Override + public void setStatusDate(Date statusDate) { + model.setStatusDate(statusDate); + } + /** * Sets the subtype of this role. * diff --git a/portal-kernel/src/com/liferay/portal/kernel/service/RoleLocalService.java b/portal-kernel/src/com/liferay/portal/kernel/service/RoleLocalService.java index f186dc320d1cca..9c239d53cbcccf 100644 --- a/portal-kernel/src/com/liferay/portal/kernel/service/RoleLocalService.java +++ b/portal-kernel/src/com/liferay/portal/kernel/service/RoleLocalService.java @@ -77,6 +77,11 @@ public interface RoleLocalService public boolean addGroupRoles(long groupId, long[] roleIds); + public Role addIncompleteRole( + String externalReferenceCode, long companyId, long userId, + String className, long classPK, String name, int type) + throws Exception; + /** * Adds the role to the database. Also notifies the appropriate model listeners. * @@ -1040,6 +1045,12 @@ public Role updateRole( @Indexable(type = IndexableType.REINDEX) public Role updateRole(Role role); + @Indexable(type = IndexableType.REINDEX) + public Role updateStatus( + long userId, long roleId, int status, ServiceContext serviceContext, + Map workflowContext) + throws PortalException; + public void validateName(String name) throws PortalException; @Override diff --git a/portal-kernel/src/com/liferay/portal/kernel/service/RoleLocalServiceUtil.java b/portal-kernel/src/com/liferay/portal/kernel/service/RoleLocalServiceUtil.java index 20ecb2f0c881ea..8e8c253b32e9d2 100644 --- a/portal-kernel/src/com/liferay/portal/kernel/service/RoleLocalServiceUtil.java +++ b/portal-kernel/src/com/liferay/portal/kernel/service/RoleLocalServiceUtil.java @@ -52,6 +52,16 @@ public static boolean addGroupRoles(long groupId, long[] roleIds) { return getService().addGroupRoles(groupId, roleIds); } + public static Role addIncompleteRole( + String externalReferenceCode, long companyId, long userId, + String className, long classPK, String name, int type) + throws Exception { + + return getService().addIncompleteRole( + externalReferenceCode, companyId, userId, className, classPK, name, + type); + } + /** * Adds the role to the database. Also notifies the appropriate model listeners. * @@ -1232,6 +1242,15 @@ public static Role updateRole(Role role) { return getService().updateRole(role); } + public static Role updateStatus( + long userId, long roleId, int status, ServiceContext serviceContext, + Map workflowContext) + throws PortalException { + + return getService().updateStatus( + userId, roleId, status, serviceContext, workflowContext); + } + public static void validateName(String name) throws PortalException { getService().validateName(name); } diff --git a/portal-kernel/src/com/liferay/portal/kernel/service/RoleLocalServiceWrapper.java b/portal-kernel/src/com/liferay/portal/kernel/service/RoleLocalServiceWrapper.java index 0e4eef838b855d..7080a81f5c8edc 100644 --- a/portal-kernel/src/com/liferay/portal/kernel/service/RoleLocalServiceWrapper.java +++ b/portal-kernel/src/com/liferay/portal/kernel/service/RoleLocalServiceWrapper.java @@ -48,6 +48,17 @@ public boolean addGroupRoles(long groupId, long[] roleIds) { return _roleLocalService.addGroupRoles(groupId, roleIds); } + @Override + public Role addIncompleteRole( + String externalReferenceCode, long companyId, long userId, + String className, long classPK, String name, int type) + throws Exception { + + return _roleLocalService.addIncompleteRole( + externalReferenceCode, companyId, userId, className, classPK, name, + type); + } + /** * Adds the role to the database. Also notifies the appropriate model listeners. * @@ -1383,6 +1394,16 @@ public Role updateRole(Role role) { return _roleLocalService.updateRole(role); } + @Override + public Role updateStatus( + long userId, long roleId, int status, ServiceContext serviceContext, + java.util.Map workflowContext) + throws com.liferay.portal.kernel.exception.PortalException { + + return _roleLocalService.updateStatus( + userId, roleId, status, serviceContext, workflowContext); + } + @Override public void validateName(String name) throws com.liferay.portal.kernel.exception.PortalException { diff --git a/sql/portal-tables.sql b/sql/portal-tables.sql index 9c7f07d60c869c..62be4440e5f1db 100644 --- a/sql/portal-tables.sql +++ b/sql/portal-tables.sql @@ -1248,6 +1248,10 @@ create table Role_ ( description TEXT null, type_ INTEGER, subtype VARCHAR(75) null, + status INTEGER, + statusByUserId LONG, + statusByUserName VARCHAR(75) null, + statusDate DATE null, primary key (roleId, ctCollectionId) ); From 1c93a6c3006336897dd758592f966a9ba07ccbdb Mon Sep 17 00:00:00 2001 From: Stefano Motta <117469730+smottal@users.noreply.github.com> Date: Wed, 26 Feb 2025 10:18:20 +0100 Subject: [PATCH 08/16] LPD-50006 Account service updates --- .../impl/AccountEntryLocalServiceImpl.java | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/modules/apps/account/account-service/src/main/java/com/liferay/account/service/impl/AccountEntryLocalServiceImpl.java b/modules/apps/account/account-service/src/main/java/com/liferay/account/service/impl/AccountEntryLocalServiceImpl.java index b31445bf359ba8..199565f63a0e4c 100644 --- a/modules/apps/account/account-service/src/main/java/com/liferay/account/service/impl/AccountEntryLocalServiceImpl.java +++ b/modules/apps/account/account-service/src/main/java/com/liferay/account/service/impl/AccountEntryLocalServiceImpl.java @@ -20,6 +20,7 @@ import com.liferay.account.validator.AccountEntryEmailAddressValidatorFactory; import com.liferay.asset.kernel.service.AssetEntryLocalService; import com.liferay.expando.kernel.service.ExpandoRowLocalService; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.function.transform.TransformUtil; import com.liferay.petra.sql.dsl.DSLFunctionFactoryUtil; import com.liferay.petra.sql.dsl.DSLQueryFactoryUtil; @@ -228,13 +229,19 @@ GroupConstants.DEFAULT_LIVE_GROUP_ID, getLocalizationMap(name), // Workflow - if (_isWorkflowEnabled(accountEntry.getCompanyId())) { + if (!LazyReferencingThreadLocal.isIncompleteModel() && + _isWorkflowEnabled(accountEntry.getCompanyId())) { + _checkStatus(accountEntry.getStatus(), status); accountEntry = _startWorkflowInstance( userId, accountEntry, workflowServiceContext); } else { + if (LazyReferencingThreadLocal.isIncompleteModel()) { + status = WorkflowConstants.STATUS_INCOMPLETE; + } + accountEntry = updateStatus( userId, accountEntryId, status, workflowServiceContext, Collections.emptyMap()); @@ -243,6 +250,41 @@ GroupConstants.DEFAULT_LIVE_GROUP_ID, getLocalizationMap(name), return accountEntry; } + @Override + public AccountEntry addIncompleteAccountEntry( + String externalReferenceCode, long companyId, long userId, + String name, String type) + throws Exception { + + if (!LazyReferencingThreadLocal.isLazyReferencingEnabled()) { + throw new UnsupportedOperationException(); + } + + AccountEntry accountEntry = + accountEntryLocalService.fetchAccountEntryByExternalReferenceCode( + externalReferenceCode, companyId); + + if (accountEntry != null) { + return accountEntry; + } + + try { + LazyReferencingThreadLocal.setIncompleteModel(true); + + accountEntry = accountEntryLocalService.addAccountEntry( + userId, AccountConstants.PARENT_ACCOUNT_ENTRY_ID_DEFAULT, + GetterUtil.get(name, externalReferenceCode), StringPool.BLANK, + null, StringPool.BLANK, null, StringPool.BLANK, type, + WorkflowConstants.STATUS_INCOMPLETE, null); + + return accountEntryLocalService.updateExternalReferenceCode( + accountEntry.getAccountEntryId(), externalReferenceCode); + } + finally { + LazyReferencingThreadLocal.setIncompleteModel(false); + } + } + @Override public AccountEntry addOrUpdateAccountEntry( String externalReferenceCode, long userId, @@ -679,6 +721,10 @@ public AccountEntry updateAccountEntry( workflowUserId = serviceContext.getUserId(); } + if (status == WorkflowConstants.STATUS_INCOMPLETE) { + status = WorkflowConstants.STATUS_APPROVED; + } + if (_isWorkflowEnabled(accountEntry.getCompanyId())) { _checkStatus(accountEntry.getStatus(), status); From deff8806d1a9e64856e40ef79bf934068bc34ab9 Mon Sep 17 00:00:00 2001 From: Stefano Motta <117469730+smottal@users.noreply.github.com> Date: Thu, 27 Feb 2025 11:32:28 +0100 Subject: [PATCH 09/16] LPD-50006 Account service integration tests --- .../test/AccountEntryLocalServiceTest.java | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/modules/apps/account/account-test/src/testIntegration/java/com/liferay/account/service/test/AccountEntryLocalServiceTest.java b/modules/apps/account/account-test/src/testIntegration/java/com/liferay/account/service/test/AccountEntryLocalServiceTest.java index ca7677fca4762b..9e9ac7275f70e3 100644 --- a/modules/apps/account/account-test/src/testIntegration/java/com/liferay/account/service/test/AccountEntryLocalServiceTest.java +++ b/modules/apps/account/account-test/src/testIntegration/java/com/liferay/account/service/test/AccountEntryLocalServiceTest.java @@ -26,6 +26,7 @@ import com.liferay.expando.kernel.model.ExpandoColumnConstants; import com.liferay.expando.kernel.model.ExpandoTableConstants; import com.liferay.expando.test.util.ExpandoTestUtil; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.object.constants.ObjectValidationRuleConstants; import com.liferay.object.exception.ObjectValidationRuleEngineException; import com.liferay.object.model.ObjectDefinition; @@ -450,6 +451,63 @@ public void testAddAccountEntryWithWorkflowEnabled() throws Exception { Assert.assertTrue(_hasWorkflowInstance(accountEntry)); } + @Test + public void testAddIncompleteAccountEntry() throws Exception { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); + + try { + AccountEntry accountEntry = + _accountEntryLocalService.addIncompleteAccountEntry( + RandomTestUtil.randomString(), + TestPropsValues.getCompanyId(), TestPropsValues.getUserId(), + RandomTestUtil.randomString(), + AccountConstants.ACCOUNT_ENTRY_TYPE_BUSINESS); + + _assertStatus( + accountEntry, WorkflowConstants.STATUS_INCOMPLETE, + TestPropsValues.getUser()); + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); + } + } + + @Test(expected = UnsupportedOperationException.class) + public void testAddIncompleteAccountEntryWithoutLazyReferencing() + throws Exception { + + _accountEntryLocalService.addIncompleteAccountEntry( + RandomTestUtil.randomString(), TestPropsValues.getCompanyId(), + TestPropsValues.getUserId(), RandomTestUtil.randomString(), + AccountConstants.ACCOUNT_ENTRY_TYPE_BUSINESS); + } + + @Test + public void testAddIncompleteAccountEntryWithWorkflowEnabled() + throws Exception { + + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); + + try { + _enableWorkflow(); + + AccountEntry accountEntry = + _accountEntryLocalService.addIncompleteAccountEntry( + RandomTestUtil.randomString(), + TestPropsValues.getCompanyId(), TestPropsValues.getUserId(), + RandomTestUtil.randomString(), + AccountConstants.ACCOUNT_ENTRY_TYPE_BUSINESS); + + _assertStatus( + accountEntry, WorkflowConstants.STATUS_INCOMPLETE, + TestPropsValues.getUser()); + Assert.assertFalse(_hasWorkflowInstance(accountEntry)); + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); + } + } + @Test public void testDeactivateAccountEntries() throws Exception { List accountEntries = @@ -1144,6 +1202,75 @@ public void testUpdateAccountEntry() throws Exception { expandoBridge.getAttribute("customFieldName"))); } + @Test + public void testUpdateAccountEntryWithStatusIncomplete() throws Exception { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); + + try { + AccountEntry accountEntry = + _accountEntryLocalService.addIncompleteAccountEntry( + RandomTestUtil.randomString(), + TestPropsValues.getCompanyId(), TestPropsValues.getUserId(), + RandomTestUtil.randomString(), + AccountConstants.ACCOUNT_ENTRY_TYPE_BUSINESS); + + _assertStatus( + accountEntry, WorkflowConstants.STATUS_INCOMPLETE, + TestPropsValues.getUser()); + + accountEntry = _accountEntryLocalService.updateAccountEntry( + accountEntry.getAccountEntryId(), + accountEntry.getParentAccountEntryId(), accountEntry.getName(), + accountEntry.getDescription(), false, null, + accountEntry.getEmailAddress(), null, + accountEntry.getTaxIdNumber(), accountEntry.getStatus(), null); + + _assertStatus( + accountEntry, WorkflowConstants.STATUS_APPROVED, + TestPropsValues.getUser()); + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); + } + } + + @Test + public void testUpdateAccountEntryWithStatusIncompleteWorkflowEnabled() + throws Exception { + + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); + + try { + _enableWorkflow(); + + AccountEntry accountEntry = + _accountEntryLocalService.addIncompleteAccountEntry( + RandomTestUtil.randomString(), + TestPropsValues.getCompanyId(), TestPropsValues.getUserId(), + RandomTestUtil.randomString(), + AccountConstants.ACCOUNT_ENTRY_TYPE_BUSINESS); + + _assertStatus( + accountEntry, WorkflowConstants.STATUS_INCOMPLETE, + TestPropsValues.getUser()); + + accountEntry = _accountEntryLocalService.updateAccountEntry( + accountEntry.getAccountEntryId(), + accountEntry.getParentAccountEntryId(), accountEntry.getName(), + accountEntry.getDescription(), false, null, + accountEntry.getEmailAddress(), null, + accountEntry.getTaxIdNumber(), accountEntry.getStatus(), null); + + _assertStatus( + accountEntry, WorkflowConstants.STATUS_PENDING, + TestPropsValues.getUser()); + Assert.assertTrue(_hasWorkflowInstance(accountEntry)); + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); + } + } + @Test public void testUpdateDomains() throws Exception { AccountEntry accountEntry = AccountEntryTestUtil.addAccountEntry(); From b7c1cffcdb40c71f76bb5b83c408a1a20d0b72b2 Mon Sep 17 00:00:00 2001 From: Stefano Motta <117469730+smottal@users.noreply.github.com> Date: Wed, 26 Feb 2025 10:19:01 +0100 Subject: [PATCH 10/16] LPD-50006 Autogenerated Code (buildService) --- .../account/service/AccountEntryLocalService.java | 5 +++++ .../account/service/AccountEntryLocalServiceUtil.java | 9 +++++++++ .../service/AccountEntryLocalServiceWrapper.java | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/modules/apps/account/account-api/src/main/java/com/liferay/account/service/AccountEntryLocalService.java b/modules/apps/account/account-api/src/main/java/com/liferay/account/service/AccountEntryLocalService.java index eab9b6281ce1af..5486c56f891660 100644 --- a/modules/apps/account/account-api/src/main/java/com/liferay/account/service/AccountEntryLocalService.java +++ b/modules/apps/account/account-api/src/main/java/com/liferay/account/service/AccountEntryLocalService.java @@ -89,6 +89,11 @@ public AccountEntry addAccountEntry( ServiceContext serviceContext) throws PortalException; + public AccountEntry addIncompleteAccountEntry( + String externalReferenceCode, long companyId, long userId, + String name, String type) + throws Exception; + public AccountEntry addOrUpdateAccountEntry( String externalReferenceCode, long userId, long parentAccountEntryId, String name, String description, diff --git a/modules/apps/account/account-api/src/main/java/com/liferay/account/service/AccountEntryLocalServiceUtil.java b/modules/apps/account/account-api/src/main/java/com/liferay/account/service/AccountEntryLocalServiceUtil.java index 0ea57e4bb3db11..cbe97faf727374 100644 --- a/modules/apps/account/account-api/src/main/java/com/liferay/account/service/AccountEntryLocalServiceUtil.java +++ b/modules/apps/account/account-api/src/main/java/com/liferay/account/service/AccountEntryLocalServiceUtil.java @@ -81,6 +81,15 @@ public static AccountEntry addAccountEntry( emailAddress, logoBytes, taxIdNumber, type, status, serviceContext); } + public static AccountEntry addIncompleteAccountEntry( + String externalReferenceCode, long companyId, long userId, + String name, String type) + throws Exception { + + return getService().addIncompleteAccountEntry( + externalReferenceCode, companyId, userId, name, type); + } + public static AccountEntry addOrUpdateAccountEntry( String externalReferenceCode, long userId, long parentAccountEntryId, String name, String description, diff --git a/modules/apps/account/account-api/src/main/java/com/liferay/account/service/AccountEntryLocalServiceWrapper.java b/modules/apps/account/account-api/src/main/java/com/liferay/account/service/AccountEntryLocalServiceWrapper.java index d5905d690529b7..12c15cb219f12a 100644 --- a/modules/apps/account/account-api/src/main/java/com/liferay/account/service/AccountEntryLocalServiceWrapper.java +++ b/modules/apps/account/account-api/src/main/java/com/liferay/account/service/AccountEntryLocalServiceWrapper.java @@ -82,6 +82,16 @@ public com.liferay.account.model.AccountEntry addAccountEntry( emailAddress, logoBytes, taxIdNumber, type, status, serviceContext); } + @Override + public com.liferay.account.model.AccountEntry addIncompleteAccountEntry( + String externalReferenceCode, long companyId, long userId, + String name, String type) + throws Exception { + + return _accountEntryLocalService.addIncompleteAccountEntry( + externalReferenceCode, companyId, userId, name, type); + } + @Override public com.liferay.account.model.AccountEntry addOrUpdateAccountEntry( String externalReferenceCode, long userId, From c89a57ab8d2dbd899763469e5dbe0d87738434aa Mon Sep 17 00:00:00 2001 From: Stefano Motta <117469730+smottal@users.noreply.github.com> Date: Wed, 26 Feb 2025 10:19:22 +0100 Subject: [PATCH 11/16] LPD-50006 Semantic Versioning (account-api) --- modules/apps/account/account-api/bnd.bnd | 2 +- .../src/main/resources/com/liferay/account/service/packageinfo | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/apps/account/account-api/bnd.bnd b/modules/apps/account/account-api/bnd.bnd index 43cd21d173be78..b45d13324e9fa9 100644 --- a/modules/apps/account/account-api/bnd.bnd +++ b/modules/apps/account/account-api/bnd.bnd @@ -1,6 +1,6 @@ Bundle-Name: Liferay Account API Bundle-SymbolicName: com.liferay.account.api -Bundle-Version: 28.0.1 +Bundle-Version: 28.1.0 Export-Package:\ com.liferay.account.configuration,\ com.liferay.account.constants,\ diff --git a/modules/apps/account/account-api/src/main/resources/com/liferay/account/service/packageinfo b/modules/apps/account/account-api/src/main/resources/com/liferay/account/service/packageinfo index 5fe394d4418edc..cf203b4314458c 100644 --- a/modules/apps/account/account-api/src/main/resources/com/liferay/account/service/packageinfo +++ b/modules/apps/account/account-api/src/main/resources/com/liferay/account/service/packageinfo @@ -1 +1 @@ -version 14.1.0 \ No newline at end of file +version 14.2.0 \ No newline at end of file From b7e5b29ad56e7470966b573dfc130324c7a45403 Mon Sep 17 00:00:00 2001 From: Stefano Motta <117469730+smottal@users.noreply.github.com> Date: Wed, 26 Feb 2025 10:20:06 +0100 Subject: [PATCH 12/16] LPD-50006 Lazy account group (yaml) --- .../rest-openapi.yaml | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/rest-openapi.yaml b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/rest-openapi.yaml index dfce15182579ee..e8f143d0bf26b8 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/rest-openapi.yaml +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/rest-openapi.yaml @@ -212,7 +212,6 @@ components: externalReferenceCode: description: The account's external reference code. - readOnly: true type: string id: description: @@ -223,7 +222,6 @@ components: name: description: The account's name. - readOnly: true type: string roleBriefs: description: @@ -232,6 +230,10 @@ components: $ref: "#/components/schemas/RoleBrief" readOnly: true type: array + type: + description: + The account's type. + type: string type: object AccountGroup: properties: @@ -240,7 +242,6 @@ components: The list of accounts associated with this account group. items: $ref: "#/components/schemas/AccountBrief" - readOnly: true type: array actions: additionalProperties: @@ -256,7 +257,6 @@ components: $ref: "#/components/schemas/Creator" description: The user who created the account group. - readOnly: true customFields: items: $ref: "#/components/schemas/CustomField" @@ -379,15 +379,21 @@ components: The type of the content. readOnly: true type: string + emailAddress: + description: + The user's email address. + type: string + externalReferenceCode: + description: + The user's external reference code. + type: string familyName: description: The user's surname (last name). - readOnly: true type: string givenName: description: The user's first name. - readOnly: true type: string id: description: @@ -412,6 +418,10 @@ components: format: uri readOnly: true type: string + screenName: + description: + The user's screen name. + type: string type: object CustomField: # @review @@ -939,7 +949,6 @@ components: description: The role's external reference code. example: AB-34098-789-N - readOnly: true type: string id: description: @@ -947,6 +956,10 @@ components: format: int64 readOnly: true type: integer + key: + description: + The role's key. + type: string name: description: The role's name. @@ -960,7 +973,6 @@ components: roleType: description: The role's type. - readOnly: true type: integer type: object RolePermission: From 54dbb56fa83ccf376740f87f560d1ffe3709b509 Mon Sep 17 00:00:00 2001 From: Stefano Motta <117469730+smottal@users.noreply.github.com> Date: Wed, 26 Feb 2025 10:21:24 +0100 Subject: [PATCH 13/16] LPD-50006 Lazy account group --- .../converter/UserResourceDTOConverter.java | 1 + .../dto/v1_0/util/AccountBriefUtil.java | 1 + .../internal/dto/v1_0/util/CreatorUtil.java | 3 + .../internal/dto/v1_0/util/RoleBriefUtil.java | 1 + .../v1_0/AccountGroupResourceImpl.java | 184 +++++++++++++++++- .../portal/vulcan/permission/Permission.java | 22 +++ .../vulcan/permission/PermissionUtil.java | 5 + 7 files changed, 207 insertions(+), 10 deletions(-) diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/dto/v1_0/converter/UserResourceDTOConverter.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/dto/v1_0/converter/UserResourceDTOConverter.java index 3420322ab64f01..a684987486dee8 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/dto/v1_0/converter/UserResourceDTOConverter.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/dto/v1_0/converter/UserResourceDTOConverter.java @@ -456,6 +456,7 @@ private AccountBrief _toAccountBrief( accountRole -> _toRoleBrief( accountRole, dtoConverterContext), RoleBrief.class)); + setType(accountEntry::getType); } }; } diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/dto/v1_0/util/AccountBriefUtil.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/dto/v1_0/util/AccountBriefUtil.java index 73a7e9dd566fcb..e7ad8700dc15d7 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/dto/v1_0/util/AccountBriefUtil.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/dto/v1_0/util/AccountBriefUtil.java @@ -24,6 +24,7 @@ public static AccountBrief toAccountBrief(AccountEntry accountEntry) { accountEntry::getExternalReferenceCode); setId(accountEntry::getAccountEntryId); setName(accountEntry::getName); + setType(accountEntry::getType); } }; } diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/dto/v1_0/util/CreatorUtil.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/dto/v1_0/util/CreatorUtil.java index 2ffa64bc67cdba..a2e03e603ffe2d 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/dto/v1_0/util/CreatorUtil.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/dto/v1_0/util/CreatorUtil.java @@ -26,6 +26,8 @@ public static Creator toCreator(Portal portal, User user) { { setAdditionalName(user::getMiddleName); setContentType(() -> "UserAccount"); + setEmailAddress(user::getEmailAddress); + setExternalReferenceCode(user::getExternalReferenceCode); setFamilyName(user::getLastName); setGivenName(user::getFirstName); setId(user::getUserId); @@ -57,6 +59,7 @@ public static Creator toCreator(Portal portal, User user) { return group.getDisplayURL(themeDisplay); }); + setScreenName(user::getScreenName); } }; } diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/dto/v1_0/util/RoleBriefUtil.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/dto/v1_0/util/RoleBriefUtil.java index 09b0190cc92569..a48ef8c3fca284 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/dto/v1_0/util/RoleBriefUtil.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/dto/v1_0/util/RoleBriefUtil.java @@ -22,6 +22,7 @@ public static RoleBrief toRoleBrief( { setExternalReferenceCode(role::getExternalReferenceCode); setId(role::getRoleId); + setKey(role::getName); setName( () -> { if (dtoConverterContext == null) { diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/AccountGroupResourceImpl.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/AccountGroupResourceImpl.java index 5b8c005d870687..4ca20cdaf88a4d 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/AccountGroupResourceImpl.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/AccountGroupResourceImpl.java @@ -6,14 +6,17 @@ package com.liferay.headless.admin.user.internal.resource.v1_0; import com.liferay.account.constants.AccountActionKeys; +import com.liferay.account.exception.DuplicateAccountGroupExternalReferenceCodeException; import com.liferay.account.exception.NoSuchGroupException; import com.liferay.account.model.AccountEntry; import com.liferay.account.model.AccountGroupRel; +import com.liferay.account.service.AccountEntryLocalService; import com.liferay.account.service.AccountGroupRelService; import com.liferay.account.service.AccountGroupService; import com.liferay.expando.kernel.service.ExpandoColumnLocalService; import com.liferay.expando.kernel.service.ExpandoTableLocalService; import com.liferay.headless.admin.user.dto.v1_0.Account; +import com.liferay.headless.admin.user.dto.v1_0.AccountBrief; import com.liferay.headless.admin.user.dto.v1_0.AccountGroup; import com.liferay.headless.admin.user.internal.dto.v1_0.converter.constants.DTOConverterConstants; import com.liferay.headless.admin.user.internal.dto.v1_0.util.CustomFieldsUtil; @@ -21,17 +24,28 @@ import com.liferay.headless.admin.user.resource.v1_0.AccountGroupResource; import com.liferay.headless.common.spi.odata.entity.EntityFieldsUtil; import com.liferay.headless.common.spi.service.context.ServiceContextBuilder; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.string.StringPool; +import com.liferay.portal.kernel.model.ResourceConstants; +import com.liferay.portal.kernel.model.Role; +import com.liferay.portal.kernel.model.role.RoleConstants; import com.liferay.portal.kernel.search.Field; +import com.liferay.portal.kernel.search.Indexer; +import com.liferay.portal.kernel.search.IndexerRegistry; import com.liferay.portal.kernel.search.Sort; import com.liferay.portal.kernel.search.filter.Filter; import com.liferay.portal.kernel.security.permission.ActionKeys; import com.liferay.portal.kernel.security.permission.resource.ModelResourcePermission; +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.util.ArrayUtil; import com.liferay.portal.kernel.util.GetterUtil; import com.liferay.portal.kernel.util.HashMapBuilder; +import com.liferay.portal.kernel.util.ListUtil; import com.liferay.portal.kernel.util.Portal; import com.liferay.portal.kernel.util.PortletKeys; +import com.liferay.portal.kernel.util.StringUtil; import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.odata.entity.EntityModel; import com.liferay.portal.search.expando.ExpandoBridgeIndexer; @@ -41,8 +55,12 @@ import com.liferay.portal.vulcan.dto.converter.util.DTOConverterUtil; import com.liferay.portal.vulcan.pagination.Page; import com.liferay.portal.vulcan.pagination.Pagination; +import com.liferay.portal.vulcan.permission.Permission; import com.liferay.portal.vulcan.util.SearchUtil; +import com.liferay.roles.admin.role.type.contributor.RoleTypeContributor; +import com.liferay.roles.admin.role.type.contributor.provider.RoleTypeContributorProvider; +import java.util.List; import java.util.Map; import javax.ws.rs.core.MultivaluedMap; @@ -217,6 +235,17 @@ public AccountGroup patchAccountGroupByExternalReferenceCode( public AccountGroup postAccountGroup(AccountGroup accountGroup) throws Exception { + if (Validator.isNotNull(accountGroup.getExternalReferenceCode())) { + com.liferay.account.model.AccountGroup serviceBuilderAccountGroup = + _accountGroupService.fetchAccountGroupByExternalReferenceCode( + accountGroup.getExternalReferenceCode(), + contextCompany.getCompanyId()); + + if (serviceBuilderAccountGroup != null) { + throw new DuplicateAccountGroupExternalReferenceCodeException(); + } + } + com.liferay.account.model.AccountGroup serviceBuilderAccountGroup = _accountGroupService.addAccountGroup( contextUser.getUserId(), accountGroup.getDescription(), @@ -227,7 +256,8 @@ public AccountGroup postAccountGroup(AccountGroup accountGroup) serviceBuilderAccountGroup.getAccountGroupId(), accountGroup.getExternalReferenceCode()); - return _toAccountGroup(serviceBuilderAccountGroup); + return _toAccountGroup( + _updateNestedResources(accountGroup, serviceBuilderAccountGroup)); } @Override @@ -258,18 +288,23 @@ public AccountGroup putAccountGroup( _createServiceContext(accountGroup)); return _toAccountGroup( - _accountGroupService.updateExternalReferenceCode( - serviceBuilderAccountGroup.getAccountGroupId(), - accountGroup.getExternalReferenceCode())); + _updateNestedResources( + accountGroup, + _accountGroupService.updateExternalReferenceCode( + serviceBuilderAccountGroup.getAccountGroupId(), + accountGroup.getExternalReferenceCode()))); } _accountGroupService.updateExternalReferenceCode( accountGroupId, accountGroup.getExternalReferenceCode()); return _toAccountGroup( - _accountGroupService.updateAccountGroup( - accountGroupId, accountGroup.getDescription(), - accountGroup.getName(), _createServiceContext(accountGroup))); + _updateNestedResources( + accountGroup, + _accountGroupService.updateAccountGroup( + accountGroupId, accountGroup.getDescription(), + accountGroup.getName(), + _createServiceContext(accountGroup)))); } @Override @@ -289,6 +324,36 @@ public AccountGroup putAccountGroupByExternalReferenceCode( serviceBuilderAccountGroup.getAccountGroupId(), accountGroup); } + private com.liferay.account.model.AccountGroup _addAccountGroupRel( + AccountBrief accountBrief, + com.liferay.account.model.AccountGroup serviceBuilderAccountGroup) + throws Exception { + + String externalReferenceCode = accountBrief.getExternalReferenceCode(); + String type = accountBrief.getType(); + + if (Validator.isNull(externalReferenceCode) || Validator.isNull(type)) { + return serviceBuilderAccountGroup; + } + + AccountEntry accountEntry = + _accountEntryLocalService.addIncompleteAccountEntry( + externalReferenceCode, + serviceBuilderAccountGroup.getCompanyId(), + contextUser.getUserId(), accountBrief.getName(), type); + + _accountGroupRelService.addAccountGroupRel( + serviceBuilderAccountGroup.getAccountGroupId(), + AccountEntry.class.getName(), accountEntry.getAccountEntryId()); + + Indexer indexer = _indexerRegistry.nullSafeGetIndexer( + AccountEntry.class); + + indexer.reindex(accountEntry); + + return serviceBuilderAccountGroup; + } + private ServiceContext _createServiceContext(AccountGroup accountGroup) throws Exception { @@ -391,6 +456,58 @@ private DTOConverterContext _getDTOConverterContext(long accountGroupId) { contextUser); } + private com.liferay.account.model.AccountGroup _setResourcePermissions( + Permission permission, + com.liferay.account.model.AccountGroup serviceBuilderAccountGroup) + throws Exception { + + String[] actionIds = permission.getActionIds(); + String externalReferenceCode = + permission.getRoleExternalReferenceCode(); + String name = permission.getRoleName(); + + if (ArrayUtil.isEmpty(actionIds) || + Validator.isNull(externalReferenceCode) || Validator.isNull(name)) { + + return serviceBuilderAccountGroup; + } + + String className = StringPool.BLANK; + + List roleTypeContributors = ListUtil.filter( + _roleTypeContributorProvider.getRoleTypeContributors(), + roleTypeContributor -> { + if (Validator.isNull(permission.getRoleType())) { + return false; + } + + return StringUtil.equals( + roleTypeContributor.getTypeLabel(), + permission.getRoleType()); + }); + + if (ListUtil.isNotEmpty(roleTypeContributors)) { + RoleTypeContributor roleTypeContributor = roleTypeContributors.get( + 0); + + className = roleTypeContributor.getClassName(); + } + + Role role = _roleLocalService.addIncompleteRole( + externalReferenceCode, serviceBuilderAccountGroup.getCompanyId(), + contextUser.getUserId(), className, 0, name, + RoleConstants.getLabelType(permission.getRoleType())); + + _resourcePermissionLocalService.setResourcePermissions( + serviceBuilderAccountGroup.getCompanyId(), + com.liferay.account.model.AccountGroup.class.getName(), + ResourceConstants.SCOPE_INDIVIDUAL, + String.valueOf(serviceBuilderAccountGroup.getAccountGroupId()), + role.getRoleId(), actionIds); + + return serviceBuilderAccountGroup; + } + private AccountGroup _toAccountGroup( com.liferay.account.model.AccountGroup accountGroup) throws Exception { @@ -414,11 +531,46 @@ private AccountGroup _updateAccountGroup( _createServiceContext(accountGroup)); return _toAccountGroup( - _accountGroupService.updateExternalReferenceCode( - serviceBuilderAccountGroup.getAccountGroupId(), - accountGroup.getExternalReferenceCode())); + _updateNestedResources( + accountGroup, + _accountGroupService.updateExternalReferenceCode( + serviceBuilderAccountGroup.getAccountGroupId(), + accountGroup.getExternalReferenceCode()))); + } + + private com.liferay.account.model.AccountGroup _updateNestedResources( + AccountGroup accountGroup, + com.liferay.account.model.AccountGroup serviceBuilderAccountGroup) + throws Exception { + + if (!LazyReferencingThreadLocal.isLazyReferencingEnabled()) { + return serviceBuilderAccountGroup; + } + + AccountBrief[] accountBriefs = accountGroup.getAccountBriefs(); + + if (ArrayUtil.isNotEmpty(accountBriefs)) { + for (AccountBrief accountBrief : accountBriefs) { + serviceBuilderAccountGroup = _addAccountGroupRel( + accountBrief, serviceBuilderAccountGroup); + } + } + + Permission[] permissions = accountGroup.getPermissions(); + + if (ArrayUtil.isNotEmpty(permissions)) { + for (Permission permission : permissions) { + serviceBuilderAccountGroup = _setResourcePermissions( + permission, serviceBuilderAccountGroup); + } + } + + return serviceBuilderAccountGroup; } + @Reference + private AccountEntryLocalService _accountEntryLocalService; + @Reference( target = "(model.class.name=com.liferay.account.model.AccountGroup)" ) @@ -449,7 +601,19 @@ private AccountGroup _updateAccountGroup( @Reference private ExpandoTableLocalService _expandoTableLocalService; + @Reference + private IndexerRegistry _indexerRegistry; + @Reference private Portal _portal; + @Reference + private ResourcePermissionLocalService _resourcePermissionLocalService; + + @Reference + private RoleLocalService _roleLocalService; + + @Reference + private RoleTypeContributorProvider _roleTypeContributorProvider; + } \ No newline at end of file diff --git a/modules/apps/portal-vulcan/portal-vulcan-api/src/main/java/com/liferay/portal/vulcan/permission/Permission.java b/modules/apps/portal-vulcan/portal-vulcan-api/src/main/java/com/liferay/portal/vulcan/permission/Permission.java index 981c623f38a84b..50d5c41f170968 100644 --- a/modules/apps/portal-vulcan/portal-vulcan-api/src/main/java/com/liferay/portal/vulcan/permission/Permission.java +++ b/modules/apps/portal-vulcan/portal-vulcan-api/src/main/java/com/liferay/portal/vulcan/permission/Permission.java @@ -27,21 +27,43 @@ public String[] getActionIds() { return actionIds; } + @GraphQLField + @JsonProperty(access = JsonProperty.Access.READ_WRITE) + public String getRoleExternalReferenceCode() { + return roleExternalReferenceCode; + } + @GraphQLField @JsonProperty(access = JsonProperty.Access.READ_WRITE) public String getRoleName() { return roleName; } + @GraphQLField + @JsonProperty(access = JsonProperty.Access.READ_WRITE) + public String getRoleType() { + return roleType; + } + public void setActionIds(String[] actionIds) { this.actionIds = actionIds; } + public void setRoleExternalReferenceCode(String roleExternalReferenceCode) { + this.roleExternalReferenceCode = roleExternalReferenceCode; + } + public void setRoleName(String roleName) { this.roleName = roleName; } + public void setRoleType(String roleType) { + this.roleType = roleType; + } + protected String[] actionIds; + protected String roleExternalReferenceCode; protected String roleName; + protected String roleType; } \ No newline at end of file diff --git a/modules/apps/portal-vulcan/portal-vulcan-api/src/main/java/com/liferay/portal/vulcan/permission/PermissionUtil.java b/modules/apps/portal-vulcan/portal-vulcan-api/src/main/java/com/liferay/portal/vulcan/permission/PermissionUtil.java index b1d73d60daecab..8acee6e0bf173d 100644 --- a/modules/apps/portal-vulcan/portal-vulcan-api/src/main/java/com/liferay/portal/vulcan/permission/PermissionUtil.java +++ b/modules/apps/portal-vulcan/portal-vulcan-api/src/main/java/com/liferay/portal/vulcan/permission/PermissionUtil.java @@ -175,7 +175,10 @@ public static Collection getPermissions( new Permission() { { actionIds = actionsIdsSet.toArray(new String[0]); + roleExternalReferenceCode = + role.getExternalReferenceCode(); roleName = role.getName(); + roleType = role.getTypeLabel(); } }); } @@ -247,7 +250,9 @@ public static Permission toPermission( return new Permission() { { actionIds = actionsIdsSet.toArray(new String[0]); + roleExternalReferenceCode = role.getExternalReferenceCode(); roleName = role.getName(); + roleType = role.getTypeLabel(); } }; } From 659271a391d1551f0c5bbdbc31865d0203853107 Mon Sep 17 00:00:00 2001 From: Stefano Motta <117469730+smottal@users.noreply.github.com> Date: Thu, 27 Feb 2025 16:26:03 +0100 Subject: [PATCH 14/16] LPD-50006 Lazy account group integration test --- .../v1_0/test/AccountGroupResourceTest.java | 233 ++++++++++++++++++ 1 file changed, 233 insertions(+) diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-test/src/testIntegration/java/com/liferay/headless/admin/user/resource/v1_0/test/AccountGroupResourceTest.java b/modules/apps/headless/headless-admin-user/headless-admin-user-test/src/testIntegration/java/com/liferay/headless/admin/user/resource/v1_0/test/AccountGroupResourceTest.java index 89077aeae0a70d..9ce631faef75dd 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-test/src/testIntegration/java/com/liferay/headless/admin/user/resource/v1_0/test/AccountGroupResourceTest.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-test/src/testIntegration/java/com/liferay/headless/admin/user/resource/v1_0/test/AccountGroupResourceTest.java @@ -7,6 +7,7 @@ import com.liferay.account.constants.AccountConstants; import com.liferay.account.model.AccountEntry; +import com.liferay.account.model.AccountGroupRel; import com.liferay.account.service.AccountEntryLocalService; import com.liferay.account.service.AccountGroupLocalService; import com.liferay.account.service.AccountGroupRelLocalService; @@ -17,35 +18,46 @@ import com.liferay.expando.kernel.model.ExpandoTable; import com.liferay.expando.kernel.service.ExpandoColumnLocalService; import com.liferay.expando.kernel.service.ExpandoTableLocalService; +import com.liferay.headless.admin.user.client.dto.v1_0.AccountBrief; import com.liferay.headless.admin.user.client.dto.v1_0.AccountGroup; import com.liferay.headless.admin.user.client.dto.v1_0.Creator; import com.liferay.headless.admin.user.client.dto.v1_0.CustomField; import com.liferay.headless.admin.user.client.dto.v1_0.CustomValue; import com.liferay.headless.admin.user.client.pagination.Page; import com.liferay.headless.admin.user.client.pagination.Pagination; +import com.liferay.headless.admin.user.client.permission.Permission; import com.liferay.headless.admin.user.client.problem.Problem; import com.liferay.headless.admin.user.client.resource.v1_0.AccountGroupResource; import com.liferay.petra.string.StringBundler; +import com.liferay.portal.kernel.json.JSONFactory; +import com.liferay.portal.kernel.json.JSONObject; +import com.liferay.portal.kernel.json.JSONUtil; import com.liferay.portal.kernel.model.ResourceConstants; import com.liferay.portal.kernel.model.Role; import com.liferay.portal.kernel.model.role.RoleConstants; import com.liferay.portal.kernel.security.permission.ActionKeys; import com.liferay.portal.kernel.service.ClassNameLocalService; +import com.liferay.portal.kernel.service.ResourceActionLocalService; 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.test.rule.DataGuard; +import com.liferay.portal.kernel.test.util.HTTPTestUtil; import com.liferay.portal.kernel.test.util.RandomTestUtil; import com.liferay.portal.kernel.test.util.RoleTestUtil; import com.liferay.portal.kernel.test.util.ServiceContextTestUtil; import com.liferay.portal.kernel.test.util.TestPropsValues; import com.liferay.portal.kernel.util.ArrayUtil; import com.liferay.portal.kernel.util.DateFormatFactoryUtil; +import com.liferay.portal.kernel.util.Http; +import com.liferay.portal.kernel.util.ListUtil; import com.liferay.portal.kernel.util.LocaleUtil; import com.liferay.portal.kernel.util.StringUtil; import com.liferay.portal.kernel.util.UnicodeProperties; import com.liferay.portal.kernel.workflow.WorkflowConstants; import com.liferay.portal.test.rule.Inject; import com.liferay.portal.util.PropsValues; +import com.liferay.portal.vulcan.permission.PermissionUtil; import java.text.DateFormat; @@ -144,6 +156,14 @@ public void testPatchAccountGroupByExternalReferenceCode() _testPatchAccountGroupByExternalReferenceCodeWithoutName(); } + @Override + @Test + public void testPostAccountGroup() throws Exception { + super.testPostAccountGroup(); + + _testPostAccountGroupBatch(); + } + @Ignore @Override @Test @@ -577,6 +597,183 @@ private void _testPatchAccountGroupWithoutName() throws Exception { assertValid(getAccountGroup); } + private void _testPostAccountGroupBatch() throws Exception { + AccountGroup randomAccountGroup = randomAccountGroup(); + + AccountEntry serviceBuilderAccountEntry1 = + _accountEntryLocalService.addAccountEntry( + TestPropsValues.getUserId(), + AccountConstants.PARENT_ACCOUNT_ENTRY_ID_DEFAULT, + RandomTestUtil.randomString(), null, new String[0], null, null, + null, AccountConstants.ACCOUNT_ENTRY_TYPE_BUSINESS, + WorkflowConstants.STATUS_APPROVED, null); + + AccountBrief accountBrief1 = new AccountBrief() { + { + externalReferenceCode = + serviceBuilderAccountEntry1.getExternalReferenceCode(); + name = serviceBuilderAccountEntry1.getName(); + type = serviceBuilderAccountEntry1.getType(); + } + }; + AccountBrief accountBrief2 = new AccountBrief() { + { + externalReferenceCode = RandomTestUtil.randomString(); + name = RandomTestUtil.randomString(); + type = AccountConstants.ACCOUNT_ENTRY_TYPE_BUSINESS; + } + }; + + randomAccountGroup.setAccountBriefs( + new AccountBrief[] {accountBrief1, accountBrief2}); + + Role serviceBuilderRole1 = RoleTestUtil.addRole( + RoleConstants.TYPE_REGULAR); + + Permission permission1 = new Permission() { + { + actionIds = new String[] {ActionKeys.VIEW}; + roleExternalReferenceCode = + serviceBuilderRole1.getExternalReferenceCode(); + roleName = serviceBuilderRole1.getName(); + roleType = RoleConstants.getTypeLabel( + serviceBuilderRole1.getType()); + } + }; + Permission permission2 = new Permission() { + { + actionIds = new String[] {ActionKeys.UPDATE}; + roleExternalReferenceCode = RandomTestUtil.randomString(); + roleName = RandomTestUtil.randomString(); + roleType = RoleConstants.getTypeLabel( + RoleConstants.TYPE_REGULAR); + } + }; + + randomAccountGroup.setPermissions( + new Permission[] {permission1, permission2}); + + _waitForFinish( + "COMPLETED", true, + HTTPTestUtil.invokeToJSONObject( + JSONUtil.put( + "items", + JSONUtil.put( + _jsonFactory.createJSONObject( + randomAccountGroup.toString())) + ).toString(), + "headless-admin-user/v1.0/account-groups/batch", + Http.Method.POST)); + + com.liferay.account.model.AccountGroup serviceBuilderAccountGroup = + _accountGroupLocalService.fetchAccountGroupByExternalReferenceCode( + randomAccountGroup.getExternalReferenceCode(), + TestPropsValues.getCompanyId()); + + Assert.assertNotNull(serviceBuilderAccountGroup); + + AccountEntry serviceBuilderAccountEntry2 = + _accountEntryLocalService.fetchAccountEntryByExternalReferenceCode( + accountBrief1.getExternalReferenceCode(), + TestPropsValues.getCompanyId()); + + Assert.assertNotNull(serviceBuilderAccountEntry2); + Assert.assertEquals( + serviceBuilderAccountEntry1.getAccountEntryId(), + serviceBuilderAccountEntry2.getAccountEntryId()); + + List serviceBuilderAccountGroupRels = + _accountGroupRelLocalService.getAccountGroupRels( + serviceBuilderAccountGroup.getAccountGroupId(), + AccountEntry.class.getName()); + + Assert.assertTrue( + ListUtil.exists( + serviceBuilderAccountGroupRels, + serviceBuilderAccountGroupRel -> + serviceBuilderAccountGroupRel.getClassPK() == + serviceBuilderAccountEntry2.getAccountEntryId())); + + AccountEntry serviceBuilderAccountEntry3 = + _accountEntryLocalService.fetchAccountEntryByExternalReferenceCode( + accountBrief2.getExternalReferenceCode(), + TestPropsValues.getCompanyId()); + + Assert.assertNotNull(serviceBuilderAccountEntry3); + Assert.assertEquals( + accountBrief2.getName(), serviceBuilderAccountEntry3.getName()); + Assert.assertEquals( + WorkflowConstants.STATUS_INCOMPLETE, + serviceBuilderAccountEntry3.getStatus()); + Assert.assertEquals( + accountBrief2.getType(), serviceBuilderAccountEntry3.getType()); + Assert.assertTrue( + ListUtil.exists( + serviceBuilderAccountGroupRels, + serviceBuilderAccountGroupRel -> + serviceBuilderAccountGroupRel.getClassPK() == + serviceBuilderAccountEntry3.getAccountEntryId())); + + Role serviceBuilderRole2 = + _roleLocalService.fetchRoleByExternalReferenceCode( + permission1.getRoleExternalReferenceCode(), + TestPropsValues.getCompanyId()); + + Assert.assertNotNull(serviceBuilderRole2); + Assert.assertEquals( + serviceBuilderRole1.getRoleId(), serviceBuilderRole2.getRoleId()); + + List permissions = + ListUtil.fromCollection( + PermissionUtil.getPermissions( + TestPropsValues.getCompanyId(), + _resourceActionLocalService.getResourceActions( + com.liferay.account.model.AccountGroup.class.getName()), + serviceBuilderAccountGroup.getAccountGroupId(), + com.liferay.account.model.AccountGroup.class.getName(), + null)); + + Assert.assertTrue( + ListUtil.exists( + permissions, + permission -> { + String[] actionIds = permission.getActionIds(); + + return (actionIds.length == 1) && + Objects.equals(ActionKeys.VIEW, actionIds[0]) && + Objects.equals( + serviceBuilderRole2.getExternalReferenceCode(), + permission.getRoleExternalReferenceCode()); + })); + + Role serviceBuilderRole3 = + _roleLocalService.fetchRoleByExternalReferenceCode( + permission2.getRoleExternalReferenceCode(), + TestPropsValues.getCompanyId()); + + Assert.assertNotNull(serviceBuilderRole3); + Assert.assertEquals( + permission2.getRoleName(), serviceBuilderRole3.getName()); + Assert.assertEquals( + WorkflowConstants.STATUS_INCOMPLETE, + serviceBuilderRole3.getStatus()); + Assert.assertEquals( + RoleConstants.getLabelType(permission2.getRoleType()), + serviceBuilderRole3.getType()); + Assert.assertTrue( + ListUtil.exists( + permissions, + permission -> { + String[] actionIds = permission.getActionIds(); + + return (actionIds.length == 1) && + Objects.equals(ActionKeys.UPDATE, actionIds[0]) && + Objects.equals( + serviceBuilderRole3.getExternalReferenceCode(), + permission.getRoleExternalReferenceCode()); + })); + } + private void _testPutAccountGroupByExternalReferenceWithoutName() throws Exception { @@ -622,6 +819,33 @@ private void _testPutAccountGroupWithoutName() throws Exception { } } + private JSONObject _waitForFinish( + String expectedExecuteStatus, boolean importTask, + JSONObject jsonObject) + throws Exception { + + String endpoint = StringBundler.concat( + "headless-batch-engine/v1.0/", + importTask ? "import-task" : "export-task", + "/by-external-reference-code/"); + + while (true) { + jsonObject = HTTPTestUtil.invokeToJSONObject( + null, endpoint + jsonObject.getString("externalReferenceCode"), + Http.Method.GET); + + String executeStatus = jsonObject.getString("executeStatus"); + + if (StringUtil.equals(executeStatus, "COMPLETED") || + StringUtil.equals(executeStatus, "FAILED")) { + + Assert.assertEquals(expectedExecuteStatus, executeStatus); + + return jsonObject; + } + } + } + private AccountEntry _accountEntry; @Inject @@ -642,9 +866,18 @@ private void _testPutAccountGroupWithoutName() throws Exception { @Inject private ExpandoTableLocalService _expandoTableLocalService; + @Inject + private JSONFactory _jsonFactory; + + @Inject + private ResourceActionLocalService _resourceActionLocalService; + @Inject private ResourcePermissionLocalService _resourcePermissionLocalService; + @Inject + private RoleLocalService _roleLocalService; + private ServiceContext _serviceContext; } \ No newline at end of file From 0a03e22399ca551cfd5407a48234da76698e4e1d Mon Sep 17 00:00:00 2001 From: Stefano Motta <117469730+smottal@users.noreply.github.com> Date: Wed, 26 Feb 2025 10:21:55 +0100 Subject: [PATCH 15/16] LPD-50006 Update rest builder generator --- .../dependencies/base_resource_impl.ftl | 606 +++++++++--------- .../dependencies/client_permission.ftl | 54 ++ 2 files changed, 361 insertions(+), 299 deletions(-) diff --git a/modules/util/portal-tools-rest-builder/src/main/resources/com/liferay/portal/tools/rest/builder/dependencies/base_resource_impl.ftl b/modules/util/portal-tools-rest-builder/src/main/resources/com/liferay/portal/tools/rest/builder/dependencies/base_resource_impl.ftl index 09c02d3b8c700a..97feea47053f0a 100644 --- a/modules/util/portal-tools-rest-builder/src/main/resources/com/liferay/portal/tools/rest/builder/dependencies/base_resource_impl.ftl +++ b/modules/util/portal-tools-rest-builder/src/main/resources/com/liferay/portal/tools/rest/builder/dependencies/base_resource_impl.ftl @@ -6,6 +6,7 @@ package ${configYAML.apiPackagePath}.internal.resource.${escapedVersion}; import ${configYAML.apiPackagePath}.resource.${escapedVersion}.${schemaName}Resource; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.function.UnsafeBiConsumer; import com.liferay.petra.function.UnsafeBiFunction; import com.liferay.petra.function.UnsafeConsumer; @@ -581,413 +582,420 @@ public abstract class Base${schemaName}ResourceImpl @Override @SuppressWarnings("PMD.UnusedLocalVariable") public void create(Collection<${javaDataType}> ${schemaVarNames}, Map parameters) throws Exception { - <#if createStrategies?has_content> - UnsafeFunction<${javaDataType}, ${javaDataType}, Exception> ${schemaVarName}UnsafeFunction = null; + try { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); - String createStrategy = (String)parameters.getOrDefault("createStrategy", "INSERT"); - + <#if createStrategies?has_content> + UnsafeFunction<${javaDataType}, ${javaDataType}, Exception> ${schemaVarName}UnsafeFunction = null; - <#if createStrategies?seq_contains("INSERT")> - <#assign parentParameterNames = [] /> + String createStrategy = (String)parameters.getOrDefault("createStrategy", "INSERT"); + - if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { - <#if postBatchJavaMethodSignature??> - <#if stringUtil.equals(javaDataType, postBatchJavaMethodSignature.returnType)> - ${schemaVarName}UnsafeFunction = ${schemaVarName} -> ${postBatchJavaMethodSignature.methodName}( - <#else> - ${schemaVarName}UnsafeFunction = ${schemaVarName} -> { - ${postBatchJavaMethodSignature.methodName}( + <#if createStrategies?seq_contains("INSERT")> + <#assign parentParameterNames = [] /> + + if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { + <#if postBatchJavaMethodSignature??> + <#if stringUtil.equals(javaDataType, postBatchJavaMethodSignature.returnType)> + ${schemaVarName}UnsafeFunction = ${schemaVarName} -> ${postBatchJavaMethodSignature.methodName}( + <#else> + ${schemaVarName}UnsafeFunction = ${schemaVarName} -> { + ${postBatchJavaMethodSignature.methodName}( + + + <@getPOSTBatchJavaMethodParameters + javaMethodParameters = postBatchJavaMethodSignature.javaMethodParameters + schemaVarName = schemaVarName + /> + + ); + + <#if !stringUtil.equals(javaDataType, postBatchJavaMethodSignature.returnType)> + return null; + }; + - <@getPOSTBatchJavaMethodParameters - javaMethodParameters = postBatchJavaMethodSignature.javaMethodParameters - schemaVarName = schemaVarName - /> + <#if postParentBatchJavaMethodSignatures?has_content> + <#list postParentBatchJavaMethodSignatures as postParentBatchJavaMethodSignature> + <#assign parentParameterNames = parentParameterNames + [postParentBatchJavaMethodSignature.parentSchemaName!?uncap_first + "Id"] /> - ); + if (parameters.containsKey("${postParentBatchJavaMethodSignature.parentSchemaName?uncap_first}Id")) { + <#if stringUtil.equals(javaDataType, postParentBatchJavaMethodSignature.returnType)> + ${schemaVarName}UnsafeFunction = ${schemaVarName} -> ${postParentBatchJavaMethodSignature.methodName}( + <#else> + ${schemaVarName}UnsafeFunction = ${schemaVarName} -> { + ${postParentBatchJavaMethodSignature.methodName}( + + + <@getPOSTBatchJavaMethodParameters + javaMethodParameters = postParentBatchJavaMethodSignature.javaMethodParameters + schemaVarName = schemaVarName + /> - <#if !stringUtil.equals(javaDataType, postBatchJavaMethodSignature.returnType)> - return null; - }; + ); + + <#if !stringUtil.equals(javaDataType, postParentBatchJavaMethodSignature.returnType)> + return null; + }; + + } + + <#if postParentBatchJavaMethodSignature?has_next> + else + + - - <#if postParentBatchJavaMethodSignatures?has_content> - <#list postParentBatchJavaMethodSignatures as postParentBatchJavaMethodSignature> - <#assign parentParameterNames = parentParameterNames + [postParentBatchJavaMethodSignature.parentSchemaName!?uncap_first + "Id"] /> + <#if postParentByERCBatchJavaMethodSignatures?has_content> + <#list postParentByERCBatchJavaMethodSignatures as postParentByERCBatchJavaMethodSignature> + <#assign parentParameterNames = parentParameterNames + [postParentByERCBatchJavaMethodSignature.javaMethodParameters[0].parameterName] /> + + <#if postParentBatchJavaMethodSignatures?has_content> + else + + + if (parameters.containsKey("${postParentByERCBatchJavaMethodSignature.javaMethodParameters[0].parameterName}")) { + <#if stringUtil.equals(javaDataType, postParentByERCBatchJavaMethodSignature.returnType)> + ${schemaVarName}UnsafeFunction = ${schemaVarName} -> ${postParentByERCBatchJavaMethodSignature.methodName}( + <#else> + ${schemaVarName}UnsafeFunction = ${schemaVarName} -> { + ${postParentByERCBatchJavaMethodSignature.methodName}( + + + <@getPOSTBatchJavaMethodParameters + javaMethodParameters = postParentByERCBatchJavaMethodSignature.javaMethodParameters + schemaVarName = schemaVarName + /> + + ); + + <#if !stringUtil.equals(javaDataType, postParentByERCBatchJavaMethodSignature.returnType)> + return null; + }; + + } + + <#if postParentByERCBatchJavaMethodSignature?has_next> + else + + + + + <#if postAssetLibraryBatchJavaMethodSignature??> + <#assign parentParameterNames = parentParameterNames + ["assetLibraryId"] /> + + <#if postParentBatchJavaMethodSignatures?has_content || postParentByERCBatchJavaMethodSignatures?has_content> + else + - if (parameters.containsKey("${postParentBatchJavaMethodSignature.parentSchemaName?uncap_first}Id")) { - <#if stringUtil.equals(javaDataType, postParentBatchJavaMethodSignature.returnType)> - ${schemaVarName}UnsafeFunction = ${schemaVarName} -> ${postParentBatchJavaMethodSignature.methodName}( + if (parameters.containsKey("assetLibraryId")) { + <#if stringUtil.equals(javaDataType, postAssetLibraryBatchJavaMethodSignature.returnType)> + ${schemaVarName}UnsafeFunction = ${schemaVarName} -> ${postAssetLibraryBatchJavaMethodSignature.methodName}( <#else> - ${schemaVarName}UnsafeFunction = ${schemaVarName} -> { - ${postParentBatchJavaMethodSignature.methodName}( + ${schemaVarName}UnsafeFunction = ${schemaVarName} -> { ${postAssetLibraryBatchJavaMethodSignature.methodName}( <@getPOSTBatchJavaMethodParameters - javaMethodParameters = postParentBatchJavaMethodSignature.javaMethodParameters + javaMethodParameters = postAssetLibraryBatchJavaMethodSignature.javaMethodParameters schemaVarName = schemaVarName /> ); - <#if !stringUtil.equals(javaDataType, postParentBatchJavaMethodSignature.returnType)> + <#if !stringUtil.equals(javaDataType, postAssetLibraryBatchJavaMethodSignature.returnType)> return null; }; } + - <#if postParentBatchJavaMethodSignature?has_next> - else - - - - - <#if postParentByERCBatchJavaMethodSignatures?has_content> - <#list postParentByERCBatchJavaMethodSignatures as postParentByERCBatchJavaMethodSignature> - <#assign parentParameterNames = parentParameterNames + [postParentByERCBatchJavaMethodSignature.javaMethodParameters[0].parameterName] /> + <#if postSiteBatchJavaMethodSignature??> + <#assign parentParameterNames = parentParameterNames + ["siteId"] /> - <#if postParentBatchJavaMethodSignatures?has_content> + <#if postParentBatchJavaMethodSignatures?has_content || postParentByERCBatchJavaMethodSignatures?has_content || postAssetLibraryBatchJavaMethodSignature??> else - if (parameters.containsKey("${postParentByERCBatchJavaMethodSignature.javaMethodParameters[0].parameterName}")) { - <#if stringUtil.equals(javaDataType, postParentByERCBatchJavaMethodSignature.returnType)> - ${schemaVarName}UnsafeFunction = ${schemaVarName} -> ${postParentByERCBatchJavaMethodSignature.methodName}( + if (parameters.containsKey("siteId")) { + <#if stringUtil.equals(javaDataType, postSiteBatchJavaMethodSignature.returnType)> + ${schemaVarName}UnsafeFunction = ${schemaVarName} -> ${postSiteBatchJavaMethodSignature.methodName}( <#else> - ${schemaVarName}UnsafeFunction = ${schemaVarName} -> { - ${postParentByERCBatchJavaMethodSignature.methodName}( + ${schemaVarName}UnsafeFunction = ${schemaVarName} -> { ${postSiteBatchJavaMethodSignature.methodName}( <@getPOSTBatchJavaMethodParameters - javaMethodParameters = postParentByERCBatchJavaMethodSignature.javaMethodParameters + javaMethodParameters = postSiteBatchJavaMethodSignature.javaMethodParameters schemaVarName = schemaVarName /> ); - <#if !stringUtil.equals(javaDataType, postParentByERCBatchJavaMethodSignature.returnType)> + <#if !stringUtil.equals(javaDataType, postSiteBatchJavaMethodSignature.returnType)> return null; }; } + - <#if postParentByERCBatchJavaMethodSignature?has_next> - else - - - - - <#if postAssetLibraryBatchJavaMethodSignature??> - <#assign parentParameterNames = parentParameterNames + ["assetLibraryId"] /> - - <#if postParentBatchJavaMethodSignatures?has_content || postParentByERCBatchJavaMethodSignatures?has_content> - else + <#if !postBatchJavaMethodSignature?? && parentParameterNames?has_content> + else { + throw new NotSupportedException("One of the following parameters must be specified: [${parentParameterNames?join(", ")}]"); + } + } + - if (parameters.containsKey("assetLibraryId")) { - <#if stringUtil.equals(javaDataType, postAssetLibraryBatchJavaMethodSignature.returnType)> - ${schemaVarName}UnsafeFunction = ${schemaVarName} -> ${postAssetLibraryBatchJavaMethodSignature.methodName}( - <#else> - ${schemaVarName}UnsafeFunction = ${schemaVarName} -> { ${postAssetLibraryBatchJavaMethodSignature.methodName}( - + <#if createStrategies?seq_contains("UPSERT")> + if (StringUtil.equalsIgnoreCase(createStrategy, "UPSERT")) { + String updateStrategy = (String)parameters.getOrDefault("updateStrategy", "UPDATE"); - <@getPOSTBatchJavaMethodParameters - javaMethodParameters = postAssetLibraryBatchJavaMethodSignature.javaMethodParameters - schemaVarName = schemaVarName - /> + <#if putByERCBatchJavaMethodSignature??> + if(StringUtil.equalsIgnoreCase(updateStrategy, "UPDATE")) { + <#if stringUtil.equals(javaDataType, putByERCBatchJavaMethodSignature.returnType)> + ${schemaVarName}UnsafeFunction = ${schemaVarName} -> ${putByERCBatchJavaMethodSignature.methodName}( + <#else> + ${schemaVarName}UnsafeFunction = ${schemaVarName} -> { ${putByERCBatchJavaMethodSignature.methodName}( + - ); + <#list putByERCBatchJavaMethodSignature.javaMethodParameters as javaMethodParameter> + <#if stringUtil.equals(javaMethodParameter.parameterName, "externalReferenceCode")> + ${schemaVarName}.get${javaMethodParameter.parameterName?cap_first}() + <#elseif putByERCBatchJavaMethodSignature.parentSchemaName?? && stringUtil.equals(javaMethodParameter.parameterName, putByERCBatchJavaMethodSignature.parentSchemaName!?uncap_first + "Id")> + <#if properties?keys?seq_contains(javaMethodParameter.parameterName)> + ${schemaVarName}.get${javaMethodParameter.parameterName?cap_first}() != null ? + ${schemaVarName}.get${javaMethodParameter.parameterName?cap_first}() : + - <#if !stringUtil.equals(javaDataType, postAssetLibraryBatchJavaMethodSignature.returnType)> - return null; - }; - - } - + <@castParameters + type = javaMethodParameter.parameterType + value = "${javaMethodParameter.parameterName}" + /> + <#elseif stringUtil.equals(javaMethodParameter.parameterName, schemaVarName)> + ${schemaVarName} + <#else> + null + - <#if postSiteBatchJavaMethodSignature??> - <#assign parentParameterNames = parentParameterNames + ["siteId"] /> + <#sep>, + + ); - <#if postParentBatchJavaMethodSignatures?has_content || postParentByERCBatchJavaMethodSignatures?has_content || postAssetLibraryBatchJavaMethodSignature??> - else + <#if !stringUtil.equals(javaDataType, putByERCBatchJavaMethodSignature.returnType)> + return null; + }; + + } - if (parameters.containsKey("siteId")) { - <#if stringUtil.equals(javaDataType, postSiteBatchJavaMethodSignature.returnType)> - ${schemaVarName}UnsafeFunction = ${schemaVarName} -> ${postSiteBatchJavaMethodSignature.methodName}( - <#else> - ${schemaVarName}UnsafeFunction = ${schemaVarName} -> { ${postSiteBatchJavaMethodSignature.methodName}( - - - <@getPOSTBatchJavaMethodParameters - javaMethodParameters = postSiteBatchJavaMethodSignature.javaMethodParameters - schemaVarName = schemaVarName - /> - - ); - - <#if !stringUtil.equals(javaDataType, postSiteBatchJavaMethodSignature.returnType)> - return null; - }; - - } - - - <#if !postBatchJavaMethodSignature?? && parentParameterNames?has_content> - else { - throw new NotSupportedException("One of the following parameters must be specified: [${parentParameterNames?join(", ")}]"); - } - - } - + <#if getByERCBatchJavaMethodSignature?? && patchBatchJavaMethodSignature?? && (postAssetLibraryBatchJavaMethodSignature?? || postBatchJavaMethodSignature?? || postParentBatchJavaMethodSignatures?has_content || postParentByERCBatchJavaMethodSignatures?has_content || postSiteBatchJavaMethodSignature??)> + if(StringUtil.equalsIgnoreCase(updateStrategy, "PARTIAL_UPDATE")) { + ${schemaVarName}UnsafeFunction = ${schemaVarName} -> { + ${schemaName} persisted${schemaName} = null; + + try { + ${schemaName} get${schemaName} = ${getByERCBatchJavaMethodSignature.methodName}( + + <#list getByERCBatchJavaMethodSignature.javaMethodParameters as javaMethodParameter> + <#if stringUtil.equals(javaMethodParameter.parameterName, "externalReferenceCode")> + ${schemaVarName}.get${javaMethodParameter.parameterName?cap_first}() + <#elseif getByERCBatchJavaMethodSignature.parentSchemaName?? && stringUtil.equals(javaMethodParameter.parameterName, getByERCBatchJavaMethodSignature.parentSchemaName!?uncap_first + "Id")> + <#if properties?keys?seq_contains(javaMethodParameter.parameterName)> + ${schemaVarName}.get${javaMethodParameter.parameterName?cap_first}() != null ? + ${schemaVarName}.get${javaMethodParameter.parameterName?cap_first}() : + + + <@castParameters + type = javaMethodParameter.parameterType + value = "${javaMethodParameter.parameterName}" + /> + <#elseif stringUtil.equals(javaMethodParameter.parameterName, schemaVarName)> + ${schemaVarName} + <#else> + null + - <#if createStrategies?seq_contains("UPSERT")> - if (StringUtil.equalsIgnoreCase(createStrategy, "UPSERT")) { - String updateStrategy = (String)parameters.getOrDefault("updateStrategy", "UPDATE"); + <#sep>, + - <#if putByERCBatchJavaMethodSignature??> - if(StringUtil.equalsIgnoreCase(updateStrategy, "UPDATE")) { - <#if stringUtil.equals(javaDataType, putByERCBatchJavaMethodSignature.returnType)> - ${schemaVarName}UnsafeFunction = ${schemaVarName} -> ${putByERCBatchJavaMethodSignature.methodName}( - <#else> - ${schemaVarName}UnsafeFunction = ${schemaVarName} -> { ${putByERCBatchJavaMethodSignature.methodName}( - + ); - <#list putByERCBatchJavaMethodSignature.javaMethodParameters as javaMethodParameter> - <#if stringUtil.equals(javaMethodParameter.parameterName, "externalReferenceCode")> - ${schemaVarName}.get${javaMethodParameter.parameterName?cap_first}() - <#elseif putByERCBatchJavaMethodSignature.parentSchemaName?? && stringUtil.equals(javaMethodParameter.parameterName, putByERCBatchJavaMethodSignature.parentSchemaName!?uncap_first + "Id")> - <#if properties?keys?seq_contains(javaMethodParameter.parameterName)> - ${schemaVarName}.get${javaMethodParameter.parameterName?cap_first}() != null ? - ${schemaVarName}.get${javaMethodParameter.parameterName?cap_first}() : - + <#if stringUtil.equals(javaDataType, patchBatchJavaMethodSignature.returnType)> + persisted${schemaName} = patch${schemaName}( + <#else> + patch${schemaName}( + - <@castParameters - type = javaMethodParameter.parameterType - value = "${javaMethodParameter.parameterName}" - /> - <#elseif stringUtil.equals(javaMethodParameter.parameterName, schemaVarName)> - ${schemaVarName} - <#else> - null - + <#list patchBatchJavaMethodSignature.javaMethodParameters as javaMethodParameter> + <#if stringUtil.equals(javaMethodParameter.parameterName, schemaVarName)> + ${schemaVarName} + <#elseif stringUtil.equals(javaMethodParameter.parameterName, schemaVarName + "Id") || stringUtil.equals(javaMethodParameter.parameterName, "id")> + <#if properties?keys?seq_contains("id")> + get${schemaName}.getId() != null ? get${schemaName}.getId() : + <#elseif properties?keys?seq_contains(schemaVarName + "Id")> + (get${schemaName}.get${schemaName}Id() != null) ? get${schemaName}.get${schemaName}Id() : + + + <@castParameters + type = javaMethodParameter.parameterType + value = "${schemaVarName}Id" + /> + <#elseif stringUtil.equals(javaMethodParameter.parameterName, "multipartBody")> + null + <#else> + ${javaMethodParameter.parameterName} + - <#sep>, - - ); + <#sep>, + - <#if !stringUtil.equals(javaDataType, putByERCBatchJavaMethodSignature.returnType)> - return null; - }; - - } - + ); + } + catch (NoSuchModelException noSuchModelException) { + <#assign parentParameterNames = [] /> - <#if getByERCBatchJavaMethodSignature?? && patchBatchJavaMethodSignature?? && (postAssetLibraryBatchJavaMethodSignature?? || postBatchJavaMethodSignature?? || postParentBatchJavaMethodSignatures?has_content || postParentByERCBatchJavaMethodSignatures?has_content || postSiteBatchJavaMethodSignature??)> - if(StringUtil.equalsIgnoreCase(updateStrategy, "PARTIAL_UPDATE")) { - ${schemaVarName}UnsafeFunction = ${schemaVarName} -> { - ${schemaName} persisted${schemaName} = null; - - try { - ${schemaName} get${schemaName} = ${getByERCBatchJavaMethodSignature.methodName}( - - <#list getByERCBatchJavaMethodSignature.javaMethodParameters as javaMethodParameter> - <#if stringUtil.equals(javaMethodParameter.parameterName, "externalReferenceCode")> - ${schemaVarName}.get${javaMethodParameter.parameterName?cap_first}() - <#elseif getByERCBatchJavaMethodSignature.parentSchemaName?? && stringUtil.equals(javaMethodParameter.parameterName, getByERCBatchJavaMethodSignature.parentSchemaName!?uncap_first + "Id")> - <#if properties?keys?seq_contains(javaMethodParameter.parameterName)> - ${schemaVarName}.get${javaMethodParameter.parameterName?cap_first}() != null ? - ${schemaVarName}.get${javaMethodParameter.parameterName?cap_first}() : - + <#if postBatchJavaMethodSignature?? && !postParentBatchJavaMethodSignatures?has_content && !postParentByERCBatchJavaMethodSignatures?has_content> + persisted${schemaName} = ${postBatchJavaMethodSignature.methodName}( - <@castParameters - type = javaMethodParameter.parameterType - value = "${javaMethodParameter.parameterName}" + <@getPOSTBatchJavaMethodParameters + javaMethodParameters = postBatchJavaMethodSignature.javaMethodParameters + schemaVarName = schemaVarName /> - <#elseif stringUtil.equals(javaMethodParameter.parameterName, schemaVarName)> - ${schemaVarName} - <#else> - null - - <#sep>, - + ); + - ); + <#if postParentBatchJavaMethodSignatures?has_content || postParentByERCBatchJavaMethodSignatures?has_content> + <#list postParentBatchJavaMethodSignatures as postParentBatchJavaMethodSignature> + <#assign parentParameterNames = parentParameterNames + [postParentBatchJavaMethodSignature.parentSchemaName!?uncap_first + "Id"] /> - <#if stringUtil.equals(javaDataType, patchBatchJavaMethodSignature.returnType)> - persisted${schemaName} = patch${schemaName}( - <#else> - patch${schemaName}( - + if (parameters.containsKey("${postParentBatchJavaMethodSignature.parentSchemaName?uncap_first}Id")) { + persisted${schemaName} = ${postParentBatchJavaMethodSignature.methodName}( - <#list patchBatchJavaMethodSignature.javaMethodParameters as javaMethodParameter> - <#if stringUtil.equals(javaMethodParameter.parameterName, schemaVarName)> - ${schemaVarName} - <#elseif stringUtil.equals(javaMethodParameter.parameterName, schemaVarName + "Id") || stringUtil.equals(javaMethodParameter.parameterName, "id")> - <#if properties?keys?seq_contains("id")> - get${schemaName}.getId() != null ? get${schemaName}.getId() : - <#elseif properties?keys?seq_contains(schemaVarName + "Id")> - (get${schemaName}.get${schemaName}Id() != null) ? get${schemaName}.get${schemaName}Id() : - + <@getPOSTBatchJavaMethodParameters + javaMethodParameters = postParentBatchJavaMethodSignature.javaMethodParameters + schemaVarName = schemaVarName + /> - <@castParameters - type = javaMethodParameter.parameterType - value = "${schemaVarName}Id" - /> - <#elseif stringUtil.equals(javaMethodParameter.parameterName, "multipartBody")> - null - <#else> - ${javaMethodParameter.parameterName} - + ); - <#sep>, - + } - ); - } - catch (NoSuchModelException noSuchModelException) { - <#assign parentParameterNames = [] /> + <#if postParentBatchJavaMethodSignature?has_next> + else + + - <#if postBatchJavaMethodSignature?? && !postParentBatchJavaMethodSignatures?has_content && !postParentByERCBatchJavaMethodSignatures?has_content> - persisted${schemaName} = ${postBatchJavaMethodSignature.methodName}( + <#list postParentByERCBatchJavaMethodSignatures as postParentByERCBatchJavaMethodSignature> + <#assign parentParameterNames = parentParameterNames + [postParentByERCBatchJavaMethodSignature.javaMethodParameters[0].parameterName] /> - <@getPOSTBatchJavaMethodParameters - javaMethodParameters = postBatchJavaMethodSignature.javaMethodParameters - schemaVarName = schemaVarName - /> + <#if postParentBatchJavaMethodSignatures?has_content> + else + - ); - + if (parameters.containsKey("${postParentByERCBatchJavaMethodSignature.javaMethodParameters[0].parameterName}")) { + persisted${schemaName} = ${postParentByERCBatchJavaMethodSignature.methodName}( - <#if postParentBatchJavaMethodSignatures?has_content || postParentByERCBatchJavaMethodSignatures?has_content> - <#list postParentBatchJavaMethodSignatures as postParentBatchJavaMethodSignature> - <#assign parentParameterNames = parentParameterNames + [postParentBatchJavaMethodSignature.parentSchemaName!?uncap_first + "Id"] /> + <@getPOSTBatchJavaMethodParameters + javaMethodParameters = postParentByERCBatchJavaMethodSignature.javaMethodParameters + schemaVarName = schemaVarName + /> - if (parameters.containsKey("${postParentBatchJavaMethodSignature.parentSchemaName?uncap_first}Id")) { - persisted${schemaName} = ${postParentBatchJavaMethodSignature.methodName}( + ); + } - <@getPOSTBatchJavaMethodParameters - javaMethodParameters = postParentBatchJavaMethodSignature.javaMethodParameters - schemaVarName = schemaVarName - /> + <#if postParentByERCBatchJavaMethodSignature?has_next> + else + + - ); + <#if postBatchJavaMethodSignature??> + else { + persisted${schemaName} = ${postBatchJavaMethodSignature.methodName}( - } + <@getPOSTBatchJavaMethodParameters + javaMethodParameters = postBatchJavaMethodSignature.javaMethodParameters + schemaVarName = schemaVarName + /> - <#if postParentBatchJavaMethodSignature?has_next> - else + ); + } - + - <#list postParentByERCBatchJavaMethodSignatures as postParentByERCBatchJavaMethodSignature> - <#assign parentParameterNames = parentParameterNames + [postParentByERCBatchJavaMethodSignature.javaMethodParameters[0].parameterName] /> + <#if postAssetLibraryBatchJavaMethodSignature??> + <#assign parentParameterNames = parentParameterNames + ["assetLibraryId"] /> - <#if postParentBatchJavaMethodSignatures?has_content> + <#if postParentBatchJavaMethodSignatures?has_content || postParentByERCBatchJavaMethodSignatures?has_content> else - if (parameters.containsKey("${postParentByERCBatchJavaMethodSignature.javaMethodParameters[0].parameterName}")) { - persisted${schemaName} = ${postParentByERCBatchJavaMethodSignature.methodName}( + if (parameters.containsKey("assetLibraryId")) { + persisted${schemaName} = ${postAssetLibraryBatchJavaMethodSignature.methodName}( <@getPOSTBatchJavaMethodParameters - javaMethodParameters = postParentByERCBatchJavaMethodSignature.javaMethodParameters + javaMethodParameters = postAssetLibraryBatchJavaMethodSignature.javaMethodParameters schemaVarName = schemaVarName /> ); } + - <#if postParentByERCBatchJavaMethodSignature?has_next> + <#if postSiteBatchJavaMethodSignature??> + <#if postParentBatchJavaMethodSignatures?has_content || postParentByERCBatchJavaMethodSignatures?has_content || postAssetLibraryBatchJavaMethodSignature??> else - - <#if postBatchJavaMethodSignature??> - else { - persisted${schemaName} = ${postBatchJavaMethodSignature.methodName}( + if (parameters.containsKey("siteId")) { + persisted${schemaName} = ${postSiteBatchJavaMethodSignature.methodName}( <@getPOSTBatchJavaMethodParameters - javaMethodParameters = postBatchJavaMethodSignature.javaMethodParameters + javaMethodParameters = postSiteBatchJavaMethodSignature.javaMethodParameters schemaVarName = schemaVarName /> ); } - - - <#if postAssetLibraryBatchJavaMethodSignature??> - <#assign parentParameterNames = parentParameterNames + ["assetLibraryId"] /> - <#if postParentBatchJavaMethodSignatures?has_content || postParentByERCBatchJavaMethodSignatures?has_content> - else - - - if (parameters.containsKey("assetLibraryId")) { - persisted${schemaName} = ${postAssetLibraryBatchJavaMethodSignature.methodName}( - - <@getPOSTBatchJavaMethodParameters - javaMethodParameters = postAssetLibraryBatchJavaMethodSignature.javaMethodParameters - schemaVarName = schemaVarName - /> - - ); - } - - - <#if postSiteBatchJavaMethodSignature??> - <#if postParentBatchJavaMethodSignatures?has_content || postParentByERCBatchJavaMethodSignatures?has_content || postAssetLibraryBatchJavaMethodSignature??> - else + <#if !postBatchJavaMethodSignature?? && parentParameterNames?has_content> + else { + throw new NotSupportedException("One of the following parameters must be specified: [${parentParameterNames?join(", ")}]"); + } + } - if (parameters.containsKey("siteId")) { - persisted${schemaName} = ${postSiteBatchJavaMethodSignature.methodName}( - - <@getPOSTBatchJavaMethodParameters - javaMethodParameters = postSiteBatchJavaMethodSignature.javaMethodParameters - schemaVarName = schemaVarName - /> - - ); - } - + return persisted${schemaName}; + }; + } + + } + - <#if !postBatchJavaMethodSignature?? && parentParameterNames?has_content> - else { - throw new NotSupportedException("One of the following parameters must be specified: [${parentParameterNames?join(", ")}]"); - } - - } + <#if createStrategies?has_content> + if (${schemaVarName}UnsafeFunction == null) { + throw new NotSupportedException("Create strategy \"" + createStrategy + "\" is not supported for ${schemaVarName?cap_first}"); + } - return persisted${schemaName}; - }; + if (contextBatchUnsafeBiConsumer != null) { + contextBatchUnsafeBiConsumer.accept(${schemaVarNames}, ${schemaVarName}UnsafeFunction); + } + else if (contextBatchUnsafeConsumer != null) { + contextBatchUnsafeConsumer.accept(${schemaVarNames}, ${schemaVarName}UnsafeFunction::apply); + } + else { + for (${javaDataType} ${schemaVarName} : ${schemaVarNames}) { + ${schemaVarName}UnsafeFunction.apply(${schemaVarName}); } - - } - - - <#if createStrategies?has_content> - if (${schemaVarName}UnsafeFunction == null) { - throw new NotSupportedException("Create strategy \"" + createStrategy + "\" is not supported for ${schemaVarName?cap_first}"); - } - - if (contextBatchUnsafeBiConsumer != null) { - contextBatchUnsafeBiConsumer.accept(${schemaVarNames}, ${schemaVarName}UnsafeFunction); - } - else if (contextBatchUnsafeConsumer != null) { - contextBatchUnsafeConsumer.accept(${schemaVarNames}, ${schemaVarName}UnsafeFunction::apply); - } - else { - for (${javaDataType} ${schemaVarName} : ${schemaVarNames}) { - ${schemaVarName}UnsafeFunction.apply(${schemaVarName}); } - } - <#else> - throw new UnsupportedOperationException("This method needs to be implemented"); - + <#else> + throw new UnsupportedOperationException("This method needs to be implemented"); + + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); + } } @Override diff --git a/modules/util/portal-tools-rest-builder/src/main/resources/com/liferay/portal/tools/rest/builder/dependencies/client_permission.ftl b/modules/util/portal-tools-rest-builder/src/main/resources/com/liferay/portal/tools/rest/builder/dependencies/client_permission.ftl index b312b3439f14e7..4728cc120b2b9f 100644 --- a/modules/util/portal-tools-rest-builder/src/main/resources/com/liferay/portal/tools/rest/builder/dependencies/client_permission.ftl +++ b/modules/util/portal-tools-rest-builder/src/main/resources/com/liferay/portal/tools/rest/builder/dependencies/client_permission.ftl @@ -24,18 +24,34 @@ public class Permission { return actionIds; } + public String getRoleExternalReferenceCode() { + return roleExternalReferenceCode; + } + public String getRoleName() { return roleName; } + public String getRoleType() { + return roleType; + } + public void setActionIds(Object[] actionIds) { this.actionIds = actionIds; } + public void setRoleExternalReferenceCode(String roleExternalReferenceCode) { + this.roleExternalReferenceCode = roleExternalReferenceCode; + } + public void setRoleName(String roleName) { this.roleName = roleName; } + public void setRoleType(String roleType) { + this.roleType = roleType; + } + @Override public String toString() { StringBuilder sb = new StringBuilder(); @@ -58,6 +74,16 @@ public class Permission { sb.append("]"); } + if (roleExternalReferenceCode != null) { + if (sb.length() > 1) { + sb.append(", "); + } + + sb.append("\"roleExternalReferenceCode\": \""); + sb.append(roleExternalReferenceCode); + sb.append("\""); + } + if (roleName != null) { if (sb.length() > 1) { sb.append(", "); @@ -68,13 +94,25 @@ public class Permission { sb.append("\""); } + if (roleType != null) { + if (sb.length() > 1) { + sb.append(", "); + } + + sb.append("\"roleType\": \""); + sb.append(roleType); + sb.append("\""); + } + sb.append("}"); return sb.toString(); } protected Object[] actionIds; + protected String roleExternalReferenceCode; protected String roleName; + protected String roleType; private static class PermissionJSONParser extends BaseJSONParser { @@ -93,9 +131,15 @@ public class Permission { if (Objects.equals(jsonParserFieldName, "actionIds")) { return false; } + else if (Objects.equals(jsonParserFieldName, "roleExternalReferenceCode")) { + return false; + } else if (Objects.equals(jsonParserFieldName, "roleName")) { return false; } + else if (Objects.equals(jsonParserFieldName, "roleType")) { + return false; + } else { throw new IllegalArgumentException("Unsupported field name " + jsonParserFieldName); } @@ -108,11 +152,21 @@ public class Permission { permission.setActionIds((Object[])jsonParserFieldValue); } } + else if (Objects.equals(jsonParserFieldName, "roleExternalReferenceCode")) { + if (jsonParserFieldValue != null) { + permission.setRoleExternalReferenceCode((String)jsonParserFieldValue); + } + } else if (Objects.equals(jsonParserFieldName, "roleName")) { if (jsonParserFieldValue != null) { permission.setRoleName((String)jsonParserFieldValue); } } + else if (Objects.equals(jsonParserFieldName, "roleType")) { + if (jsonParserFieldValue != null) { + permission.setRoleType((String)jsonParserFieldValue); + } + } else { throw new IllegalArgumentException("Unsupported field name " + jsonParserFieldName); } From 77e78e880b09ae4ddb886ab884e0ce486a32b007 Mon Sep 17 00:00:00 2001 From: Stefano Motta <117469730+smottal@users.noreply.github.com> Date: Wed, 26 Feb 2025 10:22:32 +0100 Subject: [PATCH 16/16] LPD-50006 Autogenerated Code (buildRest) --- .../admin/user/dto/v1_0/AccountBrief.java | 59 +++++- .../admin/user/dto/v1_0/AccountGroup.java | 4 +- .../headless/admin/user/dto/v1_0/Creator.java | 175 +++++++++++++++++- .../admin/user/dto/v1_0/RoleBrief.java | 59 +++++- .../user/client/dto/v1_0/AccountBrief.java | 19 ++ .../admin/user/client/dto/v1_0/Creator.java | 63 +++++++ .../admin/user/client/dto/v1_0/RoleBrief.java | 19 ++ .../user/client/permission/Permission.java | 59 ++++++ .../serdes/v1_0/AccountBriefSerDes.java | 29 +++ .../client/serdes/v1_0/CreatorSerDes.java | 94 ++++++++++ .../client/serdes/v1_0/RoleBriefSerDes.java | 29 +++ .../v1_0/BaseAccountGroupResourceImpl.java | 132 +++++++------ .../v1_0/BaseAccountResourceImpl.java | 116 +++++++----- .../v1_0/BaseAccountRoleResourceImpl.java | 70 +++---- .../v1_0/BaseEmailAddressResourceImpl.java | 12 +- .../v1_0/BaseOrganizationResourceImpl.java | 117 ++++++------ .../resource/v1_0/BasePhoneResourceImpl.java | 12 +- .../v1_0/BasePostalAddressResourceImpl.java | 150 ++++++++------- .../resource/v1_0/BaseRoleResourceImpl.java | 106 ++++++----- .../v1_0/BaseSegmentResourceImpl.java | 12 +- .../v1_0/BaseSegmentUserResourceImpl.java | 12 +- .../resource/v1_0/BaseSiteResourceImpl.java | 12 +- .../v1_0/BaseSubscriptionResourceImpl.java | 12 +- .../v1_0/BaseUserAccountResourceImpl.java | 137 +++++++------- .../v1_0/BaseUserGroupResourceImpl.java | 119 ++++++------ .../resource/v1_0/BaseWebUrlResourceImpl.java | 12 +- 26 files changed, 1193 insertions(+), 447 deletions(-) diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-api/src/main/java/com/liferay/headless/admin/user/dto/v1_0/AccountBrief.java b/modules/apps/headless/headless-admin-user/headless-admin-user-api/src/main/java/com/liferay/headless/admin/user/dto/v1_0/AccountBrief.java index 57af9d861c3938..79a49651561c08 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-api/src/main/java/com/liferay/headless/admin/user/dto/v1_0/AccountBrief.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-api/src/main/java/com/liferay/headless/admin/user/dto/v1_0/AccountBrief.java @@ -88,7 +88,7 @@ public void setExternalReferenceCode( } @GraphQLField(description = "The account's external reference code.") - @JsonProperty(access = JsonProperty.Access.READ_ONLY) + @JsonProperty(access = JsonProperty.Access.READ_WRITE) protected String externalReferenceCode; @JsonIgnore @@ -166,7 +166,7 @@ public void setName(UnsafeSupplier nameUnsafeSupplier) { } @GraphQLField(description = "The account's name.") - @JsonProperty(access = JsonProperty.Access.READ_ONLY) + @JsonProperty(access = JsonProperty.Access.READ_WRITE) protected String name; @JsonIgnore @@ -214,6 +214,45 @@ public void setRoleBriefs( @JsonIgnore private Supplier _roleBriefsSupplier; + @Schema(description = "The account's type.") + public String getType() { + if (_typeSupplier != null) { + type = _typeSupplier.get(); + + _typeSupplier = null; + } + + return type; + } + + public void setType(String type) { + this.type = type; + + _typeSupplier = null; + } + + @JsonIgnore + public void setType(UnsafeSupplier typeUnsafeSupplier) { + _typeSupplier = () -> { + try { + return typeUnsafeSupplier.get(); + } + catch (RuntimeException runtimeException) { + throw runtimeException; + } + catch (Exception exception) { + throw new RuntimeException(exception); + } + }; + } + + @GraphQLField(description = "The account's type.") + @JsonProperty(access = JsonProperty.Access.READ_WRITE) + protected String type; + + @JsonIgnore + private Supplier _typeSupplier; + @Override public boolean equals(Object object) { if (this == object) { @@ -307,6 +346,22 @@ public String toString() { sb.append("]"); } + String type = getType(); + + if (type != null) { + if (sb.length() > 1) { + sb.append(", "); + } + + sb.append("\"type\": "); + + sb.append("\""); + + sb.append(_escape(type)); + + sb.append("\""); + } + sb.append("}"); return sb.toString(); diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-api/src/main/java/com/liferay/headless/admin/user/dto/v1_0/AccountGroup.java b/modules/apps/headless/headless-admin-user/headless-admin-user-api/src/main/java/com/liferay/headless/admin/user/dto/v1_0/AccountGroup.java index c5372f4ff296d1..edbd04e3aab56f 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-api/src/main/java/com/liferay/headless/admin/user/dto/v1_0/AccountGroup.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-api/src/main/java/com/liferay/headless/admin/user/dto/v1_0/AccountGroup.java @@ -95,7 +95,7 @@ public void setAccountBriefs( @GraphQLField( description = "The list of accounts associated with this account group." ) - @JsonProperty(access = JsonProperty.Access.READ_ONLY) + @JsonProperty(access = JsonProperty.Access.READ_WRITE) protected AccountBrief[] accountBriefs; @JsonIgnore @@ -184,7 +184,7 @@ public void setCreator( } @GraphQLField(description = "The user who created the account group.") - @JsonProperty(access = JsonProperty.Access.READ_ONLY) + @JsonProperty(access = JsonProperty.Access.READ_WRITE) protected Creator creator; @JsonIgnore diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-api/src/main/java/com/liferay/headless/admin/user/dto/v1_0/Creator.java b/modules/apps/headless/headless-admin-user/headless-admin-user-api/src/main/java/com/liferay/headless/admin/user/dto/v1_0/Creator.java index 7a7a941e7d9162..4b81c23fd85967 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-api/src/main/java/com/liferay/headless/admin/user/dto/v1_0/Creator.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-api/src/main/java/com/liferay/headless/admin/user/dto/v1_0/Creator.java @@ -137,6 +137,88 @@ public void setContentType( @JsonIgnore private Supplier _contentTypeSupplier; + @Schema(description = "The user's email address.") + public String getEmailAddress() { + if (_emailAddressSupplier != null) { + emailAddress = _emailAddressSupplier.get(); + + _emailAddressSupplier = null; + } + + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + + _emailAddressSupplier = null; + } + + @JsonIgnore + public void setEmailAddress( + UnsafeSupplier emailAddressUnsafeSupplier) { + + _emailAddressSupplier = () -> { + try { + return emailAddressUnsafeSupplier.get(); + } + catch (RuntimeException runtimeException) { + throw runtimeException; + } + catch (Exception exception) { + throw new RuntimeException(exception); + } + }; + } + + @GraphQLField(description = "The user's email address.") + @JsonProperty(access = JsonProperty.Access.READ_WRITE) + protected String emailAddress; + + @JsonIgnore + private Supplier _emailAddressSupplier; + + @Schema(description = "The user's external reference code.") + public String getExternalReferenceCode() { + if (_externalReferenceCodeSupplier != null) { + externalReferenceCode = _externalReferenceCodeSupplier.get(); + + _externalReferenceCodeSupplier = null; + } + + return externalReferenceCode; + } + + public void setExternalReferenceCode(String externalReferenceCode) { + this.externalReferenceCode = externalReferenceCode; + + _externalReferenceCodeSupplier = null; + } + + @JsonIgnore + public void setExternalReferenceCode( + UnsafeSupplier externalReferenceCodeUnsafeSupplier) { + + _externalReferenceCodeSupplier = () -> { + try { + return externalReferenceCodeUnsafeSupplier.get(); + } + catch (RuntimeException runtimeException) { + throw runtimeException; + } + catch (Exception exception) { + throw new RuntimeException(exception); + } + }; + } + + @GraphQLField(description = "The user's external reference code.") + @JsonProperty(access = JsonProperty.Access.READ_WRITE) + protected String externalReferenceCode; + + @JsonIgnore + private Supplier _externalReferenceCodeSupplier; + @Schema(description = "The user's surname (last name).") public String getFamilyName() { if (_familyNameSupplier != null) { @@ -172,7 +254,7 @@ public void setFamilyName( } @GraphQLField(description = "The user's surname (last name).") - @JsonProperty(access = JsonProperty.Access.READ_ONLY) + @JsonProperty(access = JsonProperty.Access.READ_WRITE) protected String familyName; @JsonIgnore @@ -213,7 +295,7 @@ public void setGivenName( } @GraphQLField(description = "The user's first name.") - @JsonProperty(access = JsonProperty.Access.READ_ONLY) + @JsonProperty(access = JsonProperty.Access.READ_WRITE) protected String givenName; @JsonIgnore @@ -379,6 +461,47 @@ public void setProfileURL( @JsonIgnore private Supplier _profileURLSupplier; + @Schema(description = "The user's screen name.") + public String getScreenName() { + if (_screenNameSupplier != null) { + screenName = _screenNameSupplier.get(); + + _screenNameSupplier = null; + } + + return screenName; + } + + public void setScreenName(String screenName) { + this.screenName = screenName; + + _screenNameSupplier = null; + } + + @JsonIgnore + public void setScreenName( + UnsafeSupplier screenNameUnsafeSupplier) { + + _screenNameSupplier = () -> { + try { + return screenNameUnsafeSupplier.get(); + } + catch (RuntimeException runtimeException) { + throw runtimeException; + } + catch (Exception exception) { + throw new RuntimeException(exception); + } + }; + } + + @GraphQLField(description = "The user's screen name.") + @JsonProperty(access = JsonProperty.Access.READ_WRITE) + protected String screenName; + + @JsonIgnore + private Supplier _screenNameSupplier; + @Override public boolean equals(Object object) { if (this == object) { @@ -438,6 +561,38 @@ public String toString() { sb.append("\""); } + String emailAddress = getEmailAddress(); + + if (emailAddress != null) { + if (sb.length() > 1) { + sb.append(", "); + } + + sb.append("\"emailAddress\": "); + + sb.append("\""); + + sb.append(_escape(emailAddress)); + + sb.append("\""); + } + + String externalReferenceCode = getExternalReferenceCode(); + + if (externalReferenceCode != null) { + if (sb.length() > 1) { + sb.append(", "); + } + + sb.append("\"externalReferenceCode\": "); + + sb.append("\""); + + sb.append(_escape(externalReferenceCode)); + + sb.append("\""); + } + String familyName = getFamilyName(); if (familyName != null) { @@ -530,6 +685,22 @@ public String toString() { sb.append("\""); } + String screenName = getScreenName(); + + if (screenName != null) { + if (sb.length() > 1) { + sb.append(", "); + } + + sb.append("\"screenName\": "); + + sb.append("\""); + + sb.append(_escape(screenName)); + + sb.append("\""); + } + sb.append("}"); return sb.toString(); diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-api/src/main/java/com/liferay/headless/admin/user/dto/v1_0/RoleBrief.java b/modules/apps/headless/headless-admin-user/headless-admin-user-api/src/main/java/com/liferay/headless/admin/user/dto/v1_0/RoleBrief.java index a17d3ddfd7b03c..8670f62112fda2 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-api/src/main/java/com/liferay/headless/admin/user/dto/v1_0/RoleBrief.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-api/src/main/java/com/liferay/headless/admin/user/dto/v1_0/RoleBrief.java @@ -91,7 +91,7 @@ public void setExternalReferenceCode( } @GraphQLField(description = "The role's external reference code.") - @JsonProperty(access = JsonProperty.Access.READ_ONLY) + @JsonProperty(access = JsonProperty.Access.READ_WRITE) protected String externalReferenceCode; @JsonIgnore @@ -136,6 +136,45 @@ public void setId(UnsafeSupplier idUnsafeSupplier) { @JsonIgnore private Supplier _idSupplier; + @Schema(description = "The role's key.") + public String getKey() { + if (_keySupplier != null) { + key = _keySupplier.get(); + + _keySupplier = null; + } + + return key; + } + + public void setKey(String key) { + this.key = key; + + _keySupplier = null; + } + + @JsonIgnore + public void setKey(UnsafeSupplier keyUnsafeSupplier) { + _keySupplier = () -> { + try { + return keyUnsafeSupplier.get(); + } + catch (RuntimeException runtimeException) { + throw runtimeException; + } + catch (Exception exception) { + throw new RuntimeException(exception); + } + }; + } + + @GraphQLField(description = "The role's key.") + @JsonProperty(access = JsonProperty.Access.READ_WRITE) + protected String key; + + @JsonIgnore + private Supplier _keySupplier; + @Schema(description = "The role's name.") public String getName() { if (_nameSupplier != null) { @@ -253,7 +292,7 @@ public void setRoleType( } @GraphQLField(description = "The role's type.") - @JsonProperty(access = JsonProperty.Access.READ_ONLY) + @JsonProperty(access = JsonProperty.Access.READ_WRITE) protected Integer roleType; @JsonIgnore @@ -314,6 +353,22 @@ public String toString() { sb.append(id); } + String key = getKey(); + + if (key != null) { + if (sb.length() > 1) { + sb.append(", "); + } + + sb.append("\"key\": "); + + sb.append("\""); + + sb.append(_escape(key)); + + sb.append("\""); + } + String name = getName(); if (name != null) { diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/dto/v1_0/AccountBrief.java b/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/dto/v1_0/AccountBrief.java index 787d5db6c9cff1..0c8347f06cfb29 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/dto/v1_0/AccountBrief.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/dto/v1_0/AccountBrief.java @@ -105,6 +105,25 @@ public void setRoleBriefs( protected RoleBrief[] roleBriefs; + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public void setType(UnsafeSupplier typeUnsafeSupplier) { + try { + type = typeUnsafeSupplier.get(); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected String type; + @Override public AccountBrief clone() throws CloneNotSupportedException { return (AccountBrief)super.clone(); diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/dto/v1_0/Creator.java b/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/dto/v1_0/Creator.java index 8730fdc2a3f1b8..7f75da35b458b6 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/dto/v1_0/Creator.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/dto/v1_0/Creator.java @@ -67,6 +67,48 @@ public void setContentType( protected String contentType; + public String getEmailAddress() { + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + public void setEmailAddress( + UnsafeSupplier emailAddressUnsafeSupplier) { + + try { + emailAddress = emailAddressUnsafeSupplier.get(); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected String emailAddress; + + public String getExternalReferenceCode() { + return externalReferenceCode; + } + + public void setExternalReferenceCode(String externalReferenceCode) { + this.externalReferenceCode = externalReferenceCode; + } + + public void setExternalReferenceCode( + UnsafeSupplier externalReferenceCodeUnsafeSupplier) { + + try { + externalReferenceCode = externalReferenceCodeUnsafeSupplier.get(); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected String externalReferenceCode; + public String getFamilyName() { return familyName; } @@ -189,6 +231,27 @@ public void setProfileURL( protected String profileURL; + public String getScreenName() { + return screenName; + } + + public void setScreenName(String screenName) { + this.screenName = screenName; + } + + public void setScreenName( + UnsafeSupplier screenNameUnsafeSupplier) { + + try { + screenName = screenNameUnsafeSupplier.get(); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected String screenName; + @Override public Creator clone() throws CloneNotSupportedException { return (Creator)super.clone(); diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/dto/v1_0/RoleBrief.java b/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/dto/v1_0/RoleBrief.java index 043357325a686d..6a1c5e42c97b47 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/dto/v1_0/RoleBrief.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/dto/v1_0/RoleBrief.java @@ -66,6 +66,25 @@ public void setId(UnsafeSupplier idUnsafeSupplier) { protected Long id; + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public void setKey(UnsafeSupplier keyUnsafeSupplier) { + try { + key = keyUnsafeSupplier.get(); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected String key; + public String getName() { return name; } diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/permission/Permission.java b/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/permission/Permission.java index 3aeec7b53b064e..a69dabd1802c28 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/permission/Permission.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/permission/Permission.java @@ -29,18 +29,34 @@ public Object[] getActionIds() { return actionIds; } + public String getRoleExternalReferenceCode() { + return roleExternalReferenceCode; + } + public String getRoleName() { return roleName; } + public String getRoleType() { + return roleType; + } + public void setActionIds(Object[] actionIds) { this.actionIds = actionIds; } + public void setRoleExternalReferenceCode(String roleExternalReferenceCode) { + this.roleExternalReferenceCode = roleExternalReferenceCode; + } + public void setRoleName(String roleName) { this.roleName = roleName; } + public void setRoleType(String roleType) { + this.roleType = roleType; + } + @Override public String toString() { StringBuilder sb = new StringBuilder(); @@ -63,6 +79,16 @@ public String toString() { sb.append("]"); } + if (roleExternalReferenceCode != null) { + if (sb.length() > 1) { + sb.append(", "); + } + + sb.append("\"roleExternalReferenceCode\": \""); + sb.append(roleExternalReferenceCode); + sb.append("\""); + } + if (roleName != null) { if (sb.length() > 1) { sb.append(", "); @@ -73,13 +99,25 @@ public String toString() { sb.append("\""); } + if (roleType != null) { + if (sb.length() > 1) { + sb.append(", "); + } + + sb.append("\"roleType\": \""); + sb.append(roleType); + sb.append("\""); + } + sb.append("}"); return sb.toString(); } protected Object[] actionIds; + protected String roleExternalReferenceCode; protected String roleName; + protected String roleType; private static class PermissionJSONParser extends BaseJSONParser { @@ -99,9 +137,17 @@ protected boolean parseMaps(String jsonParserFieldName) { if (Objects.equals(jsonParserFieldName, "actionIds")) { return false; } + else if (Objects.equals( + jsonParserFieldName, "roleExternalReferenceCode")) { + + return false; + } else if (Objects.equals(jsonParserFieldName, "roleName")) { return false; } + else if (Objects.equals(jsonParserFieldName, "roleType")) { + return false; + } else { throw new IllegalArgumentException( "Unsupported field name " + jsonParserFieldName); @@ -118,11 +164,24 @@ protected void setField( permission.setActionIds((Object[])jsonParserFieldValue); } } + else if (Objects.equals( + jsonParserFieldName, "roleExternalReferenceCode")) { + + if (jsonParserFieldValue != null) { + permission.setRoleExternalReferenceCode( + (String)jsonParserFieldValue); + } + } else if (Objects.equals(jsonParserFieldName, "roleName")) { if (jsonParserFieldValue != null) { permission.setRoleName((String)jsonParserFieldValue); } } + else if (Objects.equals(jsonParserFieldName, "roleType")) { + if (jsonParserFieldValue != null) { + permission.setRoleType((String)jsonParserFieldValue); + } + } else { throw new IllegalArgumentException( "Unsupported field name " + jsonParserFieldName); diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/serdes/v1_0/AccountBriefSerDes.java b/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/serdes/v1_0/AccountBriefSerDes.java index d5c5f82c9a5497..410b2ed2bcd1c0 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/serdes/v1_0/AccountBriefSerDes.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/serdes/v1_0/AccountBriefSerDes.java @@ -105,6 +105,20 @@ public static String toJSON(AccountBrief accountBrief) { sb.append("]"); } + if (accountBrief.getType() != null) { + if (sb.length() > 1) { + sb.append(", "); + } + + sb.append("\"type\": "); + + sb.append("\""); + + sb.append(_escape(accountBrief.getType())); + + sb.append("\""); + } + sb.append("}"); return sb.toString(); @@ -154,6 +168,13 @@ public static Map toMap(AccountBrief accountBrief) { map.put("roleBriefs", String.valueOf(accountBrief.getRoleBriefs())); } + if (accountBrief.getType() == null) { + map.put("type", null); + } + else { + map.put("type", String.valueOf(accountBrief.getType())); + } + return map; } @@ -184,6 +205,9 @@ else if (Objects.equals(jsonParserFieldName, "name")) { else if (Objects.equals(jsonParserFieldName, "roleBriefs")) { return false; } + else if (Objects.equals(jsonParserFieldName, "type")) { + return false; + } return false; } @@ -226,6 +250,11 @@ else if (Objects.equals(jsonParserFieldName, "roleBriefs")) { accountBrief.setRoleBriefs(roleBriefsArray); } } + else if (Objects.equals(jsonParserFieldName, "type")) { + if (jsonParserFieldValue != null) { + accountBrief.setType((String)jsonParserFieldValue); + } + } } } diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/serdes/v1_0/CreatorSerDes.java b/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/serdes/v1_0/CreatorSerDes.java index 0ffeeb6fedb50f..a982672cb3734c 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/serdes/v1_0/CreatorSerDes.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/serdes/v1_0/CreatorSerDes.java @@ -72,6 +72,34 @@ public static String toJSON(Creator creator) { sb.append("\""); } + if (creator.getEmailAddress() != null) { + if (sb.length() > 1) { + sb.append(", "); + } + + sb.append("\"emailAddress\": "); + + sb.append("\""); + + sb.append(_escape(creator.getEmailAddress())); + + sb.append("\""); + } + + if (creator.getExternalReferenceCode() != null) { + if (sb.length() > 1) { + sb.append(", "); + } + + sb.append("\"externalReferenceCode\": "); + + sb.append("\""); + + sb.append(_escape(creator.getExternalReferenceCode())); + + sb.append("\""); + } + if (creator.getFamilyName() != null) { if (sb.length() > 1) { sb.append(", "); @@ -152,6 +180,20 @@ public static String toJSON(Creator creator) { sb.append("\""); } + if (creator.getScreenName() != null) { + if (sb.length() > 1) { + sb.append(", "); + } + + sb.append("\"screenName\": "); + + sb.append("\""); + + sb.append(_escape(creator.getScreenName())); + + sb.append("\""); + } + sb.append("}"); return sb.toString(); @@ -185,6 +227,22 @@ public static Map toMap(Creator creator) { map.put("contentType", String.valueOf(creator.getContentType())); } + if (creator.getEmailAddress() == null) { + map.put("emailAddress", null); + } + else { + map.put("emailAddress", String.valueOf(creator.getEmailAddress())); + } + + if (creator.getExternalReferenceCode() == null) { + map.put("externalReferenceCode", null); + } + else { + map.put( + "externalReferenceCode", + String.valueOf(creator.getExternalReferenceCode())); + } + if (creator.getFamilyName() == null) { map.put("familyName", null); } @@ -227,6 +285,13 @@ public static Map toMap(Creator creator) { map.put("profileURL", String.valueOf(creator.getProfileURL())); } + if (creator.getScreenName() == null) { + map.put("screenName", null); + } + else { + map.put("screenName", String.valueOf(creator.getScreenName())); + } + return map; } @@ -250,6 +315,14 @@ protected boolean parseMaps(String jsonParserFieldName) { else if (Objects.equals(jsonParserFieldName, "contentType")) { return false; } + else if (Objects.equals(jsonParserFieldName, "emailAddress")) { + return false; + } + else if (Objects.equals( + jsonParserFieldName, "externalReferenceCode")) { + + return false; + } else if (Objects.equals(jsonParserFieldName, "familyName")) { return false; } @@ -268,6 +341,9 @@ else if (Objects.equals(jsonParserFieldName, "name")) { else if (Objects.equals(jsonParserFieldName, "profileURL")) { return false; } + else if (Objects.equals(jsonParserFieldName, "screenName")) { + return false; + } return false; } @@ -287,6 +363,19 @@ else if (Objects.equals(jsonParserFieldName, "contentType")) { creator.setContentType((String)jsonParserFieldValue); } } + else if (Objects.equals(jsonParserFieldName, "emailAddress")) { + if (jsonParserFieldValue != null) { + creator.setEmailAddress((String)jsonParserFieldValue); + } + } + else if (Objects.equals( + jsonParserFieldName, "externalReferenceCode")) { + + if (jsonParserFieldValue != null) { + creator.setExternalReferenceCode( + (String)jsonParserFieldValue); + } + } else if (Objects.equals(jsonParserFieldName, "familyName")) { if (jsonParserFieldValue != null) { creator.setFamilyName((String)jsonParserFieldValue); @@ -317,6 +406,11 @@ else if (Objects.equals(jsonParserFieldName, "profileURL")) { creator.setProfileURL((String)jsonParserFieldValue); } } + else if (Objects.equals(jsonParserFieldName, "screenName")) { + if (jsonParserFieldValue != null) { + creator.setScreenName((String)jsonParserFieldValue); + } + } } } diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/serdes/v1_0/RoleBriefSerDes.java b/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/serdes/v1_0/RoleBriefSerDes.java index e32f60d32f83d4..ca7b9fcce845b8 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/serdes/v1_0/RoleBriefSerDes.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/serdes/v1_0/RoleBriefSerDes.java @@ -68,6 +68,20 @@ public static String toJSON(RoleBrief roleBrief) { sb.append(roleBrief.getId()); } + if (roleBrief.getKey() != null) { + if (sb.length() > 1) { + sb.append(", "); + } + + sb.append("\"key\": "); + + sb.append("\""); + + sb.append(_escape(roleBrief.getKey())); + + sb.append("\""); + } + if (roleBrief.getName() != null) { if (sb.length() > 1) { sb.append(", "); @@ -136,6 +150,13 @@ public static Map toMap(RoleBrief roleBrief) { map.put("id", String.valueOf(roleBrief.getId())); } + if (roleBrief.getKey() == null) { + map.put("key", null); + } + else { + map.put("key", String.valueOf(roleBrief.getKey())); + } + if (roleBrief.getName() == null) { map.put("name", null); } @@ -180,6 +201,9 @@ protected boolean parseMaps(String jsonParserFieldName) { else if (Objects.equals(jsonParserFieldName, "id")) { return false; } + else if (Objects.equals(jsonParserFieldName, "key")) { + return false; + } else if (Objects.equals(jsonParserFieldName, "name")) { return false; } @@ -209,6 +233,11 @@ else if (Objects.equals(jsonParserFieldName, "id")) { roleBrief.setId(Long.valueOf((String)jsonParserFieldValue)); } } + else if (Objects.equals(jsonParserFieldName, "key")) { + if (jsonParserFieldValue != null) { + roleBrief.setKey((String)jsonParserFieldValue); + } + } else if (Objects.equals(jsonParserFieldName, "name")) { if (jsonParserFieldValue != null) { roleBrief.setName((String)jsonParserFieldValue); diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseAccountGroupResourceImpl.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseAccountGroupResourceImpl.java index bab406c33d2ddd..4851a2dec47971 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseAccountGroupResourceImpl.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseAccountGroupResourceImpl.java @@ -7,6 +7,7 @@ import com.liferay.headless.admin.user.dto.v1_0.AccountGroup; import com.liferay.headless.admin.user.resource.v1_0.AccountGroupResource; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.function.UnsafeBiConsumer; import com.liferay.petra.function.UnsafeConsumer; import com.liferay.petra.function.UnsafeFunction; @@ -205,7 +206,7 @@ public Response postAccountGroupsPageExportBatch( /** * Invoke this method with the command line: * - * curl -X 'POST' 'http://localhost:8080/o/headless-admin-user/v1.0/account-groups' -d $'{"customFields": ___, "description": ___, "externalReferenceCode": ___, "name": ___, "permissions": ___}' --header 'Content-Type: application/json' -u 'test@liferay.com:test' + * curl -X 'POST' 'http://localhost:8080/o/headless-admin-user/v1.0/account-groups' -d $'{"accountBriefs": ___, "creator": ___, "customFields": ___, "description": ___, "externalReferenceCode": ___, "name": ___, "permissions": ___}' --header 'Content-Type: application/json' -u 'test@liferay.com:test' */ @io.swagger.v3.oas.annotations.Operation( description = "Creates a new account group" @@ -420,7 +421,7 @@ public AccountGroup getAccountGroupByExternalReferenceCode( /** * Invoke this method with the command line: * - * curl -X 'PATCH' 'http://localhost:8080/o/headless-admin-user/v1.0/account-groups/by-external-reference-code/{externalReferenceCode}' -d $'{"customFields": ___, "description": ___, "externalReferenceCode": ___, "name": ___, "permissions": ___}' --header 'Content-Type: application/json' -u 'test@liferay.com:test' + * curl -X 'PATCH' 'http://localhost:8080/o/headless-admin-user/v1.0/account-groups/by-external-reference-code/{externalReferenceCode}' -d $'{"accountBriefs": ___, "creator": ___, "customFields": ___, "description": ___, "externalReferenceCode": ___, "name": ___, "permissions": ___}' --header 'Content-Type: application/json' -u 'test@liferay.com:test' */ @io.swagger.v3.oas.annotations.Operation( description = "Updates the account with information sent in the request body. Only the provided fields are updated." @@ -482,7 +483,7 @@ public AccountGroup patchAccountGroupByExternalReferenceCode( /** * Invoke this method with the command line: * - * curl -X 'PUT' 'http://localhost:8080/o/headless-admin-user/v1.0/account-groups/by-external-reference-code/{externalReferenceCode}' -d $'{"customFields": ___, "description": ___, "externalReferenceCode": ___, "name": ___, "permissions": ___}' --header 'Content-Type: application/json' -u 'test@liferay.com:test' + * curl -X 'PUT' 'http://localhost:8080/o/headless-admin-user/v1.0/account-groups/by-external-reference-code/{externalReferenceCode}' -d $'{"accountBriefs": ___, "creator": ___, "customFields": ___, "description": ___, "externalReferenceCode": ___, "name": ___, "permissions": ___}' --header 'Content-Type: application/json' -u 'test@liferay.com:test' */ @io.swagger.v3.oas.annotations.Operation( description = "Replaces the account group with information sent in the request body. Any missing fields are deleted unless they are required." @@ -624,7 +625,7 @@ public AccountGroup getAccountGroup( /** * Invoke this method with the command line: * - * curl -X 'PATCH' 'http://localhost:8080/o/headless-admin-user/v1.0/account-groups/{accountGroupId}' -d $'{"customFields": ___, "description": ___, "externalReferenceCode": ___, "name": ___, "permissions": ___}' --header 'Content-Type: application/json' -u 'test@liferay.com:test' + * curl -X 'PATCH' 'http://localhost:8080/o/headless-admin-user/v1.0/account-groups/{accountGroupId}' -d $'{"accountBriefs": ___, "creator": ___, "customFields": ___, "description": ___, "externalReferenceCode": ___, "name": ___, "permissions": ___}' --header 'Content-Type: application/json' -u 'test@liferay.com:test' */ @io.swagger.v3.oas.annotations.Operation( description = "Updates the account group with information sent in the request body. Only the provided fields are updated." @@ -682,7 +683,7 @@ public AccountGroup patchAccountGroup( /** * Invoke this method with the command line: * - * curl -X 'PUT' 'http://localhost:8080/o/headless-admin-user/v1.0/account-groups/{accountGroupId}' -d $'{"customFields": ___, "description": ___, "externalReferenceCode": ___, "name": ___, "permissions": ___}' --header 'Content-Type: application/json' -u 'test@liferay.com:test' + * curl -X 'PUT' 'http://localhost:8080/o/headless-admin-user/v1.0/account-groups/{accountGroupId}' -d $'{"accountBriefs": ___, "creator": ___, "customFields": ___, "description": ___, "externalReferenceCode": ___, "name": ___, "permissions": ___}' --header 'Content-Type: application/json' -u 'test@liferay.com:test' */ @io.swagger.v3.oas.annotations.Operation( description = "Replaces the account group with information sent in the request body. Any missing fields are deleted unless they are required." @@ -915,71 +916,82 @@ public void create( Map parameters) throws Exception { - UnsafeFunction - accountGroupUnsafeFunction = null; + try { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); - String createStrategy = (String)parameters.getOrDefault( - "createStrategy", "INSERT"); + UnsafeFunction + accountGroupUnsafeFunction = null; - if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { - accountGroupUnsafeFunction = accountGroup -> postAccountGroup( - accountGroup); - } - - if (StringUtil.equalsIgnoreCase(createStrategy, "UPSERT")) { - String updateStrategy = (String)parameters.getOrDefault( - "updateStrategy", "UPDATE"); + String createStrategy = (String)parameters.getOrDefault( + "createStrategy", "INSERT"); - if (StringUtil.equalsIgnoreCase(updateStrategy, "UPDATE")) { - accountGroupUnsafeFunction = - accountGroup -> putAccountGroupByExternalReferenceCode( - accountGroup.getExternalReferenceCode(), accountGroup); + if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { + accountGroupUnsafeFunction = accountGroup -> postAccountGroup( + accountGroup); } - if (StringUtil.equalsIgnoreCase(updateStrategy, "PARTIAL_UPDATE")) { - accountGroupUnsafeFunction = accountGroup -> { - AccountGroup persistedAccountGroup = null; - - try { - AccountGroup getAccountGroup = - getAccountGroupByExternalReferenceCode( - accountGroup.getExternalReferenceCode()); - - persistedAccountGroup = patchAccountGroup( - getAccountGroup.getId() != null ? - getAccountGroup.getId() : - _parseLong( - (String)parameters.get( - "accountGroupId")), - accountGroup); - } - catch (NoSuchModelException noSuchModelException) { - persistedAccountGroup = postAccountGroup(accountGroup); - } + if (StringUtil.equalsIgnoreCase(createStrategy, "UPSERT")) { + String updateStrategy = (String)parameters.getOrDefault( + "updateStrategy", "UPDATE"); - return persistedAccountGroup; - }; + if (StringUtil.equalsIgnoreCase(updateStrategy, "UPDATE")) { + accountGroupUnsafeFunction = + accountGroup -> putAccountGroupByExternalReferenceCode( + accountGroup.getExternalReferenceCode(), + accountGroup); + } + + if (StringUtil.equalsIgnoreCase( + updateStrategy, "PARTIAL_UPDATE")) { + + accountGroupUnsafeFunction = accountGroup -> { + AccountGroup persistedAccountGroup = null; + + try { + AccountGroup getAccountGroup = + getAccountGroupByExternalReferenceCode( + accountGroup.getExternalReferenceCode()); + + persistedAccountGroup = patchAccountGroup( + getAccountGroup.getId() != null ? + getAccountGroup.getId() : + _parseLong( + (String)parameters.get( + "accountGroupId")), + accountGroup); + } + catch (NoSuchModelException noSuchModelException) { + persistedAccountGroup = postAccountGroup( + accountGroup); + } + + return persistedAccountGroup; + }; + } } - } - if (accountGroupUnsafeFunction == null) { - throw new NotSupportedException( - "Create strategy \"" + createStrategy + - "\" is not supported for AccountGroup"); - } + if (accountGroupUnsafeFunction == null) { + throw new NotSupportedException( + "Create strategy \"" + createStrategy + + "\" is not supported for AccountGroup"); + } - if (contextBatchUnsafeBiConsumer != null) { - contextBatchUnsafeBiConsumer.accept( - accountGroups, accountGroupUnsafeFunction); - } - else if (contextBatchUnsafeConsumer != null) { - contextBatchUnsafeConsumer.accept( - accountGroups, accountGroupUnsafeFunction::apply); - } - else { - for (AccountGroup accountGroup : accountGroups) { - accountGroupUnsafeFunction.apply(accountGroup); + if (contextBatchUnsafeBiConsumer != null) { + contextBatchUnsafeBiConsumer.accept( + accountGroups, accountGroupUnsafeFunction); } + else if (contextBatchUnsafeConsumer != null) { + contextBatchUnsafeConsumer.accept( + accountGroups, accountGroupUnsafeFunction::apply); + } + else { + for (AccountGroup accountGroup : accountGroups) { + accountGroupUnsafeFunction.apply(accountGroup); + } + } + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); } } diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseAccountResourceImpl.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseAccountResourceImpl.java index c0ca9ca1f0e63a..e9852fe407cc3a 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseAccountResourceImpl.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseAccountResourceImpl.java @@ -7,6 +7,7 @@ import com.liferay.headless.admin.user.dto.v1_0.Account; import com.liferay.headless.admin.user.resource.v1_0.AccountResource; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.function.UnsafeBiConsumer; import com.liferay.petra.function.UnsafeConsumer; import com.liferay.petra.function.UnsafeFunction; @@ -1625,66 +1626,79 @@ public void create( Collection accounts, Map parameters) throws Exception { - UnsafeFunction accountUnsafeFunction = - null; + try { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); - String createStrategy = (String)parameters.getOrDefault( - "createStrategy", "INSERT"); + UnsafeFunction accountUnsafeFunction = + null; - if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { - accountUnsafeFunction = account -> postAccount(account); - } + String createStrategy = (String)parameters.getOrDefault( + "createStrategy", "INSERT"); - if (StringUtil.equalsIgnoreCase(createStrategy, "UPSERT")) { - String updateStrategy = (String)parameters.getOrDefault( - "updateStrategy", "UPDATE"); - - if (StringUtil.equalsIgnoreCase(updateStrategy, "UPDATE")) { - accountUnsafeFunction = - account -> putAccountByExternalReferenceCode( - account.getExternalReferenceCode(), account); + if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { + accountUnsafeFunction = account -> postAccount(account); } - if (StringUtil.equalsIgnoreCase(updateStrategy, "PARTIAL_UPDATE")) { - accountUnsafeFunction = account -> { - Account persistedAccount = null; - - try { - Account getAccount = getAccountByExternalReferenceCode( - account.getExternalReferenceCode()); - - persistedAccount = patchAccount( - getAccount.getId() != null ? getAccount.getId() : - _parseLong((String)parameters.get("accountId")), - account); - } - catch (NoSuchModelException noSuchModelException) { - persistedAccount = postAccount(account); - } - - return persistedAccount; - }; + if (StringUtil.equalsIgnoreCase(createStrategy, "UPSERT")) { + String updateStrategy = (String)parameters.getOrDefault( + "updateStrategy", "UPDATE"); + + if (StringUtil.equalsIgnoreCase(updateStrategy, "UPDATE")) { + accountUnsafeFunction = + account -> putAccountByExternalReferenceCode( + account.getExternalReferenceCode(), account); + } + + if (StringUtil.equalsIgnoreCase( + updateStrategy, "PARTIAL_UPDATE")) { + + accountUnsafeFunction = account -> { + Account persistedAccount = null; + + try { + Account getAccount = + getAccountByExternalReferenceCode( + account.getExternalReferenceCode()); + + persistedAccount = patchAccount( + getAccount.getId() != null ? + getAccount.getId() : + _parseLong( + (String)parameters.get( + "accountId")), + account); + } + catch (NoSuchModelException noSuchModelException) { + persistedAccount = postAccount(account); + } + + return persistedAccount; + }; + } } - } - if (accountUnsafeFunction == null) { - throw new NotSupportedException( - "Create strategy \"" + createStrategy + - "\" is not supported for Account"); - } + if (accountUnsafeFunction == null) { + throw new NotSupportedException( + "Create strategy \"" + createStrategy + + "\" is not supported for Account"); + } - if (contextBatchUnsafeBiConsumer != null) { - contextBatchUnsafeBiConsumer.accept( - accounts, accountUnsafeFunction); - } - else if (contextBatchUnsafeConsumer != null) { - contextBatchUnsafeConsumer.accept( - accounts, accountUnsafeFunction::apply); - } - else { - for (Account account : accounts) { - accountUnsafeFunction.apply(account); + if (contextBatchUnsafeBiConsumer != null) { + contextBatchUnsafeBiConsumer.accept( + accounts, accountUnsafeFunction); } + else if (contextBatchUnsafeConsumer != null) { + contextBatchUnsafeConsumer.accept( + accounts, accountUnsafeFunction::apply); + } + else { + for (Account account : accounts) { + accountUnsafeFunction.apply(account); + } + } + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); } } diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseAccountRoleResourceImpl.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseAccountRoleResourceImpl.java index a134cf2b5561a1..295d06c303b47f 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseAccountRoleResourceImpl.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseAccountRoleResourceImpl.java @@ -7,6 +7,7 @@ import com.liferay.headless.admin.user.dto.v1_0.AccountRole; import com.liferay.headless.admin.user.resource.v1_0.AccountRoleResource; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.function.UnsafeBiConsumer; import com.liferay.petra.function.UnsafeConsumer; import com.liferay.petra.function.UnsafeFunction; @@ -993,43 +994,50 @@ public void create( Map parameters) throws Exception { - UnsafeFunction - accountRoleUnsafeFunction = null; + try { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); + + UnsafeFunction + accountRoleUnsafeFunction = null; + + String createStrategy = (String)parameters.getOrDefault( + "createStrategy", "INSERT"); + + if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { + if (parameters.containsKey("accountId")) { + accountRoleUnsafeFunction = + accountRole -> postAccountAccountRole( + _parseLong((String)parameters.get("accountId")), + accountRole); + } + else { + throw new NotSupportedException( + "One of the following parameters must be specified: [accountId]"); + } + } - String createStrategy = (String)parameters.getOrDefault( - "createStrategy", "INSERT"); + if (accountRoleUnsafeFunction == null) { + throw new NotSupportedException( + "Create strategy \"" + createStrategy + + "\" is not supported for AccountRole"); + } - if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { - if (parameters.containsKey("accountId")) { - accountRoleUnsafeFunction = - accountRole -> postAccountAccountRole( - _parseLong((String)parameters.get("accountId")), - accountRole); + if (contextBatchUnsafeBiConsumer != null) { + contextBatchUnsafeBiConsumer.accept( + accountRoles, accountRoleUnsafeFunction); + } + else if (contextBatchUnsafeConsumer != null) { + contextBatchUnsafeConsumer.accept( + accountRoles, accountRoleUnsafeFunction::apply); } else { - throw new NotSupportedException( - "One of the following parameters must be specified: [accountId]"); + for (AccountRole accountRole : accountRoles) { + accountRoleUnsafeFunction.apply(accountRole); + } } } - - if (accountRoleUnsafeFunction == null) { - throw new NotSupportedException( - "Create strategy \"" + createStrategy + - "\" is not supported for AccountRole"); - } - - if (contextBatchUnsafeBiConsumer != null) { - contextBatchUnsafeBiConsumer.accept( - accountRoles, accountRoleUnsafeFunction); - } - else if (contextBatchUnsafeConsumer != null) { - contextBatchUnsafeConsumer.accept( - accountRoles, accountRoleUnsafeFunction::apply); - } - else { - for (AccountRole accountRole : accountRoles) { - accountRoleUnsafeFunction.apply(accountRole); - } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); } } diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseEmailAddressResourceImpl.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseEmailAddressResourceImpl.java index c800af0de95a6c..46456650084d01 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseEmailAddressResourceImpl.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseEmailAddressResourceImpl.java @@ -7,6 +7,7 @@ import com.liferay.headless.admin.user.dto.v1_0.EmailAddress; import com.liferay.headless.admin.user.resource.v1_0.EmailAddressResource; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.function.UnsafeBiConsumer; import com.liferay.petra.function.UnsafeConsumer; import com.liferay.petra.function.UnsafeFunction; @@ -745,8 +746,15 @@ public void create( Map parameters) throws Exception { - throw new UnsupportedOperationException( - "This method needs to be implemented"); + try { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); + + throw new UnsupportedOperationException( + "This method needs to be implemented"); + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); + } } @Override diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseOrganizationResourceImpl.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseOrganizationResourceImpl.java index 79488fcc2f837d..68bcde4e1782c3 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseOrganizationResourceImpl.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseOrganizationResourceImpl.java @@ -8,6 +8,7 @@ import com.liferay.headless.admin.user.dto.v1_0.Organization; import com.liferay.headless.admin.user.dto.v1_0.UserAccount; import com.liferay.headless.admin.user.resource.v1_0.OrganizationResource; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.function.UnsafeBiConsumer; import com.liferay.petra.function.UnsafeConsumer; import com.liferay.petra.function.UnsafeFunction; @@ -1680,69 +1681,81 @@ public void create( Map parameters) throws Exception { - UnsafeFunction - organizationUnsafeFunction = null; + try { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); - String createStrategy = (String)parameters.getOrDefault( - "createStrategy", "INSERT"); + UnsafeFunction + organizationUnsafeFunction = null; - if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { - organizationUnsafeFunction = organization -> postOrganization( - organization); - } - - if (StringUtil.equalsIgnoreCase(createStrategy, "UPSERT")) { - String updateStrategy = (String)parameters.getOrDefault( - "updateStrategy", "UPDATE"); + String createStrategy = (String)parameters.getOrDefault( + "createStrategy", "INSERT"); - if (StringUtil.equalsIgnoreCase(updateStrategy, "UPDATE")) { - organizationUnsafeFunction = - organization -> putOrganizationByExternalReferenceCode( - organization.getExternalReferenceCode(), organization); + if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { + organizationUnsafeFunction = organization -> postOrganization( + organization); } - if (StringUtil.equalsIgnoreCase(updateStrategy, "PARTIAL_UPDATE")) { - organizationUnsafeFunction = organization -> { - Organization persistedOrganization = null; - - try { - Organization getOrganization = - getOrganizationByExternalReferenceCode( - organization.getExternalReferenceCode()); + if (StringUtil.equalsIgnoreCase(createStrategy, "UPSERT")) { + String updateStrategy = (String)parameters.getOrDefault( + "updateStrategy", "UPDATE"); - persistedOrganization = patchOrganization( - getOrganization.getId() != null ? - getOrganization.getId() : - (String)parameters.get("organizationId"), + if (StringUtil.equalsIgnoreCase(updateStrategy, "UPDATE")) { + organizationUnsafeFunction = + organization -> putOrganizationByExternalReferenceCode( + organization.getExternalReferenceCode(), organization); - } - catch (NoSuchModelException noSuchModelException) { - persistedOrganization = postOrganization(organization); - } - - return persistedOrganization; - }; + } + + if (StringUtil.equalsIgnoreCase( + updateStrategy, "PARTIAL_UPDATE")) { + + organizationUnsafeFunction = organization -> { + Organization persistedOrganization = null; + + try { + Organization getOrganization = + getOrganizationByExternalReferenceCode( + organization.getExternalReferenceCode()); + + persistedOrganization = patchOrganization( + getOrganization.getId() != null ? + getOrganization.getId() : + (String)parameters.get( + "organizationId"), + organization); + } + catch (NoSuchModelException noSuchModelException) { + persistedOrganization = postOrganization( + organization); + } + + return persistedOrganization; + }; + } } - } - if (organizationUnsafeFunction == null) { - throw new NotSupportedException( - "Create strategy \"" + createStrategy + - "\" is not supported for Organization"); - } + if (organizationUnsafeFunction == null) { + throw new NotSupportedException( + "Create strategy \"" + createStrategy + + "\" is not supported for Organization"); + } - if (contextBatchUnsafeBiConsumer != null) { - contextBatchUnsafeBiConsumer.accept( - organizations, organizationUnsafeFunction); - } - else if (contextBatchUnsafeConsumer != null) { - contextBatchUnsafeConsumer.accept( - organizations, organizationUnsafeFunction::apply); - } - else { - for (Organization organization : organizations) { - organizationUnsafeFunction.apply(organization); + if (contextBatchUnsafeBiConsumer != null) { + contextBatchUnsafeBiConsumer.accept( + organizations, organizationUnsafeFunction); } + else if (contextBatchUnsafeConsumer != null) { + contextBatchUnsafeConsumer.accept( + organizations, organizationUnsafeFunction::apply); + } + else { + for (Organization organization : organizations) { + organizationUnsafeFunction.apply(organization); + } + } + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); } } diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BasePhoneResourceImpl.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BasePhoneResourceImpl.java index 8b402c5588c25d..c2378d157794da 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BasePhoneResourceImpl.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BasePhoneResourceImpl.java @@ -7,6 +7,7 @@ import com.liferay.headless.admin.user.dto.v1_0.Phone; import com.liferay.headless.admin.user.resource.v1_0.PhoneResource; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.function.UnsafeBiConsumer; import com.liferay.petra.function.UnsafeConsumer; import com.liferay.petra.function.UnsafeFunction; @@ -734,8 +735,15 @@ public void create( Collection phones, Map parameters) throws Exception { - throw new UnsupportedOperationException( - "This method needs to be implemented"); + try { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); + + throw new UnsupportedOperationException( + "This method needs to be implemented"); + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); + } } @Override diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BasePostalAddressResourceImpl.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BasePostalAddressResourceImpl.java index db6a9cfe1c6d54..54edbf22963e74 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BasePostalAddressResourceImpl.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BasePostalAddressResourceImpl.java @@ -7,6 +7,7 @@ import com.liferay.headless.admin.user.dto.v1_0.PostalAddress; import com.liferay.headless.admin.user.resource.v1_0.PostalAddressResource; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.function.UnsafeBiConsumer; import com.liferay.petra.function.UnsafeConsumer; import com.liferay.petra.function.UnsafeFunction; @@ -1116,88 +1117,101 @@ public void create( Map parameters) throws Exception { - UnsafeFunction - postalAddressUnsafeFunction = null; + try { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); - String createStrategy = (String)parameters.getOrDefault( - "createStrategy", "INSERT"); + UnsafeFunction + postalAddressUnsafeFunction = null; - if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { - if (parameters.containsKey("accountId")) { - postalAddressUnsafeFunction = - postalAddress -> postAccountPostalAddress( - _parseLong((String)parameters.get("accountId")), - postalAddress); - } - else { - throw new NotSupportedException( - "One of the following parameters must be specified: [accountId]"); + String createStrategy = (String)parameters.getOrDefault( + "createStrategy", "INSERT"); + + if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { + if (parameters.containsKey("accountId")) { + postalAddressUnsafeFunction = + postalAddress -> postAccountPostalAddress( + _parseLong((String)parameters.get("accountId")), + postalAddress); + } + else { + throw new NotSupportedException( + "One of the following parameters must be specified: [accountId]"); + } } - } - if (StringUtil.equalsIgnoreCase(createStrategy, "UPSERT")) { - String updateStrategy = (String)parameters.getOrDefault( - "updateStrategy", "UPDATE"); + if (StringUtil.equalsIgnoreCase(createStrategy, "UPSERT")) { + String updateStrategy = (String)parameters.getOrDefault( + "updateStrategy", "UPDATE"); - if (StringUtil.equalsIgnoreCase(updateStrategy, "UPDATE")) { - postalAddressUnsafeFunction = - postalAddress -> putPostalAddressByExternalReferenceCode( - postalAddress.getExternalReferenceCode(), - postalAddress); - } + if (StringUtil.equalsIgnoreCase(updateStrategy, "UPDATE")) { + postalAddressUnsafeFunction = + postalAddress -> + putPostalAddressByExternalReferenceCode( + postalAddress.getExternalReferenceCode(), + postalAddress); + } - if (StringUtil.equalsIgnoreCase(updateStrategy, "PARTIAL_UPDATE")) { - postalAddressUnsafeFunction = postalAddress -> { - PostalAddress persistedPostalAddress = null; - - try { - PostalAddress getPostalAddress = - getPostalAddressByExternalReferenceCode( - postalAddress.getExternalReferenceCode()); - - persistedPostalAddress = patchPostalAddress( - getPostalAddress.getId() != null ? - getPostalAddress.getId() : - _parseLong( - (String)parameters.get( - "postalAddressId")), - postalAddress); - } - catch (NoSuchModelException noSuchModelException) { - if (parameters.containsKey("accountId")) { - persistedPostalAddress = postAccountPostalAddress( - _parseLong((String)parameters.get("accountId")), + if (StringUtil.equalsIgnoreCase( + updateStrategy, "PARTIAL_UPDATE")) { + + postalAddressUnsafeFunction = postalAddress -> { + PostalAddress persistedPostalAddress = null; + + try { + PostalAddress getPostalAddress = + getPostalAddressByExternalReferenceCode( + postalAddress.getExternalReferenceCode()); + + persistedPostalAddress = patchPostalAddress( + getPostalAddress.getId() != null ? + getPostalAddress.getId() : + _parseLong( + (String)parameters.get( + "postalAddressId")), postalAddress); } - else { - throw new NotSupportedException( - "One of the following parameters must be specified: [accountId]"); + catch (NoSuchModelException noSuchModelException) { + if (parameters.containsKey("accountId")) { + persistedPostalAddress = + postAccountPostalAddress( + _parseLong( + (String)parameters.get( + "accountId")), + postalAddress); + } + else { + throw new NotSupportedException( + "One of the following parameters must be specified: [accountId]"); + } } - } - return persistedPostalAddress; - }; + return persistedPostalAddress; + }; + } } - } - if (postalAddressUnsafeFunction == null) { - throw new NotSupportedException( - "Create strategy \"" + createStrategy + - "\" is not supported for PostalAddress"); - } + if (postalAddressUnsafeFunction == null) { + throw new NotSupportedException( + "Create strategy \"" + createStrategy + + "\" is not supported for PostalAddress"); + } - if (contextBatchUnsafeBiConsumer != null) { - contextBatchUnsafeBiConsumer.accept( - postalAddresses, postalAddressUnsafeFunction); - } - else if (contextBatchUnsafeConsumer != null) { - contextBatchUnsafeConsumer.accept( - postalAddresses, postalAddressUnsafeFunction::apply); - } - else { - for (PostalAddress postalAddress : postalAddresses) { - postalAddressUnsafeFunction.apply(postalAddress); + if (contextBatchUnsafeBiConsumer != null) { + contextBatchUnsafeBiConsumer.accept( + postalAddresses, postalAddressUnsafeFunction); } + else if (contextBatchUnsafeConsumer != null) { + contextBatchUnsafeConsumer.accept( + postalAddresses, postalAddressUnsafeFunction::apply); + } + else { + for (PostalAddress postalAddress : postalAddresses) { + postalAddressUnsafeFunction.apply(postalAddress); + } + } + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); } } diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseRoleResourceImpl.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseRoleResourceImpl.java index 714d69cda5c62d..ceb057499bdeab 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseRoleResourceImpl.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseRoleResourceImpl.java @@ -7,6 +7,7 @@ import com.liferay.headless.admin.user.dto.v1_0.Role; import com.liferay.headless.admin.user.resource.v1_0.RoleResource; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.function.UnsafeBiConsumer; import com.liferay.petra.function.UnsafeConsumer; import com.liferay.petra.function.UnsafeFunction; @@ -1265,62 +1266,73 @@ public void create( Collection roles, Map parameters) throws Exception { - UnsafeFunction roleUnsafeFunction = null; - - String createStrategy = (String)parameters.getOrDefault( - "createStrategy", "INSERT"); + try { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); - if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { - roleUnsafeFunction = role -> postRole(role); - } + UnsafeFunction roleUnsafeFunction = null; - if (StringUtil.equalsIgnoreCase(createStrategy, "UPSERT")) { - String updateStrategy = (String)parameters.getOrDefault( - "updateStrategy", "UPDATE"); + String createStrategy = (String)parameters.getOrDefault( + "createStrategy", "INSERT"); - if (StringUtil.equalsIgnoreCase(updateStrategy, "UPDATE")) { - roleUnsafeFunction = role -> putRoleByExternalReferenceCode( - role.getExternalReferenceCode(), role); + if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { + roleUnsafeFunction = role -> postRole(role); } - if (StringUtil.equalsIgnoreCase(updateStrategy, "PARTIAL_UPDATE")) { - roleUnsafeFunction = role -> { - Role persistedRole = null; - - try { - Role getRole = getRoleByExternalReferenceCode( - role.getExternalReferenceCode()); - - persistedRole = patchRole( - getRole.getId() != null ? getRole.getId() : - _parseLong((String)parameters.get("roleId")), - role); - } - catch (NoSuchModelException noSuchModelException) { - persistedRole = postRole(role); - } - - return persistedRole; - }; + if (StringUtil.equalsIgnoreCase(createStrategy, "UPSERT")) { + String updateStrategy = (String)parameters.getOrDefault( + "updateStrategy", "UPDATE"); + + if (StringUtil.equalsIgnoreCase(updateStrategy, "UPDATE")) { + roleUnsafeFunction = role -> putRoleByExternalReferenceCode( + role.getExternalReferenceCode(), role); + } + + if (StringUtil.equalsIgnoreCase( + updateStrategy, "PARTIAL_UPDATE")) { + + roleUnsafeFunction = role -> { + Role persistedRole = null; + + try { + Role getRole = getRoleByExternalReferenceCode( + role.getExternalReferenceCode()); + + persistedRole = patchRole( + getRole.getId() != null ? getRole.getId() : + _parseLong( + (String)parameters.get("roleId")), + role); + } + catch (NoSuchModelException noSuchModelException) { + persistedRole = postRole(role); + } + + return persistedRole; + }; + } } - } - if (roleUnsafeFunction == null) { - throw new NotSupportedException( - "Create strategy \"" + createStrategy + - "\" is not supported for Role"); - } + if (roleUnsafeFunction == null) { + throw new NotSupportedException( + "Create strategy \"" + createStrategy + + "\" is not supported for Role"); + } - if (contextBatchUnsafeBiConsumer != null) { - contextBatchUnsafeBiConsumer.accept(roles, roleUnsafeFunction); - } - else if (contextBatchUnsafeConsumer != null) { - contextBatchUnsafeConsumer.accept(roles, roleUnsafeFunction::apply); - } - else { - for (Role role : roles) { - roleUnsafeFunction.apply(role); + if (contextBatchUnsafeBiConsumer != null) { + contextBatchUnsafeBiConsumer.accept(roles, roleUnsafeFunction); + } + else if (contextBatchUnsafeConsumer != null) { + contextBatchUnsafeConsumer.accept( + roles, roleUnsafeFunction::apply); } + else { + for (Role role : roles) { + roleUnsafeFunction.apply(role); + } + } + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); } } diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseSegmentResourceImpl.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseSegmentResourceImpl.java index dccc224027096e..6f89ee8f190adf 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseSegmentResourceImpl.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseSegmentResourceImpl.java @@ -7,6 +7,7 @@ import com.liferay.headless.admin.user.dto.v1_0.Segment; import com.liferay.headless.admin.user.resource.v1_0.SegmentResource; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.function.UnsafeBiConsumer; import com.liferay.petra.function.UnsafeConsumer; import com.liferay.petra.function.UnsafeFunction; @@ -226,8 +227,15 @@ public void create( Collection segments, Map parameters) throws Exception { - throw new UnsupportedOperationException( - "This method needs to be implemented"); + try { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); + + throw new UnsupportedOperationException( + "This method needs to be implemented"); + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); + } } @Override diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseSegmentUserResourceImpl.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseSegmentUserResourceImpl.java index fec0aa243e4ecb..edec2aafbaffa9 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseSegmentUserResourceImpl.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseSegmentUserResourceImpl.java @@ -7,6 +7,7 @@ import com.liferay.headless.admin.user.dto.v1_0.SegmentUser; import com.liferay.headless.admin.user.resource.v1_0.SegmentUserResource; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.function.UnsafeBiConsumer; import com.liferay.petra.function.UnsafeConsumer; import com.liferay.petra.function.UnsafeFunction; @@ -116,8 +117,15 @@ public void create( Map parameters) throws Exception { - throw new UnsupportedOperationException( - "This method needs to be implemented"); + try { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); + + throw new UnsupportedOperationException( + "This method needs to be implemented"); + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); + } } @Override diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseSiteResourceImpl.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseSiteResourceImpl.java index d1103c6781b7c6..7bf928c056ff3c 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseSiteResourceImpl.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseSiteResourceImpl.java @@ -7,6 +7,7 @@ import com.liferay.headless.admin.user.dto.v1_0.Site; import com.liferay.headless.admin.user.resource.v1_0.SiteResource; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.function.UnsafeBiConsumer; import com.liferay.petra.function.UnsafeConsumer; import com.liferay.petra.function.UnsafeFunction; @@ -166,8 +167,15 @@ public void create( Collection sites, Map parameters) throws Exception { - throw new UnsupportedOperationException( - "This method needs to be implemented"); + try { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); + + throw new UnsupportedOperationException( + "This method needs to be implemented"); + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); + } } @Override diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseSubscriptionResourceImpl.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseSubscriptionResourceImpl.java index 4f17fac01c78d4..1aaba859a41402 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseSubscriptionResourceImpl.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseSubscriptionResourceImpl.java @@ -7,6 +7,7 @@ import com.liferay.headless.admin.user.dto.v1_0.Subscription; import com.liferay.headless.admin.user.resource.v1_0.SubscriptionResource; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.function.UnsafeBiConsumer; import com.liferay.petra.function.UnsafeConsumer; import com.liferay.petra.function.UnsafeFunction; @@ -170,8 +171,15 @@ public void create( Map parameters) throws Exception { - throw new UnsupportedOperationException( - "This method needs to be implemented"); + try { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); + + throw new UnsupportedOperationException( + "This method needs to be implemented"); + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); + } } @Override diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseUserAccountResourceImpl.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseUserAccountResourceImpl.java index f983affa4bce64..569c8ad15a17c2 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseUserAccountResourceImpl.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseUserAccountResourceImpl.java @@ -7,6 +7,7 @@ import com.liferay.headless.admin.user.dto.v1_0.UserAccount; import com.liferay.headless.admin.user.resource.v1_0.UserAccountResource; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.function.UnsafeBiConsumer; import com.liferay.petra.function.UnsafeConsumer; import com.liferay.petra.function.UnsafeFunction; @@ -2479,85 +2480,97 @@ public void create( Map parameters) throws Exception { - UnsafeFunction - userAccountUnsafeFunction = null; + try { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); - String createStrategy = (String)parameters.getOrDefault( - "createStrategy", "INSERT"); + UnsafeFunction + userAccountUnsafeFunction = null; - if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { - userAccountUnsafeFunction = userAccount -> postUserAccount( - userAccount); + String createStrategy = (String)parameters.getOrDefault( + "createStrategy", "INSERT"); + + if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { + userAccountUnsafeFunction = userAccount -> postUserAccount( + userAccount); - if (parameters.containsKey("accountId")) { - userAccountUnsafeFunction = - userAccount -> postAccountUserAccount( - _parseLong((String)parameters.get("accountId")), - userAccount); + if (parameters.containsKey("accountId")) { + userAccountUnsafeFunction = + userAccount -> postAccountUserAccount( + _parseLong((String)parameters.get("accountId")), + userAccount); + } } - } - if (StringUtil.equalsIgnoreCase(createStrategy, "UPSERT")) { - String updateStrategy = (String)parameters.getOrDefault( - "updateStrategy", "UPDATE"); + if (StringUtil.equalsIgnoreCase(createStrategy, "UPSERT")) { + String updateStrategy = (String)parameters.getOrDefault( + "updateStrategy", "UPDATE"); - if (StringUtil.equalsIgnoreCase(updateStrategy, "UPDATE")) { - userAccountUnsafeFunction = - userAccount -> putUserAccountByExternalReferenceCode( - userAccount.getExternalReferenceCode(), userAccount); - } + if (StringUtil.equalsIgnoreCase(updateStrategy, "UPDATE")) { + userAccountUnsafeFunction = + userAccount -> putUserAccountByExternalReferenceCode( + userAccount.getExternalReferenceCode(), + userAccount); + } - if (StringUtil.equalsIgnoreCase(updateStrategy, "PARTIAL_UPDATE")) { - userAccountUnsafeFunction = userAccount -> { - UserAccount persistedUserAccount = null; + if (StringUtil.equalsIgnoreCase( + updateStrategy, "PARTIAL_UPDATE")) { - try { - UserAccount getUserAccount = - getUserAccountByExternalReferenceCode( - userAccount.getExternalReferenceCode()); + userAccountUnsafeFunction = userAccount -> { + UserAccount persistedUserAccount = null; - persistedUserAccount = patchUserAccount( - getUserAccount.getId() != null ? - getUserAccount.getId() : - _parseLong( - (String)parameters.get( - "userAccountId")), - userAccount); - } - catch (NoSuchModelException noSuchModelException) { - if (parameters.containsKey("accountId")) { - persistedUserAccount = postAccountUserAccount( - _parseLong((String)parameters.get("accountId")), + try { + UserAccount getUserAccount = + getUserAccountByExternalReferenceCode( + userAccount.getExternalReferenceCode()); + + persistedUserAccount = patchUserAccount( + getUserAccount.getId() != null ? + getUserAccount.getId() : + _parseLong( + (String)parameters.get( + "userAccountId")), userAccount); } - else { - persistedUserAccount = postUserAccount(userAccount); + catch (NoSuchModelException noSuchModelException) { + if (parameters.containsKey("accountId")) { + persistedUserAccount = postAccountUserAccount( + _parseLong( + (String)parameters.get("accountId")), + userAccount); + } + else { + persistedUserAccount = postUserAccount( + userAccount); + } } - } - return persistedUserAccount; - }; + return persistedUserAccount; + }; + } } - } - if (userAccountUnsafeFunction == null) { - throw new NotSupportedException( - "Create strategy \"" + createStrategy + - "\" is not supported for UserAccount"); - } + if (userAccountUnsafeFunction == null) { + throw new NotSupportedException( + "Create strategy \"" + createStrategy + + "\" is not supported for UserAccount"); + } - if (contextBatchUnsafeBiConsumer != null) { - contextBatchUnsafeBiConsumer.accept( - userAccounts, userAccountUnsafeFunction); - } - else if (contextBatchUnsafeConsumer != null) { - contextBatchUnsafeConsumer.accept( - userAccounts, userAccountUnsafeFunction::apply); - } - else { - for (UserAccount userAccount : userAccounts) { - userAccountUnsafeFunction.apply(userAccount); + if (contextBatchUnsafeBiConsumer != null) { + contextBatchUnsafeBiConsumer.accept( + userAccounts, userAccountUnsafeFunction); + } + else if (contextBatchUnsafeConsumer != null) { + contextBatchUnsafeConsumer.accept( + userAccounts, userAccountUnsafeFunction::apply); } + else { + for (UserAccount userAccount : userAccounts) { + userAccountUnsafeFunction.apply(userAccount); + } + } + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); } } diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseUserGroupResourceImpl.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseUserGroupResourceImpl.java index 9c432a687622f7..fbe7b7866726ca 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseUserGroupResourceImpl.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseUserGroupResourceImpl.java @@ -7,6 +7,7 @@ import com.liferay.headless.admin.user.dto.v1_0.UserGroup; import com.liferay.headless.admin.user.resource.v1_0.UserGroupResource; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.function.UnsafeBiConsumer; import com.liferay.petra.function.UnsafeConsumer; import com.liferay.petra.function.UnsafeFunction; @@ -807,69 +808,79 @@ public void create( Map parameters) throws Exception { - UnsafeFunction - userGroupUnsafeFunction = null; + try { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); - String createStrategy = (String)parameters.getOrDefault( - "createStrategy", "INSERT"); + UnsafeFunction + userGroupUnsafeFunction = null; - if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { - userGroupUnsafeFunction = userGroup -> postUserGroup(userGroup); - } + String createStrategy = (String)parameters.getOrDefault( + "createStrategy", "INSERT"); - if (StringUtil.equalsIgnoreCase(createStrategy, "UPSERT")) { - String updateStrategy = (String)parameters.getOrDefault( - "updateStrategy", "UPDATE"); - - if (StringUtil.equalsIgnoreCase(updateStrategy, "UPDATE")) { - userGroupUnsafeFunction = - userGroup -> putUserGroupByExternalReferenceCode( - userGroup.getExternalReferenceCode(), userGroup); + if (StringUtil.equalsIgnoreCase(createStrategy, "INSERT")) { + userGroupUnsafeFunction = userGroup -> postUserGroup(userGroup); } - if (StringUtil.equalsIgnoreCase(updateStrategy, "PARTIAL_UPDATE")) { - userGroupUnsafeFunction = userGroup -> { - UserGroup persistedUserGroup = null; - - try { - UserGroup getUserGroup = - getUserGroupByExternalReferenceCode( - userGroup.getExternalReferenceCode()); - - persistedUserGroup = patchUserGroup( - getUserGroup.getId() != null ? - getUserGroup.getId() : - _parseLong( - (String)parameters.get("userGroupId")), - userGroup); - } - catch (NoSuchModelException noSuchModelException) { - persistedUserGroup = postUserGroup(userGroup); - } - - return persistedUserGroup; - }; + if (StringUtil.equalsIgnoreCase(createStrategy, "UPSERT")) { + String updateStrategy = (String)parameters.getOrDefault( + "updateStrategy", "UPDATE"); + + if (StringUtil.equalsIgnoreCase(updateStrategy, "UPDATE")) { + userGroupUnsafeFunction = + userGroup -> putUserGroupByExternalReferenceCode( + userGroup.getExternalReferenceCode(), userGroup); + } + + if (StringUtil.equalsIgnoreCase( + updateStrategy, "PARTIAL_UPDATE")) { + + userGroupUnsafeFunction = userGroup -> { + UserGroup persistedUserGroup = null; + + try { + UserGroup getUserGroup = + getUserGroupByExternalReferenceCode( + userGroup.getExternalReferenceCode()); + + persistedUserGroup = patchUserGroup( + getUserGroup.getId() != null ? + getUserGroup.getId() : + _parseLong( + (String)parameters.get( + "userGroupId")), + userGroup); + } + catch (NoSuchModelException noSuchModelException) { + persistedUserGroup = postUserGroup(userGroup); + } + + return persistedUserGroup; + }; + } } - } - if (userGroupUnsafeFunction == null) { - throw new NotSupportedException( - "Create strategy \"" + createStrategy + - "\" is not supported for UserGroup"); - } + if (userGroupUnsafeFunction == null) { + throw new NotSupportedException( + "Create strategy \"" + createStrategy + + "\" is not supported for UserGroup"); + } - if (contextBatchUnsafeBiConsumer != null) { - contextBatchUnsafeBiConsumer.accept( - userGroups, userGroupUnsafeFunction); - } - else if (contextBatchUnsafeConsumer != null) { - contextBatchUnsafeConsumer.accept( - userGroups, userGroupUnsafeFunction::apply); - } - else { - for (UserGroup userGroup : userGroups) { - userGroupUnsafeFunction.apply(userGroup); + if (contextBatchUnsafeBiConsumer != null) { + contextBatchUnsafeBiConsumer.accept( + userGroups, userGroupUnsafeFunction); } + else if (contextBatchUnsafeConsumer != null) { + contextBatchUnsafeConsumer.accept( + userGroups, userGroupUnsafeFunction::apply); + } + else { + for (UserGroup userGroup : userGroups) { + userGroupUnsafeFunction.apply(userGroup); + } + } + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); } } diff --git a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseWebUrlResourceImpl.java b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseWebUrlResourceImpl.java index 7e9f9d19999ef2..154c2d10c470b8 100644 --- a/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseWebUrlResourceImpl.java +++ b/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/resource/v1_0/BaseWebUrlResourceImpl.java @@ -7,6 +7,7 @@ import com.liferay.headless.admin.user.dto.v1_0.WebUrl; import com.liferay.headless.admin.user.resource.v1_0.WebUrlResource; +import com.liferay.lazy.referencing.kernel.LazyReferencingThreadLocal; import com.liferay.petra.function.UnsafeBiConsumer; import com.liferay.petra.function.UnsafeConsumer; import com.liferay.petra.function.UnsafeFunction; @@ -733,8 +734,15 @@ public void create( Collection webUrls, Map parameters) throws Exception { - throw new UnsupportedOperationException( - "This method needs to be implemented"); + try { + LazyReferencingThreadLocal.setLazyReferencingEnabled(true); + + throw new UnsupportedOperationException( + "This method needs to be implemented"); + } + finally { + LazyReferencingThreadLocal.setLazyReferencingEnabled(false); + } } @Override