Fix default theme loading issue (#98)

Co-authored-by: Dharmakeerthi Lasantha <tcdlpds@gmail.com>
Co-authored-by: Pahansith Gunathilake <pahansith@entgra.io>
Reviewed-on: community/device-mgt-core#98
Co-authored-by: Lasantha Dharmakeerthi <lasantha@entgra.io>
Co-committed-by: Lasantha Dharmakeerthi <lasantha@entgra.io>
scopeMapAPILayer
parent b4d5babd93
commit 63889f4e05

@ -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);

@ -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;
}

@ -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) {
String msg = "Whitelabel theme not found for tenant: " + tenantId;
addDefaultWhiteLabelThemeIfNotExist(tenantId);
metadata = getWhiteLabelMetaData(tenantId);
if (metadata == null) {
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);
}
/**
* 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);

Loading…
Cancel
Save