Add DAO improvements for user APIs

Fixes https://roadmap.entgra.net/issues/10169
fix-try-it-meta-info
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.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.exception.ApplicationManagementException;
@ -44,4 +45,7 @@ public interface VPPApplicationManager {
boolean addAssociation(VppAssetDTO asset, List<VppUserDTO> vppUsers) throws
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)
throws ApplicationManagementDAOException {
String sql = "UPDATE "
+ "AP_VPP_USER "
+ "SET "
+ "CLIENT_USER_ID = ?,"
+ "DM_USERNAME = ?, "
+ "TENANT_ID = ?, "
+ "EMAIL = ?, "
+ "INVITE_CODE = ?, "
+ "STATUS = ?, "
+ "LAST_UPDATED_TIME = ?, "
+ "MANAGED_ID = ?, "
+ "TEMP_PASSWORD = ? "
+ "WHERE ID = ?";
String sql = "UPDATE AP_VPP_USER SET ";
if (userDTO.getClientUserId() != null && !userDTO.getClientUserId().isEmpty()) {
sql += "CLIENT_USER_ID = ?,";
}
if (userDTO.getDmUsername() != null && !userDTO.getDmUsername().isEmpty()) {
sql += "DM_USERNAME = ?,";
}
if (userDTO.getEmail() != null && !userDTO.getEmail().isEmpty()) {
sql += "EMAIL = ?,";
}
if (userDTO.getInviteCode() != null && !userDTO.getInviteCode().isEmpty()) {
sql += "INVITE_CODE = ?,";
}
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 {
Connection conn = this.getDBConnection();
long updatedTime = System.currentTimeMillis();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, userDTO.getClientUserId());
stmt.setString(2, userDTO.getDmUsername());
stmt.setInt(3, tenantId);
stmt.setString(4, userDTO.getEmail());
stmt.setString(5, userDTO.getInviteCode());
stmt.setString(6, userDTO.getStatus());
stmt.setLong(7, updatedTime);
stmt.setString(8, userDTO.getManagedId());
stmt.setString(9, userDTO.getTmpPassword());
stmt.setInt(10, userDTO.getId());
stmt.executeUpdate();
int x = 0;
if (userDTO.getClientUserId() != null && !userDTO.getClientUserId().isEmpty()) {
stmt.setString(++x, userDTO.getClientUserId());
}
if (userDTO.getDmUsername() != null && !userDTO.getDmUsername().isEmpty()) {
stmt.setString(++x, userDTO.getDmUsername());
}
if (userDTO.getEmail() != null && !userDTO.getEmail().isEmpty()) {
stmt.setString(++x, userDTO.getEmail());
}
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) {
return userDTO;
}
@ -147,6 +174,7 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
+ "LAST_UPDATED_TIME, "
+ "MANAGED_ID, "
+ "TEMP_PASSWORD "
+ "DM_USERNAME "
+ "FROM AP_VPP_USER "
+ "WHERE DM_USERNAME = ? AND TENANT_ID = ?";
try {

@ -110,9 +110,6 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
wrapper.getUser().add(ituneUserDTO);
Gson gson = new Gson();
// Gson gson = new GsonBuilder()
// .setExclusionStrategies(new NullEmptyExclusionStrategy())
// .create();
String userPayload = gson.toJson(wrapper);
ProxyResponse proxyResponse = callVPPBackend(USER_CREATE, userPayload, TOKEN, Constants.VPP.POST);
@ -131,8 +128,12 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
log.error("userDTO " + userDTO.toString());
try {
ConnectionManagerUtil.beginDBTransaction();
if (vppApplicationDAO.addVppUser(userDTO, tenantId) != -1) {
int id = vppApplicationDAO.addVppUser(userDTO, tenantId);
if (id != -1) {
ConnectionManagerUtil.commitDBTransaction();
userDTO.setId(id);
userDTO.setTenantId(PrivilegedCarbonContext
.getThreadLocalCarbonContext().getTenantId());
return userDTO;
}
ConnectionManagerUtil.rollbackDBTransaction();
@ -507,4 +508,11 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
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 TYPE = "type";;
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 ARTWORK = "artwork";

@ -362,9 +362,18 @@ public class DAOUtil {
vppUserDTO.setTenantId(rs.getInt("TENANT_ID"));
vppUserDTO.setEmail(rs.getString("EMAIL"));
vppUserDTO.setInviteCode(rs.getString("INVITE_CODE"));
vppUserDTO.setStatus(rs.getString("STATUS"));
vppUserDTO.setManagedId(rs.getString("MANAGED_ID"));
vppUserDTO.setTmpPassword(rs.getString("TEMP_PASSWORD"));
if (columnExist(rs,"STATUS")) {
vppUserDTO.setStatus(rs.getString("STATUS"));
}
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) {
vppUserDTO.setCreatedTime(new Date(rs.getLong(("CREATED_TIME")) * 1000).toString());
}
@ -376,6 +385,16 @@ public class DAOUtil {
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 {
List<VppAssetDTO> vppAssetDTOS = loadAssets(rs);
if (vppAssetDTOS.isEmpty()) {

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

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

Loading…
Cancel
Save