-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
filtering out inactive tags based on configuration
- Loading branch information
Showing
3 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,17 @@ | |
import com.ecwid.maleorang.method.v3_0.lists.merge_fields.GetMergeFieldsMethod; | ||
import com.ecwid.maleorang.method.v3_0.lists.merge_fields.MergeFieldInfo; | ||
import com.impactupgrade.nucleus.environment.EnvironmentConfig; | ||
import org.apache.commons.collections.CollectionUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.io.IOException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.ArrayList; | ||
import java.util.Calendar; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
@@ -174,4 +178,39 @@ public String exceptionToString(MailchimpException e) { | |
} | ||
return description; | ||
} | ||
|
||
public static void main(String[] args) { | ||
EnvironmentConfig.ContactTagFilters contactTagFilters = new EnvironmentConfig.ContactTagFilters(); | ||
contactTagFilters.tags = Set.of("ftag1", "ftag2"); | ||
contactTagFilters.tagPrefixes = Set.of("pref1", "pref2"); | ||
|
||
EnvironmentConfig.EmailPlatform emailPlatform = new EnvironmentConfig.EmailPlatform(); | ||
emailPlatform.secretKey = "e9bd13aeaa928b7cfd9c7fc8cba88e32-us14"; | ||
emailPlatform.contactTagFilters = contactTagFilters; | ||
|
||
MailchimpClient mailchimpClient = new MailchimpClient(emailPlatform); | ||
|
||
String listId = "3d215dac12"; | ||
String email = "[email protected]"; | ||
|
||
updateTags(listId, email, mailchimpClient, emailPlatform); | ||
} | ||
|
||
protected static void updateTags(String listId, String email, MailchimpClient mailchimpClient, EnvironmentConfig.EmailPlatform emailPlatform) { | ||
try { | ||
List<String> contactTags = mailchimpClient.getContactTags(listId, email); | ||
|
||
List<String> activeTags = List.of("newtag2"); | ||
|
||
String[] tagPrefixesArray = emailPlatform.contactTagFilters.tagPrefixes.toArray(new String[]{}); | ||
List<String> inactiveTags = contactTags.stream() | ||
.filter(tag -> !activeTags.contains(tag)) | ||
.filter(tag -> emailPlatform.contactTagFilters.tags.contains(tag) || StringUtils.startsWithAny(tag, tagPrefixesArray)) | ||
.collect(Collectors.toList()); | ||
|
||
mailchimpClient.updateContactTags(listId, email, activeTags, inactiveTags); | ||
} catch (Exception e) { | ||
log.error("updating tags failed for contact: {} {}", email, e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters