Add DAO improvements for user APIs

Fixes https://roadmap.entgra.net/issues/10169
vpp-v2
inoshperera 1 year ago
parent 949fbef41b
commit 026986cd93

@ -20,6 +20,7 @@ package io.entgra.device.mgt.core.application.mgt.common.services;
import io.entgra.device.mgt.core.application.mgt.common.dto.ProxyResponse; import io.entgra.device.mgt.core.application.mgt.common.dto.ProxyResponse;
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssociationDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO; import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException; import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
@ -44,4 +45,7 @@ public interface VPPApplicationManager {
boolean addAssociation(VppAssetDTO asset, List<VppUserDTO> vppUsers) throws boolean addAssociation(VppAssetDTO asset, List<VppUserDTO> vppUsers) throws
ApplicationManagementException; ApplicationManagementException;
VppAssociationDTO getUserAssociation(String adamId, String emmUsername) throws
ApplicationManagementException;
} }

@ -89,34 +89,61 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
public VppUserDTO updateVppUser(VppUserDTO userDTO, int tenantId) public VppUserDTO updateVppUser(VppUserDTO userDTO, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
String sql = "UPDATE " String sql = "UPDATE AP_VPP_USER SET ";
+ "AP_VPP_USER " if (userDTO.getClientUserId() != null && !userDTO.getClientUserId().isEmpty()) {
+ "SET " sql += "CLIENT_USER_ID = ?,";
+ "CLIENT_USER_ID = ?," }
+ "DM_USERNAME = ?, " if (userDTO.getDmUsername() != null && !userDTO.getDmUsername().isEmpty()) {
+ "TENANT_ID = ?, " sql += "DM_USERNAME = ?,";
+ "EMAIL = ?, " }
+ "INVITE_CODE = ?, " if (userDTO.getEmail() != null && !userDTO.getEmail().isEmpty()) {
+ "STATUS = ?, " sql += "EMAIL = ?,";
+ "LAST_UPDATED_TIME = ?, " }
+ "MANAGED_ID = ?, " if (userDTO.getInviteCode() != null && !userDTO.getInviteCode().isEmpty()) {
+ "TEMP_PASSWORD = ? " sql += "INVITE_CODE = ?,";
+ "WHERE ID = ?"; }
if (userDTO.getStatus() != null && !userDTO.getStatus().isEmpty()) {
sql += "STATUS = ?,";
}
if (userDTO.getManagedId() != null && !userDTO.getManagedId().isEmpty()) {
sql += "MANAGED_ID = ?,";
}
if (userDTO.getTmpPassword() != null && !userDTO.getTmpPassword().isEmpty()) {
sql += "TEMP_PASSWORD = ?,";
}
sql += " TENANT_ID = ?, LAST_UPDATED_TIME = ? WHERE 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.setString(1, userDTO.getClientUserId()); int x = 0;
stmt.setString(2, userDTO.getDmUsername());
stmt.setInt(3, tenantId); if (userDTO.getClientUserId() != null && !userDTO.getClientUserId().isEmpty()) {
stmt.setString(4, userDTO.getEmail()); stmt.setString(++x, userDTO.getClientUserId());
stmt.setString(5, userDTO.getInviteCode()); }
stmt.setString(6, userDTO.getStatus()); if (userDTO.getDmUsername() != null && !userDTO.getDmUsername().isEmpty()) {
stmt.setLong(7, updatedTime); stmt.setString(++x, userDTO.getDmUsername());
stmt.setString(8, userDTO.getManagedId()); }
stmt.setString(9, userDTO.getTmpPassword()); if (userDTO.getEmail() != null && !userDTO.getEmail().isEmpty()) {
stmt.setInt(10, userDTO.getId()); stmt.setString(++x, userDTO.getEmail());
stmt.executeUpdate(); }
if (userDTO.getInviteCode() != null && !userDTO.getInviteCode().isEmpty()) {
stmt.setString(++x, userDTO.getInviteCode());
}
if (userDTO.getStatus() != null && !userDTO.getStatus().isEmpty()) {
stmt.setString(++x, userDTO.getStatus());
}
if (userDTO.getManagedId() != null && !userDTO.getManagedId().isEmpty()) {
stmt.setString(++x, userDTO.getManagedId());
}
if (userDTO.getTmpPassword() != null && !userDTO.getTmpPassword().isEmpty()) {
stmt.setString(++x, userDTO.getTmpPassword());
}
stmt.setInt(++x, tenantId);
stmt.setLong(++x, updatedTime);
stmt.setInt(++x, userDTO.getId());
if (stmt.executeUpdate() == 1) { if (stmt.executeUpdate() == 1) {
return userDTO; return userDTO;
} }
@ -147,6 +174,7 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
+ "LAST_UPDATED_TIME, " + "LAST_UPDATED_TIME, "
+ "MANAGED_ID, " + "MANAGED_ID, "
+ "TEMP_PASSWORD " + "TEMP_PASSWORD "
+ "DM_USERNAME "
+ "FROM AP_VPP_USER " + "FROM AP_VPP_USER "
+ "WHERE DM_USERNAME = ? AND TENANT_ID = ?"; + "WHERE DM_USERNAME = ? AND TENANT_ID = ?";
try { try {

@ -110,9 +110,6 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
wrapper.getUser().add(ituneUserDTO); wrapper.getUser().add(ituneUserDTO);
Gson gson = new Gson(); Gson gson = new Gson();
// Gson gson = new GsonBuilder()
// .setExclusionStrategies(new NullEmptyExclusionStrategy())
// .create();
String userPayload = gson.toJson(wrapper); String userPayload = gson.toJson(wrapper);
ProxyResponse proxyResponse = callVPPBackend(USER_CREATE, userPayload, TOKEN, Constants.VPP.POST); ProxyResponse proxyResponse = callVPPBackend(USER_CREATE, userPayload, TOKEN, Constants.VPP.POST);
@ -131,8 +128,12 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
log.error("userDTO " + userDTO.toString()); log.error("userDTO " + userDTO.toString());
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
if (vppApplicationDAO.addVppUser(userDTO, tenantId) != -1) { int id = vppApplicationDAO.addVppUser(userDTO, tenantId);
if (id != -1) {
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
userDTO.setId(id);
userDTO.setTenantId(PrivilegedCarbonContext
.getThreadLocalCarbonContext().getTenantId());
return userDTO; return userDTO;
} }
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
@ -507,4 +508,11 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
return false; return false;
} }
@Override
public VppAssociationDTO getUserAssociation(String adamId, String emmUsername) throws ApplicationManagementException {
// Todo: Join the 3 tables and find a matching association
return null;
}
} }

