Skip to content

Commit d601a7f

Browse files
authored
[MT-1462] - deletePersistentData added to DataManager (#13)
- adds deletePersistentData added to DataManager - bumps version up to 1.3.2
1 parent 727205d commit d601a7f

6 files changed

Lines changed: 61 additions & 11 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ AudienceStream™ allows you to create a unified view of your customers, correla
2727
* If you have **account specific questions** please contact your Tealium account manager
2828

2929
## Change Log
30+
31+
- 1.3.2 Persistent Data Deletion
32+
- `deletePersistentData` method added to the `DataManager` class
3033
- 1.3.1 Persistent Data
3134
- Updated track method to use a copy of Persistent Data to stop event data unexpectedly being stored.
3235
- 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
7477

7578

7679
---
77-
Copyright (C) 2012-2021, Tealium Inc.
80+
Copyright (C) 2012-2024, Tealium Inc.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.tealium</groupId>
55
<artifactId>java</artifactId>
6-
<version>1.3.1</version>
6+
<version>1.3.2</version>
77
<name>TealiumJava</name>
88

99
<packaging>jar</packaging>

src/main/java/com/tealium/DataManager.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.tealium;
22

33
import java.security.SecureRandom;
4+
import java.util.List;
45
import java.util.Random;
56

67
/**
@@ -74,6 +75,19 @@ public void addPersistentData(Udo data) throws UdoSerializationException {
7475
this.persistentData.writeData(persistent);
7576
}
7677

78+
/**
79+
* Convenience to remove specific keys from the persistent data map
80+
*
81+
* @param keys The list of keys to be removed.
82+
*/
83+
public void deletePersistentData(List<String> keys) throws UdoSerializationException {
84+
Udo persistent = getPersistentData();
85+
for (String key : keys) {
86+
persistent.remove(key);
87+
}
88+
this.persistentData.writeData(persistent);
89+
}
90+
7791
/**
7892
* Convenience to reset session ID
7993
*

src/main/java/com/tealium/LibraryContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @author Jason Koo, Chad Hartman, Karen Tamayo, Merritt Tidwell, Chris Anderberg
1111
*/
1212
class LibraryContext {
13-
public static final String version = "1.3.1";
13+
public static final String version = "1.3.2";
1414

1515
private final String account;
1616
private final String profile;

src/test/java/com/tealium/DataManagerTests.java

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* Jason Koo, Chad Hartman, Karen Tamayo, Merritt Tidwell, Chris Anderberg
1616
*/
1717
public class DataManagerTests {
18-
1918
@Test
2019
public void testInit() throws Exception {
2120
TestLibraryContext testCtx = TestLibraryContext.newInstance();
@@ -49,6 +48,23 @@ public void testGetPersistentData() throws Exception {
4948

5049
LibraryContext ctx = TestLibraryContext.newInstance();
5150

51+
Udo map = new Udo();
52+
String key = "testKey";
53+
String value = "testValue";
54+
map.put(key, value);
55+
56+
DataManager data = new DataManager(ctx, TestUtils.dummyPersistentUdo(map));
57+
Udo savedData = data.getPersistentData();
58+
59+
assertTrue(savedData.containsKey(key));
60+
assertTrue(savedData.containsValue(value));
61+
}
62+
63+
@Test
64+
public void testAddPersistentDataAddsDataToPersistentUdo() throws Exception {
65+
66+
LibraryContext ctx = TestLibraryContext.newInstance();
67+
5268
DataManager data = new DataManager(ctx, TestUtils.dummyPersistentUdo());
5369
Udo map = new Udo();
5470

@@ -60,17 +76,30 @@ public void testGetPersistentData() throws Exception {
6076
// Write to disk first
6177
data.addPersistentData(map);
6278

63-
Class<? extends DataManager> myclass = data.getClass();
64-
Method method = myclass.getDeclaredMethod("getPersistentData");
65-
method.setAccessible(true);
66-
67-
@SuppressWarnings("unchecked")
68-
Udo savedData = (Udo) method.invoke(data);
79+
Udo savedData = data.getPersistentData();
6980

7081
assertTrue(savedData.containsKey(key));
7182
assertTrue(savedData.containsValue(value));
7283
}
7384

85+
@Test
86+
public void testDeletePersistentDataRemovesDataFromPersistentUdo() throws Exception {
87+
88+
LibraryContext ctx = TestLibraryContext.newInstance();
89+
90+
Udo map = new Udo();
91+
String key = "testKey";
92+
String value = "testValue";
93+
map.put(key, value);
94+
95+
DataManager data = new DataManager(ctx, TestUtils.dummyPersistentUdo(map));
96+
data.deletePersistentData(Collections.singletonList("testKey"));
97+
Udo savedData = data.getPersistentData();
98+
99+
assertFalse(savedData.containsKey(key));
100+
assertFalse(savedData.containsValue(value));
101+
}
102+
74103
/*
75104
* Test that new data doesn't contain visitor id or vid
76105
* Test that new data contains expected variables

src/test/java/com/tealium/TestUtils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@ public Boolean exists() {
7171
}
7272

7373
public static PersistentUdo dummyPersistentUdo() {
74+
return dummyPersistentUdo(null);
75+
}
76+
77+
public static PersistentUdo dummyPersistentUdo(final Udo initialUdo) {
7478
return new PersistentUdo(null) {
75-
private Udo udo;
79+
private Udo udo = initialUdo;
7680

7781
@Override
7882
public Udo readOrCreateUdo(Udo defaultData) {

0 commit comments

Comments
 (0)