Skip to content

Commit

Permalink
Merge pull request #277 from darshanasbg/master
Browse files Browse the repository at this point in the history
Fix sonar warnings in TemplatePersistenceManagerFactory
  • Loading branch information
darshanasbg authored Nov 11, 2024
2 parents b9eef14 + 834b2fd commit 3e7a7b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 59 deletions.
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 @@ public NotificationTemplateManagerImpl() {
TemplatePersistenceManagerFactory templatePersistenceManagerFactory = new TemplatePersistenceManagerFactory();
this.userDefinedTemplatePersistenceManager =
templatePersistenceManagerFactory.getUserDefinedTemplatePersistenceManager();
this.systemTemplatePersistenceManager = templatePersistenceManagerFactory.getSystemTemplatePersistenceManager();
this.systemTemplatePersistenceManager = new SystemDefaultTemplateManager();
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;
}
}

0 comments on commit 3e7a7b1

Please sign in to comment.