Skip to content

Commit

Permalink
Add delete templates functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Avarjana committed Mar 4, 2024
1 parent 0840bfb commit 7a3ef92
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@ void deleteEmailTemplate(String templateTypeName,
String localeCode,
String tenantDomain) throws I18nEmailMgtException;

/**
* Delete all email templates from the tenant registry. Email templates are identified with the templateTypeName and
* localeCode.
*
* @param templateTypeName Email template type name.
* @param tenantDomain Tenant domain.
* @throws I18nEmailMgtException If an error occurred while deleting the email templates.
*/
void deleteEmailTemplates(String templateTypeName, String tenantDomain) throws I18nEmailMgtException;

/**
* Delete all email templates from the tenant registry. Email templates are identified with the templateTypeName,
* localeCode and application UUID.
*
* @param templateTypeName Email template type name.
* @param tenantDomain Tenant domain.
* @param applicationUuid Application UUID.
* @throws I18nEmailMgtException If an error occurred while deleting the email templates.
*/
void deleteEmailTemplates(String templateTypeName,
String tenantDomain,
String applicationUuid) throws I18nEmailMgtException;


/**
* Get an email template from tenant registry.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,52 @@ public void deleteEmailTemplate(String templateTypeName, String localeCode, Stri
deleteEmailTemplate(templateTypeName, localeCode, tenantDomain, null);
}

@Override
public void deleteEmailTemplates(String templateTypeName, String tenantDomain) throws I18nEmailMgtException {

validateTemplateType(templateTypeName, tenantDomain);

String templateType = I18nEmailUtil.getNormalizedName(templateTypeName);
String path = EMAIL_TEMPLATE_PATH + PATH_SEPARATOR + templateType;

try {
Collection templates = (Collection) resourceMgtService.getIdentityResource(path, tenantDomain);
for (String subPath : templates.getChildren()) {
// Exclude the app templates.
if (!subPath.contains(APP_TEMPLATE_PATH)) {
resourceMgtService.deleteIdentityResource(subPath, tenantDomain);
}
}
} catch (IdentityRuntimeException | RegistryException ex) {
String errorMsg = String.format
("Error deleting email template type %s from %s tenant.", templateType, tenantDomain);
handleServerException(errorMsg, ex);
}
}

@Override
public void deleteEmailTemplates(String templateTypeName, String tenantDomain, String applicationUuid)
throws I18nEmailMgtException {

validateTemplateType(templateTypeName, tenantDomain);

String templateType = I18nEmailUtil.getNormalizedName(templateTypeName);
String path = EMAIL_TEMPLATE_PATH + PATH_SEPARATOR + templateType + APP_TEMPLATE_PATH +
PATH_SEPARATOR + applicationUuid;

try {
if (!resourceMgtService.isResourceExists(path, tenantDomain)) {
// No templates found for the given application UUID.
return;
}
resourceMgtService.deleteIdentityResource(path, tenantDomain);
} catch (IdentityRuntimeException ex) {
String errorMsg = String.format("Error deleting email template type %s from %s tenant for application %s.",
templateType, tenantDomain, applicationUuid);
handleServerException(errorMsg, ex);
}
}

@Override
public void addDefaultEmailTemplates(String tenantDomain) throws I18nEmailMgtException {

Expand Down

0 comments on commit 7a3ef92

Please sign in to comment.