Add icon and resolve bug

fixes https://roadmap.entgra.net/issues/9274
scep-fix2
osh 2 years ago
parent 21669f8dba
commit a5177208f8

@ -17,7 +17,6 @@
*/
package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
@ -28,6 +27,7 @@ import io.swagger.annotations.Info;
import io.swagger.annotations.ResponseHeader;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag;
import io.swagger.annotations.ApiParam;
import org.apache.axis2.transport.http.HTTPConstants;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes;
@ -40,6 +40,7 @@ import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@ -86,7 +87,7 @@ import javax.ws.rs.core.Response;
public interface WhiteLabelService {
@GET
@Path("/favicon")
@Path("/{tenantDomain}/favicon")
@ApiOperation(
httpMethod = HTTPConstants.HEADER_GET,
value = "Get whitelabel favicon",
@ -117,10 +118,13 @@ public interface WhiteLabelService {
"\n Server error occurred while getting white label artifact.",
response = ErrorResponse.class)
})
Response getWhiteLabelFavicon();
Response getWhiteLabelFavicon( @ApiParam(
name = "tenantDomain",
value = "The tenant domain.",
required = true) @PathParam("tenantDomain") String tenantDomain);
@GET
@Path("/logo")
@Path("/{tenantDomain}/logo")
@ApiOperation(
httpMethod = HTTPConstants.HEADER_GET,
value = "Get whitelabel logo",
@ -152,7 +156,50 @@ public interface WhiteLabelService {
"\n Server error occurred while getting white label artifact.",
response = ErrorResponse.class)
})
Response getWhiteLabelLogo();
Response getWhiteLabelLogo(
@ApiParam(
name = "tenantDomain",
value = "The tenant domain.",
required = true)
@PathParam("tenantDomain") String tenantDomain);
@GET
@Path("/{tenantDomain}/icon")
@ApiOperation(
httpMethod = HTTPConstants.HEADER_GET,
value = "Get whitelabel logo icon",
notes = "Get whitelabel logo icon for the tenant of the logged in user",
tags = "Tenant Metadata Management"
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved white label logo.",
response = Metadata.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 500,
message = "Internal Server Error. " +
"\n Server error occurred while getting white label artifact.",
response = ErrorResponse.class)
})
Response getWhiteLabelLogoIcon( @ApiParam(
name = "tenantDomain",
value = "The tenant domain.",
required = true) @PathParam("tenantDomain") String tenantDomain);
@PUT
@ApiOperation(

@ -20,7 +20,9 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.FileResponse;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.MetadataManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.NotFoundException;
import org.wso2.carbon.device.mgt.common.metadata.mgt.WhiteLabelTheme;
@ -33,6 +35,7 @@ import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.ByteArrayInputStream;
@ -50,10 +53,10 @@ public class WhiteLabelServiceImpl implements WhiteLabelService {
@GET
@Override
@Path("/favicon")
public Response getWhiteLabelFavicon() {
@Path("/{tenantDomain}/favicon")
public Response getWhiteLabelFavicon(@PathParam("tenantDomain") String tenantDomain) {
try {
FileResponse fileResponse = DeviceMgtAPIUtils.getWhiteLabelManagementService().getWhiteLabelFavicon();
FileResponse fileResponse = DeviceMgtAPIUtils.getWhiteLabelManagementService().getWhiteLabelFavicon(tenantDomain);
return sendFileStream(fileResponse);
} catch (NotFoundException e) {
String msg = "Favicon white label image cannot be found in the system. Updating the whitelabel theme might" +
@ -69,10 +72,29 @@ public class WhiteLabelServiceImpl implements WhiteLabelService {
@GET
@Override
@Path("/logo")
public Response getWhiteLabelLogo() {
@Path("/{tenantDomain}/logo")
public Response getWhiteLabelLogo(@PathParam("tenantDomain") String tenantDomain) {
try {
FileResponse fileResponse = DeviceMgtAPIUtils.getWhiteLabelManagementService().getWhiteLabelLogo();
FileResponse fileResponse = DeviceMgtAPIUtils.getWhiteLabelManagementService().getWhiteLabelLogo(tenantDomain);
return sendFileStream(fileResponse);
} catch (NotFoundException e) {
String msg = "Logo white label image cannot be found in the system. Updating the whitelabel theme might" +
"help restore it";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (MetadataManagementException e) {
String msg = "Error occurred while getting logo";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Override
@Path("/{tenantDomain}/icon")
public Response getWhiteLabelLogoIcon(@PathParam("tenantDomain") String tenantDomain) {
try {
FileResponse fileResponse = DeviceMgtAPIUtils.getWhiteLabelManagementService().getWhiteLabelLogoIcon(tenantDomain);
return sendFileStream(fileResponse);
} catch (NotFoundException e) {
String msg = "Logo white label image cannot be found in the system. Updating the whitelabel theme might" +
@ -104,7 +126,8 @@ public class WhiteLabelServiceImpl implements WhiteLabelService {
@Override
public Response getWhiteLabelTheme() {
try {
WhiteLabelTheme whiteLabelTheme = DeviceMgtAPIUtils.getWhiteLabelManagementService().getWhiteLabelTheme();
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
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";
@ -114,6 +137,10 @@ public class WhiteLabelServiceImpl implements WhiteLabelService {
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);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}

@ -696,6 +696,13 @@ public class RequestValidationUtil {
new ErrorResponse.ErrorResponseBuilder()
.setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
}
if (whiteLabelThemeCreateRequest.getLogoIcon() == null) {
String msg = "Logo Icon is required to whitelabel";
log.error(msg);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder()
.setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
}
if (whiteLabelThemeCreateRequest.getFooterText() == null) {
String msg = "Footer text is required to whitelabel";
log.error(msg);
@ -713,6 +720,7 @@ public class RequestValidationUtil {
try {
validateWhiteLabelImage(whiteLabelThemeCreateRequest.getFavicon());
validateWhiteLabelImage(whiteLabelThemeCreateRequest.getLogo());
validateWhiteLabelImage(whiteLabelThemeCreateRequest.getLogoIcon());
} catch (InputValidationException e) {
String msg = "Payload contains invalid base64 files";
log.error(msg, e);

@ -49,8 +49,9 @@
<param-name>nonSecuredEndPoints</param-name>
<param-value>
/api/device-mgt/v1.0/users/validate,
/api/device-mgt/v1.0/whitelabel/favicon,
/api/device-mgt/v1.0/whitelabel/logo
/api/device-mgt/v1.0/whitelabel/.*/favicon,
/api/device-mgt/v1.0/whitelabel/.*/logo,
/api/device-mgt/v1.0/whitelabel/.*/icon,
</param-value>
</context-param>

@ -21,14 +21,16 @@ package org.wso2.carbon.device.mgt.common.metadata.mgt;
public class WhiteLabelArtifactPath {
private String faviconPath;
private String logoPath;
private String logoIconPath;
public WhiteLabelArtifactPath() {
}
public WhiteLabelArtifactPath(String faviconPath, String logoPath) {
public WhiteLabelArtifactPath(String faviconPath, String logoPath, String logoIconPath) {
this.faviconPath = faviconPath;
this.logoPath = logoPath;
this.logoIconPath = logoIconPath;
}
public String getFaviconPath() {
@ -46,4 +48,12 @@ public class WhiteLabelArtifactPath {
public void setLogoPath(String logoPath) {
this.logoPath = logoPath;
}
public String getLogoIconPath() {
return logoIconPath;
}
public void setLogoIconPath(String logoIconPath) {
this.logoIconPath = logoIconPath;
}
}

@ -40,7 +40,8 @@ public class WhiteLabelImage {
public enum ImageName {
FAVICON,
LOGO;
LOGO,
LOGO_ICON;
@Override
public String toString() {

@ -19,6 +19,7 @@
package org.wso2.carbon.device.mgt.common.metadata.mgt;
import org.wso2.carbon.device.mgt.common.FileResponse;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.MetadataManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.NotFoundException;
@ -33,7 +34,7 @@ public interface WhiteLabelManagementService {
* @throws MetadataManagementException if error occurred while retrieving favicon
* @throws NotFoundException if favicon is not found
*/
FileResponse getWhiteLabelFavicon() throws
FileResponse getWhiteLabelFavicon(String tenantDomain) throws
MetadataManagementException, NotFoundException;
/**
@ -42,7 +43,16 @@ public interface WhiteLabelManagementService {
* @throws MetadataManagementException if error occurred while retrieving logo
* @throws NotFoundException if logo is not found
*/
FileResponse getWhiteLabelLogo() throws
FileResponse getWhiteLabelLogo(String tenantDomain) throws
MetadataManagementException, NotFoundException;
/**
* Use to get byte content of logo icon whitelabel image
* @return byte content of logo icon
* @throws MetadataManagementException if error occurred while retrieving logo icon
* @throws NotFoundException if logo icon is not found
*/
FileResponse getWhiteLabelLogoIcon(String tenantDomain) throws
MetadataManagementException, NotFoundException;
/**
@ -69,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() throws MetadataManagementException, NotFoundException;
WhiteLabelTheme getWhiteLabelTheme(String tenantDomain) throws MetadataManagementException, NotFoundException, DeviceManagementException;
}

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.common.metadata.mgt;
public class WhiteLabelTheme {
private WhiteLabelImage faviconImage;
private WhiteLabelImage logoImage;
private WhiteLabelImage logoIconImage;
private String footerText;
private String appTitle;
@ -55,4 +56,12 @@ public class WhiteLabelTheme {
public void setAppTitle(String appTitle) {
this.appTitle = appTitle;
}
public WhiteLabelImage getLogoIconImage() {
return logoIconImage;
}
public void setLogoIconImage(WhiteLabelImage logoIconImage) {
this.logoIconImage = logoIconImage;
}
}

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.common.metadata.mgt;
public class WhiteLabelThemeCreateRequest {
private WhiteLabelImageRequestPayload favicon;
private WhiteLabelImageRequestPayload logo;
private WhiteLabelImageRequestPayload logoIcon;
private String footerText;
private String appTitle;
@ -55,4 +56,12 @@ public class WhiteLabelThemeCreateRequest {
public void setAppTitle(String appTitle) {
this.appTitle = appTitle;
}
public WhiteLabelImageRequestPayload getLogoIcon() {
return logoIcon;
}
public void setLogoIcon(WhiteLabelImageRequestPayload logoIcon) {
this.logoIcon = logoIcon;
}
}

@ -28,6 +28,7 @@ public class WhiteLabelImages {
private String defaultImagesLocation;
private String defaultFaviconName;
private String defaultLogoName;
private String defaultLogoIconName;
@XmlElement(name = "StoragePath", required = true)
public String getStoragePath() {
@ -61,6 +62,15 @@ public class WhiteLabelImages {
return defaultImagesLocation;
}
@XmlElement(name = "DefaultLogoIconName", required = true)
public String getDefaultLogoIconName() {
return defaultLogoIconName;
}
public void setDefaultLogoIconName(String defaultLogoIconName) {
this.defaultLogoIconName = defaultLogoIconName;
}
public void setDefaultImagesLocation(String defaultImagesLocation) {
this.defaultImagesLocation = defaultImagesLocation;
}

@ -26,9 +26,11 @@ 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;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.MetadataManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.NotFoundException;
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
@ -48,6 +50,8 @@ import org.wso2.carbon.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOExc
import org.wso2.carbon.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.metadata.mgt.dao.util.MetadataConstants;
import org.wso2.carbon.device.mgt.core.metadata.mgt.util.WhiteLabelStorageUtil;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@ -67,38 +71,62 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
}
@Override
public FileResponse getWhiteLabelFavicon() throws MetadataManagementException, NotFoundException {
public FileResponse getWhiteLabelFavicon(String tenantDomain) throws MetadataManagementException, NotFoundException {
try {
WhiteLabelTheme whiteLabelTheme = getWhiteLabelTheme();
return getImageFileResponse(whiteLabelTheme.getFaviconImage(), WhiteLabelImage.ImageName.FAVICON);
WhiteLabelTheme whiteLabelTheme = getWhiteLabelTheme(tenantDomain);
return getImageFileResponse(whiteLabelTheme.getFaviconImage(), WhiteLabelImage.ImageName.FAVICON, tenantDomain);
} catch (IOException e) {
String msg = "Error occurred while getting byte content of favicon";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} catch (DeviceManagementException e) {
String msg = "Error occurred while getting tenant details of favicon";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
}
}
@Override
public FileResponse getWhiteLabelLogo(String tenantDomain) throws MetadataManagementException, NotFoundException {
try {
WhiteLabelTheme whiteLabelTheme = getWhiteLabelTheme(tenantDomain);
return getImageFileResponse(whiteLabelTheme.getLogoImage(), WhiteLabelImage.ImageName.LOGO, tenantDomain);
} catch (IOException e) {
String msg = "Error occurred while getting byte content of logo";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} catch (DeviceManagementException e) {
String msg = "Error occurred while getting tenant details of logo";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
}
}
@Override
public FileResponse getWhiteLabelLogo() throws MetadataManagementException, NotFoundException {
public FileResponse getWhiteLabelLogoIcon(String tenantDomain) throws MetadataManagementException, NotFoundException {
try {
WhiteLabelTheme whiteLabelTheme = getWhiteLabelTheme();
return getImageFileResponse(whiteLabelTheme.getLogoImage(), WhiteLabelImage.ImageName.LOGO);
WhiteLabelTheme whiteLabelTheme = getWhiteLabelTheme(tenantDomain);
return getImageFileResponse(whiteLabelTheme.getLogoIconImage(), WhiteLabelImage.ImageName.LOGO_ICON, tenantDomain);
} catch (IOException e) {
String msg = "Error occurred while getting byte content of logo";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} catch (DeviceManagementException e) {
String msg = "Error occurred while getting tenant details of icon";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
}
}
/**
* Useful to get white label image file response for provided {@link WhiteLabelImage.ImageName}
*/
private FileResponse getImageFileResponse(WhiteLabelImage image, WhiteLabelImage.ImageName imageName) throws
IOException, MetadataManagementException, NotFoundException {
private FileResponse getImageFileResponse(WhiteLabelImage image, WhiteLabelImage.ImageName imageName, String tenantDomain) throws
IOException, MetadataManagementException, NotFoundException, DeviceManagementException {
if (image.getImageLocationType() == WhiteLabelImage.ImageLocationType.URL) {
return getImageFileResponseFromUrl(image.getImageLocation());
}
return WhiteLabelStorageUtil.getWhiteLabelImageStream(image, imageName);
return WhiteLabelStorageUtil.getWhiteLabelImageStream(image, imageName, tenantDomain);
}
/**
@ -169,10 +197,12 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
String appTitle = getDefaultAppTitle();
WhiteLabelImage favicon = constructDefaultFaviconImage();
WhiteLabelImage logo = constructDefaultLogoImage();
WhiteLabelImage logoIcon = constructDefaultLogoIconImage();
WhiteLabelTheme defaultTheme = new WhiteLabelTheme();
defaultTheme.setFooterText(footerText);
defaultTheme.setAppTitle(appTitle);
defaultTheme.setLogoImage(logo);
defaultTheme.setLogoIconImage(logoIcon);
defaultTheme.setFaviconImage(favicon);
return defaultTheme;
}
@ -227,6 +257,21 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
return logo;
}
/**
* This is useful to construct and get the default logo whitelabel image
*
* @return {@link WhiteLabelImage}
*/
private WhiteLabelImage constructDefaultLogoIconImage() {
MetaDataConfiguration metaDataConfiguration = DeviceConfigurationManager.getInstance().
getDeviceManagementConfig().getMetaDataConfiguration();
WhiteLabelConfiguration whiteLabelConfiguration = metaDataConfiguration.getWhiteLabelConfiguration();
WhiteLabelImage logoIcon = new WhiteLabelImage();
logoIcon.setImageLocation(whiteLabelConfiguration.getWhiteLabelImages().getDefaultLogoIconName());
setDefaultWhiteLabelImageCommonProperties(logoIcon);
return logoIcon;
}
/**
* This is useful to set common properties such as DEFAULT_FILE type for {@link WhiteLabelImage.ImageLocationType}
* for default white label image bean{@link WhiteLabelImage}
@ -242,18 +287,24 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
log.debug("Creating Metadata : [" + createWhiteLabelTheme.toString() + "]");
}
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
File existingFaviconImage = null;
File existingLogoImage = null;
File existingLogoIconImage = null;
try {
WhiteLabelTheme theme = getWhiteLabelTheme();
WhiteLabelTheme theme = getWhiteLabelTheme(tenantDomain);
if (theme.getFaviconImage().getImageLocationType() == WhiteLabelImage.ImageLocationType.CUSTOM_FILE) {
existingFaviconImage = WhiteLabelStorageUtil.getWhiteLabelImageFile(theme.getFaviconImage(), WhiteLabelImage.ImageName.FAVICON);
existingFaviconImage = WhiteLabelStorageUtil.getWhiteLabelImageFile(theme.getFaviconImage(), WhiteLabelImage.ImageName.FAVICON, tenantDomain);
}
if (theme.getLogoImage().getImageLocationType() == WhiteLabelImage.ImageLocationType.CUSTOM_FILE) {
existingLogoImage = WhiteLabelStorageUtil.getWhiteLabelImageFile(theme.getLogoImage(), WhiteLabelImage.ImageName.LOGO);
existingLogoImage = WhiteLabelStorageUtil.getWhiteLabelImageFile(theme.getLogoImage(), WhiteLabelImage.ImageName.LOGO, tenantDomain);
}
if (theme.getLogoIconImage().getImageLocationType() == WhiteLabelImage.ImageLocationType.CUSTOM_FILE) {
existingLogoIconImage = WhiteLabelStorageUtil.getWhiteLabelImageFile(theme.getLogoIconImage(), WhiteLabelImage.ImageName.LOGO_ICON, tenantDomain);
}
storeWhiteLabelImageIfRequired(createWhiteLabelTheme.getFavicon(), WhiteLabelImage.ImageName.FAVICON, tenantId);
storeWhiteLabelImageIfRequired(createWhiteLabelTheme.getLogo(), WhiteLabelImage.ImageName.LOGO, tenantId);
storeWhiteLabelImageIfRequired(createWhiteLabelTheme.getLogoIcon(), WhiteLabelImage.ImageName.LOGO_ICON, tenantId);
WhiteLabelTheme whiteLabelTheme = constructWhiteLabelTheme(createWhiteLabelTheme);
Metadata metadataWhiteLabelTheme = constructWhiteLabelThemeMetadata(whiteLabelTheme);
try {
@ -266,12 +317,12 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
return whiteLabelTheme;
} catch (MetadataManagementDAOException e) {
MetadataManagementDAOFactory.rollbackTransaction();
restoreWhiteLabelImages(existingFaviconImage, existingLogoImage, tenantId);
restoreWhiteLabelImages(existingFaviconImage, existingLogoImage, existingLogoIconImage, tenantId);
String msg = "Error occurred while creating the metadata entry. " + createWhiteLabelTheme;
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} catch (TransactionManagementException e) {
restoreWhiteLabelImages(existingFaviconImage, existingLogoImage, tenantId);
restoreWhiteLabelImages(existingFaviconImage, existingLogoImage, existingLogoIconImage, tenantId);
String msg = "Error occurred while opening a connection to the data source";
log.error(msg, e);
throw new MetadataManagementException("Error occurred while creating metadata record", e);
@ -282,6 +333,11 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
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);
throw new MetadataManagementException(msg, e);
}
}
@ -294,7 +350,7 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
* @param existingFavicon existing favicon image file
* @param existingLogo existing logo image file
*/
private void restoreWhiteLabelImages(File existingFavicon, File existingLogo, int tenantId)
private void restoreWhiteLabelImages(File existingFavicon, File existingLogo, File existingLogoIcon, int tenantId)
throws MetadataManagementException {
WhiteLabelStorageUtil.deleteWhiteLabelImageForTenantIfExists(tenantId);
if (existingFavicon != null) {
@ -303,6 +359,9 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
if (existingLogo != null) {
WhiteLabelStorageUtil.storeWhiteLabelImage(existingLogo, WhiteLabelImage.ImageName.LOGO, tenantId);
}
if (existingLogoIcon != null) {
WhiteLabelStorageUtil.storeWhiteLabelImage(existingLogoIcon, WhiteLabelImage.ImageName.LOGO_ICON, tenantId);
}
}
/**
@ -328,10 +387,13 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
WhiteLabelTheme whiteLabelTheme = new WhiteLabelTheme();
WhiteLabelImageRequestPayload faviconPayload = whiteLabelThemeCreateRequest.getFavicon();
WhiteLabelImageRequestPayload logoPayload = whiteLabelThemeCreateRequest.getLogo();
WhiteLabelImageRequestPayload logoIconPayload = whiteLabelThemeCreateRequest.getLogoIcon();
WhiteLabelImage faviconImage = constructWhiteLabelImageDTO(faviconPayload);
WhiteLabelImage logoImage = constructWhiteLabelImageDTO(logoPayload);
WhiteLabelImage logoIconImage = constructWhiteLabelImageDTO(logoIconPayload);
whiteLabelTheme.setFaviconImage(faviconImage);
whiteLabelTheme.setLogoImage(logoImage);
whiteLabelTheme.setLogoIconImage(logoIconImage);
whiteLabelTheme.setFooterText(whiteLabelThemeCreateRequest.getFooterText());
whiteLabelTheme.setAppTitle(whiteLabelThemeCreateRequest.getAppTitle());
return whiteLabelTheme;
@ -367,8 +429,8 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
}
@Override
public WhiteLabelTheme getWhiteLabelTheme() throws MetadataManagementException, NotFoundException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
public WhiteLabelTheme getWhiteLabelTheme(String tenantDomain) throws MetadataManagementException, NotFoundException, DeviceManagementException {
int tenantId = DeviceManagerUtil.getTenantId(tenantDomain);
if (log.isDebugEnabled()) {
log.debug("Retrieving whitelabel theme for tenant: " + tenantId);
}

@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Base64File;
import org.wso2.carbon.device.mgt.common.FileResponse;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.MetadataManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.NotFoundException;
import org.wso2.carbon.device.mgt.common.metadata.mgt.WhiteLabelImage;
@ -31,6 +32,8 @@ import org.wso2.carbon.device.mgt.core.common.util.FileUtil;
import org.wso2.carbon.device.mgt.core.common.util.StorageManagementUtil;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.metadata.mgt.MetaDataConfiguration;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@ -115,9 +118,9 @@ public class WhiteLabelStorageUtil {
* @param imageName (i.e: LOGO)
* @return white label image file {@link File}
*/
public static File getWhiteLabelImageFile(WhiteLabelImage image, WhiteLabelImage.ImageName imageName)
throws MetadataManagementException {
String fullPathToImage = getPathToImage(image, imageName);
public static File getWhiteLabelImageFile(WhiteLabelImage image, WhiteLabelImage.ImageName imageName, String tenantDomain)
throws MetadataManagementException, DeviceManagementException {
String fullPathToImage = getPathToImage(image, imageName, tenantDomain);
return new File(fullPathToImage);
}
@ -128,10 +131,10 @@ public class WhiteLabelStorageUtil {
* @param imageName (i.e: LOGO)
* @return white label image input stream
*/
public static FileResponse getWhiteLabelImageStream(WhiteLabelImage image, WhiteLabelImage.ImageName imageName)
throws MetadataManagementException, NotFoundException {
public static FileResponse getWhiteLabelImageStream(WhiteLabelImage image, WhiteLabelImage.ImageName imageName, String tenantDomain)
throws MetadataManagementException, NotFoundException, DeviceManagementException {
FileResponse fileResponse = new FileResponse();
String fullPathToFile = getPathToImage(image, imageName);
String fullPathToFile = getPathToImage(image, imageName, tenantDomain);
try {
InputStream imageStream = StorageManagementUtil.getInputStream(fullPathToFile);
if (imageStream == null) {
@ -159,15 +162,22 @@ public class WhiteLabelStorageUtil {
* @param imageName (i.e: LOGO)
* @return Full path to white label image in the system
*/
private static String getPathToImage(WhiteLabelImage image, WhiteLabelImage.ImageName imageName)
throws MetadataManagementException {
private static String getPathToImage(WhiteLabelImage image, WhiteLabelImage.ImageName imageName, String tenantDomain)
throws MetadataManagementException, DeviceManagementException {
WhiteLabelImage.ImageLocationType imageLocationType = image.getImageLocationType();
if (imageLocationType == WhiteLabelImage.ImageLocationType.URL) {
String msg = "White label images of URL type is not stored, hence it doesn't have a path in file system.";
log.error(msg);
throw new MetadataManagementException(msg);
}
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
int tenantId = 0;
try {
tenantId = DeviceManagerUtil.getTenantId(tenantDomain);
} catch (DeviceManagementException e) {
String msg = "Error occurred while getting tenant details of logo";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
String fileName = image.getImageLocation();
String filePath = String.valueOf(tenantId);
if (imageLocationType == WhiteLabelImage.ImageLocationType.DEFAULT_FILE) {

@ -197,6 +197,7 @@
<StoragePath>repository/resources/whitelabel</StoragePath>
<DefaultFaviconName>favicon.png</DefaultFaviconName>
<DefaultLogoName>logo.png</DefaultLogoName>
<DefaultLogoIconName>icon.png</DefaultLogoIconName>
<DefaultImagesLocation>default</DefaultImagesLocation>
</WhiteLabelImages>
</WhiteLabelConfiguration>

@ -336,6 +336,7 @@
<StoragePath>repository/resources/whitelabel</StoragePath>
<DefaultFaviconName>favicon.png</DefaultFaviconName>
<DefaultLogoName>logo.png</DefaultLogoName>
<DefaultLogoIconName>icon.png</DefaultLogoIconName>
<DefaultImagesLocation>default</DefaultImagesLocation>
</WhiteLabelImages>
</WhiteLabelConfiguration>

Loading…
Cancel
Save