Add release version report getting function

notification-11094
Lasantha Dharmakeerthi 3 months ago
commit 16365f95a0

@ -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;
}
}

@ -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<ReleaseVersionInfo> getApplicationReleaseVersions(String uuid) throws ApplicationManagementException;
}

@ -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<ReleaseVersionInfo> getApplicationReleaseVersions(String uuid, int tenantId) throws ApplicationManagementDAOException;
}

@ -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<ReleaseVersionInfo> getApplicationReleaseVersions(String uuid, int tenantId) throws ApplicationManagementDAOException {
List<ReleaseVersionInfo> 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;
}
}

@ -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;

@ -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<ReleaseVersionInfo> 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();
}
}
}

@ -240,6 +240,7 @@
<Scope>am:admin:store:app:review:update</Scope>
<Scope>am:admin:store:app:sub:view</Scope>
<Scope>am:admin:store:app:sub:modify</Scope>
<Scope>am:admin:store:app:release-versions:view</Scope>
<Scope>dm:device-type:view</Scope>
<Scope>and:enterprise:modify</Scope>
<Scope>and:enterprise:view</Scope>

Loading…
Cancel
Save