From d55ea733e702c7e07e6f11cd6cd258e4580eaa2d Mon Sep 17 00:00:00 2001 From: Dharmakeerthi Lasantha Date: Mon, 9 Jan 2023 19:46:12 +0530 Subject: [PATCH] Add download URL generating method --- .../otp/mgt/wrapper/DownloadURLDetails.java | 49 +++++++++++++++ .../mgt/common/spi/OTPManagementService.java | 12 +++- .../mgt/core/DeviceManagementConstants.java | 1 + .../mgt/service/OTPManagementServiceImpl.java | 26 ++++++++ .../templates/share-product-download-url.vm | 61 +++++++++++++++++++ .../email/templates/user-registration.vm | 2 +- 6 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/otp/mgt/wrapper/DownloadURLDetails.java create mode 100644 features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/share-product-download-url.vm diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/otp/mgt/wrapper/DownloadURLDetails.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/otp/mgt/wrapper/DownloadURLDetails.java new file mode 100644 index 0000000000..e6a8557b66 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/otp/mgt/wrapper/DownloadURLDetails.java @@ -0,0 +1,49 @@ +/* Copyright (c) 2023, 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.common.otp.mgt.wrapper; + +public class DownloadURLDetails { + + private String firstName; + private String URL; + private String email; + + public String getURL() { + return URL; + } + + public void setURL(String URL) { + this.URL = URL; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/OTPManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/OTPManagementService.java index 6349407dc1..27e20328c5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/OTPManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/OTPManagementService.java @@ -22,6 +22,7 @@ import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.exceptions.OTPManagementException; import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitation; import org.wso2.carbon.device.mgt.common.otp.mgt.dto.OneTimePinDTO; +import org.wso2.carbon.device.mgt.common.otp.mgt.wrapper.DownloadURLDetails; import org.wso2.carbon.device.mgt.common.otp.mgt.wrapper.OTPWrapper; import java.util.Map; @@ -62,4 +63,13 @@ public interface OTPManagementService { */ void sendDeviceEnrollmentInvitationMail(DeviceEnrollmentInvitation deviceEnrollmentInvitation) throws OTPManagementException; -} + + /** + * Send an e-mail to the requesting e-mail address with a product download URL + * @param downloadURLDetails Contains the details to send product download e-mail + * @throws OTPManagementException if request payload doesn't contains required details to send the product + * download mail. + */ + void shareProductDownloadUrl(DownloadURLDetails downloadURLDetails) throws OTPManagementException; + + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java index 8e03917f55..f991a39852 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java @@ -131,6 +131,7 @@ public final class DeviceManagementConstants { public static final String USER_REGISTRATION_TEMPLATE = "user-registration"; public static final String USER_ENROLLMENT_TEMPLATE = "user-enrollment"; public static final String USER_VERIFY_TEMPLATE = "user-verify"; + public static final String PRODUCT_DOWNLOAD_LINK_SHARING_TEMPLATE = "share-product-download-url"; public static final String POLICY_VIOLATE_TEMPLATE = "policy-violating-notifier"; public static final String USER_WELCOME_TEMPLATE = "user-welcome"; public static final String DEFAULT_ENROLLMENT_TEMPLATE = "default-enrollment-invitation"; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java index 985fe76486..caec00197d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java @@ -35,6 +35,7 @@ import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentType; import org.wso2.carbon.device.mgt.common.metadata.mgt.Metadata; import org.wso2.carbon.device.mgt.common.otp.mgt.OTPEmailTypes; import org.wso2.carbon.device.mgt.common.otp.mgt.dto.OneTimePinDTO; +import org.wso2.carbon.device.mgt.common.otp.mgt.wrapper.DownloadURLDetails; import org.wso2.carbon.device.mgt.common.spi.OTPManagementService; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; @@ -109,6 +110,31 @@ public class OTPManagementServiceImpl implements OTPManagementService { } } + @Override + public void shareProductDownloadUrl(DownloadURLDetails downloadURLDetails) throws OTPManagementException { + if (StringUtils.isBlank(downloadURLDetails.getURL())) { + String msg = "Couldn't find the download URL with the request."; + log.error(msg); + throw new OTPManagementException(msg); + } + if (StringUtils.isBlank(downloadURLDetails.getFirstName())) { + String msg = "Couldn't find the First Name with the request."; + log.error(msg); + throw new OTPManagementException(msg); + } + if (StringUtils.isBlank(downloadURLDetails.getEmail())) { + String msg = "Couldn't find the e-mail address with the request."; + log.error(msg); + throw new OTPManagementException(msg); + } + + Properties props = new Properties(); + props.setProperty("first-name", downloadURLDetails.getFirstName()); + props.setProperty("download-url", downloadURLDetails.getFirstName()); + sendMail(props, downloadURLDetails.getEmail(), + DeviceManagementConstants.EmailAttributes.PRODUCT_DOWNLOAD_LINK_SHARING_TEMPLATE); + } + @Override public OneTimePinDTO isValidOTP(String oneTimeToken) throws OTPManagementException, BadRequestException { if (StringUtils.isBlank(oneTimeToken)){ diff --git a/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/share-product-download-url.vm b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/share-product-download-url.vm new file mode 100644 index 0000000000..965a927370 --- /dev/null +++ b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/share-product-download-url.vm @@ -0,0 +1,61 @@ +#* + Copyright (c) 2023, 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. +*# + + You have been invited to enroll your device in Entgra IoT + + + + Entgra IoT Server + + +
+
+
+
+ entgra +
+
+
+

+ Hi $first-name, +

+

+ Thank you very much for your interest in the Entgra IoT server. Please click + Click here to download the latest release of the Entgra IoT server.

+ +

+ If you need assistance, please contact us through Entgra + contact us > +

+ +

+ Regards, +

+ +

+ Entgra IoT Administrator +

+
+
+
+ + + ]]> + +
diff --git a/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-registration.vm b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-registration.vm index 0593f32166..66197fd0a3 100644 --- a/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-registration.vm +++ b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-registration.vm @@ -38,7 +38,7 @@

You have been registered in Entgra IoT and invited to enrol your device. - Click here to begin device enrolment.

+ Click here to begin device enrolment.

Use following credentials to log in to Entgra IoT Device Management application.