From 402e4e769dbdfb6422499f22679fd0431747f3fa Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Tue, 23 May 2023 22:44:08 +0530 Subject: [PATCH 1/7] Fix operation log timing incorrectness --- .../mgt/dao/impl/operation/SQLServerOperationDAOImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/operation/SQLServerOperationDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/operation/SQLServerOperationDAOImpl.java index 6de5008fc8..c9e957987d 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/operation/SQLServerOperationDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/operation/SQLServerOperationDAOImpl.java @@ -194,12 +194,12 @@ public class SQLServerOperationDAOImpl extends GenericOperationDAOImpl { operation = new Operation(); operation.setId(rs.getInt("ID")); operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); - operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); + operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toInstant().toString()); if (rs.getLong("UPDATED_TIMESTAMP") == 0) { operation.setReceivedTimeStamp(""); } else { operation.setReceivedTimeStamp( - new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); + new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toInstant().toString()); } operation.setCode(rs.getString("OPERATION_CODE")); operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); From 1436332b32d641da6fa0cf946be9672ed8fbd5a4 Mon Sep 17 00:00:00 2001 From: osh Date: Tue, 21 Nov 2023 14:52:38 +0530 Subject: [PATCH 2/7] Fix app invisibility when retired --- .../mgt/core/application/mgt/common/Filter.java | 13 +++++++++++++ .../impl/application/GenericApplicationDAOImpl.java | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/Filter.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/Filter.java index 97f9688b6d..272e9ba8a3 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/Filter.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/Filter.java @@ -113,6 +113,11 @@ public class Filter { */ private String favouredBy; + /** + * Checking if retired apps needs to be excluded + */ + private boolean isNotRetired; + public int getLimit() { return limit; } @@ -208,4 +213,12 @@ public class Filter { public void setFavouredBy(String favouredBy) { this.favouredBy = favouredBy; } + + public boolean isNotRetired() { + return isNotRetired; + } + + public void setNotRetired(boolean notRetired) { + isNotRetired = notRetired; + } } diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 1e403e5848..09bea80fa5 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -180,6 +180,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic if (deviceTypeId != -1) { sql += "AND AP_APP.DEVICE_TYPE_ID = ? "; } + if (filter.isNotRetired()) { + sql += "AND AP_APP.STATUS != 'RETIRED' "; + } sql += "GROUP BY AP_APP.ID ORDER BY AP_APP.ID "; if (StringUtils.isNotEmpty(filter.getSortBy())) { sql += filter.getSortBy() +" "; @@ -308,6 +311,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic if (deviceTypeId != -1) { sql += " AND AP_APP.DEVICE_TYPE_ID = ?"; } + if (filter.isNotRetired()) { + sql += " AND AP_APP.STATUS != 'RETIRED'"; + } try { conn = this.getDBConnection(); From c4be66bc2e3e27c19e5ab7c9b4daf147f559788b Mon Sep 17 00:00:00 2001 From: osh Date: Mon, 27 Nov 2023 08:32:08 +0530 Subject: [PATCH 3/7] Add fix for apps not loading --- .../mgt/core/dao/impl/ApplicationDAOImpl.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/ApplicationDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/ApplicationDAOImpl.java index 4f46d5b4f6..1f48c3dc92 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/ApplicationDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/ApplicationDAOImpl.java @@ -285,32 +285,37 @@ public class ApplicationDAOImpl implements ApplicationDAO { "MEMORY_USAGE, " + "IS_ACTIVE, " + "TENANT_ID " + - "FROM DM_APPLICATION " + - "WHERE NOT EXISTS " + - "(SELECT " + - "ID " + - "FROM DM_APPLICATION A " + - "WHERE A.NAME = DM_APPLICATION.NAME " + - "AND A.ID < DM_APPLICATION.ID) " + - "AND PLATFORM = ? " + - "AND TENANT_ID = ? "; + "FROM DM_APPLICATION " + + "WHERE PLATFORM = ? AND " + + "TENANT_ID = ? AND " + + "NOT EXISTS (SELECT ID " + + "FROM DM_APPLICATION A " + + "WHERE A.NAME = DM_APPLICATION.NAME " + + "AND A.ID < DM_APPLICATION.ID AND " + + "PLATFORM = ? AND TENANT_ID = ?) "; + try { String filter = request.getFilter(); if (filter != null) { sql = sql + "AND NAME LIKE ? "; } - sql = sql + "LIMIT ? OFFSET ?"; + if (request != null && request.getRowCount() != -1) { + sql = sql + "LIMIT ? OFFSET ?"; + } Connection conn = this.getConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { int paramIdx = 1; stmt.setString(paramIdx++, request.getDeviceType()); stmt.setInt(paramIdx++, tenantId); + stmt.setString(paramIdx++, request.getDeviceType()); + stmt.setInt(paramIdx++, tenantId); if (filter != null){ stmt.setString(paramIdx++, filter); } - stmt.setInt(paramIdx++, request.getRowCount()); - stmt.setInt(paramIdx, request.getStartIndex()); - + if (request != null && request.getRowCount() != -1) { + stmt.setInt(paramIdx++, request.getRowCount()); + stmt.setInt(paramIdx, request.getStartIndex()); + } try (ResultSet rs = stmt.executeQuery()) { while (rs.next()) { application = loadApplication(rs); From 8c0ae2511e5bffce32cc12453d9002f9bcc03fff Mon Sep 17 00:00:00 2001 From: Rajitha Kumara Date: Mon, 4 Dec 2023 11:46:37 +0530 Subject: [PATCH 4/7] Add enrollment mails --- .../invitation/mgt/EnrollmentTypeMail.java | 57 +++ .../invitation/mgt/UserMailAttributes.java | 61 +++ .../mgt/core/DeviceManagementConstants.java | 3 + .../mgt/service/OTPManagementServiceImpl.java | 160 ++++-- .../email/templates/user-registration.vm | 478 ++++++++++++++++-- 5 files changed, 657 insertions(+), 102 deletions(-) create mode 100644 components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/EnrollmentTypeMail.java create mode 100644 components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/UserMailAttributes.java diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/EnrollmentTypeMail.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/EnrollmentTypeMail.java new file mode 100644 index 0000000000..86bec9ebff --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/EnrollmentTypeMail.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2018 - 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 io.entgra.device.mgt.core.device.mgt.common.invitation.mgt; + +import java.util.Properties; + +public class EnrollmentTypeMail { + private String template; + private String username; + private String recipient; + private Properties properties; + + public String getTemplate() { + return template; + } + + public void setTemplate(String template) { + this.template = template; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + public String getRecipient() { + return recipient; + } + public void setRecipient(String recipient) { + this.recipient = recipient; + } + + public Properties getProperties() { + return properties; + } + public void setProperties(Properties properties) { + this.properties = properties; + } +} diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/UserMailAttributes.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/UserMailAttributes.java new file mode 100644 index 0000000000..147298a666 --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/UserMailAttributes.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2018 - 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 io.entgra.device.mgt.core.device.mgt.common.invitation.mgt; + +public class UserMailAttributes { + private String username; + private String firstName; + private String email; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + 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; + } + + public String getUsernamePlaceholder() { + return "username"; + } + + public String getEmailPlaceholder() { + return "email"; + } + + public String getFirstNamePlaceholder() { + return "first-name"; + } +} diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/DeviceManagementConstants.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/DeviceManagementConstants.java index 8fc2e2804a..872b25205a 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/DeviceManagementConstants.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/DeviceManagementConstants.java @@ -121,6 +121,9 @@ public final class DeviceManagementConstants { public static final String USER_WELCOME_TEMPLATE = "user-welcome"; public static final String DEFAULT_ENROLLMENT_TEMPLATE = "default-enrollment-invitation"; public static final String ENROLLMENT_GUIDE_TEMPLATE = "enrollment-guide"; + public static final String DEVICE_ENROLLMENT_MAIL_KEY = "enrollment"; + public static final String TEMPLATE_NAME_PART_JOINER = "-"; + public static final String ENROLLMENT_TYPE_SPLITTER = "_"; } public static final class OperationAttributes { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java index bc9204eecb..564c9f073e 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java @@ -18,6 +18,7 @@ package io.entgra.device.mgt.core.device.mgt.core.otp.mgt.service; import com.google.gson.Gson; +import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.*; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -28,9 +29,6 @@ import io.entgra.device.mgt.core.device.mgt.common.exceptions.DBConnectionExcept import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.OTPManagementException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException; -import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitation; -import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitationDetails; -import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.DeviceEnrollmentType; import io.entgra.device.mgt.core.device.mgt.common.otp.mgt.OTPEmailTypes; import io.entgra.device.mgt.core.device.mgt.common.otp.mgt.dto.OneTimePinDTO; import io.entgra.device.mgt.core.device.mgt.common.spi.OTPManagementService; @@ -47,13 +45,7 @@ import org.wso2.carbon.user.api.Tenant; import org.wso2.carbon.user.api.UserStoreException; import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.UUID; +import java.util.*; public class OTPManagementServiceImpl implements OTPManagementService { @@ -218,53 +210,12 @@ public class OTPManagementServiceImpl implements OTPManagementService { } } - @Override public void sendDeviceEnrollmentInvitationMail(DeviceEnrollmentInvitation deviceEnrollmentInvitation) - throws OTPManagementException { - DeviceManagementProviderService dms = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider(); - StringBuilder enrollmentSteps = new StringBuilder(); - DeviceEnrollmentInvitationDetails deviceEnrollmentInvitationDetails; - for (DeviceEnrollmentType deviceEnrollmentType : deviceEnrollmentInvitation.getDeviceEnrollmentTypes()) { - deviceEnrollmentInvitationDetails = dms.getDeviceEnrollmentInvitationDetails( - deviceEnrollmentType.getDeviceType()); - if (deviceEnrollmentInvitationDetails != null && - deviceEnrollmentInvitationDetails.getEnrollmentDetails() != null) { - for (String enrollmentType : deviceEnrollmentType.getEnrollmentType()) { - deviceEnrollmentInvitationDetails.getEnrollmentDetails().stream() - .filter(details -> enrollmentType.equals(details.getEnrollmentType())).findFirst() - .ifPresent(details -> enrollmentSteps.append(details.getEnrollmentSteps())); - } - } - } - Properties props = new Properties(); - props.setProperty("enrollment-steps", enrollmentSteps.toString()); - try { - ConnectionManagerUtil.beginDBTransaction(); - for (String username : deviceEnrollmentInvitation.getUsernames()) { - String emailAddress = DeviceManagerUtil.getUserClaimValue( - username, DeviceManagementConstants.User.CLAIM_EMAIL_ADDRESS); - props.setProperty("first-name", DeviceManagerUtil. - getUserClaimValue(username, DeviceManagementConstants.User.CLAIM_FIRST_NAME)); - props.setProperty("username", username); - sendMail(props, emailAddress, DeviceManagementConstants.EmailAttributes.USER_ENROLLMENT_TEMPLATE); - } - ConnectionManagerUtil.commitDBTransaction(); - } catch (UserStoreException e) { - String msg = "Error occurred while getting claim values to invite user"; - log.error(msg, e); - throw new OTPManagementException(msg, e); - } catch (DBConnectionException e) { - String msg = "Error occurred while getting database connection to add OPT data."; - log.error(msg, e); - throw new OTPManagementException(msg, e); - } catch (TransactionManagementException e) { - String msg = "SQL Error occurred when adding OPT data to send device enrollment Invitation."; - log.error(msg, e); - throw new OTPManagementException(msg, e); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } + throws OTPManagementException { + List enrollmentTypeMails = + getEnrollmentTypeMails(deviceEnrollmentInvitation.getDeviceEnrollmentTypes()); + sendEnrollmentTypeMails(deviceEnrollmentInvitation.getUsernames(), enrollmentTypeMails); } /** @@ -380,4 +331,103 @@ public class OTPManagementServiceImpl implements OTPManagementService { ConnectionManagerUtil.closeDBConnection(); } } + + /** + * Send enrollment type mails to users + * @param usernames List of usernames to send enrollment type mails + * @param enrollmentTypeMails List of enrollment types + * @throws OTPManagementException Throws when error occurred while sending emails + */ + private void sendEnrollmentTypeMails(List usernames, List enrollmentTypeMails) + throws OTPManagementException { + try { + ConnectionManagerUtil.beginDBTransaction(); + for (String username : usernames) { + populateUserAttributes(getUserMailAttributes(username), enrollmentTypeMails); + for (EnrollmentTypeMail enrollmentTypeMail : enrollmentTypeMails) { + sendMail(enrollmentTypeMail); + } + } + ConnectionManagerUtil.commitDBTransaction(); + } catch (UserStoreException e) { + String msg = "Error occurred while populating user attributes"; + log.error(msg, e); + throw new OTPManagementException(msg, e); + } catch (DBConnectionException e) { + String msg = "Error occurred while getting database connection to add OTP data."; + log.error(msg, e); + throw new OTPManagementException(msg, e); + } catch (TransactionManagementException e) { + String msg = "SQL Error occurred when adding OPT data to send device enrollment Invitation."; + log.error(msg, e); + throw new OTPManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } + + /** + * Send enrollment type mail + * @param enrollmentTypeMail Data related to the enrollment mail + * @throws OTPManagementException Throws when error occurred while sending email + */ + private void sendMail(EnrollmentTypeMail enrollmentTypeMail) throws OTPManagementException { + sendMail(enrollmentTypeMail.getProperties(), enrollmentTypeMail.getRecipient(), enrollmentTypeMail.getTemplate()); + } + + /** + * Get user claims based on the username + * @param username Username + * @return {@link UserMailAttributes} + * @throws UserStoreException Throws when error occurred while retrieving user claims + */ + private UserMailAttributes getUserMailAttributes(String username) throws UserStoreException { + UserMailAttributes userMailAttributes = new UserMailAttributes(); + userMailAttributes.setEmail(DeviceManagerUtil.getUserClaimValue( + username, DeviceManagementConstants.User.CLAIM_EMAIL_ADDRESS)); + userMailAttributes.setFirstName(DeviceManagerUtil. + getUserClaimValue(username, DeviceManagementConstants.User.CLAIM_FIRST_NAME)); + userMailAttributes.setUsername(username); + return userMailAttributes; + } + + private void populateUserAttributes(UserMailAttributes userMailAttributes, List enrollmentTypeMails) { + for (EnrollmentTypeMail enrollmentTypeMail : enrollmentTypeMails) { + Properties properties = new Properties(); + properties.setProperty(userMailAttributes.getEmailPlaceholder(), userMailAttributes.getEmail()); + properties.setProperty(userMailAttributes.getFirstNamePlaceholder(), userMailAttributes.getFirstName()); + properties.setProperty(userMailAttributes.getUsernamePlaceholder(), userMailAttributes.getUsername()); + enrollmentTypeMail.setProperties(properties); + enrollmentTypeMail.setUsername(userMailAttributes.getUsername()); + enrollmentTypeMail.setRecipient(userMailAttributes.getEmail()); + } + } + + /** + * Generate enrollment type mail + * @param deviceType Device type of the enrollment type + * @param enrollmentType Enrollment type + * @return {@link EnrollmentTypeMail} + */ + private EnrollmentTypeMail getEnrollmentTypeMail(String deviceType, String enrollmentType) { + EnrollmentTypeMail enrollmentTypeMail = new EnrollmentTypeMail(); + enrollmentTypeMail.setUsername(enrollmentTypeMail.getUsername()); + enrollmentTypeMail.setTemplate(String.join(DeviceManagementConstants.EmailAttributes.TEMPLATE_NAME_PART_JOINER, + deviceType.toLowerCase(), enrollmentType.toLowerCase(). + replace(DeviceManagementConstants.EmailAttributes.ENROLLMENT_TYPE_SPLITTER, + DeviceManagementConstants.EmailAttributes.TEMPLATE_NAME_PART_JOINER), + DeviceManagementConstants.EmailAttributes.DEVICE_ENROLLMENT_MAIL_KEY)); + return enrollmentTypeMail; + } + + private List getEnrollmentTypeMails(List deviceEnrollmentTypes) { + List enrollmentTypeMails = new ArrayList<>(); + for (DeviceEnrollmentType deviceEnrollmentType : deviceEnrollmentTypes) { + String deviceType = deviceEnrollmentType.getDeviceType(); + for (String enrollmentType : deviceEnrollmentType.getEnrollmentType()) { + enrollmentTypeMails.add(getEnrollmentTypeMail(deviceType, enrollmentType)); + } + } + return enrollmentTypeMails; + } } \ No newline at end of file diff --git a/features/transport-mgt/email-sender/io.entgra.device.mgt.core.email.sender.feature/src/main/resources/email/templates/user-registration.vm b/features/transport-mgt/email-sender/io.entgra.device.mgt.core.email.sender.feature/src/main/resources/email/templates/user-registration.vm index bcca3b19ca..1bdea39053 100644 --- a/features/transport-mgt/email-sender/io.entgra.device.mgt.core.email.sender.feature/src/main/resources/email/templates/user-registration.vm +++ b/features/transport-mgt/email-sender/io.entgra.device.mgt.core.email.sender.feature/src/main/resources/email/templates/user-registration.vm @@ -15,56 +15,440 @@ specific language governing permissions and limitations under the License. *# + - You have successfully been registered in Entgra IoT + You have been invited to enroll your device in Entgra UEM - - Entgra IoT Server - - -
-
-
-
- entgra -
-
-
-

- Hi $first-name, -

- -

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

- -

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

- -

- Username: $username -
- Password: $password -

- -

- Should you need assistance, please contact your administrator. -

- -

- Regards, -

- -

- Entgra IoT Administrator -

-
-
-
- + + + + + + + + + + Entgra UEM Server + + + + + + + + + + + +
+ +
+
+
+ + +
+
+ +
+ + + + + + + +
+ + + + +
+ +
+
+ +
+ +
+
+ + +
+
+
+
+
+
+ + +
+
+ +
+ + + + + + + +
+
+

Dear $first-name,

+
+

We have completed your Entgra UEM registration. You are now invited to proceed with the enrollment of your device.

+
+
+

Please click on the link below to initiate this process.

+
+
+ + + + + + +
+ + +
+ + + + + + +
+
+

Here are your login credentials:

+
+

Username: $username

+

Password: $password

+
+

If you require any assistance or have questions during the enrollment process, reach out to your designated administrator via the Entgra Support Portal.

+
+

Thank you.

+
+

Best wishes,

+

Entgra team

+
+
+ +
+ +
+
+ + +
+
+
+
+
+
+ + +
+
+ +
+ + + + + + + +
+ + + + + + +
+
+
+ + + + + + +
+ +
+ + + + + + +
+
+

Follow Entgra on social media

+
+
+ + + + + + +
+
+
+ + + + + + + + +
+ + Facebook + +
+ + + + + + + + +
+ + LinkedIn + +
+ + + + + + + + +
+ + X + +
+ + + + + + + + +
+ + YouTube + +
+ + +
+
+
+ +
+ +
+
+ + +
+
+
+ +
+ + + ]]> From 6ee86e8cd2018500411e6092129d383c4bbe0db0 Mon Sep 17 00:00:00 2001 From: Rajitha Kumara Date: Tue, 5 Dec 2023 09:47:55 +0530 Subject: [PATCH 5/7] Add java doc comments --- .../invitation/mgt/EnrollmentTypeMail.java | 3 ++ .../mgt/service/OTPManagementServiceImpl.java | 40 +++++++++++-------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/EnrollmentTypeMail.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/EnrollmentTypeMail.java index 86bec9ebff..e8fd8484f6 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/EnrollmentTypeMail.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/EnrollmentTypeMail.java @@ -41,9 +41,11 @@ public class EnrollmentTypeMail { public void setUsername(String username) { this.username = username; } + public String getRecipient() { return recipient; } + public void setRecipient(String recipient) { this.recipient = recipient; } @@ -51,6 +53,7 @@ public class EnrollmentTypeMail { public Properties getProperties() { return properties; } + public void setProperties(Properties properties) { this.properties = properties; } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java index 564c9f073e..55e4fe46d8 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java @@ -18,18 +18,12 @@ package io.entgra.device.mgt.core.device.mgt.core.otp.mgt.service; import com.google.gson.Gson; -import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.*; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.context.CarbonContext; import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.ConfigurationManagementException; -import io.entgra.device.mgt.core.device.mgt.common.exceptions.BadRequestException; -import io.entgra.device.mgt.core.device.mgt.common.exceptions.DBConnectionException; -import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException; -import io.entgra.device.mgt.core.device.mgt.common.exceptions.OTPManagementException; -import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException; -import io.entgra.device.mgt.core.device.mgt.common.otp.mgt.OTPEmailTypes; +import io.entgra.device.mgt.core.device.mgt.common.exceptions.*; +import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitation; +import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.DeviceEnrollmentType; +import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.EnrollmentTypeMail; +import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.UserMailAttributes; import io.entgra.device.mgt.core.device.mgt.common.otp.mgt.dto.OneTimePinDTO; import io.entgra.device.mgt.core.device.mgt.common.spi.OTPManagementService; import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants; @@ -38,9 +32,11 @@ import io.entgra.device.mgt.core.device.mgt.core.otp.mgt.dao.OTPManagementDAO; import io.entgra.device.mgt.core.device.mgt.core.otp.mgt.dao.OTPManagementDAOFactory; import io.entgra.device.mgt.core.device.mgt.core.otp.mgt.exception.OTPManagementDAOException; import io.entgra.device.mgt.core.device.mgt.core.otp.mgt.util.ConnectionManagerUtil; -import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService; import io.entgra.device.mgt.core.device.mgt.core.service.EmailMetaInfo; import io.entgra.device.mgt.core.device.mgt.core.util.DeviceManagerUtil; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.user.api.Tenant; import org.wso2.carbon.user.api.UserStoreException; @@ -212,7 +208,7 @@ public class OTPManagementServiceImpl implements OTPManagementService { @Override public void sendDeviceEnrollmentInvitationMail(DeviceEnrollmentInvitation deviceEnrollmentInvitation) - throws OTPManagementException { + throws OTPManagementException { List enrollmentTypeMails = getEnrollmentTypeMails(deviceEnrollmentInvitation.getDeviceEnrollmentTypes()); sendEnrollmentTypeMails(deviceEnrollmentInvitation.getUsernames(), enrollmentTypeMails); @@ -247,7 +243,7 @@ public class OTPManagementServiceImpl implements OTPManagementService { throw new OTPManagementException(msg, e); } catch (OTPManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occurred while saving the OTP data for given email" ; + String msg = "Error occurred while saving the OTP data for given email"; log.error(msg, e); throw new OTPManagementException(msg, e); } finally { @@ -263,7 +259,7 @@ public class OTPManagementServiceImpl implements OTPManagementService { * @return {@link OneTimePinDTO} * @throws OTPManagementException if error occurred while getting OTP data for given OTP in DB */ - private OneTimePinDTO getOTPDataByToken (String oneTimeToken) throws OTPManagementException { + private OneTimePinDTO getOTPDataByToken(String oneTimeToken) throws OTPManagementException { try { ConnectionManagerUtil.openDBConnection(); return otpManagementDAO.getOTPDataByToken(oneTimeToken); @@ -284,7 +280,7 @@ public class OTPManagementServiceImpl implements OTPManagementService { * If OTP expired, resend the user verifying mail with renewed OTP * @param props Mail body properties * @param mailAddress Mail Address of the User - * @param template Mail template to be used + * @param template Mail template to be used * @throws OTPManagementException if error occurred while resend the user verifying mail */ private void sendMail(Properties props, String mailAddress, String template) throws OTPManagementException { @@ -306,7 +302,7 @@ public class OTPManagementServiceImpl implements OTPManagementService { /** * Renew the OTP * @param oneTimePinDTO {@link OneTimePinDTO} - * @param renewedOTP Renewed OTP + * @param renewedOTP Renewed OTP * @throws OTPManagementException if error occurred while renew the OTP */ private void renewOTP(OneTimePinDTO oneTimePinDTO, String renewedOTP) throws OTPManagementException { @@ -391,6 +387,11 @@ public class OTPManagementServiceImpl implements OTPManagementService { return userMailAttributes; } + /** + * Populate enrollment type mails with provided user attributes + * @param userMailAttributes User attributes + * @param enrollmentTypeMails Enrollment type mails + */ private void populateUserAttributes(UserMailAttributes userMailAttributes, List enrollmentTypeMails) { for (EnrollmentTypeMail enrollmentTypeMail : enrollmentTypeMails) { Properties properties = new Properties(); @@ -420,6 +421,11 @@ public class OTPManagementServiceImpl implements OTPManagementService { return enrollmentTypeMail; } + /** + * Generate enrollment type mails from device enrollment types + * @param deviceEnrollmentTypes List of device enrollment types + * @return List of enrollment type mails + */ private List getEnrollmentTypeMails(List deviceEnrollmentTypes) { List enrollmentTypeMails = new ArrayList<>(); for (DeviceEnrollmentType deviceEnrollmentType : deviceEnrollmentTypes) { From 31c79d5bc93c935563d0defea66f20f9a53432f2 Mon Sep 17 00:00:00 2001 From: Arshana Date: Tue, 5 Dec 2023 15:42:58 +0530 Subject: [PATCH 6/7] Changing the data type of DESCRIPTION from VARCHAR to TEXT --- .../main/resources/dbscripts/cdm/application-mgt/mysql.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/application-mgt/io.entgra.device.mgt.core.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/io.entgra.device.mgt.core.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index 448c249b85..7021c2af14 100644 --- a/features/application-mgt/io.entgra.device.mgt.core.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/io.entgra.device.mgt.core.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -19,7 +19,7 @@ CREATE TABLE IF NOT EXISTS AP_APP( -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS AP_APP_RELEASE( ID INTEGER NOT NULL AUTO_INCREMENT, - DESCRIPTION VARCHAR(200) NOT NULL, + DESCRIPTION TEXT NOT NULL, VERSION VARCHAR(70) NOT NULL, TENANT_ID INTEGER NOT NULL, UUID VARCHAR(200) NOT NULL, @@ -328,4 +328,4 @@ CREATE TABLE IF NOT EXISTS AP_VPP_ASSOCIATION ( PRIMARY KEY (ID), CONSTRAINT AP_VPP_ASSETS_fk FOREIGN KEY (ASSET_ID) REFERENCES AP_ASSETS (ID) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT AP_VPP_VPP_USER_fk FOREIGN KEY (USER_ID) REFERENCES AP_VPP_USER (ID) ON DELETE CASCADE ON UPDATE CASCADE -); \ No newline at end of file +); From bd79e4a8340aa83e5248ce6880e06b0639bbd439 Mon Sep 17 00:00:00 2001 From: Arshana Date: Thu, 7 Dec 2023 10:07:19 +0530 Subject: [PATCH 7/7] Changing the data type of APP_META_INFO from VARCHAR to TEXT --- .../src/main/resources/dbscripts/cdm/application-mgt/mysql.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/application-mgt/io.entgra.device.mgt.core.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/io.entgra.device.mgt.core.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index 7021c2af14..5b608e15a6 100644 --- a/features/application-mgt/io.entgra.device.mgt.core.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/io.entgra.device.mgt.core.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -34,7 +34,7 @@ CREATE TABLE IF NOT EXISTS AP_APP_RELEASE( SC_3_LOCATION VARCHAR(100) NULL DEFAULT NULL, APP_HASH_VALUE VARCHAR(1000) NOT NULL, SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, - APP_META_INFO VARCHAR(150) NULL DEFAULT NULL, + APP_META_INFO TEXT NULL DEFAULT NULL, SUPPORTED_OS_VERSIONS VARCHAR(45) NOT NULL, RATING DOUBLE NULL DEFAULT NULL, CURRENT_STATE VARCHAR(45) NOT NULL,