Add docUrl into metadata.

Nipuni Kavindya 2 months ago
parent 97ee77fc19
commit 26a54a7a49

@ -24,6 +24,7 @@ public class WhiteLabelTheme {
private WhiteLabelImage logoIconImage; private WhiteLabelImage logoIconImage;
private String footerText; private String footerText;
private String appTitle; private String appTitle;
private String docUrl;
public String getFooterText() { public String getFooterText() {
return footerText; return footerText;
@ -64,4 +65,12 @@ public class WhiteLabelTheme {
public void setLogoIconImage(WhiteLabelImage logoIconImage) { public void setLogoIconImage(WhiteLabelImage logoIconImage) {
this.logoIconImage = logoIconImage; this.logoIconImage = logoIconImage;
} }
public String getDocUrl() {
return docUrl;
}
public void setDocUrl(String docUrl) {
this.docUrl = docUrl;
}
} }

@ -24,6 +24,7 @@ public class WhiteLabelThemeCreateRequest {
private WhiteLabelImageRequestPayload logoIcon; private WhiteLabelImageRequestPayload logoIcon;
private String footerText; private String footerText;
private String appTitle; private String appTitle;
private String docUrl;
public WhiteLabelImageRequestPayload getFavicon() { public WhiteLabelImageRequestPayload getFavicon() {
return favicon; return favicon;
@ -64,4 +65,12 @@ public class WhiteLabelThemeCreateRequest {
public void setLogoIcon(WhiteLabelImageRequestPayload logoIcon) { public void setLogoIcon(WhiteLabelImageRequestPayload logoIcon) {
this.logoIcon = logoIcon; this.logoIcon = logoIcon;
} }
public String getDocUrl() {
return docUrl;
}
public void setDocUrl(String docUrl) {
this.docUrl = docUrl;
}
} }

@ -26,6 +26,16 @@ public class WhiteLabelConfiguration {
private String footerText; private String footerText;
private String appTitle; private String appTitle;
private WhiteLabelImages whiteLabelImages; private WhiteLabelImages whiteLabelImages;
private String docUrl;
@XmlElement(name = "DocUrl", required = true)
public String getDocUrl() {
return docUrl;
}
public void setDocUrl(String docUrl) {
this.docUrl = docUrl;
}
@XmlElement(name = "FooterText", required = true) @XmlElement(name = "FooterText", required = true)
public String getFooterText() { public String getFooterText() {

@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.device.mgt.core.internal; package io.entgra.device.mgt.core.device.mgt.core.internal;
import io.entgra.device.mgt.core.device.mgt.common.authorization.GroupAccessAuthorizationService; import io.entgra.device.mgt.core.device.mgt.common.authorization.GroupAccessAuthorizationService;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService; import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import io.entgra.device.mgt.core.device.mgt.core.authorization.GroupAccessAuthorizationServiceImpl; import io.entgra.device.mgt.core.device.mgt.core.authorization.GroupAccessAuthorizationServiceImpl;
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.DeviceStatusManagementServiceImpl; import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.DeviceStatusManagementServiceImpl;
@ -335,15 +336,14 @@ public class DeviceManagementServiceComponent {
bundleContext.registerService(MetadataManagementService.class.getName(), metadataManagementService, null); bundleContext.registerService(MetadataManagementService.class.getName(), metadataManagementService, null);
/* Registering Whitelabel Service */ /* Registering Whitelabel Service */
try {
WhiteLabelManagementService whiteLabelManagementService = new WhiteLabelManagementServiceImpl(); WhiteLabelManagementService whiteLabelManagementService = new WhiteLabelManagementServiceImpl();
DeviceManagementDataHolder.getInstance().setWhiteLabelManagementService(whiteLabelManagementService); DeviceManagementDataHolder.getInstance().setWhiteLabelManagementService(whiteLabelManagementService);
try {
whiteLabelManagementService.addDefaultWhiteLabelThemeIfNotExist(tenantId); whiteLabelManagementService.addDefaultWhiteLabelThemeIfNotExist(tenantId);
} catch (Throwable e) {
log.error("Error occurred while adding default tenant white label theme", e);
}
bundleContext.registerService(WhiteLabelManagementService.class.getName(), whiteLabelManagementService, null); bundleContext.registerService(WhiteLabelManagementService.class.getName(), whiteLabelManagementService, null);
} catch (MetadataManagementException e) {
log.error("Error occurred while initializing the white label management service", e);
}
/* Registering DeviceState Filter Service */ /* Registering DeviceState Filter Service */
DeviceStatusManagementService deviceStatusManagementService = new DeviceStatusManagementServiceImpl(); DeviceStatusManagementService deviceStatusManagementService = new DeviceStatusManagementServiceImpl();

@ -60,8 +60,48 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
private final MetadataDAO metadataDAO; private final MetadataDAO metadataDAO;
public WhiteLabelManagementServiceImpl() { public WhiteLabelManagementServiceImpl() throws MetadataManagementException {
this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO(); this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO();
initializeWhiteLabelThemes();
}
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);
}
}
} else {
addDefaultWhiteLabelThemeIfNotExist(tenantId);
}
} 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();
}
} }
@Override @Override
@ -183,6 +223,16 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
WhiteLabelStorageUtil.deleteWhiteLabelImageForTenantIfExists(tenantId); WhiteLabelStorageUtil.deleteWhiteLabelImageForTenantIfExists(tenantId);
} }
/**
* Get default metaDataConfiguration DocUrl from config
*/
private String getDefaultDocUrl() {
MetaDataConfiguration metaDataConfiguration = DeviceConfigurationManager.getInstance().
getDeviceManagementConfig().getMetaDataConfiguration();
WhiteLabelConfiguration whiteLabelConfiguration = metaDataConfiguration.getWhiteLabelConfiguration();
return whiteLabelConfiguration.getDocUrl();
}
/** /**
* Construct and return default whitelabel detail bean {@link WhiteLabelImage} * Construct and return default whitelabel detail bean {@link WhiteLabelImage}
*/ */
@ -193,11 +243,13 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
WhiteLabelImage logo = constructDefaultLogoImage(); WhiteLabelImage logo = constructDefaultLogoImage();
WhiteLabelImage logoIcon = constructDefaultLogoIconImage(); WhiteLabelImage logoIcon = constructDefaultLogoIconImage();
WhiteLabelTheme defaultTheme = new WhiteLabelTheme(); WhiteLabelTheme defaultTheme = new WhiteLabelTheme();
String docUrl = getDefaultDocUrl();
defaultTheme.setFooterText(footerText); defaultTheme.setFooterText(footerText);
defaultTheme.setAppTitle(appTitle); defaultTheme.setAppTitle(appTitle);
defaultTheme.setLogoImage(logo); defaultTheme.setLogoImage(logo);
defaultTheme.setLogoIconImage(logoIcon); defaultTheme.setLogoIconImage(logoIcon);
defaultTheme.setFaviconImage(favicon); defaultTheme.setFaviconImage(favicon);
defaultTheme.setDocUrl(docUrl);
return defaultTheme; return defaultTheme;
} }
@ -386,6 +438,7 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
whiteLabelTheme.setLogoIconImage(logoIconImage); whiteLabelTheme.setLogoIconImage(logoIconImage);
whiteLabelTheme.setFooterText(whiteLabelThemeCreateRequest.getFooterText()); whiteLabelTheme.setFooterText(whiteLabelThemeCreateRequest.getFooterText());
whiteLabelTheme.setAppTitle(whiteLabelThemeCreateRequest.getAppTitle()); whiteLabelTheme.setAppTitle(whiteLabelThemeCreateRequest.getAppTitle());
whiteLabelTheme.setDocUrl(whiteLabelThemeCreateRequest.getDocUrl());
return whiteLabelTheme; return whiteLabelTheme;
} }
@ -418,6 +471,38 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
return metadata; return metadata;
} }
/**
* updates the given WhiteLabelTheme with default value for docUrl
*
* @param whiteLabelTheme the WhiteLabelTheme to be updated with defaults if necessary.
* @param tenantId the ID of the tenant whose metadata is being updated.
* @throws MetadataManagementException exception for an error occurs during the update or transaction commit.
*/
private void updateWhiteLabelThemeWithDefaults(WhiteLabelTheme whiteLabelTheme, int tenantId)
throws MetadataManagementException {
WhiteLabelTheme defaultTheme = getDefaultWhiteLabelTheme();
if (whiteLabelTheme.getDocUrl() == null) {
whiteLabelTheme.setDocUrl(defaultTheme.getDocUrl());
}
Metadata updatedMetadata = constructWhiteLabelThemeMetadata(whiteLabelTheme);
try {
MetadataManagementDAOFactory.beginTransaction();
metadataDAO.updateMetadata(tenantId, updatedMetadata);
MetadataManagementDAOFactory.commitTransaction();
} catch (MetadataManagementDAOException e) {
MetadataManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while updating metadata for tenant: " + tenantId;
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while committing the transaction for tenant: " + tenantId;
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} finally {
MetadataManagementDAOFactory.closeConnection();
}
}
@Override @Override
public WhiteLabelTheme getWhiteLabelTheme(String tenantDomain) throws MetadataManagementException, DeviceManagementException { public WhiteLabelTheme getWhiteLabelTheme(String tenantDomain) throws MetadataManagementException, DeviceManagementException {
int tenantId = DeviceManagerUtil.getTenantId(tenantDomain); int tenantId = DeviceManagerUtil.getTenantId(tenantDomain);
@ -435,7 +520,11 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
throw new MetadataManagementException(msg); throw new MetadataManagementException(msg);
} }
} }
return new Gson().fromJson(metadata.getMetaValue(), WhiteLabelTheme.class); WhiteLabelTheme whiteLabelTheme = new Gson().fromJson(metadata.getMetaValue(), WhiteLabelTheme.class);
if (whiteLabelTheme.getDocUrl() == null) {
updateWhiteLabelThemeWithDefaults(whiteLabelTheme, tenantId);
}
return whiteLabelTheme;
} }
/** /**

@ -200,10 +200,8 @@
<DefaultLogoIconName>icon.png</DefaultLogoIconName> <DefaultLogoIconName>icon.png</DefaultLogoIconName>
<DefaultImagesLocation>default</DefaultImagesLocation> <DefaultImagesLocation>default</DefaultImagesLocation>
</WhiteLabelImages> </WhiteLabelImages>
</WhiteLabelConfiguration>
<DocConfiguration>
<DocUrl>https://docs.entgra.io/uem/6.0.0</DocUrl> <DocUrl>https://docs.entgra.io/uem/6.0.0</DocUrl>
</DocConfiguration> </WhiteLabelConfiguration>
</MetaDataConfiguration> </MetaDataConfiguration>
<OperationTimeoutConfigurations> <OperationTimeoutConfigurations>

@ -348,12 +348,10 @@
<DefaultLogoIconName>icon.png</DefaultLogoIconName> <DefaultLogoIconName>icon.png</DefaultLogoIconName>
<DefaultImagesLocation>default</DefaultImagesLocation> <DefaultImagesLocation>default</DefaultImagesLocation>
</WhiteLabelImages> </WhiteLabelImages>
</WhiteLabelConfiguration>
<DocConfiguration>
{% if product_conf is defined %} {% if product_conf is defined %}
<DocUrl>https://docs.entgra.io/uem/{{product_conf.server_version}}</DocUrl> <DocUrl>https://docs.entgra.io/uem/{{product_conf.server_version}}</DocUrl>
{% endif %} {% endif %}
</DocConfiguration> </WhiteLabelConfiguration>
</MetaDataConfiguration> </MetaDataConfiguration>
<OperationTimeoutConfigurations> <OperationTimeoutConfigurations>
<OperationTimeouts> <OperationTimeouts>

Loading…
Cancel
Save