From 476fe5f849d0888e6d00d5bce9ee1d9048a231b9 Mon Sep 17 00:00:00 2001 From: Rajitha Kumara Date: Wed, 21 Aug 2024 08:21:51 +0530 Subject: [PATCH] Add release version report supportablility --- .../mgt/common/ReleaseVersionInfo.java | 68 +++++++++++++++++++ .../common/services/ApplicationManager.java | 9 +++ .../mgt/core/dao/ApplicationDAO.java | 3 + .../GenericApplicationDAOImpl.java | 47 +++++++++++++ .../GenericApplicationReleaseDAOImpl.java | 1 + .../mgt/core/impl/ApplicationManagerImpl.java | 22 ++++++ .../src/main/resources/conf/mdm-ui-config.xml | 1 + 7 files changed, 151 insertions(+) create mode 100644 components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/ReleaseVersionInfo.java 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/ReleaseVersionInfo.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/ReleaseVersionInfo.java new file mode 100644 index 0000000000..218f92187b --- /dev/null +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/ReleaseVersionInfo.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2018 - 2024, 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.application.mgt.common; + +public class ReleaseVersionInfo { + private String version; + private String releaseType; + private String rating; + private String state; + private String uuid; + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getReleaseType() { + return releaseType; + } + + public String getRating() { + return rating; + } + + public void setRating(String rating) { + this.rating = rating; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public void setReleaseType(String releaseType) { + this.releaseType = releaseType; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } +} 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/services/ApplicationManager.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/ApplicationManager.java index d40855db19..b0356161c6 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/ApplicationManager.java @@ -18,6 +18,7 @@ package io.entgra.device.mgt.core.application.mgt.common.services; import io.entgra.device.mgt.core.application.mgt.common.ApplicationType; +import io.entgra.device.mgt.core.application.mgt.common.ReleaseVersionInfo; import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException; import io.entgra.device.mgt.core.application.mgt.common.exception.RequestValidatingException; import io.entgra.device.mgt.core.application.mgt.common.exception.ResourceManagementException; @@ -561,4 +562,12 @@ public interface ApplicationManager { * @throws ApplicationManagementException thrown if an error occurs when deleting app folders */ void deleteApplicationArtifactsByTenantId(int tenantId) throws ApplicationManagementException; + + /** + * Extract and retrieve application release version data for a given UUID + * @param uuid UUID of the application + * @return List of {@link ReleaseVersionInfo} + * @throws ApplicationManagementException throws when error encountered while retrieving data + */ + List getApplicationReleaseVersions(String uuid) throws ApplicationManagementException; } 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/ApplicationDAO.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/ApplicationDAO.java index 9777469cea..b86747c207 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/ApplicationDAO.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/ApplicationDAO.java @@ -18,6 +18,7 @@ package io.entgra.device.mgt.core.application.mgt.core.dao; import io.entgra.device.mgt.core.application.mgt.common.Filter; +import io.entgra.device.mgt.core.application.mgt.common.ReleaseVersionInfo; import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.CategoryDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.TagDTO; @@ -286,4 +287,6 @@ public interface ApplicationDAO { * @throws ApplicationManagementDAOException thrown if an error occurs while deleting data */ void deleteApplicationsByTenant(int tenantId) throws ApplicationManagementDAOException; + + List getApplicationReleaseVersions(String uuid, int tenantId) throws ApplicationManagementDAOException; } 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 0c4e6c12d7..b327d9803d 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 @@ -23,6 +23,7 @@ import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.CategoryDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.TagDTO; import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException; +import io.entgra.device.mgt.core.application.mgt.common.ReleaseVersionInfo; import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationDAO; import io.entgra.device.mgt.core.application.mgt.core.dao.impl.AbstractDAOImpl; import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException; @@ -2049,4 +2050,50 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } } + @Override + public List getApplicationReleaseVersions(String uuid, int tenantId) throws ApplicationManagementDAOException { + List releaseVersionInfos = new ArrayList<>(); + String sql = "SELECT VERSION, " + + "RELEASE_TYPE, " + + "RATING, " + + "CURRENT_STATE, " + + "UUID FROM " + + "AP_APP_RELEASE WHERE " + + "AP_APP_ID=" + + "(SELECT AP_APP_ID " + + "FROM AP_APP_RELEASE " + + "WHERE UUID = ? " + + "AND TENANT_ID = ?)"; + try { + Connection connection = getDBConnection(); + try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { + preparedStatement.setString(1, uuid); + preparedStatement.setInt(2, tenantId); + try (ResultSet resultSet = preparedStatement.executeQuery()) { + ReleaseVersionInfo releaseVersionInfo; + while(resultSet.next()) { + releaseVersionInfo = new ReleaseVersionInfo(); + releaseVersionInfo.setVersion(resultSet.getString("VERSION")); + releaseVersionInfo.setReleaseType(resultSet.getString("RELEASE_TYPE")); + releaseVersionInfo.setRating(resultSet.getString("RATING")); + releaseVersionInfo.setState(resultSet.getString("CURRENT_STATE")); + releaseVersionInfo.setUuid(resultSet.getString("UUID")); + releaseVersionInfos.add(releaseVersionInfo); + } + } + } + } catch (DBConnectionException e) { + String msg = "Error encountered while acquiring database connection to get available release versions for " + + "UUID : " + uuid ; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "SQL error occurred while getting available release versions for : " + uuid + + "Executed query : [" + sql + "]"; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } + return releaseVersionInfos; + } + } 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/release/GenericApplicationReleaseDAOImpl.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/release/GenericApplicationReleaseDAOImpl.java index 8dc97494c0..95b7c8584c 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/release/GenericApplicationReleaseDAOImpl.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/release/GenericApplicationReleaseDAOImpl.java @@ -30,6 +30,7 @@ import org.apache.commons.logging.LogFactory; import java.sql.*; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.StringJoiner; 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/impl/ApplicationManagerImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationManagerImpl.java index 29d7d84ae5..e37ec062a3 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationManagerImpl.java @@ -18,6 +18,7 @@ package io.entgra.device.mgt.core.application.mgt.core.impl; +import io.entgra.device.mgt.core.application.mgt.common.ReleaseVersionInfo; import io.entgra.device.mgt.core.application.mgt.common.exception.FileDownloaderServiceException; import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException; import io.entgra.device.mgt.core.application.mgt.core.dao.*; @@ -4500,4 +4501,25 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException(msg, e); } } + + /** + * Retrieve {@link ReleaseVersionInfo} for a given package name + * @param uuid UUID of the application release + * @return List of {@link ReleaseVersionInfo} + * @throws ApplicationManagementException throws when error encountered while retrieving data + */ + @Override + public List getApplicationReleaseVersions(String uuid) throws ApplicationManagementException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + try { + ConnectionManagerUtil.openDBConnection(); + return applicationDAO.getApplicationReleaseVersions(uuid, tenantId); + } catch (ApplicationManagementDAOException e) { + String msg = "Error occurred while getting available application releases for uuid : " + uuid; + log.error(msg, e); + throw new ApplicationManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } } diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml index da4191cff2..43e5c59f98 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml @@ -240,6 +240,7 @@ am:admin:store:app:review:update am:admin:store:app:sub:view am:admin:store:app:sub:modify + am:admin:store:app:release-versions:view dm:device-type:view and:enterprise:modify and:enterprise:view