You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by am...@apache.org on 2017/10/31 17:23:52 UTC
[1/2] incubator-unomi git commit: UNOMI-129 : review
Repository: incubator-unomi
Updated Branches:
refs/heads/master de5dea661 -> adbb62a54
UNOMI-129 : review
Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/adbb62a5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/adbb62a5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/adbb62a5
Branch: refs/heads/master
Commit: adbb62a543f32e2db623f2a4e100d790de6900f0
Parents: f408771
Author: Abdelkader Midani <am...@apache.org>
Authored: Tue Oct 31 18:23:39 2017 +0100
Committer: Abdelkader Midani <am...@apache.org>
Committed: Tue Oct 31 18:23:45 2017 +0100
----------------------------------------------------------------------
.../actions/UpdatePropertiesAction.java | 57 ++++++++++----------
1 file changed, 28 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/adbb62a5/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/UpdatePropertiesAction.java
----------------------------------------------------------------------
diff --git a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/UpdatePropertiesAction.java b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/UpdatePropertiesAction.java
index 98d7408..04d2e9b 100644
--- a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/UpdatePropertiesAction.java
+++ b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/UpdatePropertiesAction.java
@@ -30,10 +30,7 @@ import org.apache.unomi.persistence.spi.PropertyHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
public class UpdatePropertiesAction implements ActionExecutor {
@@ -57,9 +54,9 @@ public class UpdatePropertiesAction implements ActionExecutor {
String targetId = (String) event.getProperty(TARGET_ID_KEY);
String targetType = (String) event.getProperty(TARGET_TYPE_KEY);
-
+
if (StringUtils.isNotBlank(targetId) && event.getProfile() != null && !targetId.equals(event.getProfile().getItemId())) {
- target = TARGET_TYPE_PROFILE.equals(targetType)?profileService.load(targetId) : profileService.loadPersona(targetId);
+ target = TARGET_TYPE_PROFILE.equals(targetType) ? profileService.load(targetId) : profileService.loadPersona(targetId);
if (target == null) {
logger.warn("No profile found with Id : {}. Update skipped.", targetId);
return EventService.NO_CHANGE;
@@ -71,32 +68,12 @@ public class UpdatePropertiesAction implements ActionExecutor {
Map<String, Object> propsToAdd = (HashMap<String, Object>) event.getProperties().get(PROPS_TO_ADD);
if (propsToAdd != null) {
- for (String prop : propsToAdd.keySet()) {
- PropertyType propType = null;
- if (prop.startsWith("properties.")) {
- propType = profileService.getPropertyType(prop.substring("properties.".length()));
- }
- if (propType != null) {
- isProfileOrPersonaUpdated |= PropertyHelper.setProperty(target, prop, PropertyHelper.getValueByTypeId(propsToAdd.get(prop), propType.getValueTypeId()), "setIfMissing");
- } else {
- isProfileOrPersonaUpdated |= PropertyHelper.setProperty(target, prop, propsToAdd.get(prop), "setIfMissing");
- }
- }
+ isProfileOrPersonaUpdated |= processProperties(target, propsToAdd, "setIfMissing");
}
Map<String, Object> propsToUpdate = (HashMap<String, Object>) event.getProperties().get(PROPS_TO_UPDATE);
if (propsToUpdate != null) {
- for (String prop : propsToUpdate.keySet()) {
- PropertyType propType = null;
- if (prop.startsWith("properties.")) {
- propType = profileService.getPropertyType(prop.substring("properties.".length()));
- }
- if (propType != null) {
- isProfileOrPersonaUpdated |= PropertyHelper.setProperty(target, prop, PropertyHelper.getValueByTypeId(propsToUpdate.get(prop), propType.getValueTypeId()), "alwaysSet");
- } else {
- isProfileOrPersonaUpdated |= PropertyHelper.setProperty(target, prop, propsToUpdate.get(prop), "alwaysSet");
- }
- }
+ isProfileOrPersonaUpdated |= processProperties(target, propsToUpdate, "alwaysSet");
}
List<String> propsToDelete = (List<String>) event.getProperties().get(PROPS_TO_DELETE);
@@ -108,7 +85,7 @@ public class UpdatePropertiesAction implements ActionExecutor {
if (StringUtils.isNotBlank(targetId) && isProfileOrPersonaUpdated &&
event.getProfile() != null && !targetId.equals(event.getProfile().getItemId())) {
- if(TARGET_TYPE_PROFILE.equals(event.getProfile().getItemType())) {
+ if (TARGET_TYPE_PROFILE.equals(targetType)) {
profileService.save(target);
Event profileUpdated = new Event("profileUpdated", null, target, null, null, target, new Date());
profileUpdated.setPersistent(false);
@@ -128,6 +105,28 @@ public class UpdatePropertiesAction implements ActionExecutor {
}
+ private boolean processProperties(Profile target, Map<String, Object> propsMap, String strategy) {
+ boolean isProfileOrPersonaUpdated = false;
+ for (String prop : propsMap.keySet()) {
+ PropertyType propType = null;
+ if (prop.startsWith("properties.") || prop.startsWith("systemProperties.")) {
+ propType = profileService.getPropertyType(prop.substring(prop.indexOf('.') + 1));
+ } else {
+ propType = profileService.getPropertyType(prop);
+ //ideally each property must have a matching propertyType
+ if(prop.equals("segments")) {
+ propsMap.put(prop, new HashSet<String>((ArrayList<String>)propsMap.get(prop)));
+ }
+ }
+ if (propType != null) {
+ isProfileOrPersonaUpdated |= PropertyHelper.setProperty(target, prop, PropertyHelper.getValueByTypeId(propsMap.get(prop), propType.getValueTypeId()), "alwaysSet");
+ } else {
+ isProfileOrPersonaUpdated |= PropertyHelper.setProperty(target, prop, propsMap.get(prop), strategy);
+ }
+ }
+ return isProfileOrPersonaUpdated;
+ }
+
public void setProfileService(ProfileService profileService) {
this.profileService = profileService;
}
[2/2] incubator-unomi git commit: UNOMI-128 : Fix import/export
config IT
Posted by am...@apache.org.
UNOMI-128 : Fix import/export config IT
Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/f4087719
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/f4087719
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/f4087719
Branch: refs/heads/master
Commit: f40877191a4b848128d005a52b3687c502caa82b
Parents: de5dea6
Author: Abdelkader Midani <am...@apache.org>
Authored: Tue Oct 31 17:56:10 2017 +0100
Committer: Abdelkader Midani <am...@apache.org>
Committed: Tue Oct 31 18:23:45 2017 +0100
----------------------------------------------------------------------
.../org/apache/unomi/itests/ProfileExportIT.java | 15 +--------------
.../apache/unomi/itests/ProfileImportActorsIT.java | 15 +--------------
.../apache/unomi/itests/ProfileImportRankingIT.java | 15 +--------------
.../itests/ProfileImportSurfersOverwriteIT.java | 15 +--------------
4 files changed, 4 insertions(+), 56 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f4087719/itests/src/test/java/org/apache/unomi/itests/ProfileExportIT.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/unomi/itests/ProfileExportIT.java b/itests/src/test/java/org/apache/unomi/itests/ProfileExportIT.java
index 1391497..1f43b08 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileExportIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileExportIT.java
@@ -112,20 +112,7 @@ public class ProfileExportIT extends BaseIT {
exportConfiguration.getProperties().put("destination", "file://" + exportDir.getAbsolutePath() + "?fileName=profiles-actors-export.csv");
exportConfiguration.setActive(true);
- ExportConfiguration savedExportConfig = exportConfigurationService.save(exportConfiguration, true);
-
- CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpPut httpPut = new HttpPut(URL + "/configUpdate/exportConfigAdmin");
-
- String json = new ObjectMapper().writeValueAsString(savedExportConfig);
- StringEntity entity = new StringEntity(json);
- entity.setContentType(MediaType.APPLICATION_JSON);
- httpPut.setEntity(entity);
-
- HttpResponse response = httpclient.execute(httpPut);
- assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
-
- httpclient.close();
+ exportConfigurationService.save(exportConfiguration, true);
}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f4087719/itests/src/test/java/org/apache/unomi/itests/ProfileImportActorsIT.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/unomi/itests/ProfileImportActorsIT.java b/itests/src/test/java/org/apache/unomi/itests/ProfileImportActorsIT.java
index c8de826..e145ac3 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileImportActorsIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileImportActorsIT.java
@@ -106,20 +106,7 @@ public class ProfileImportActorsIT extends BaseIT {
importConfigActors.getProperties().put("source", "file://" + importSurfersFile.getAbsolutePath() + "?fileName=6-actors-test.csv&consumer.delay=10m&move=.done");
importConfigActors.setActive(true);
- ImportConfiguration savedImportConfig = importConfigurationService.save(importConfigActors, true);
-
- CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpPut httpPut = new HttpPut(URL + "/configUpdate/importConfigAdmin");
-
- String json = new ObjectMapper().writeValueAsString(savedImportConfig);
- StringEntity entity = new StringEntity(json);
- entity.setContentType(MediaType.APPLICATION_JSON);
- httpPut.setEntity(entity);
-
- HttpResponse response = httpclient.execute(httpPut);
- assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
-
- httpclient.close();
+ importConfigurationService.save(importConfigActors, true);
}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f4087719/itests/src/test/java/org/apache/unomi/itests/ProfileImportRankingIT.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/unomi/itests/ProfileImportRankingIT.java b/itests/src/test/java/org/apache/unomi/itests/ProfileImportRankingIT.java
index 447b422..afbb172 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileImportRankingIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileImportRankingIT.java
@@ -109,20 +109,7 @@ public class ProfileImportRankingIT extends BaseIT {
importConfigRanking.getProperties().put("source", "file://" + importSurfersFile.getAbsolutePath() + "?fileName=5-ranking-test.csv&consumer.delay=10m&move=.done");
importConfigRanking.setActive(true);
- ImportConfiguration savedImportConfig = importConfigurationService.save(importConfigRanking, true);
-
- CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpPut httpPut = new HttpPut(URL + "/configUpdate/importConfigAdmin");
-
- String json = new ObjectMapper().writeValueAsString(savedImportConfig);
- StringEntity entity = new StringEntity(json);
- entity.setContentType(MediaType.APPLICATION_JSON);
- httpPut.setEntity(entity);
-
- HttpResponse response = httpclient.execute(httpPut);
- assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
-
- httpclient.close();
+ importConfigurationService.save(importConfigRanking, true);
}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f4087719/itests/src/test/java/org/apache/unomi/itests/ProfileImportSurfersOverwriteIT.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/unomi/itests/ProfileImportSurfersOverwriteIT.java b/itests/src/test/java/org/apache/unomi/itests/ProfileImportSurfersOverwriteIT.java
index 8f97c3f..d837f4c 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileImportSurfersOverwriteIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileImportSurfersOverwriteIT.java
@@ -93,20 +93,7 @@ public class ProfileImportSurfersOverwriteIT extends BaseIT {
importConfigSurfers.getProperties().put("source", "file://" + importSurfersFile.getAbsolutePath() + "?fileName=3-surfers-overwrite-test.csv&consumer.delay=10m&move=.done");
importConfigSurfers.setActive(true);
- ImportConfiguration savedImportConfig = importConfigurationService.save(importConfigSurfers, true);
-
- CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpPut httpPut = new HttpPut(URL + "/configUpdate/importConfigAdmin");
-
- String json = new ObjectMapper().writeValueAsString(savedImportConfig);
- StringEntity entity = new StringEntity(json);
- entity.setContentType(MediaType.APPLICATION_JSON);
- httpPut.setEntity(entity);
-
- HttpResponse response = httpclient.execute(httpPut);
- assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
-
- httpclient.close();
+ importConfigurationService.save(importConfigSurfers, true);
}