Add icon and resolve bug

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

@ -17,7 +17,6 @@
*/ */
package org.wso2.carbon.device.mgt.jaxrs.service.api; package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
@ -28,6 +27,7 @@ import io.swagger.annotations.Info;
import io.swagger.annotations.ResponseHeader; import io.swagger.annotations.ResponseHeader;
import io.swagger.annotations.SwaggerDefinition; import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag; import io.swagger.annotations.Tag;
import io.swagger.annotations.ApiParam;
import org.apache.axis2.transport.http.HTTPConstants; import org.apache.axis2.transport.http.HTTPConstants;
import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes; 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.PUT;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@ -86,7 +87,7 @@ import javax.ws.rs.core.Response;
public interface WhiteLabelService { public interface WhiteLabelService {
@GET @GET
@Path("/favicon") @Path("/{tenantDomain}/favicon")
@ApiOperation( @ApiOperation(
httpMethod = HTTPConstants.HEADER_GET, httpMethod = HTTPConstants.HEADER_GET,
value = "Get whitelabel favicon", value = "Get whitelabel favicon",
@ -117,10 +118,13 @@ public interface WhiteLabelService {
"\n Server error occurred while getting white label artifact.", "\n Server error occurred while getting white label artifact.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getWhiteLabelFavicon(); Response getWhiteLabelFavicon( @ApiParam(
name = "tenantDomain",
value = "The tenant domain.",
required = true) @PathParam("tenantDomain") String tenantDomain);
@GET @GET
@Path("/logo") @Path("/{tenantDomain}/logo")
@ApiOperation( @ApiOperation(
httpMethod = HTTPConstants.HEADER_GET, httpMethod = HTTPConstants.HEADER_GET,
value = "Get whitelabel logo", value = "Get whitelabel logo",
@ -152,7 +156,50 @@ public interface WhiteLabelService {
"\n Server error occurred while getting white label artifact.", "\n Server error occurred while getting white label artifact.",
response = ErrorResponse.class) 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 @PUT
@ApiOperation( @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.Log;
import org.apache.commons.logging.LogFactory; 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.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.MetadataManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.NotFoundException; import org.wso2.carbon.device.mgt.common.exceptions.NotFoundException;
import org.wso2.carbon.device.mgt.common.metadata.mgt.WhiteLabelTheme; 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.PUT;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -50,10 +53,10 @@ public class WhiteLabelServiceImpl implements WhiteLabelService {
@GET @GET
@Override @Override
@Path("/favicon") @Path("/{tenantDomain}/favicon")
public Response getWhiteLabelFavicon() { public Response getWhiteLabelFavicon(@PathParam("tenantDomain") String tenantDomain) {
try { try {
FileResponse fileResponse = DeviceMgtAPIUtils.getWhiteLabelManagementService().getWhiteLabelFavicon(); FileResponse fileResponse = DeviceMgtAPIUtils.getWhiteLabelManagementService().getWhiteLabelFavicon(tenantDomain);
return sendFileStream(fileResponse); return sendFileStream(fileResponse);
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Favicon white label image cannot be found in the system. Updating the whitelabel theme might" + 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 @GET
@Override @Override
@Path("/logo") @Path("/{tenantDomain}/logo")
public Response getWhiteLabelLogo() { public Response getWhiteLabelLogo(@PathParam("tenantDomain") String tenantDomain) {
try { 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); return sendFileStream(fileResponse);
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Logo white label image cannot be found in the system. Updating the whitelabel theme might" + 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 @Override
public Response getWhiteLabelTheme() { public Response getWhiteLabelTheme() {
try { 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(); return Response.status(Response.Status.CREATED).entity(whiteLabelTheme).build();
} catch (MetadataManagementException e) { } catch (MetadataManagementException e) {
String msg = "Error occurred while deleting whitelabel for tenant"; 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"; String msg = "Not white label theme configured for this tenant";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); 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() new ErrorResponse.ErrorResponseBuilder()
.setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build()); .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) { if (whiteLabelThemeCreateRequest.getFooterText() == null) {
String msg = "Footer text is required to whitelabel"; String msg = "Footer text is required to whitelabel";
log.error(msg); log.error(msg);
@ -713,6 +720,7 @@ public class RequestValidationUtil {
try { try {
validateWhiteLabelImage(whiteLabelThemeCreateRequest.getFavicon()); validateWhiteLabelImage(whiteLabelThemeCreateRequest.getFavicon());
validateWhiteLabelImage(whiteLabelThemeCreateRequest.getLogo()); validateWhiteLabelImage(whiteLabelThemeCreateRequest.getLogo());
validateWhiteLabelImage(whiteLabelThemeCreateRequest.getLogoIcon());
} catch (InputValidationException e) { } catch (InputValidationException e) {
String msg = "Payload contains invalid base64 files"; String msg = "Payload contains invalid base64 files";
log.error(msg, e); log.error(msg, e);

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

@ -21,14 +21,16 @@ package org.wso2.carbon.device.mgt.common.metadata.mgt;
public class WhiteLabelArtifactPath { public class WhiteLabelArtifactPath {
private String faviconPath; private String faviconPath;
private String logoPath; private String logoPath;
private String logoIconPath;
public WhiteLabelArtifactPath() { public WhiteLabelArtifactPath() {
} }
public WhiteLabelArtifactPath(String faviconPath, String logoPath) { public WhiteLabelArtifactPath(String faviconPath, String logoPath, String logoIconPath) {
this.faviconPath = faviconPath; this.faviconPath = faviconPath;
this.logoPath = logoPath; this.logoPath = logoPath;
this.logoIconPath = logoIconPath;
} }
public String getFaviconPath() { public String getFaviconPath() {
@ -46,4 +48,12 @@ public class WhiteLabelArtifactPath {
public void setLogoPath(String logoPath) { public void setLogoPath(String logoPath) {
this.logoPath = 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 { public enum ImageName {
FAVICON, FAVICON,
LOGO; LOGO,
LOGO_ICON;
@Override @Override
public String toString() { public String toString() {

@ -19,6 +19,7 @@
package org.wso2.carbon.device.mgt.common.metadata.mgt; package org.wso2.carbon.device.mgt.common.metadata.mgt;
import org.wso2.carbon.device.mgt.common.FileResponse; 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.MetadataManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.NotFoundException; 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 MetadataManagementException if error occurred while retrieving favicon
* @throws NotFoundException if favicon is not found * @throws NotFoundException if favicon is not found
*/ */
FileResponse getWhiteLabelFavicon() throws FileResponse getWhiteLabelFavicon(String tenantDomain) throws
MetadataManagementException, NotFoundException; MetadataManagementException, NotFoundException;
/** /**
@ -42,7 +43,16 @@ public interface WhiteLabelManagementService {
* @throws MetadataManagementException if error occurred while retrieving logo * @throws MetadataManagementException if error occurred while retrieving logo
* @throws NotFoundException if logo is not found * @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; MetadataManagementException, NotFoundException;
/** /**
@ -69,5 +79,5 @@ public interface WhiteLabelManagementService {
* This method is useful to get existing white label theme * This method is useful to get existing white label theme
* @throws MetadataManagementException if error while getting 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 { public class WhiteLabelTheme {
private WhiteLabelImage faviconImage; private WhiteLabelImage faviconImage;
private WhiteLabelImage logoImage; private WhiteLabelImage logoImage;
private WhiteLabelImage logoIconImage;
private String footerText; private String footerText;
private String appTitle; private String appTitle;
@ -55,4 +56,12 @@ public class WhiteLabelTheme {
public void setAppTitle(String appTitle) { public void setAppTitle(String appTitle) {
this.appTitle = 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 { public class WhiteLabelThemeCreateRequest {
private WhiteLabelImageRequestPayload favicon; private WhiteLabelImageRequestPayload favicon;
private WhiteLabelImageRequestPayload logo; private WhiteLabelImageRequestPayload logo;
private WhiteLabelImageRequestPayload logoIcon;
private String footerText; private String footerText;
private String appTitle; private String appTitle;
@ -55,4 +56,12 @@ public class WhiteLabelThemeCreateRequest {
public void setAppTitle(String appTitle) { public void setAppTitle(String appTitle) {
this.appTitle = 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 defaultImagesLocation;
private String defaultFaviconName; private String defaultFaviconName;
private String defaultLogoName; private String defaultLogoName;
private String defaultLogoIconName;
@XmlElement(name = "StoragePath", required = true) @XmlElement(name = "StoragePath", required = true)
public String getStoragePath() { public String getStoragePath() {
@ -61,6 +62,15 @@ public class WhiteLabelImages {
return defaultImagesLocation; 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) { public void setDefaultImagesLocation(String defaultImagesLocation) {
this.defaultImagesLocation = defaultImagesLocation; this.defaultImagesLocation = defaultImagesLocation;
} }

@ -26,9 +26,11 @@ import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Base64File; import org.wso2.carbon.device.mgt.common.Base64File;
import org.wso2.carbon.device.mgt.common.FileResponse; 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.MetadataManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.NotFoundException; import org.wso2.carbon.device.mgt.common.exceptions.NotFoundException;
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; 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.MetadataManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.metadata.mgt.dao.util.MetadataConstants; 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.metadata.mgt.util.WhiteLabelStorageUtil;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -67,38 +71,62 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
} }
@Override @Override
public FileResponse getWhiteLabelFavicon() throws MetadataManagementException, NotFoundException { public FileResponse getWhiteLabelFavicon(String tenantDomain) throws MetadataManagementException, NotFoundException {
try { try {
WhiteLabelTheme whiteLabelTheme = getWhiteLabelTheme(); WhiteLabelTheme whiteLabelTheme = getWhiteLabelTheme(tenantDomain);
return getImageFileResponse(whiteLabelTheme.getFaviconImage(), WhiteLabelImage.ImageName.FAVICON); return getImageFileResponse(whiteLabelTheme.getFaviconImage(), WhiteLabelImage.ImageName.FAVICON, tenantDomain);
} catch (IOException e) { } catch (IOException e) {
String msg = "Error occurred while getting byte content of favicon"; String msg = "Error occurred while getting byte content of favicon";
log.error(msg, e); log.error(msg, e);
throw new MetadataManagementException(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 @Override
public FileResponse getWhiteLabelLogo() throws MetadataManagementException, NotFoundException { public FileResponse getWhiteLabelLogoIcon(String tenantDomain) throws MetadataManagementException, NotFoundException {
try { try {
WhiteLabelTheme whiteLabelTheme = getWhiteLabelTheme(); WhiteLabelTheme whiteLabelTheme = getWhiteLabelTheme(tenantDomain);
return getImageFileResponse(whiteLabelTheme.getLogoImage(), WhiteLabelImage.ImageName.LOGO); return getImageFileResponse(whiteLabelTheme.getLogoIconImage(), WhiteLabelImage.ImageName.LOGO_ICON, tenantDomain);
} catch (IOException e) { } catch (IOException e) {
String msg = "Error occurred while getting byte content of logo"; String msg = "Error occurred while getting byte content of logo";
log.error(msg, e); log.error(msg, e);
throw new MetadataManagementException(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} * Useful to get white label image file response for provided {@link WhiteLabelImage.ImageName}
*/ */
private FileResponse getImageFileResponse(WhiteLabelImage image, WhiteLabelImage.ImageName imageName) throws private FileResponse getImageFileResponse(WhiteLabelImage image, WhiteLabelImage.ImageName imageName, String tenantDomain) throws
IOException, MetadataManagementException, NotFoundException { IOException, MetadataManagementException, NotFoundException, DeviceManagementException {
if (image.getImageLocationType() == WhiteLabelImage.ImageLocationType.URL) { if (image.getImageLocationType() == WhiteLabelImage.ImageLocationType.URL) {
return getImageFileResponseFromUrl(image.getImageLocation()); 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(); String appTitle = getDefaultAppTitle();
WhiteLabelImage favicon = constructDefaultFaviconImage(); WhiteLabelImage favicon = constructDefaultFaviconImage();
WhiteLabelImage logo = constructDefaultLogoImage(); WhiteLabelImage logo = constructDefaultLogoImage();
WhiteLabelImage logoIcon = constructDefaultLogoIconImage();
WhiteLabelTheme defaultTheme = new WhiteLabelTheme(); WhiteLabelTheme defaultTheme = new WhiteLabelTheme();
defaultTheme.setFooterText(footerText); defaultTheme.setFooterText(footerText);
defaultTheme.setAppTitle(appTitle); defaultTheme.setAppTitle(appTitle);
defaultTheme.setLogoImage(logo); defaultTheme.setLogoImage(logo);
defaultTheme.setLogoIconImage(logoIcon);
defaultTheme.setFaviconImage(favicon); defaultTheme.setFaviconImage(favicon);
return defaultTheme; return defaultTheme;
} }
@ -227,6 +257,21 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
return logo; 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} * This is useful to set common properties such as DEFAULT_FILE type for {@link WhiteLabelImage.ImageLocationType}
* for default white label image bean{@link WhiteLabelImage} * for default white label image bean{@link WhiteLabelImage}
@ -242,18 +287,24 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
log.debug("Creating Metadata : [" + createWhiteLabelTheme.toString() + "]"); log.debug("Creating Metadata : [" + createWhiteLabelTheme.toString() + "]");
} }
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
File existingFaviconImage = null; File existingFaviconImage = null;
File existingLogoImage = null; File existingLogoImage = null;
File existingLogoIconImage = null;
try { try {
WhiteLabelTheme theme = getWhiteLabelTheme(); WhiteLabelTheme theme = getWhiteLabelTheme(tenantDomain);
if (theme.getFaviconImage().getImageLocationType() == WhiteLabelImage.ImageLocationType.CUSTOM_FILE) { 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) { 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.getFavicon(), WhiteLabelImage.ImageName.FAVICON, tenantId);
storeWhiteLabelImageIfRequired(createWhiteLabelTheme.getLogo(), WhiteLabelImage.ImageName.LOGO, tenantId); storeWhiteLabelImageIfRequired(createWhiteLabelTheme.getLogo(), WhiteLabelImage.ImageName.LOGO, tenantId);
storeWhiteLabelImageIfRequired(createWhiteLabelTheme.getLogoIcon(), WhiteLabelImage.ImageName.LOGO_ICON, tenantId);
WhiteLabelTheme whiteLabelTheme = constructWhiteLabelTheme(createWhiteLabelTheme); WhiteLabelTheme whiteLabelTheme = constructWhiteLabelTheme(createWhiteLabelTheme);
Metadata metadataWhiteLabelTheme = constructWhiteLabelThemeMetadata(whiteLabelTheme); Metadata metadataWhiteLabelTheme = constructWhiteLabelThemeMetadata(whiteLabelTheme);
try { try {
@ -266,12 +317,12 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
return whiteLabelTheme; return whiteLabelTheme;
} catch (MetadataManagementDAOException e) { } catch (MetadataManagementDAOException e) {
MetadataManagementDAOFactory.rollbackTransaction(); MetadataManagementDAOFactory.rollbackTransaction();
restoreWhiteLabelImages(existingFaviconImage, existingLogoImage, tenantId); restoreWhiteLabelImages(existingFaviconImage, existingLogoImage, existingLogoIconImage, tenantId);
String msg = "Error occurred while creating the metadata entry. " + createWhiteLabelTheme; String msg = "Error occurred while creating the metadata entry. " + createWhiteLabelTheme;
log.error(msg, e); log.error(msg, e);
throw new MetadataManagementException(msg, e); throw new MetadataManagementException(msg, e);
} catch (TransactionManagementException 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"; String msg = "Error occurred while opening a connection to the data source";
log.error(msg, e); log.error(msg, e);
throw new MetadataManagementException("Error occurred while creating metadata record", 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"; String msg = "Error occurred while retrieving existing white label theme";
log.error(msg, e); log.error(msg, e);
throw new MetadataManagementException(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 existingFavicon existing favicon image file
* @param existingLogo existing logo 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 { throws MetadataManagementException {
WhiteLabelStorageUtil.deleteWhiteLabelImageForTenantIfExists(tenantId); WhiteLabelStorageUtil.deleteWhiteLabelImageForTenantIfExists(tenantId);
if (existingFavicon != null) { if (existingFavicon != null) {
@ -303,6 +359,9 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
if (existingLogo != null) { if (existingLogo != null) {
WhiteLabelStorageUtil.storeWhiteLabelImage(existingLogo, WhiteLabelImage.ImageName.LOGO, tenantId); 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(); WhiteLabelTheme whiteLabelTheme = new WhiteLabelTheme();
WhiteLabelImageRequestPayload faviconPayload = whiteLabelThemeCreateRequest.getFavicon(); WhiteLabelImageRequestPayload faviconPayload = whiteLabelThemeCreateRequest.getFavicon();
WhiteLabelImageRequestPayload logoPayload = whiteLabelThemeCreateRequest.getLogo(); WhiteLabelImageRequestPayload logoPayload = whiteLabelThemeCreateRequest.getLogo();
WhiteLabelImageRequestPayload logoIconPayload = whiteLabelThemeCreateRequest.getLogoIcon();
WhiteLabelImage faviconImage = constructWhiteLabelImageDTO(faviconPayload); WhiteLabelImage faviconImage = constructWhiteLabelImageDTO(faviconPayload);
WhiteLabelImage logoImage = constructWhiteLabelImageDTO(logoPayload); WhiteLabelImage logoImage = constructWhiteLabelImageDTO(logoPayload);
WhiteLabelImage logoIconImage = constructWhiteLabelImageDTO(logoIconPayload);
whiteLabelTheme.setFaviconImage(faviconImage); whiteLabelTheme.setFaviconImage(faviconImage);
whiteLabelTheme.setLogoImage(logoImage); whiteLabelTheme.setLogoImage(logoImage);
whiteLabelTheme.setLogoIconImage(logoIconImage);
whiteLabelTheme.setFooterText(whiteLabelThemeCreateRequest.getFooterText()); whiteLabelTheme.setFooterText(whiteLabelThemeCreateRequest.getFooterText());
whiteLabelTheme.setAppTitle(whiteLabelThemeCreateRequest.getAppTitle()); whiteLabelTheme.setAppTitle(whiteLabelThemeCreateRequest.getAppTitle());
return whiteLabelTheme; return whiteLabelTheme;
@ -367,8 +429,8 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
} }
@Override @Override
public WhiteLabelTheme getWhiteLabelTheme() throws MetadataManagementException, NotFoundException { public WhiteLabelTheme getWhiteLabelTheme(String tenantDomain) throws MetadataManagementException, NotFoundException, DeviceManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = DeviceManagerUtil.getTenantId(tenantDomain);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Retrieving whitelabel theme for tenant: " + tenantId); 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.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Base64File; import org.wso2.carbon.device.mgt.common.Base64File;
import org.wso2.carbon.device.mgt.common.FileResponse; 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.MetadataManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.NotFoundException; import org.wso2.carbon.device.mgt.common.exceptions.NotFoundException;
import org.wso2.carbon.device.mgt.common.metadata.mgt.WhiteLabelImage; 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.common.util.StorageManagementUtil;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; 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.config.metadata.mgt.MetaDataConfiguration;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -115,9 +118,9 @@ public class WhiteLabelStorageUtil {
* @param imageName (i.e: LOGO) * @param imageName (i.e: LOGO)
* @return white label image file {@link File} * @return white label image file {@link File}
*/ */
public static File getWhiteLabelImageFile(WhiteLabelImage image, WhiteLabelImage.ImageName imageName) public static File getWhiteLabelImageFile(WhiteLabelImage image, WhiteLabelImage.ImageName imageName, String tenantDomain)
throws MetadataManagementException { throws MetadataManagementException, DeviceManagementException {
String fullPathToImage = getPathToImage(image, imageName); String fullPathToImage = getPathToImage(image, imageName, tenantDomain);
return new File(fullPathToImage); return new File(fullPathToImage);
} }
@ -128,10 +131,10 @@ public class WhiteLabelStorageUtil {
* @param imageName (i.e: LOGO) * @param imageName (i.e: LOGO)
* @return white label image input stream * @return white label image input stream
*/ */
public static FileResponse getWhiteLabelImageStream(WhiteLabelImage image, WhiteLabelImage.ImageName imageName) public static FileResponse getWhiteLabelImageStream(WhiteLabelImage image, WhiteLabelImage.ImageName imageName, String tenantDomain)
throws MetadataManagementException, NotFoundException { throws MetadataManagementException, NotFoundException, DeviceManagementException {
FileResponse fileResponse = new FileResponse(); FileResponse fileResponse = new FileResponse();
String fullPathToFile = getPathToImage(image, imageName); String fullPathToFile = getPathToImage(image, imageName, tenantDomain);
try { try {
InputStream imageStream = StorageManagementUtil.getInputStream(fullPathToFile); InputStream imageStream = StorageManagementUtil.getInputStream(fullPathToFile);
if (imageStream == null) { if (imageStream == null) {
@ -159,15 +162,22 @@ public class WhiteLabelStorageUtil {
* @param imageName (i.e: LOGO) * @param imageName (i.e: LOGO)
* @return Full path to white label image in the system * @return Full path to white label image in the system
*/ */
private static String getPathToImage(WhiteLabelImage image, WhiteLabelImage.ImageName imageName) private static String getPathToImage(WhiteLabelImage image, WhiteLabelImage.ImageName imageName, String tenantDomain)
throws MetadataManagementException { throws MetadataManagementException, DeviceManagementException {
WhiteLabelImage.ImageLocationType imageLocationType = image.getImageLocationType(); WhiteLabelImage.ImageLocationType imageLocationType = image.getImageLocationType();
if (imageLocationType == WhiteLabelImage.ImageLocationType.URL) { 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."; String msg = "White label images of URL type is not stored, hence it doesn't have a path in file system.";
log.error(msg); log.error(msg);
throw new MetadataManagementException(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 fileName = image.getImageLocation();
String filePath = String.valueOf(tenantId); String filePath = String.valueOf(tenantId);
if (imageLocationType == WhiteLabelImage.ImageLocationType.DEFAULT_FILE) { if (imageLocationType == WhiteLabelImage.ImageLocationType.DEFAULT_FILE) {

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

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

Loading…
Cancel
Save