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

Fix sonar warnings in TemplatePersistenceManagerFactory #277

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.email.mgt.constants.TemplateMgtConstants;
import org.wso2.carbon.email.mgt.internal.I18nMgtDataHolder;
import org.wso2.carbon.email.mgt.store.SystemDefaultTemplateManager;
import org.wso2.carbon.email.mgt.store.TemplatePersistenceManager;
import org.wso2.carbon.email.mgt.store.TemplatePersistenceManagerFactory;
import org.wso2.carbon.email.mgt.util.I18nEmailUtil;
Expand Down Expand Up @@ -61,7 +62,7 @@
TemplatePersistenceManagerFactory templatePersistenceManagerFactory = new TemplatePersistenceManagerFactory();
this.userDefinedTemplatePersistenceManager =
templatePersistenceManagerFactory.getUserDefinedTemplatePersistenceManager();
this.systemTemplatePersistenceManager = templatePersistenceManagerFactory.getSystemTemplatePersistenceManager();
this.systemTemplatePersistenceManager = new SystemDefaultTemplateManager();

Check warning on line 65 in components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/NotificationTemplateManagerImpl.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/NotificationTemplateManagerImpl.java#L65

Added line #L65 was not covered by tests
this.templatePersistenceManager = templatePersistenceManagerFactory.getTemplatePersistenceManager();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,25 @@ public class TemplatePersistenceManagerFactory {
private static final Log log = LogFactory.getLog(TemplatePersistenceManagerFactory.class);

/**
* 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.
* 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.
* Returns a {@link TemplatePersistenceManager} implementation that handles both system templates and user defined
* templates.
* Based on the configuration, the returning {@link UnifiedTemplateManager} instance will use an instance
* of user defined template manager as follows:
* if the storage type is configured as database, {@link DBBasedTemplateManager} will be used.
* if the storage type is configured as hybrid, {@link HybridTemplateManager} will be used.
* if the storage type is configured as registry, {@link RegistryBasedTemplateManager} will be used.
* For any other case, {@link DBBasedTemplateManager} will be used.
*
* @return an implementation of {@link TemplatePersistenceManager}.
*/
public TemplatePersistenceManager getTemplatePersistenceManager() {

String notificationTemplatesStorageType = IdentityUtil.getProperty(NOTIFICATION_TEMPLATES_STORAGE_CONFIG);

TemplatePersistenceManager persistenceManager = new DBBasedTemplateManager();

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

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

/**
* 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.
Expand All @@ -86,15 +66,12 @@ public TemplatePersistenceManager getUserDefinedTemplatePersistenceManager() {
TemplatePersistenceManager persistenceManager = new DBBasedTemplateManager();

if (StringUtils.isNotBlank(notificationTemplatesStorageType)) {
switch (notificationTemplatesStorageType) {
case "hybrid":
persistenceManager = new HybridTemplateManager();
log.info("Hybrid template persistent manager initialized.");
break;
case "registry":
persistenceManager = new RegistryBasedTemplateManager();
log.warn("Registry based template persistent manager initialized.");
break;
if (notificationTemplatesStorageType.equals("hybrid")) {
persistenceManager = new HybridTemplateManager();
log.info("Hybrid template persistent manager initialized.");
} else if (notificationTemplatesStorageType.equals("registry")) {
persistenceManager = new RegistryBasedTemplateManager();
log.warn("Registry based template persistent manager initialized.");
}
}

Expand All @@ -103,24 +80,4 @@ public TemplatePersistenceManager getUserDefinedTemplatePersistenceManager() {
}
return persistenceManager;
}

/**
* 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();
if (log.isDebugEnabled()) {
log.debug("Template persistent manager initialized with the type: " + inMemoryTemplateManager.getClass());
}
return inMemoryTemplateManager;
}
}
Loading