Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Merge meeds-io/MIPs#171 #4324

Merged
merged 12 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,10 @@ public interface ProfilePropertyService {
*/
List<Long> getHiddenProfilePropertyIds(long userIdentityId);

/**
* Gets excluded analytics index properties
*
* @return {@link List} of {@link String}
*/
List<String> getExcludedAnalyticsIndexProperties();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.profileproperty.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ProfilePropertyOption {

private Long id;

private String value;

private Long propertySettingId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,48 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/


package org.exoplatform.social.core.profileproperty.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ProfilePropertySetting {

private String propertyName;
private Long id;

private String propertyName;

private String propertyType;

private boolean isDropdownList;

private boolean isVisible;

private boolean isEditable;

private String propertyType;

private boolean isVisible;
private Long parentId;

private boolean isEditable;
private Long order;

private Long parentId;
private boolean isActive;

private Long order;
private boolean isGroupSynchronized;

private boolean isActive;
private boolean isHiddenbale;

private boolean isGroupSynchronized;
private boolean indexInAnalytics;

private boolean isHiddenbale;

private boolean isRequired;
private boolean isRequired;

private boolean isMultiValued;
private boolean isMultiValued;

private Long id;
private List<ProfilePropertyOption> propertyOptions;

private Long updated;
private Long updated;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.exoplatform.commons.cache.future.FutureExoCache;
import org.exoplatform.services.cache.CacheService;
import org.exoplatform.services.cache.ExoCache;
import org.exoplatform.social.core.jpa.storage.dao.jpa.ProfilePropertyOptionDAO;
import org.exoplatform.social.core.jpa.storage.dao.jpa.ProfilePropertySettingDAO;
import org.exoplatform.social.core.profileproperty.model.ProfilePropertySetting;
import org.exoplatform.social.core.profileproperty.storage.ProfileSettingStorage;
Expand All @@ -44,8 +45,9 @@ public class CachedProfileSettingStorage extends ProfileSettingStorage {
private List<Long> profileSettingIds;

public CachedProfileSettingStorage(CacheService cacheService,
ProfilePropertySettingDAO profilePropertySettingDAO) {
super(profilePropertySettingDAO);
ProfilePropertySettingDAO profilePropertySettingDAO,
ProfilePropertyOptionDAO profilePropertyOptionDAO) {
super(profilePropertySettingDAO, profilePropertyOptionDAO);
cache = cacheService.getCacheInstance("social.profileSettings");
idByNameCache = cacheService.getCacheInstance("social.profileSettingIdsByName");
futureCache = new FutureExoCache<>((c, id) -> super.getProfileSettingById(id), cache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.Set;
import java.util.stream.Collectors;

import io.meeds.social.translation.model.TranslationField;
import io.meeds.social.translation.service.TranslationService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

Expand All @@ -40,6 +42,7 @@
import org.exoplatform.social.core.jpa.storage.dao.IdentityDAO;
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.exoplatform.social.core.relationship.model.Relationship;

Expand All @@ -61,18 +64,26 @@ public class ProfileIndexingServiceConnector extends ElasticIndexingServiceConne

private final ProfilePropertyService profilePropertyService;

private static final String HIDDEN_VALUE = "hidden";
private final TranslationService translationService;

private static final String HIDDEN_VALUE = "hidden";

private static final String PROFILE_PROPERTY_FIELD_NAME = "optionValue";

private static final String PROFILE_PROPERTY_OBJECT_TYPE = "propertySettingOption";

public ProfileIndexingServiceConnector(InitParams initParams,
IdentityManager identityManager,
IdentityDAO identityDAO,
ConnectionDAO connectionDAO,
ProfilePropertyService profilePropertyService) {
ProfilePropertyService profilePropertyService,
TranslationService translationService) {
super(initParams);
this.identityManager = identityManager;
this.identityDAO = identityDAO;
this.connectionDAO = connectionDAO;
this.profilePropertyService = profilePropertyService;
this.translationService = translationService;
}

@Override
Expand Down Expand Up @@ -256,21 +267,25 @@ private Document getDocument(String id) {

for (ProfilePropertySetting profilePropertySetting : profilePropertyService.getPropertySettings()) {
if (profilePropertySetting.isVisible() && !fields.containsKey(profilePropertySetting.getPropertyName())) {
// Avoid indexing invisible and not editable properties
if (profile.getProperty(profilePropertySetting.getPropertyName()) != null && profile.getProperty(profilePropertySetting.getPropertyName()) instanceof String value) {
if (StringUtils.isNotEmpty(value)) {
// Avoid having dots in field names in ES, otherwise properties with String values may be converted in Objects in some cases
addPropertyToDocumentFields(fields, profilePropertySetting.getPropertyName(), value, Long.parseLong(id));
}
} else {
List<Map<String, String>> multiValues = (List<Map<String, String>>) profile.getProperty(profilePropertySetting.getPropertyName());
Object propertyValue = profile.getProperty(profilePropertySetting.getPropertyName());
if (propertyValue instanceof String value && StringUtils.isNotEmpty(value)) {
addPropertyToDocumentFields(fields,
profilePropertySetting.getPropertyName(),
parseValue(profilePropertySetting, value),
Long.parseLong(id));
} else if (propertyValue instanceof List) {
List<Map<String, String>> multiValues = (List<Map<String, String>>) propertyValue;
if (CollectionUtils.isNotEmpty(multiValues)) {
String value = multiValues.stream()
.filter(property -> property.get("value") != null)
.map(property -> property.get("value"))
.collect(Collectors.joining(",", "", ""));
.filter(property -> property.get("value") != null)
.map(property -> parseValue(profilePropertySetting, property.get("value")))
.collect(Collectors.joining(",", "", ""));

if (StringUtils.isNotEmpty(value)) {
addPropertyToDocumentFields(fields, profilePropertySetting.getPropertyName(), removeAccents(value), Long.parseLong(id));
addPropertyToDocumentFields(fields,
profilePropertySetting.getPropertyName(),
removeAccents(value),
Long.parseLong(id));
}
}
}
Expand Down Expand Up @@ -315,4 +330,28 @@ private static String removeAccents(String string) {
}
return string;
}

private String parseValue(ProfilePropertySetting profilePropertySetting, String value) {
if (!profilePropertySetting.isDropdownList()) {
return value;
}
String optionValue = profilePropertySetting.getPropertyOptions()
.stream()
.filter(option -> option.getId() == Long.parseLong(value))
.findFirst()
.map(ProfilePropertyOption::getValue)
.orElse(value);
try {
TranslationField translationField = translationService.getTranslationField(PROFILE_PROPERTY_OBJECT_TYPE,
Long.parseLong(value),
PROFILE_PROPERTY_FIELD_NAME);
if (translationField != null && !translationField.getLabels().isEmpty()) {
String translations = String.join("-", translationField.getLabels().values());
return String.join("-", optionValue, translations);
}
} catch (Exception e) {
LOG.error("Error parsing profile property value translations", e);
}
return optionValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.jpa.storage.dao.jpa;

import jakarta.persistence.TypedQuery;
import org.apache.commons.collections.CollectionUtils;
import org.exoplatform.commons.persistence.impl.GenericDAOJPAImpl;
import org.exoplatform.social.core.jpa.storage.entity.ProfilePropertyOptionEntity;

import java.util.Collections;
import java.util.List;

public class ProfilePropertyOptionDAO extends GenericDAOJPAImpl<ProfilePropertyOptionEntity, Long> {

public List<ProfilePropertyOptionEntity> findPropertyOptionsBySettingId(long settingId, int offset, int limit) {
TypedQuery<ProfilePropertyOptionEntity> query =
getEntityManager().createNamedQuery("ProfilePropertyOptionEntity.findPropertyOptionsBySettingId",
ProfilePropertyOptionEntity.class);
query.setParameter("settingId", settingId);
if (offset > 0) {
query.setFirstResult(offset);
}
if (limit > 0) {
query.setMaxResults(limit);
}
List<ProfilePropertyOptionEntity> list = query.getResultList();
if (CollectionUtils.isEmpty(list)) {
return Collections.emptyList();
} else {
return list;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public ProfilePropertySettingEntity findProfileSettingByName(String name) {
} catch (NoResultException e) {
return null;
}

}

public List<ProfilePropertySettingEntity> findSynchronizedSettings() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.jpa.storage.entity;

import jakarta.persistence.*;
import lombok.*;

import java.io.Serializable;

@Entity(name = "SocProfilePropertyOptionEntity")
@Table(name = "SOC_PROFILE_PROPERTY_OPTION")
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@NamedQueries({
@NamedQuery(name = "ProfilePropertyOptionEntity.findPropertyOptionsBySettingId", query = "SELECT o FROM SocProfilePropertyOptionEntity o WHERE o.propertySetting.id = :settingId") })
public class ProfilePropertyOptionEntity implements Serializable {

@Id
@SequenceGenerator(name = "SEQ_SOC_PROFILE_PROPERTY_OPTION_ID", sequenceName = "SEQ_SOC_PROFILE_PROPERTY_OPTION_ID", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_SOC_PROFILE_PROPERTY_OPTION_ID")
@Column(name = "PROPERTY_OPTION_ID")
private Long id;

@Column(name = "PROPERTY_OPTION_VALUE")
private String value;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PROPERTY_SETTING_ID", nullable = false)
@EqualsAndHashCode.Exclude
@ToString.Exclude
private ProfilePropertySettingEntity propertySetting;
}
Loading