Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Notification Template API] Event Handler Implementation #250

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6401241
Add Notification Template API SMS template functions
RushanNanayakkara Jul 2, 2024
e19c8ea
Merge remote-tracking branch 'upstream/master' into ft_notification_t…
RushanNanayakkara Aug 24, 2024
8dcafb4
Merge remote-tracking branch 'upstream/master' into ft_notification_t…
RushanNanayakkara Sep 8, 2024
3e91c12
Add Notification Template API SMS template functions
RushanNanayakkara Sep 24, 2024
ffd5c3d
Add system notification template related functions.
RushanNanayakkara Sep 26, 2024
f12d380
Allow partial deletion for system template types
RushanNanayakkara Sep 29, 2024
269cf57
Merge remote-tracking branch 'upstream/master' into ft_notification_t…
RushanNanayakkara Sep 29, 2024
9d494c3
Remove partial deletion for system template types and add deleteCusto…
RushanNanayakkara Oct 5, 2024
4a1e0b6
Merge remote-tracking branch 'upstream/master' into ft_notification_t…
RushanNanayakkara Oct 5, 2024
b07a9cd
Merge remote-tracking branch 'upstream/master' into ft_notification_t…
RushanNanayakkara Oct 15, 2024
bceca94
Get main app through application management service
RushanNanayakkara Oct 16, 2024
bdbae4c
Add deleteAllNotificationTemplates function
RushanNanayakkara Oct 17, 2024
f3b34a6
Clear cache when all templates or a type are removed.
RushanNanayakkara Oct 18, 2024
9595a60
Merge remote-tracking branch 'upstream/master' into ft_notification_t…
RushanNanayakkara Oct 18, 2024
4252c14
Refactor code
RushanNanayakkara Oct 20, 2024
b828356
Addressing comments
RushanNanayakkara Oct 21, 2024
26a332f
Code refactoring
RushanNanayakkara Oct 21, 2024
cef6060
addressing comments
RushanNanayakkara Oct 22, 2024
e012ab9
Bump governance version
RushanNanayakkara Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ private I18nMgtConstants() {}
public static final String NOTIFICATION_TEMPLATES_STORAGE_CONFIG = "DataStorageType.NotificationTemplates";
public static final String NOTIFICATION_TEMPLATES_LEGACY_TENANTS = "NotificationTemplates.LegacyTenants.Tenant";

public static final String SERVICE_PROPERTY_KEY_SERVICE_NAME = "service.name";
public static final String SERVICE_PROPERTY_VAL_EMAIL_TEMPLATE_MANAGER = "EmailTemplateManager";
public static final String SERVICE_PROPERTY_VAL_NOTIFICATION_TEMPLATE_MANAGER = "NotificationTemplateManager";

