Merge pull request 'Improve update asset DAO' (#174) from osh.silva/device-mgt-core:vpp-daos into vpp-v2

Reviewed-on: community/device-mgt-core#174
fix-try-it-meta-info
Inosh Perara 1 year ago
commit fefc66bc59

@ -261,9 +261,9 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
+ "PRICING_PARAMS," + "PRICING_PARAMS,"
+ "PRODUCT_TYPE," + "PRODUCT_TYPE,"
+ "RETIRED_COUNT," + "RETIRED_COUNT,"
+ "REVOCABLE) " + "REVOCABLE, "
// + "SUPPORTED_PLATFORMS) " + "SUPPORTED_PLATFORMS) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
try { try {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
@ -279,9 +279,9 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
stmt.setString(9, vppAssetDTO.getProductType()); stmt.setString(9, vppAssetDTO.getProductType());
stmt.setString(10, vppAssetDTO.getRetiredCount()); stmt.setString(10, vppAssetDTO.getRetiredCount());
stmt.setString(11, vppAssetDTO.getRevocable()); stmt.setString(11, vppAssetDTO.getRevocable());
// List<String> platformList = vppAssetDTO.getSupportedPlatforms(); List<String> platformList = vppAssetDTO.getSupportedPlatforms();
// String platformString = String.join(",", platformList); String platformString = String.join(",", platformList);
// stmt.setString(12, platformString); stmt.setString(12, platformString);
stmt.executeUpdate(); stmt.executeUpdate();
try (ResultSet rs = stmt.getGeneratedKeys()) { try (ResultSet rs = stmt.getGeneratedKeys()) {
if (rs.next()) { if (rs.next()) {
@ -305,39 +305,71 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
public VppAssetDTO updateAsset(VppAssetDTO vppAssetDTO, int tenantId) public VppAssetDTO updateAsset(VppAssetDTO vppAssetDTO, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
String sql = "UPDATE " String sql = "UPDATE AP_ASSETS SET ";
+ "AP_ASSETS "
+ "SET " if (vppAssetDTO.getAdamId() != null && !vppAssetDTO.getAdamId().isEmpty()) {
+ "APP_ID = ?," sql += "ADAM_ID = ?, ";
+ "LAST_UPDATED_TIME = ?, " }
+ "ADAM_ID = ?, " if (vppAssetDTO.getAssignedCount() != null && !vppAssetDTO.getAssignedCount().isEmpty()) {
+ "ASSIGNED_COUNT = ?, " sql += "ASSIGNED_COUNT = ?, ";
+ "DEVICE_ASSIGNABLE = ?, " }
+ "PRICING_PARAMS = ?, " if (vppAssetDTO.getDeviceAssignable() != null && !vppAssetDTO.getDeviceAssignable().isEmpty()) {
+ "PRODUCT_TYPE = ?, " sql += "DEVICE_ASSIGNABLE = ?, ";
+ "RETIRED_COUNT = ?, " }
+ "REVOCABLE = ? " if (vppAssetDTO.getPricingParam() != null && !vppAssetDTO.getPricingParam().isEmpty()) {
// + "SUPPORTED_PLATFORMS = ? " sql += "PRICING_PARAMS = ?, ";
+ "WHERE ID = ? AND TENANT_ID = ?"; }
if (vppAssetDTO.getProductType() != null && !vppAssetDTO.getProductType().isEmpty()) {
sql += "PRODUCT_TYPE = ?, ";
}
if (vppAssetDTO.getRetiredCount() != null && !vppAssetDTO.getRetiredCount().isEmpty()) {
sql += "RETIRED_COUNT = ?, ";
}
if (vppAssetDTO.getRevocable() != null && !vppAssetDTO.getRevocable().isEmpty()) {
sql += "REVOCABLE = ?, ";
}
if (vppAssetDTO.getSupportedPlatforms() != null && !vppAssetDTO.getSupportedPlatforms().isEmpty()) {
sql += "SUPPORTED_PLATFORMS = ?,";
}
sql += "APP_ID = ?, LAST_UPDATED_TIME = ? WHERE ID = ? AND TENANT_ID = ?";
try { try {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
long updatedTime = System.currentTimeMillis(); long updatedTime = System.currentTimeMillis();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, vppAssetDTO.getAppId()); int x = 0;
stmt.setLong(2, updatedTime);
stmt.setString(3, vppAssetDTO.getAdamId()); if (vppAssetDTO.getAdamId() != null && !vppAssetDTO.getAdamId().isEmpty()) {
stmt.setString(4, vppAssetDTO.getAssignedCount()); stmt.setString(++x, vppAssetDTO.getAdamId());
stmt.setString(5, vppAssetDTO.getDeviceAssignable()); }
stmt.setString(6, vppAssetDTO.getPricingParam()); if (vppAssetDTO.getAssignedCount() != null && !vppAssetDTO.getAssignedCount().isEmpty()) {
stmt.setString(7, vppAssetDTO.getProductType()); stmt.setString(++x, vppAssetDTO.getAssignedCount());
stmt.setString(8, vppAssetDTO.getRetiredCount()); }
stmt.setString(9, vppAssetDTO.getRevocable()); if (vppAssetDTO.getDeviceAssignable() != null && !vppAssetDTO.getDeviceAssignable().isEmpty()) {
// List<String> platformList = vppAssetDTO.getSupportedPlatforms(); stmt.setString(++x, vppAssetDTO.getDeviceAssignable());
// String platformString = String.join(",", platformList); }
// stmt.setString(10, platformString); if (vppAssetDTO.getPricingParam() != null && !vppAssetDTO.getPricingParam().isEmpty()) {
stmt.setInt(10, vppAssetDTO.getId()); stmt.setString(++x, vppAssetDTO.getPricingParam());
stmt.setLong(11, tenantId); }
stmt.executeUpdate(); if (vppAssetDTO.getProductType() != null && !vppAssetDTO.getProductType().isEmpty()) {
stmt.setString(++x, vppAssetDTO.getProductType());
}
if (vppAssetDTO.getRetiredCount() != null && !vppAssetDTO.getRetiredCount().isEmpty()) {
stmt.setString(++x, vppAssetDTO.getRetiredCount());
}
if (vppAssetDTO.getRevocable() != null && !vppAssetDTO.getRevocable().isEmpty()) {
stmt.setString(++x, vppAssetDTO.getRevocable());
}
if (vppAssetDTO.getSupportedPlatforms() != null && !vppAssetDTO.getSupportedPlatforms().isEmpty()) {
List<String> platformList = vppAssetDTO.getSupportedPlatforms();
String platformString = String.join(",", platformList);
stmt.setString(++x, platformString);
}
stmt.setInt(++x, vppAssetDTO.getAppId());
stmt.setLong(++x, updatedTime);
stmt.setInt(++x, vppAssetDTO.getId());
stmt.setLong(++x, tenantId);
if (stmt.executeUpdate() == 1) { if (stmt.executeUpdate() == 1) {
return vppAssetDTO; return vppAssetDTO;
} }

@ -315,6 +315,7 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
} }
} else { } else {
vppAssetDTOs.setAppId(application.getId()); vppAssetDTOs.setAppId(application.getId());
vppAssetDTOs.setSupportedPlatforms(vppAssetDTO.getSupportedPlatforms());
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
if (vppApplicationDAO.updateAsset(vppAssetDTOs, tenantId) == null) { if (vppApplicationDAO.updateAsset(vppAssetDTOs, tenantId) == null) {

Loading…
Cancel
Save