You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by ql...@apache.org on 2016/06/27 16:08:40 UTC
incubator-unomi git commit: UNOMI-33: Profile CSV export should
contain custom properties as well (e.g. set by form mapping)
Repository: incubator-unomi
Updated Branches:
refs/heads/master d2e1b724b -> 484c9fe53
UNOMI-33: Profile CSV export should contain custom properties as well (e.g. set by form mapping)
Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/484c9fe5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/484c9fe5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/484c9fe5
Branch: refs/heads/master
Commit: 484c9fe53b7c697741260d9a541eec760d124382
Parents: d2e1b72
Author: Quentin Lamerand <ql...@jahia.com>
Authored: Mon Jun 27 18:08:34 2016 +0200
Committer: Quentin Lamerand <ql...@jahia.com>
Committed: Mon Jun 27 18:08:34 2016 +0200
----------------------------------------------------------------------
.../services/services/ProfileServiceImpl.java | 30 +++++++++++++-------
1 file changed, 20 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/484c9fe5/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java
----------------------------------------------------------------------
diff --git a/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java
index 8b4f055..aa756b6 100644
--- a/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/services/ProfileServiceImpl.java
@@ -308,15 +308,25 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList
public String exportProfilesPropertiesToCsv(Query query) {
StringBuilder sb = new StringBuilder();
- Set<PropertyType> profileProperties = getExistingProperties("profileProperties", Profile.ITEM_TYPE);
- PropertyType[] propertyTypes = profileProperties.toArray(new PropertyType[profileProperties.size()]);
+ Set<PropertyType> propertyTypes = getExistingProperties("profileProperties", Profile.ITEM_TYPE);
PartialList<Profile> profiles = search(query, Profile.class);
+ HashMap<String, PropertyType> propertyTypesById = new LinkedHashMap<>();
+ for (PropertyType propertyType : propertyTypes) {
+ propertyTypesById.put(propertyType.getMetadata().getId(), propertyType);
+ }
+ for (Profile profile : profiles.getList()) {
+ for (String key : profile.getProperties().keySet()) {
+ if (!propertyTypesById.containsKey(key)) {
+ propertyTypesById.put(key, null);
+ }
+ }
+ }
+
sb.append("profileId;");
// headers
- for (int i = 0; i < propertyTypes.length; i++) {
- PropertyType propertyType = propertyTypes[i];
- sb.append(propertyType.getMetadata().getId());
+ for (String propertyId : propertyTypesById.keySet()) {
+ sb.append(propertyId);
sb.append(";");
}
sb.append("segments\n");
@@ -325,10 +335,10 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList
for (Profile profile : profiles.getList()) {
sb.append(profile.getItemId());
sb.append(";");
- for (int i = 0; i < propertyTypes.length; i++) {
- PropertyType propertyType = propertyTypes[i];
- if (profile.getProperties().get(propertyType.getMetadata().getId()) != null) {
- handleExportProperty(sb, profile.getProperties().get(propertyType.getMetadata().getId()), propertyType);
+ for (Map.Entry<String, PropertyType> propertyIdAndType : propertyTypesById.entrySet()) {
+ String propertyId = propertyIdAndType.getKey();
+ if (profile.getProperties().get(propertyId) != null) {
+ handleExportProperty(sb, profile.getProperties().get(propertyId), propertyIdAndType.getValue());
} else {
sb.append("");
}
@@ -347,7 +357,7 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList
// TODO may be moved this in a specific Export Utils Class and improve it to handle date format, ...
private void handleExportProperty(StringBuilder sb, Object propertyValue, PropertyType propertyType) {
- if (propertyValue instanceof Collection && propertyType.isMultivalued()) {
+ if (propertyValue instanceof Collection && propertyType != null && propertyType.isMultivalued()) {
Collection propertyValues = (Collection) propertyValue;
Collection encodedValues = new ArrayList(propertyValues.size());
for (Object value : propertyValues) {