From db205de5b4f3aa0ddfb801ec94da0b52ebb77674 Mon Sep 17 00:00:00 2001 From: nipuni Date: Sat, 28 Sep 2024 01:46:26 +0530 Subject: [PATCH] Add docUrl into metadata. --- .../mgt/WhiteLabelManagementServiceImpl.java | 59 +++++++++---------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/WhiteLabelManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/WhiteLabelManagementServiceImpl.java index 0224d388a9..15a1e82cee 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/WhiteLabelManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/WhiteLabelManagementServiceImpl.java @@ -68,39 +68,38 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ private void initializeWhiteLabelThemes() throws MetadataManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); WhiteLabelTheme defaultTheme = getDefaultWhiteLabelTheme(); - try { - Metadata whiteLabelMetadata = getWhiteLabelMetaData(tenantId); - if (whiteLabelMetadata != null) { - WhiteLabelTheme whiteLabelTheme = new Gson().fromJson(whiteLabelMetadata.getMetaValue(), - WhiteLabelTheme.class); - if (whiteLabelTheme.getDocUrl() == null) { - whiteLabelTheme.setDocUrl(defaultTheme.getDocUrl()); - Metadata updatedMetadata = constructWhiteLabelThemeMetadata(whiteLabelTheme); - try { - MetadataManagementDAOFactory.beginTransaction(); - metadataDAO.updateMetadata(tenantId, updatedMetadata); - MetadataManagementDAOFactory.commitTransaction(); - if (log.isDebugEnabled()) { - log.debug("WhiteLabel theme's DocUrl was missing and has been updated to the default value " + - "for tenant: " + tenantId); - } - } catch (TransactionManagementException e) { - MetadataManagementDAOFactory.rollbackTransaction(); - String transactionErrorMsg = "Transaction failed while updating white label theme for tenant: " - + tenantId; - log.error(transactionErrorMsg, e); - throw new MetadataManagementException(transactionErrorMsg, e); + Metadata whiteLabelMetadata = getWhiteLabelMetaData(tenantId); + if (whiteLabelMetadata != null) { + WhiteLabelTheme whiteLabelTheme = new Gson().fromJson(whiteLabelMetadata.getMetaValue(), + WhiteLabelTheme.class); + if (whiteLabelTheme.getDocUrl() == null) { + whiteLabelTheme.setDocUrl(defaultTheme.getDocUrl()); + Metadata updatedMetadata = constructWhiteLabelThemeMetadata(whiteLabelTheme); + try { + MetadataManagementDAOFactory.beginTransaction(); + metadataDAO.updateMetadata(tenantId, updatedMetadata); + MetadataManagementDAOFactory.commitTransaction(); + if (log.isDebugEnabled()) { + log.debug("WhiteLabel theme's DocUrl was missing and has been updated to the default value " + + "for tenant: " + tenantId); } } - } else { - addDefaultWhiteLabelThemeIfNotExist(tenantId); + catch (MetadataManagementDAOException e) { + MetadataManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred while fetching white label metadata for tenant: " + tenantId; + log.error(msg, e); + throw new MetadataManagementException(msg, e); + } catch (TransactionManagementException e) { + String msg = "Transaction failed while updating white label theme for tenant: " + + tenantId; + log.error(msg, e); + throw new MetadataManagementException(msg, e); + } finally { + MetadataManagementDAOFactory.closeConnection(); + } } - } catch (MetadataManagementDAOException e) { - String msg = "Error occurred while fetching white label metadata for tenant: " + tenantId; - log.error(msg, e); - throw new MetadataManagementException(msg, e); - } finally { - MetadataManagementDAOFactory.closeConnection(); + } else { + addDefaultWhiteLabelThemeIfNotExist(tenantId); } }