diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/WhiteLabelServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/WhiteLabelServiceImpl.java index 97621667dcd..9c11dcd6f06 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/WhiteLabelServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/WhiteLabelServiceImpl.java @@ -127,13 +127,9 @@ public class WhiteLabelServiceImpl implements WhiteLabelService { WhiteLabelTheme whiteLabelTheme = DeviceMgtAPIUtils.getWhiteLabelManagementService().getWhiteLabelTheme(tenantDomain); return Response.status(Response.Status.CREATED).entity(whiteLabelTheme).build(); } catch (MetadataManagementException e) { - String msg = "Error occurred while deleting whitelabel for tenant"; + String msg = "Error occurred while getting whitelabel for tenant"; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } catch (NotFoundException e) { - String msg = "Not white label theme configured for this tenant"; - log.error(msg, e); - return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (DeviceManagementException e) { String msg = "Error occurred while retrieving tenant details of whitelabel"; log.error(msg, e); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/WhiteLabelManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/WhiteLabelManagementService.java index 6ccf82eab47..6fc34c52dda 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/WhiteLabelManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/WhiteLabelManagementService.java @@ -79,5 +79,5 @@ public interface WhiteLabelManagementService { * This method is useful to get existing white label theme * @throws MetadataManagementException if error while getting existing white label theme */ - WhiteLabelTheme getWhiteLabelTheme(String tenantDomain) throws MetadataManagementException, NotFoundException, DeviceManagementException; + WhiteLabelTheme getWhiteLabelTheme(String tenantDomain) throws MetadataManagementException, DeviceManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/WhiteLabelManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/WhiteLabelManagementServiceImpl.java index ec2bca767e0..79e0c7ec017 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/WhiteLabelManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/WhiteLabelManagementServiceImpl.java @@ -26,7 +26,6 @@ import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Base64File; import org.wso2.carbon.device.mgt.common.FileResponse; @@ -329,10 +328,6 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ } finally { MetadataManagementDAOFactory.closeConnection(); } - } catch (NotFoundException e) { - String msg = "Error occurred while retrieving existing white label theme"; - log.error(msg, e); - throw new MetadataManagementException(msg, e); } catch (DeviceManagementException e) { String msg = "Error occurred while getting tenant details of white label"; log.error(msg, e); @@ -429,20 +424,36 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ } @Override - public WhiteLabelTheme getWhiteLabelTheme(String tenantDomain) throws MetadataManagementException, NotFoundException, DeviceManagementException { + public WhiteLabelTheme getWhiteLabelTheme(String tenantDomain) throws MetadataManagementException, DeviceManagementException { int tenantId = DeviceManagerUtil.getTenantId(tenantDomain); if (log.isDebugEnabled()) { log.debug("Retrieving whitelabel theme for tenant: " + tenantId); } - try { - MetadataManagementDAOFactory.openConnection(); - Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.WHITELABEL_META_KEY); + Metadata metadata = getWhiteLabelMetaData(tenantId); + if (metadata == null) { + addDefaultWhiteLabelThemeIfNotExist(tenantId); + metadata = getWhiteLabelMetaData(tenantId); if (metadata == null) { - String msg = "Whitelabel theme not found for tenant: " + tenantId; + String msg = "Whitelabel theme not found for tenant: " + tenantId + ". Further, Default White Label " + + "Theming Adding step failed."; log.error(msg); - throw new NotFoundException(msg); + throw new MetadataManagementException(msg); } - return new Gson().fromJson(metadata.getMetaValue(), WhiteLabelTheme.class); + } + return new Gson().fromJson(metadata.getMetaValue(), WhiteLabelTheme.class); + } + + /** + * Load White label Meta Data for given tenant Id. + * @param tenantId Id of the tenant + * @return {@link Metadata} + * @throws MetadataManagementException if an error occurred while getting Meta-Data info from Database for a + * given tenant ID. + */ + private Metadata getWhiteLabelMetaData (int tenantId) throws MetadataManagementException { + try { + MetadataManagementDAOFactory.openConnection(); + return metadataDAO.getMetadata(tenantId, MetadataConstants.WHITELABEL_META_KEY); } catch (MetadataManagementDAOException e) { String msg = "Error occurred while retrieving white label theme for tenant:" + tenantId; log.error(msg, e);