diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java index 58e0ebfc903..23237e54c8b 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java @@ -87,7 +87,6 @@ import io.entgra.application.mgt.core.lifecycle.LifecycleStateManager; import io.entgra.application.mgt.core.util.ConnectionManagerUtil; import io.entgra.application.mgt.core.util.Constants; import org.wso2.carbon.device.mgt.core.common.exception.StorageManagementException; -import org.wso2.carbon.device.mgt.core.common.util.StorageManagementUtil; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.core.dto.DeviceType; @@ -611,7 +610,7 @@ public class ApplicationManagerImpl implements ApplicationManager { return md5OfApp; } catch(StorageManagementException e) { String msg = "Error occurred while generating md5sum value of " + applicationArtifact.getInstallerName(); - log.error(msg); + log.error(msg, e); throw new ApplicationManagementException(msg, e); } } @@ -713,8 +712,8 @@ public class ApplicationManagerImpl implements ApplicationManager { } catch (StorageManagementException e) { String msg = "Error occurred while md5sum value retrieving process: application UUID " + applicationReleaseDTO.getUuid(); - log.error(msg); - throw new ApplicationStorageManagementException(msg); + log.error(msg, e); + throw new ApplicationStorageManagementException(msg, e); } catch (DBConnectionException e) { String msg = "Error occurred when getting database connection for verifying app release data."; log.error(msg, e); @@ -828,8 +827,8 @@ public class ApplicationManagerImpl implements ApplicationManager { } catch (StorageManagementException e) { String msg = "Error occurred while retrieving md5sum value from the binary file for application " + "release UUID " + applicationReleaseDTO.getUuid(); - log.error(msg); - throw new ApplicationStorageManagementException(msg); + log.error(msg, e); + throw new ApplicationStorageManagementException(msg, e); } catch (IOException e) { String msg = "Error occurred when getting byte array of binary file. Installer name: " + applicationArtifact .getInstallerName(); @@ -3310,8 +3309,8 @@ public class ApplicationManagerImpl implements ApplicationManager { } catch (StorageManagementException e) { String msg = "Error occurred while retrieving md5sum value from the binary file for " + "application release UUID " + applicationReleaseDTO.get().getUuid(); - log.error(msg); - throw new ApplicationStorageManagementException(msg); + log.error(msg, e); + throw new ApplicationStorageManagementException(msg, e); } catch (IOException e) { String msg = "Error occurred when getting byte array of binary file. Installer name: " + applicationArtifact.getInstallerName(); diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationStorageManagerImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationStorageManagerImpl.java index a99d759d46c..c9965d4f06f 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationStorageManagerImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationStorageManagerImpl.java @@ -1,4 +1,5 @@ -/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. * +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. 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 a0380f70323..0946ccb454f 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 @@ -136,7 +136,6 @@ public class WhiteLabelServiceImpl implements WhiteLabelService { Response.ResponseBuilder response = Response .ok(binaryDuplicate, MediaType.APPLICATION_OCTET_STREAM); response.status(Response.Status.OK); -// response.header("Content-Disposition", "attachment; filename=\"" + fileName + "\""); response.header("Content-Length", content.length); return response.build(); } catch (IOException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java index d71373c2dff..03c49ecb9dc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java @@ -662,17 +662,11 @@ public class RequestValidationUtil { } } - public static void validateWhiteLabelArtifactDownloadRequest(String whiteLabelImage) { - if (!EnumUtils.isValidEnum(WhiteLabelImage.ImageName.class, whiteLabelImage)) { - String msg = "Invalid white label image requested. Image: " + whiteLabelImage; - log.error(msg); - throw new InputValidationException(new ErrorResponse.ErrorResponseBuilder() - .setCode(HttpStatus.SC_BAD_REQUEST) - .setMessage(msg).build()); - - } - } - + /** + * Check if whitelabel theme create request contains valid payload and all required payload + * + * @param whiteLabelThemeCreateRequest {@link WhiteLabelThemeCreateRequest} + */ public static void validateWhiteLabelTheme(WhiteLabelThemeCreateRequest whiteLabelThemeCreateRequest) { if (whiteLabelThemeCreateRequest.getFavicon() == null) { String msg = "Favicon is required to whitelabel"; @@ -700,7 +694,7 @@ public class RequestValidationUtil { validateWhiteLabelImage(whiteLabelThemeCreateRequest.getLogo()); } catch (InputValidationException e) { String msg = "Payload contains invalid base64 files"; - log.error(msg); + log.error(msg, e); throw e; } } @@ -723,14 +717,13 @@ public class RequestValidationUtil { } catch (JsonSyntaxException e) { String msg = "Invalid image payload found with the request. Image object does not represent a Base64 File. " + "Hence verify the request payload object."; - log.error(msg); + log.error(msg, e); throw new InputValidationException( new ErrorResponse.ErrorResponseBuilder() .setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build()); } - return; } - if (whiteLabelImage.getImageType() == WhiteLabelImageRequestPayload.ImageType.URL) { + else if (whiteLabelImage.getImageType() == WhiteLabelImageRequestPayload.ImageType.URL) { try { String imageUrl = new Gson().fromJson(whiteLabelImage.getImage(), String.class); if (!HttpUtil.isHttpUrlValid(imageUrl)) { @@ -742,11 +735,17 @@ public class RequestValidationUtil { } } catch (JsonSyntaxException e) { String msg = "Invalid payload found with the request. Hence verify the request payload object."; - log.error(msg); + log.error(msg, e); throw new InputValidationException( new ErrorResponse.ErrorResponseBuilder() .setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build()); } + } else { + String msg = "Invalid payload found with the request. Unknown white label imageType " + whiteLabelImage.getImageType(); + log.error(msg); + throw new InputValidationException( + new ErrorResponse.ErrorResponseBuilder() + .setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build()); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java index c14649b3340..4f8b41cdabb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java @@ -526,7 +526,7 @@ public class DeviceMgtAPIUtils { whiteLabelManagementService = (WhiteLabelManagementService) ctx.getOSGiService( WhiteLabelManagementService.class, null); if (whiteLabelManagementService == null) { - throw new IllegalStateException("Metadata Management service not initialized."); + throw new IllegalStateException("Whitelabel Management service not initialized."); } } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/NotFoundException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/NotFoundException.java index 2e59a81bbe0..6a8287db01e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/NotFoundException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/NotFoundException.java @@ -1,6 +1,3 @@ -package org.wso2.carbon.device.mgt.common.exceptions; - - /* * Copyright (c) 2022, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * @@ -19,6 +16,8 @@ package org.wso2.carbon.device.mgt.common.exceptions; * under the License. */ +package org.wso2.carbon.device.mgt.common.exceptions; + /** * This exception will be thrown when the requested application or platform not found. */ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/WhiteLabelImage.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/WhiteLabelImage.java index 70003b6e60c..ba9e6f82f25 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/WhiteLabelImage.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/WhiteLabelImage.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2022, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.carbon.device.mgt.common.metadata.mgt; public class WhiteLabelImage { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/WhiteLabelImageRequestPayload.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/WhiteLabelImageRequestPayload.java index 718c9a79244..e78e85b2402 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/WhiteLabelImageRequestPayload.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/metadata/mgt/WhiteLabelImageRequestPayload.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2022, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.carbon.device.mgt.common.metadata.mgt; import com.google.gson.Gson; 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 0c84ee2ea0c..e1536b80591 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 @@ -17,9 +17,9 @@ */ package org.wso2.carbon.device.mgt.common.metadata.mgt; + import org.wso2.carbon.device.mgt.common.exceptions.MetadataManagementException; import org.wso2.carbon.device.mgt.common.exceptions.NotFoundException; -import java.io.IOException; /** * Defines the contract of WhiteLabelManagementService. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/tenant/whitelabel/MetaDataConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/tenant/whitelabel/MetaDataConfiguration.java index 859baf19790..ae95b17e0db 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/tenant/whitelabel/MetaDataConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/tenant/whitelabel/MetaDataConfiguration.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.carbon.device.mgt.core.config.tenant.whitelabel; import javax.xml.bind.annotation.XmlElement; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/tenant/whitelabel/WhiteLabelConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/tenant/whitelabel/WhiteLabelConfiguration.java index 0d544bedbf1..6b51f0e170b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/tenant/whitelabel/WhiteLabelConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/tenant/whitelabel/WhiteLabelConfiguration.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.carbon.device.mgt.core.config.tenant.whitelabel; import javax.xml.bind.annotation.XmlElement; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/tenant/whitelabel/WhiteLabelImages.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/tenant/whitelabel/WhiteLabelImages.java index 4a6039944e3..cb8efe884da 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/tenant/whitelabel/WhiteLabelImages.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/tenant/whitelabel/WhiteLabelImages.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.carbon.device.mgt.core.config.tenant.whitelabel; import javax.xml.bind.annotation.XmlElement; 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 e0596fe9971..76fda9f697b 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 @@ -70,7 +70,6 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ try { WhiteLabelTheme whiteLabelTheme = getWhiteLabelTheme(); return getImageContent(whiteLabelTheme.getFaviconImage(), WhiteLabelImage.ImageName.FAVICON); - } catch (IOException e) { String msg = "Error occurred while getting byte content of favicon"; log.error(msg, e); @@ -179,6 +178,11 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ return whiteLabelConfiguration.getFooterText(); } + /** + * This is useful to construct and get the default favicon whitelabel image + * + * @return {@link WhiteLabelImage} + */ private WhiteLabelImage constructDefaultFaviconImage() { MetaDataConfiguration metaDataConfiguration = DeviceConfigurationManager.getInstance(). getDeviceManagementConfig().getMetaDataConfiguration(); @@ -189,6 +193,11 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ return favicon; } + /** + * This is useful to construct and get the default logo whitelabel image + * + * @return {@link WhiteLabelImage} + */ private WhiteLabelImage constructDefaultLogoImage() { MetaDataConfiguration metaDataConfiguration = DeviceConfigurationManager.getInstance(). getDeviceManagementConfig().getMetaDataConfiguration(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/util/WhiteLabelStorageUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/util/WhiteLabelStorageUtil.java index 553b53a459f..d18678ec912 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/util/WhiteLabelStorageUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/metadata/mgt/util/WhiteLabelStorageUtil.java @@ -88,7 +88,7 @@ public class WhiteLabelStorageUtil { storeWhiteLabelImage(FileUtil.fileToBase64File(image), imageName, tenantId); } catch (IOException e) { String msg = "Error occurred when converting provided File object to Base64File class"; - log.error(msg); + log.error(msg, e); throw new MetadataManagementException(msg, e); } } @@ -178,7 +178,9 @@ public class WhiteLabelStorageUtil { try { StorageManagementUtil.delete(artifact); } catch (IOException e) { - throw new MetadataManagementException("Error occurred while deleting whitelabel artifacts", e); + String msg = "Error occurred while deleting whitelabel artifacts"; + log.error(msg, e); + throw new MetadataManagementException(msg, e); } } } @@ -193,7 +195,9 @@ public class WhiteLabelStorageUtil { try { StorageManagementUtil.delete(artifact); } catch (IOException e) { - throw new MetadataManagementException("Error occurred while deleting whitelabel artifacts", e); + String msg = "Error occurred while deleting whitelabel artifacts"; + log.error(msg, e); + throw new MetadataManagementException(msg, e); } } }