@ -196,7 +196,7 @@ public class Constants {
public static final String PAID_SUB_METHOD = "PAID"; public static final String PAID_SUB_METHOD = "PAID";
public static final String TYPE = "type";; public static final String TYPE = "type";;
public static final String PACKAGE_NAME = "packageName"; public static final String PACKAGE_NAME = "packageName";
public static final String APPLE_STORE_SYNCED_APP_CATEGORY = "APPLE_STORE_SYNCED_APP"; public static final String APPLE_STORE_SYNCED_APP_CATEGORY = "AppleStoreSyncedApp";
public static final String RESULTS = "results"; public static final String RESULTS = "results";
public static final String ARTWORK = "artwork"; public static final String ARTWORK = "artwork";

@ -362,9 +362,18 @@ public class DAOUtil {
vppUserDTO.setTenantId(rs.getInt("TENANT_ID")); vppUserDTO.setTenantId(rs.getInt("TENANT_ID"));
vppUserDTO.setEmail(rs.getString("EMAIL")); vppUserDTO.setEmail(rs.getString("EMAIL"));
vppUserDTO.setInviteCode(rs.getString("INVITE_CODE")); vppUserDTO.setInviteCode(rs.getString("INVITE_CODE"));
vppUserDTO.setStatus(rs.getString("STATUS")); if (columnExist(rs,"STATUS")) {
vppUserDTO.setManagedId(rs.getString("MANAGED_ID")); vppUserDTO.setStatus(rs.getString("STATUS"));
vppUserDTO.setTmpPassword(rs.getString("TEMP_PASSWORD")); }
if (columnExist(rs,"MANAGED_ID")) {
vppUserDTO.setManagedId(rs.getString("MANAGED_ID"));
}
if (columnExist(rs,"TEMP_PASSWORD")) {
vppUserDTO.setTmpPassword(rs.getString("TEMP_PASSWORD"));
}
if (columnExist(rs,"DM_USERNAME")) {
vppUserDTO.setDmUsername(rs.getString("DM_USERNAME"));
}
if (rs.getLong("CREATED_TIME") != 0) { if (rs.getLong("CREATED_TIME") != 0) {
vppUserDTO.setCreatedTime(new Date(rs.getLong(("CREATED_TIME")) * 1000).toString()); vppUserDTO.setCreatedTime(new Date(rs.getLong(("CREATED_TIME")) * 1000).toString());
} }
@ -376,6 +385,16 @@ public class DAOUtil {
return vppUserDTOS; return vppUserDTOS;
} }
private static boolean columnExist(ResultSet rs, String column){
try{
rs.findColumn(column);
return true;
} catch (SQLException sqlex){
}
return false;
}
public static VppAssetDTO loadAsset(ResultSet rs) throws SQLException, UnexpectedServerErrorException { public static VppAssetDTO loadAsset(ResultSet rs) throws SQLException, UnexpectedServerErrorException {
List<VppAssetDTO> vppAssetDTOS = loadAssets(rs); List<VppAssetDTO> vppAssetDTOS = loadAssets(rs);
if (vppAssetDTOS.isEmpty()) { if (vppAssetDTOS.isEmpty()) {

@ -171,6 +171,7 @@
<Category>Video Players &amp; Editors</Category> <Category>Video Players &amp; Editors</Category>
<Category>Weather</Category> <Category>Weather</Category>
<Category>GooglePlaySyncedApp</Category> <Category>GooglePlaySyncedApp</Category>
<Category>AppleStoreSyncedApp</Category>
</AppCategories> </AppCategories>
<RatingConfig> <RatingConfig>

@ -202,6 +202,7 @@
<Category>Video Players &amp; Editors</Category> <Category>Video Players &amp; Editors</Category>
<Category>Weather</Category> <Category>Weather</Category>
<Category>GooglePlaySyncedApp</Category> <Category>GooglePlaySyncedApp</Category>
<Category>AppleStoreSyncedApp</Category>
{% if application_mgt_conf.app_categories is defined %} {% if application_mgt_conf.app_categories is defined %}
{%- for app_category in application_mgt_conf.app_categories -%} {%- for app_category in application_mgt_conf.app_categories -%}
<Category>{{app_category}}</Category> <Category>{{app_category}}</Category>

Loading…
Cancel
Save