Update user service and token retrieval

sync^2
osh 1 year ago
parent dae8c09761
commit 81fd5687ef

@ -114,12 +114,12 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
Gson gson = new Gson();
String userPayload = gson.toJson(wrapper);
ProxyResponse proxyResponse = callVPPBackend(USER_CREATE, userPayload, TOKEN, Constants.VPP.POST);
ProxyResponse proxyResponse = callVPPBackend(USER_CREATE, userPayload, getVppToken(), Constants.VPP.POST);
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.EVENT_ID)) {
// Create user does not return any useful data. Its needed to call the backend again
ProxyResponse getUserResponse = callVPPBackend(USER_GET + Constants.VPP.CLIENT_USER_ID_PARAM +
userDTO.getClientUserId(), userPayload, TOKEN, Constants.VPP.GET);
userDTO.getClientUserId(), userPayload, getVppToken(), Constants.VPP.GET);
if ((getUserResponse.getCode() == HttpStatus.SC_OK || getUserResponse.getCode() ==
HttpStatus.SC_CREATED) && getUserResponse.getData().contains(Constants.VPP.TOTAL_PAGES)) {
VppItuneUserResponseWrapper vppItuneUserResponseWrapper = gson.fromJson
@ -196,12 +196,13 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
Gson gson = new Gson();
String userPayload = gson.toJson(wrapper);
try {
ProxyResponse proxyResponse = callVPPBackend(USER_UPDATE, userPayload, TOKEN, Constants.VPP.POST);
ProxyResponse proxyResponse = callVPPBackend(USER_UPDATE, userPayload, getVppToken(), Constants.VPP.POST);
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.EVENT_ID)) {
log.error("userDTO " + userDTO.toString());
VppUserDTO currentUserDTO = getUserByDMUsername(userDTO.getDmUsername());
if (currentUserDTO != null) {
userDTO.setId(currentUserDTO.getId());
}
try {
ConnectionManagerUtil.beginDBTransaction();
if (vppApplicationDAO.updateVppUser(userDTO, tenantId) == null) {
@ -228,6 +229,7 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
ConnectionManagerUtil.closeDBConnection();
}
}
} catch (IOException e) {
String msg = "Error while calling VPP backend to update";
log.error(msg, e);
@ -239,7 +241,7 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
public void syncUsers(String clientId) throws ApplicationManagementException {
ProxyResponse proxyResponse = null;
try {
proxyResponse = callVPPBackend(USER_GET, null, TOKEN, Constants
proxyResponse = callVPPBackend(USER_GET, null, getVppToken(), Constants
.VPP.GET);
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.TOTAL_PAGES)) {
@ -266,7 +268,7 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
if (nextPageIndex > 0) { // Not the first page
url += "?pageIndex=" + nextPageIndex;
}
proxyResponse = callVPPBackend(url, null, TOKEN, Constants.VPP.GET);
proxyResponse = callVPPBackend(url, null, getVppToken(), Constants.VPP.GET);
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.TOTAL_PAGES)) {
Gson gson = new Gson();
@ -360,7 +362,7 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
private ItuneAppDTO lookupAsset(String packageName) throws ApplicationManagementException {
String lookupURL = LOOKUP_API + packageName + LOOKUP_API_PREFIX;
try {
ProxyResponse proxyResponse = callVPPBackend(lookupURL, null, TOKEN, Constants.VPP.GET);
ProxyResponse proxyResponse = callVPPBackend(lookupURL, null, getVppToken(), Constants.VPP.GET);
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.GET_APP_DATA_RESPONSE_START)) {
String responseData = proxyResponse.getData();
@ -467,12 +469,12 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
Gson gson = new Gson();
String payload = gson.toJson(vppAssociate);
ProxyResponse proxyResponse = callVPPBackend(ASSIGNMENTS_POST, payload, TOKEN,
ProxyResponse proxyResponse = callVPPBackend(ASSIGNMENTS_POST, payload, getVppToken(),
Constants.VPP.POST);
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.EVENT_ID)) {
// Create assignment does not return any useful data. Its needed to call the backend again
ProxyResponse getAssignmentResponse = callVPPBackend(ASSIGNMENTS_GET, null, TOKEN, Constants.VPP.GET);
ProxyResponse getAssignmentResponse = callVPPBackend(ASSIGNMENTS_GET, null, getVppToken(), Constants.VPP.GET);
if ((getAssignmentResponse.getCode() == HttpStatus.SC_OK || getAssignmentResponse.getCode() ==
HttpStatus.SC_CREATED) && getAssignmentResponse.getData().contains(Constants.VPP.TOTAL_PAGES)) {
// VppAssociateResponseWrapper vppAssociateResponseWrapper = gson.fromJson

@ -33,6 +33,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
@ -375,10 +376,16 @@ public class DAOUtil {
vppUserDTO.setDmUsername(rs.getString("DM_USERNAME"));
}
if (rs.getLong("CREATED_TIME") != 0) {
vppUserDTO.setCreatedTime(new Date(rs.getLong(("CREATED_TIME")) * 1000).toString());
Date date = new Date(rs.getLong("CREATED_TIME"));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = dateFormat.format(date);
vppUserDTO.setCreatedTime(dateString);
}
if (rs.getLong("LAST_UPDATED_TIME") != 0) {
vppUserDTO.setLastUpdatedTime(new Date(rs.getLong(("LAST_UPDATED_TIME")) * 1000).toString());
Date date = new Date(rs.getLong("LAST_UPDATED_TIME"));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = dateFormat.format(date);
vppUserDTO.setLastUpdatedTime(dateString);
}
vppUserDTOS.add(vppUserDTO);
}
@ -416,10 +423,16 @@ public class DAOUtil {
vppAssetDTO.setAppId(rs.getInt("APP_ID"));
vppAssetDTO.setTenantId(rs.getInt("TENANT_ID"));
if (rs.getLong("CREATED_TIME") != 0) {
vppAssetDTO.setCreatedTime(new Date(rs.getLong(("CREATED_TIME")) * 1000).toString());
Date date = new Date(rs.getLong("CREATED_TIME"));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = dateFormat.format(date);
vppAssetDTO.setCreatedTime(dateString);
}
if (rs.getLong("LAST_UPDATED_TIME") != 0) {
vppAssetDTO.setLastUpdatedTime(new Date(rs.getLong(("LAST_UPDATED_TIME")) * 1000).toString());
Date date = new Date(rs.getLong("LAST_UPDATED_TIME"));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = dateFormat.format(date);
vppAssetDTO.setLastUpdatedTime(dateString);
}
vppAssetDTO.setAdamId(rs.getString("ADAM_ID"));
vppAssetDTO.setAssignedCount(rs.getString("ASSIGNED_COUNT"));
@ -461,10 +474,16 @@ public class DAOUtil {
vppAssociationDTO.setId(rs.getInt("ID"));
vppAssociationDTO.setAssociationType(rs.getString("ASSOCIATION_TYPE"));
if (rs.getLong("CREATED_TIME") != 0) {
vppAssociationDTO.setCreatedTime(new Date(rs.getLong(("CREATED_TIME")) * 1000).toString());
Date date = new Date(rs.getLong("CREATED_TIME"));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = dateFormat.format(date);
vppAssociationDTO.setCreatedTime(dateString);
}
if (rs.getLong("LAST_UPDATED_TIME") != 0) {
vppAssociationDTO.setLastUpdatedTime(new Date(rs.getLong(("LAST_UPDATED_TIME")) * 1000).toString());
Date date = new Date(rs.getLong("LAST_UPDATED_TIME"));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = dateFormat.format(date);
vppAssociationDTO.setLastUpdatedTime(dateString);
}
vppAssociationDTO.setPricingParam(rs.getString("PRICING_PARAMS"));
vppAssociationDTOS.add(vppAssociationDTO);

Loading…
Cancel
Save