-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Reindex targeted identities when used dropdown option value tra…
…nslation updated - EXO-8007 - Meeds-io/MIPs#171 (#4348) Reindex targeted identities when used option value translation updated <!-- Ensure to provide github issue and task id in the title --> <!-- Choose between feat and fix in the title to differenciate a new feature from a fix --> <!-- Title format must be : feat: FEATURE TITLE - MEED-XXXX - Meeds-io/meeds#1234 or fix: Fix TITLE - MEED-XXXX - Meeds-io/meeds#1234 --> <!-- Description : describe the feature/the fix by answering theses questions : --> <!-- Why is this change needed?--> <!-- Prior to this change, ...--> <!-- How does it address the issue?--> <!-- This change ...--> <!-- Tips : Try To Limit Each Line to a Maximum Of 72 Characters Provide links or keys to any relevant tickets, articles or other resources Remember to - Capitalize the subject line - Use the imperative mood in the subject line - Do not end the subject line with a period - Separate subject from body with a blank line - Use the body to explain what and why vs. how - Can use multiple lines with "-" for bullet points in body -->
- Loading branch information
Showing
9 changed files
with
294 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...rg/exoplatform/social/core/listeners/ProfilePropertySettingOptionTranslationListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* This file is part of the Meeds project (https://meeds.io/). | ||
* | ||
* Copyright (C) 2025 Meeds Association [email protected] | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package org.exoplatform.social.core.listeners; | ||
|
||
import io.meeds.common.ContainerTransactional; | ||
import org.exoplatform.commons.search.index.IndexingService; | ||
import org.exoplatform.commons.utils.ListAccess; | ||
import org.exoplatform.services.listener.Asynchronous; | ||
import org.exoplatform.services.listener.Event; | ||
import org.exoplatform.services.listener.Listener; | ||
import org.exoplatform.social.core.identity.model.Identity; | ||
import org.exoplatform.social.core.identity.provider.OrganizationIdentityProvider; | ||
import org.exoplatform.social.core.jpa.search.ProfileIndexingServiceConnector; | ||
import org.exoplatform.social.core.manager.IdentityManager; | ||
import org.exoplatform.social.core.profile.ProfileFilter; | ||
import org.exoplatform.social.core.profileproperty.ProfilePropertyService; | ||
import org.exoplatform.social.core.profileproperty.model.ProfilePropertyOption; | ||
import org.exoplatform.social.core.profileproperty.model.ProfilePropertySetting; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
@Asynchronous | ||
public class ProfilePropertySettingOptionTranslationListener extends Listener<ProfilePropertyOption, Map<Locale, String>> { | ||
|
||
private final IdentityManager identityManager; | ||
|
||
private final ProfilePropertyService profilePropertyService; | ||
|
||
private final IndexingService indexingService; | ||
|
||
public ProfilePropertySettingOptionTranslationListener(IdentityManager identityManager, | ||
ProfilePropertyService profilePropertyService, | ||
IndexingService indexingService) { | ||
this.identityManager = identityManager; | ||
this.profilePropertyService = profilePropertyService; | ||
this.indexingService = indexingService; | ||
} | ||
|
||
@Override | ||
@ContainerTransactional | ||
public void onEvent(Event<ProfilePropertyOption, Map<Locale, String>> event) throws Exception { | ||
ProfilePropertyOption profilePropertyOption = event.getSource(); | ||
Map<Locale, String> oldTranslations = event.getData(); | ||
ProfilePropertySetting propertySetting = | ||
profilePropertyService.getProfileSettingById(profilePropertyOption.getPropertySettingId()); | ||
String translations = String.join("-", oldTranslations.values()); | ||
String indexedValue = String.join("-", profilePropertyOption.getValue(), translations); | ||
|
||
ProfileFilter profileFilter = new ProfileFilter(); | ||
profileFilter.setProfileSettings(Map.of(propertySetting.getPropertyName(), indexedValue)); | ||
ListAccess<Identity> identities = identityManager.getIdentitiesByProfileFilter(OrganizationIdentityProvider.NAME, | ||
profileFilter, | ||
true); | ||
List<Identity> identityList = List.of(identities.load(0, identities.getSize())); | ||
for (Identity identity : identityList) { | ||
indexingService.reindex(ProfileIndexingServiceConnector.TYPE, String.valueOf(identity.getId())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...xoplatform/social/core/listeners/ProfilePropertySettingOptionTranslationListenerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* This file is part of the Meeds project (https://meeds.io/). | ||
* | ||
* Copyright (C) 2025 Meeds Association [email protected] | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.exoplatform.social.core.listeners; | ||
|
||
import org.exoplatform.commons.search.index.IndexingService; | ||
import org.exoplatform.commons.utils.ListAccess; | ||
import org.exoplatform.services.listener.Event; | ||
import org.exoplatform.social.core.identity.model.Identity; | ||
import org.exoplatform.social.core.jpa.search.ProfileIndexingServiceConnector; | ||
import org.exoplatform.social.core.manager.IdentityManager; | ||
import org.exoplatform.social.core.profileproperty.ProfilePropertyService; | ||
import org.exoplatform.social.core.profileproperty.model.ProfilePropertyOption; | ||
import org.exoplatform.social.core.profileproperty.model.ProfilePropertySetting; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import java.util.*; | ||
|
||
import static org.mockito.ArgumentMatchers.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ProfilePropertySettingOptionTranslationListenerTest { | ||
|
||
@Mock | ||
private ProfilePropertyService profilePropertyService; | ||
|
||
@Mock | ||
private IdentityManager identityManager; | ||
|
||
@Mock | ||
private IndexingService indexingService; | ||
|
||
private ProfilePropertySettingOptionTranslationListener profilePropertySettingOptionListener; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
profilePropertySettingOptionListener = new ProfilePropertySettingOptionTranslationListener(identityManager, | ||
profilePropertyService, | ||
indexingService); | ||
} | ||
|
||
@Test | ||
public void testOnEvent() throws Exception { | ||
Identity identity1 = mock(Identity.class); | ||
Identity identity2 = mock(Identity.class); | ||
|
||
when(identity1.getId()).thenReturn("identity1"); | ||
when(identity2.getId()).thenReturn("identity2"); | ||
|
||
Map<Locale, String> labels = new HashMap<>(); | ||
labels.put(Locale.US, "option en"); | ||
labels.put(Locale.FRANCE, "option fr"); | ||
|
||
ProfilePropertySetting profilePropertySetting = new ProfilePropertySetting(); | ||
profilePropertySetting.setId(1L); | ||
profilePropertySetting.setPropertyName("test1"); | ||
|
||
ProfilePropertyOption profilePropertyOption1 = new ProfilePropertyOption(); | ||
profilePropertyOption1.setId(1L); | ||
profilePropertyOption1.setValue("value"); | ||
profilePropertyOption1.setPropertySettingId(1L); | ||
|
||
Event<ProfilePropertyOption, Map<Locale, String>> event = new Event<>("property_options_updated", | ||
profilePropertyOption1, | ||
labels); | ||
|
||
ListAccess<Identity> identityListAccess = new ListAccess<>() { | ||
public Identity[] load(int index, int length) { | ||
List<Identity> identities = new ArrayList<>(); | ||
identities.add(identity1); | ||
identities.add(identity2); | ||
Identity[] result = new Identity[identities.size()]; | ||
return identities.toArray(result); | ||
} | ||
|
||
public int getSize() { | ||
return 2; | ||
} | ||
}; | ||
when(profilePropertyService.getProfileSettingById(eq(1L))).thenReturn(profilePropertySetting); | ||
when(identityManager.getIdentitiesByProfileFilter(anyString(), any(), anyBoolean())).thenReturn(identityListAccess); | ||
profilePropertySettingOptionListener.onEvent(event); | ||
verify(indexingService, times(1)).reindex(ProfileIndexingServiceConnector.TYPE, "identity1"); | ||
verify(indexingService, times(1)).reindex(ProfileIndexingServiceConnector.TYPE, "identity1"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.