diff --git a/README.md b/README.md
index ba8fe49..8bfe5fc 100644
--- a/README.md
+++ b/README.md
@@ -27,6 +27,9 @@ AudienceStreamâ„¢ allows you to create a unified view of your customers, correla
* If you have **account specific questions** please contact your Tealium account manager
## Change Log
+
+- 1.3.2 Persistent Data Deletion
+ - `deletePersistentData` method added to the `DataManager` class
- 1.3.1 Persistent Data
- Updated track method to use a copy of Persistent Data to stop event data unexpectedly being stored.
- 1.3.0 Remove visitor_id and switch to event endpoint
@@ -74,4 +77,4 @@ Use of this software is subject to the terms and conditions of the license agree
---
-Copyright (C) 2012-2021, Tealium Inc.
+Copyright (C) 2012-2024, Tealium Inc.
diff --git a/pom.xml b/pom.xml
index 023fdf8..ee55aea 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
com.tealium
java
- 1.3.1
+ 1.3.2
TealiumJava
jar
diff --git a/src/main/java/com/tealium/DataManager.java b/src/main/java/com/tealium/DataManager.java
index 1b4a6ed..ba458c8 100644
--- a/src/main/java/com/tealium/DataManager.java
+++ b/src/main/java/com/tealium/DataManager.java
@@ -1,6 +1,7 @@
package com.tealium;
import java.security.SecureRandom;
+import java.util.List;
import java.util.Random;
/**
@@ -74,6 +75,19 @@ public void addPersistentData(Udo data) throws UdoSerializationException {
this.persistentData.writeData(persistent);
}
+ /**
+ * Convenience to remove specific keys from the persistent data map
+ *
+ * @param keys The list of keys to be removed.
+ */
+ public void deletePersistentData(List keys) throws UdoSerializationException {
+ Udo persistent = getPersistentData();
+ for (String key : keys) {
+ persistent.remove(key);
+ }
+ this.persistentData.writeData(persistent);
+ }
+
/**
* Convenience to reset session ID
*
diff --git a/src/main/java/com/tealium/LibraryContext.java b/src/main/java/com/tealium/LibraryContext.java
index a64d8cc..8c18d17 100644
--- a/src/main/java/com/tealium/LibraryContext.java
+++ b/src/main/java/com/tealium/LibraryContext.java
@@ -10,7 +10,7 @@
* @author Jason Koo, Chad Hartman, Karen Tamayo, Merritt Tidwell, Chris Anderberg
*/
class LibraryContext {
- public static final String version = "1.3.1";
+ public static final String version = "1.3.2";
private final String account;
private final String profile;
diff --git a/src/test/java/com/tealium/DataManagerTests.java b/src/test/java/com/tealium/DataManagerTests.java
index 3a35cd5..45e14a1 100644
--- a/src/test/java/com/tealium/DataManagerTests.java
+++ b/src/test/java/com/tealium/DataManagerTests.java
@@ -15,7 +15,6 @@
* Jason Koo, Chad Hartman, Karen Tamayo, Merritt Tidwell, Chris Anderberg
*/
public class DataManagerTests {
-
@Test
public void testInit() throws Exception {
TestLibraryContext testCtx = TestLibraryContext.newInstance();
@@ -49,6 +48,23 @@ public void testGetPersistentData() throws Exception {
LibraryContext ctx = TestLibraryContext.newInstance();
+ Udo map = new Udo();
+ String key = "testKey";
+ String value = "testValue";
+ map.put(key, value);
+
+ DataManager data = new DataManager(ctx, TestUtils.dummyPersistentUdo(map));
+ Udo savedData = data.getPersistentData();
+
+ assertTrue(savedData.containsKey(key));
+ assertTrue(savedData.containsValue(value));
+ }
+
+ @Test
+ public void testAddPersistentDataAddsDataToPersistentUdo() throws Exception {
+
+ LibraryContext ctx = TestLibraryContext.newInstance();
+
DataManager data = new DataManager(ctx, TestUtils.dummyPersistentUdo());
Udo map = new Udo();
@@ -60,17 +76,30 @@ public void testGetPersistentData() throws Exception {
// Write to disk first
data.addPersistentData(map);
- Class extends DataManager> myclass = data.getClass();
- Method method = myclass.getDeclaredMethod("getPersistentData");
- method.setAccessible(true);
-
- @SuppressWarnings("unchecked")
- Udo savedData = (Udo) method.invoke(data);
+ Udo savedData = data.getPersistentData();
assertTrue(savedData.containsKey(key));
assertTrue(savedData.containsValue(value));
}
+ @Test
+ public void testDeletePersistentDataRemovesDataFromPersistentUdo() throws Exception {
+
+ LibraryContext ctx = TestLibraryContext.newInstance();
+
+ Udo map = new Udo();
+ String key = "testKey";
+ String value = "testValue";
+ map.put(key, value);
+
+ DataManager data = new DataManager(ctx, TestUtils.dummyPersistentUdo(map));
+ data.deletePersistentData(Collections.singletonList("testKey"));
+ Udo savedData = data.getPersistentData();
+
+ assertFalse(savedData.containsKey(key));
+ assertFalse(savedData.containsValue(value));
+ }
+
/*
* Test that new data doesn't contain visitor id or vid
* Test that new data contains expected variables
diff --git a/src/test/java/com/tealium/TestUtils.java b/src/test/java/com/tealium/TestUtils.java
index 9dd8dca..ddd4a9d 100644
--- a/src/test/java/com/tealium/TestUtils.java
+++ b/src/test/java/com/tealium/TestUtils.java
@@ -71,8 +71,12 @@ public Boolean exists() {
}
public static PersistentUdo dummyPersistentUdo() {
+ return dummyPersistentUdo(null);
+ }
+
+ public static PersistentUdo dummyPersistentUdo(final Udo initialUdo) {
return new PersistentUdo(null) {
- private Udo udo;
+ private Udo udo = initialUdo;
@Override
public Udo readOrCreateUdo(Udo defaultData) {