Update user service and token retrieval

pull/168/head
osh 1 year ago
parent dae8c09761
commit 81fd5687ef

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

@ -33,6 +33,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -375,10 +376,16 @@ public class DAOUtil {
vppUserDTO.setDmUsername(rs.getString("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()); 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) { 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); vppUserDTOS.add(vppUserDTO);
} }
@ -416,10 +423,16 @@ public class DAOUtil {
vppAssetDTO.setAppId(rs.getInt("APP_ID")); vppAssetDTO.setAppId(rs.getInt("APP_ID"));
vppAssetDTO.setTenantId(rs.getInt("TENANT_ID")); vppAssetDTO.setTenantId(rs.getInt("TENANT_ID"));
if (rs.getLong("CREATED_TIME") != 0) { 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) { 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.setAdamId(rs.getString("ADAM_ID"));
vppAssetDTO.setAssignedCount(rs.getString("ASSIGNED_COUNT")); vppAssetDTO.setAssignedCount(rs.getString("ASSIGNED_COUNT"));
@ -461,10 +474,16 @@ public class DAOUtil {
vppAssociationDTO.setId(rs.getInt("ID")); vppAssociationDTO.setId(rs.getInt("ID"));
vppAssociationDTO.setAssociationType(rs.getString("ASSOCIATION_TYPE")); vppAssociationDTO.setAssociationType(rs.getString("ASSOCIATION_TYPE"));
if (rs.getLong("CREATED_TIME") != 0) { 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) { 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")); vppAssociationDTO.setPricingParam(rs.getString("PRICING_PARAMS"));
vppAssociationDTOS.add(vppAssociationDTO); vppAssociationDTOS.add(vppAssociationDTO);

Loading…
Cancel
Save