Class BrevoSynchronisationServiceImpl
java.lang.Object
ch.tocco.nice2.optional.newsletterbrevo.impl.BrevoSynchronisationServiceImpl
- All Implemented Interfaces:
BrevoSynchronisationService
@Component
public class BrevoSynchronisationServiceImpl
extends Object
implements BrevoSynchronisationService
-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.tocco.nice2.optional.newsletterbrevo.impl.BrevoSynchronisationService
BrevoSynchronisationService.AttributePath, BrevoSynchronisationService.AttributeType
-
Constructor Summary
ConstructorDescriptionBrevoSynchronisationServiceImpl
(PersistenceService persistenceService, org.slf4j.Logger logger) -
Method Summary
Modifier and TypeMethodDescriptionvoid
createAttribute
(String name, BrevoSynchronisationService.AttributeType type, EntityList values) creates a new attributevoid
delete an attributevoid
importUsers
(long listId, Condition synchronisationCondition, List<BrevoSynchronisationService.AttributePath> attributes) Import users to brevo.boolean
isEmailAddressInUse
(String email) despiteContactsApi.getContactInfoWithHttpInfo(String, Object, Object)
existing, a 404 still throws an exception instead of just returning the code so we can handle it ourselves.normalizeAttributeName
(String name) adjust a string to be a valid brevo attribute name this means the string fulfills the following conditions: - is all upper case - starts with a later (prepend X if not fulfilled) - has no spaces (replace with underscores if not fulfilled)void
removeUsersFromList
(long listId, Condition synchronisationCondition) void
setImportLimit
(int importLimit) void
setRemoveFromListLimit
(int removeFromListLimit) long
synchroniseFolder
(Entity folder) Synchronises a tocco folder to brevo.long
synchroniseList
(long folderId, Entity newsletterCategory) Synchronises a newsletter category with brevo.void
updateAttribute
(String name, BrevoSynchronisationService.AttributeType type, EntityList values) update attribute, only useful for category attributes, others need to be deleted and recreated for changesvoid
updateEmailAddresses
(Map<String, String> changes) update email addresses in brevo make sure that the email addresses exist in Brevo before updating them, seeBrevoSynchronisationService.isEmailAddressInUse(String)
-
Constructor Details
-
BrevoSynchronisationServiceImpl
public BrevoSynchronisationServiceImpl(PersistenceService persistenceService, org.slf4j.Logger logger)
-
-
Method Details
-
synchroniseFolder
Description copied from interface:BrevoSynchronisationService
Synchronises a tocco folder to brevo.- Specified by:
synchroniseFolder
in interfaceBrevoSynchronisationService
- Parameters:
folder
- the brevo folder entity to be synchronised- Returns:
- id of the folder in brevo
-
synchroniseList
Description copied from interface:BrevoSynchronisationService
Synchronises a newsletter category with brevo. Newsletter categories are mapped to lists in brevo.- Specified by:
synchroniseList
in interfaceBrevoSynchronisationService
- Parameters:
folderId
- the folder id to be used to create new newsletter categoriesnewsletterCategory
- the newsletter category to be synchronised- Returns:
- id of the list in brevo
-
importUsers
public void importUsers(long listId, Condition synchronisationCondition, List<BrevoSynchronisationService.AttributePath> attributes) Description copied from interface:BrevoSynchronisationService
Import users to brevo. Users are transformed to "contacts" and then imported to brevo using the import endpoint. The import endpoint handles creating / updating users and maps users using the email address.- Specified by:
importUsers
in interfaceBrevoSynchronisationService
- Parameters:
listId
- the list id to which the users should be added.synchronisationCondition
- query builder condition to be used to select the users to be synchronised
-
removeUsersFromList
- Specified by:
removeUsersFromList
in interfaceBrevoSynchronisationService
-
getAttributes
- Specified by:
getAttributes
in interfaceBrevoSynchronisationService
- Returns:
- names of all attributes configured in brevo
-
createAttribute
public void createAttribute(String name, BrevoSynchronisationService.AttributeType type, EntityList values) Description copied from interface:BrevoSynchronisationService
creates a new attribute- Specified by:
createAttribute
in interfaceBrevoSynchronisationService
- Parameters:
name
- the name of the attribute, make sure it is normalized withBrevoSynchronisationService.normalizeAttributeName(String)
type
- the type of the attributevalues
- the Brevo_attribute_value entities the attribute can take, only relevant for category attributes
-
updateAttribute
public void updateAttribute(String name, BrevoSynchronisationService.AttributeType type, EntityList values) Description copied from interface:BrevoSynchronisationService
update attribute, only useful for category attributes, others need to be deleted and recreated for changes- Specified by:
updateAttribute
in interfaceBrevoSynchronisationService
- Parameters:
name
- the name of the attribute, make sure it is normalized withBrevoSynchronisationService.normalizeAttributeName(String)
type
- the type of the attributevalues
- the Brevo_attribute_value entities the attribute can take, only relevant for category attributes
-
deleteAttribute
Description copied from interface:BrevoSynchronisationService
delete an attribute- Specified by:
deleteAttribute
in interfaceBrevoSynchronisationService
- Parameters:
name
- the name of the attribute, make sure it is normalized withBrevoSynchronisationService.normalizeAttributeName(String)
type
- the type of the attribute
-
normalizeAttributeName
Description copied from interface:BrevoSynchronisationService
adjust a string to be a valid brevo attribute name this means the string fulfills the following conditions: - is all upper case - starts with a later (prepend X if not fulfilled) - has no spaces (replace with underscores if not fulfilled)- Specified by:
normalizeAttributeName
in interfaceBrevoSynchronisationService
- Parameters:
name
- any string- Returns:
- a valid attribute name
-
updateEmailAddresses
Description copied from interface:BrevoSynchronisationService
update email addresses in brevo make sure that the email addresses exist in Brevo before updating them, seeBrevoSynchronisationService.isEmailAddressInUse(String)
- Specified by:
updateEmailAddresses
in interfaceBrevoSynchronisationService
- Parameters:
changes
- a map containing the current email addresses as keys, and the new email addresses as values
-
isEmailAddressInUse
despiteContactsApi.getContactInfoWithHttpInfo(String, Object, Object)
existing, a 404 still throws an exception instead of just returning the code so we can handle it ourselves. this means, we have to catch the exception and read the status code from there- Specified by:
isEmailAddressInUse
in interfaceBrevoSynchronisationService
- Parameters:
email
- the email address to check- Returns:
- true if a contact exists, false other
-
setRemoveFromListLimit
@Value("${nice2.brevo.removeFromListLimit}") public void setRemoveFromListLimit(int removeFromListLimit) -
setImportLimit
@Value("${nice2.brevo.importLimit}") public void setImportLimit(int importLimit)
-