public static class ErrorMsg {
private ErrorMsg() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,7 @@ public class SQLConstants {
public static final String DELETE_APP_NOTIFICATION_TEMPLATES_BY_TYPE_SQL =
"DELETE FROM IDN_NOTIFICATION_APP_TEMPLATE WHERE TYPE_ID = (" + GET_NOTIFICATION_TYPE_ID_SQL +
") AND APP_ID = :APP_ID; AND TENANT_ID = :TENANT_ID;";
public static final String DELETE_ALL_APP_NOTIFICATION_TEMPLATES_BY_TYPE_SQL =
"DELETE FROM IDN_NOTIFICATION_APP_TEMPLATE WHERE TYPE_ID = (" + GET_NOTIFICATION_TYPE_ID_SQL +
") AND TENANT_ID = :TENANT_ID;";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright (c) 2023-2024, WSO2 LLC. (http://www.wso2.com).
*
RushanNanayakkara marked this conversation as resolved.
Show resolved Hide resolved
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.email.mgt.constants;

public class TemplateMgtConstants {

private TemplateMgtConstants() {}

public static final String DEFAULT_EMAIL_NOTIFICATION_LOCALE = "en_US";
public static final String DEFAULT_SMS_NOTIFICATION_LOCALE = "en_US";

/**
* Class which contains the error scenarios.
*/
public static class ErrorScenarios {

Check warning on line 31 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L31

Added line #L31 was not covered by tests

// NTM - NOTIFICATION TEMPLATE MANAGER
public static final String NOTIFICATION_TEMPLATE_MANAGER = "NTM";
}

/**
* Class which contains the error codes for template management.
*/
public static class ErrorCodes {

Check warning on line 40 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L40

Added line #L40 was not covered by tests
RushanNanayakkara marked this conversation as resolved.
Show resolved Hide resolved

public static final String TEMPLATE_TYPE_ALREADY_EXISTS = "65001";
public static final String TEMPLATE_TYPE_NOT_FOUND = "65002";
public static final String TEMPLATE_ALREADY_EXISTS = "65003";
public static final String TEMPLATE_NOT_FOUND = "65004";
public static final String ERROR_ADDING_TEMPLATE = "65005";
public static final String ERROR_UPDATING_TEMPLATE = "65006";
public static final String ERROR_SYSTEM_RESOURCE_DELETION_NOT_ALLOWED = "65007";
public static final String ERROR_RESOLVING_MAIN_APPLICATION = "65008";
}

/**
* Enum which contains error codes and corresponding error messages.
*/
public enum ErrorMessages {

Check warning on line 55 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L55

Added line #L55 was not covered by tests

ERROR_CODE_EMPTY_TEMPLATE_NAME("60001", "Notification template name cannot be empty."),
ERROR_CODE_EMPTY_LOCALE("60002", "Locale code cannot be empty"),
ERROR_CODE_INVALID_LOCALE("60003", "Locale code is invalid."),
ERROR_CODE_EMPTY_TEMPLATE_CHANNEL("60004", "Notification template channel cannot be empty"),
ERROR_CODE_INVALID_SMS_TEMPLATE("60005", "Body of a SMS template cannot be empty."),
ERROR_CODE_INVALID_SMS_TEMPLATE_CONTENT("60006", "SMS template cannot have a subject or footer"),
ERROR_CODE_INVALID_EMAIL_TEMPLATE("60007", "Subject/Body/Footer sections of an email template " +

Check warning on line 63 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L57-L63

Added lines #L57 - L63 were not covered by tests
"cannot be empty."),
ERROR_CODE_INVALID_TEMPLATE_DISPLAY_NAME("60008", "Invalid template display name."),
ERROR_CODE_NULL_TEMPLATE_OBJECT("60009", "Notification template is not provided."),
ERROR_CODE_TEMPLATE_TYPE_ALREADY_EXISTS(ErrorCodes.TEMPLATE_TYPE_ALREADY_EXISTS,

Check warning on line 67 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L65-L67

Added lines #L65 - L67 were not covered by tests
"Notification template type : %s already exists in tenant : %s"),
ERROR_CODE_TEMPLATE_TYPE_NOT_FOUND(ErrorCodes.TEMPLATE_TYPE_NOT_FOUND, "Notification template type :" +

Check warning on line 69 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L69

Added line #L69 was not covered by tests
" %s doesn't exist in tenant : %s"),
ERROR_CODE_TEMPLATE_ALREADY_EXISTS(ErrorCodes.TEMPLATE_ALREADY_EXISTS, "Notification template : %s" +

Check warning on line 71 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L71

Added line #L71 was not covered by tests
" already exists in tenant : %s"),
ERROR_CODE_TEMPLATE_NOT_FOUND(ErrorCodes.TEMPLATE_NOT_FOUND, "Notification template : %s " +

Check warning on line 73 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L73

Added line #L73 was not covered by tests
"doesn't exist in tenant : %s"),
ERROR_CODE_SYSTEM_TEMPLATE_TYPE_NOT_FOUND(ErrorCodes.TEMPLATE_TYPE_NOT_FOUND,

Check warning on line 75 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L75

Added line #L75 was not covered by tests
"System notification template type : %s doesn't exist."),
ERROR_CODE_SYSTEM_TEMPLATE_NOT_FOUND(ErrorCodes.TEMPLATE_NOT_FOUND, "System notification " +

Check warning on line 77 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L77

Added line #L77 was not covered by tests
"template : %s doesn't exist"),
ERROR_CODE_ERROR_ADDING_TEMPLATE(ErrorCodes.ERROR_ADDING_TEMPLATE, "Error when adding template : %s" +

Check warning on line 79 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L79

Added line #L79 was not covered by tests
" to tenant : %s"),
ERROR_CODE_ERROR_UPDATING_TEMPLATE(ErrorCodes.ERROR_UPDATING_TEMPLATE, "Error when updating " +

Check warning on line 81 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L81

Added line #L81 was not covered by tests
"template : %s on tenant : %s"),
ERROR_CODE_SYSTEM_RESOURCE_DELETION_NOT_ALLOWED(ErrorCodes.ERROR_SYSTEM_RESOURCE_DELETION_NOT_ALLOWED,

Check warning on line 83 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L83

Added line #L83 was not covered by tests
"System resource deletion not allowed. %S"),
ERROR_CODE_ERROR_RESOLVING_MAIN_APPLICATION(ErrorCodes.ERROR_RESOLVING_MAIN_APPLICATION,

Check warning on line 85 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L85

Added line #L85 was not covered by tests
"Error when resolving main application : %s");

private final String code;
private final String message;

ErrorMessages(String code, String message) {

Check warning on line 91 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L91

Added line #L91 was not covered by tests

this.code = code;
this.message = message;
}

Check warning on line 95 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L93-L95

Added lines #L93 - L95 were not covered by tests

public String getCode() {

return code;

Check warning on line 99 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L99

Added line #L99 was not covered by tests
}

public String getMessage() {

return message;

Check warning on line 104 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L104

Added line #L104 was not covered by tests
}

@Override
public String toString() {

return code + " - " + message;

Check warning on line 110 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/constants/TemplateMgtConstants.java#L110

Added line #L110 was not covered by tests
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.email.mgt.EmailTemplateManager;
import org.wso2.carbon.email.mgt.EmailTemplateManagerImpl;
import org.wso2.carbon.email.mgt.NotificationTemplateManagerImpl;
import org.wso2.carbon.email.mgt.SMSProviderPayloadTemplateManager;
import org.wso2.carbon.email.mgt.SMSProviderPayloadTemplateManagerImpl;
import org.wso2.carbon.email.mgt.constants.I18nMgtConstants;
Expand Down Expand Up @@ -61,6 +62,7 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand All @@ -71,6 +73,9 @@
import javax.xml.stream.XMLStreamReader;

import static org.wso2.carbon.email.mgt.constants.I18nMgtConstants.NOTIFICATION_TEMPLATES_LEGACY_TENANTS;
import static org.wso2.carbon.email.mgt.constants.I18nMgtConstants.SERVICE_PROPERTY_KEY_SERVICE_NAME;
import static org.wso2.carbon.email.mgt.constants.I18nMgtConstants.SERVICE_PROPERTY_VAL_EMAIL_TEMPLATE_MANAGER;
import static org.wso2.carbon.email.mgt.constants.I18nMgtConstants.SERVICE_PROPERTY_VAL_NOTIFICATION_TEMPLATE_MANAGER;
import static org.wso2.carbon.email.mgt.constants.I18nMgtConstants.SMS_PROVIDER;
import static org.wso2.carbon.email.mgt.constants.I18nMgtConstants.SMS_PROVIDER_POST_BODY_TEMPLATES_DIR_PATH;
import static org.wso2.carbon.email.mgt.constants.I18nMgtConstants.TEMPLATE_BODY;
RushanNanayakkara marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -111,12 +116,28 @@ protected void activate(ComponentContext context) {
}

// Register EmailTemplateManagerImpl.
Hashtable<String, String> emailTemplateManagerServiceProperties = new Hashtable<>();
emailTemplateManagerServiceProperties.put(SERVICE_PROPERTY_KEY_SERVICE_NAME,
SERVICE_PROPERTY_VAL_EMAIL_TEMPLATE_MANAGER);
ServiceRegistration notificationManagerSR = bundleCtx
.registerService(NotificationTemplateManager.class.getName(), emailTemplateManager, null);
.registerService(NotificationTemplateManager.class.getName(), emailTemplateManager,
emailTemplateManagerServiceProperties);
if (notificationManagerSR != null) {
if (log.isDebugEnabled()) {
log.debug("Notification Template Mgt Service registered.");
}
log.debug("Notification Template Mgt Service registered.");
} else {
log.error("Error registering Notification Template Mgt Service.");
}

// Register Notification Template Mgt Service as an OSGi service.
NotificationTemplateManagerImpl notificationTemplateManager = new NotificationTemplateManagerImpl();
Hashtable<String, String> notificationTemplateManagerServiceProperties = new Hashtable<>();
notificationTemplateManagerServiceProperties.put(SERVICE_PROPERTY_KEY_SERVICE_NAME,
SERVICE_PROPERTY_VAL_NOTIFICATION_TEMPLATE_MANAGER);
ServiceRegistration notificationTemplateSR = bundleCtx
.registerService(NotificationTemplateManager.class.getName(), notificationTemplateManager,
notificationTemplateManagerServiceProperties);
if (notificationTemplateSR != null) {
log.debug("Notification Template Mgt Service registered.");
} else {
log.error("Error registering Notification Template Mgt Service.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,25 @@
}
}

@Override
public void deleteAllNotificationTemplates(String displayName, String notificationChannel, String tenantDomain)
throws NotificationTemplateManagerServerException {

String templateTypeKey = displayName.toLowerCase();
int tenantId = getTenantId(tenantDomain);

Check warning on line 336 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/DBBasedTemplateManager.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/DBBasedTemplateManager.java#L335-L336

Added lines #L335 - L336 were not covered by tests

orgNotificationTemplateDAO.removeNotificationTemplates(templateTypeKey, notificationChannel, tenantId);

Check warning on line 338 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/DBBasedTemplateManager.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/DBBasedTemplateManager.java#L338

Added line #L338 was not covered by tests
if (log.isDebugEnabled()) {
log.debug(String.format("Org %s templates for type: %s for tenant: %s successfully deleted.",

Check warning on line 340 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/DBBasedTemplateManager.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/DBBasedTemplateManager.java#L340

Added line #L340 was not covered by tests
notificationChannel, displayName, tenantDomain));
}
appNotificationTemplateDAO.removeAllNotificationTemplates(templateTypeKey, notificationChannel, tenantId);

Check warning on line 343 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/DBBasedTemplateManager.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/DBBasedTemplateManager.java#L343

Added line #L343 was not covered by tests
if (log.isDebugEnabled()) {
log.debug(String.format("App %s templates for type: %s for all applications for tenant: %s " +

Check warning on line 345 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/DBBasedTemplateManager.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/DBBasedTemplateManager.java#L345

Added line #L345 was not covered by tests
"successfully deleted.", notificationChannel, displayName, tenantDomain));
}
}

Check warning on line 348 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/DBBasedTemplateManager.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/DBBasedTemplateManager.java#L348

Added line #L348 was not covered by tests

/**
* Get the tenant id of the given tenant domain.
* @param tenantDomain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@
}
}

@Override
public void deleteAllNotificationTemplates(String displayName, String notificationChannel, String tenantDomain)
throws NotificationTemplateManagerServerException {

if (dbBasedTemplateManager.isNotificationTemplateTypeExists(displayName, notificationChannel, tenantDomain)) {
dbBasedTemplateManager.deleteAllNotificationTemplates(displayName, notificationChannel, tenantDomain);

Check warning on line 110 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/HybridTemplateManager.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/HybridTemplateManager.java#L110

Added line #L110 was not covered by tests
}

if (registryBasedTemplateManager.isNotificationTemplateTypeExists(displayName, notificationChannel,
tenantDomain)) {
registryBasedTemplateManager.deleteAllNotificationTemplates(displayName, notificationChannel, tenantDomain);

Check warning on line 115 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/HybridTemplateManager.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/HybridTemplateManager.java#L115

Added line #L115 was not covered by tests
}
}

Check warning on line 117 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/HybridTemplateManager.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/HybridTemplateManager.java#L117

Added line #L117 was not covered by tests

@Override
public void addOrUpdateNotificationTemplate(NotificationTemplate notificationTemplate, String applicationUuid,
String tenantDomain) throws NotificationTemplateManagerServerException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,23 @@
}
}

@Override
public void deleteAllNotificationTemplates(String displayName, String notificationChannel, String tenantDomain)
throws NotificationTemplateManagerServerException {

String path = buildTemplateRootDirectoryPath(I18nEmailUtil.getNormalizedName(displayName),

Check warning on line 304 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/RegistryBasedTemplateManager.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/RegistryBasedTemplateManager.java#L304

Added line #L304 was not covered by tests
notificationChannel, null);

try {
Collection templates = (Collection) resourceMgtService.getIdentityResource(path, tenantDomain);

Check warning on line 308 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/RegistryBasedTemplateManager.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/RegistryBasedTemplateManager.java#L308

Added line #L308 was not covered by tests
for (String subPath : templates.getChildren()) {
resourceMgtService.deleteIdentityResource(subPath, tenantDomain);

Check warning on line 310 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/RegistryBasedTemplateManager.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/RegistryBasedTemplateManager.java#L310

Added line #L310 was not covered by tests
}
} catch (IdentityRuntimeException | RegistryException e) {
throw new NotificationTemplateManagerServerException("Error while deleting notification templates.", e);
}
}

Check warning on line 315 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/RegistryBasedTemplateManager.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/RegistryBasedTemplateManager.java#L312-L315

Added lines #L312 - L315 were not covered by tests

/**
* Get the notification template from resource.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@
throw new UnsupportedOperationException();
}

@Override
public void deleteAllNotificationTemplates(String displayName, String notificationChannel, String tenantDomain)
throws NotificationTemplateManagerServerException {

throw new UnsupportedOperationException();

Check warning on line 119 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/SystemDefaultTemplateManager.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/SystemDefaultTemplateManager.java#L119

Added line #L119 was not covered by tests
}

@Override
public void addOrUpdateNotificationTemplate(NotificationTemplate notificationTemplate, String applicationUuid,
String tenantDomain) throws NotificationTemplateManagerServerException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@
void deleteNotificationTemplateType(String displayName, String notificationChannel, String tenantDomain)
throws NotificationTemplateManagerServerException;

/**
* Delete both organization level and application level notification templates under a notification template type.
*
* @param displayName Display Name.
* @param notificationChannel Notification channel.
* @param tenantDomain Tenant domain.
* @throws NotificationTemplateManagerServerException If an error occurred while resetting the template type.
*/
default void deleteAllNotificationTemplates(String displayName, String notificationChannel, String tenantDomain)
throws NotificationTemplateManagerServerException {
// not implemented
}

Check warning on line 87 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManager.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManager.java#L87

Added line #L87 was not covered by tests

/**
* Update the notification template if exists or add a new template if not exists.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
private static final Log log = LogFactory.getLog(TemplatePersistenceManagerFactory.class);

/**
* Returns a {@link TemplatePersistenceManager} implementation based on the configuration.
* Returns a {@link TemplatePersistenceManager} implementation based on the configuration that handles both system
* templates and user defined templates.
*
* If the storage type is configured as database, an instance of {@link DBBasedTemplateManager} will be returned.
* If the storage type is configured as hybrid, an instance of {@link HybridTemplateManager} will be returned.
Expand Down Expand Up @@ -66,4 +67,60 @@
}
return new UnifiedTemplateManager(persistenceManager);
}

/**
* Returns a {@link TemplatePersistenceManager} implementation based on the configuration that handles only user
* defined templates.
*
* If the storage type is configured as database, an instance of {@link DBBasedTemplateManager} will be returned.
* If the storage type is configured as hybrid, an instance of {@link HybridTemplateManager} will be returned.
* If the storage type is configured as registry, an instance of {@link RegistryBasedTemplateManager} will be returned.
* For any other case, an instance of {@link DBBasedTemplateManager} will be returned.
*
* @return an implementation of {@link TemplatePersistenceManager}.
*/
public TemplatePersistenceManager getUserDefinedTemplatePersistenceManager() {

String notificationTemplatesStorageType = IdentityUtil.getProperty(NOTIFICATION_TEMPLATES_STORAGE_CONFIG);

Check warning on line 84 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java#L84

Added line #L84 was not covered by tests

TemplatePersistenceManager persistenceManager = new DBBasedTemplateManager();

Check warning on line 86 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java#L86

Added line #L86 was not covered by tests

if (StringUtils.isNotBlank(notificationTemplatesStorageType)) {
switch (notificationTemplatesStorageType) {
case "hybrid":
persistenceManager = new HybridTemplateManager();
log.info("Hybrid template persistent manager initialized.");
break;

Check warning on line 93 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java#L91-L93

Added lines #L91 - L93 were not covered by tests
case "registry":
persistenceManager = new RegistryBasedTemplateManager();
log.warn("Registry based template persistent manager initialized.");

Check warning on line 96 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java#L95-L96

Added lines #L95 - L96 were not covered by tests
break;
}
}

if (log.isDebugEnabled()) {
log.debug("Template persistent manager initialized with the type: " + persistenceManager.getClass());

Check warning on line 102 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java#L102

Added line #L102 was not covered by tests
}
return persistenceManager;

Check warning on line 104 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java#L104

Added line #L104 was not covered by tests
}

/**
* Returns a {@link TemplatePersistenceManager} implementation based on the configuration that handles only
* system templates.
*
* If the storage type is configured as database, an instance of {@link DBBasedTemplateManager} will be returned.
* If the storage type is configured as hybrid, an instance of {@link HybridTemplateManager} will be returned.
* If the storage type is configured as registry, an instance of {@link RegistryBasedTemplateManager} will be returned.
* For any other case, an instance of {@link DBBasedTemplateManager} will be returned.
*
* @return an implementation of {@link TemplatePersistenceManager}.
*/
public TemplatePersistenceManager getSystemTemplatePersistenceManager() {

SystemDefaultTemplateManager inMemoryTemplateManager = new SystemDefaultTemplateManager();

Check warning on line 120 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java#L120

Added line #L120 was not covered by tests
if (log.isDebugEnabled()) {
log.debug("Template persistent manager initialized with the type: " + inMemoryTemplateManager.getClass());

Check warning on line 122 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java#L122

Added line #L122 was not covered by tests
}
return inMemoryTemplateManager;

Check warning on line 124 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/TemplatePersistenceManagerFactory.java#L124

Added line #L124 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@
}
}

@Override
public void deleteAllNotificationTemplates(String displayName, String notificationChannel, String tenantDomain)
throws NotificationTemplateManagerServerException {

if (templatePersistenceManager.isNotificationTemplateTypeExists(displayName, notificationChannel,
tenantDomain)) {
templatePersistenceManager.deleteAllNotificationTemplates(displayName, notificationChannel, tenantDomain);

Check warning on line 91 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/UnifiedTemplateManager.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/UnifiedTemplateManager.java#L91

Added line #L91 was not covered by tests
}
}

Check warning on line 93 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/UnifiedTemplateManager.java

View check run for this annotation

Codecov / codecov/patch

components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/UnifiedTemplateManager.java#L93

Added line #L93 was not covered by tests

@Override
public void addOrUpdateNotificationTemplate(NotificationTemplate notificationTemplate, String applicationUuid,
String tenantDomain) throws NotificationTemplateManagerServerException {
Expand Down
Loading
Loading