Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,8 @@ public String dataSyncToServer(@RequestBody String requestOBJ,
@RequestHeader(value = "Authorization") String Authorization, HttpServletRequest request) {
OutputResponse response = new OutputResponse();

logger.info("test: vanto server auth="+Authorization);
try {
String jwtToken = CookieUtil.getJwtTokenFromCookie(request);
logger.info("test: vanto server token="+jwtToken);

String s = getDataFromVanAndSyncToDBImpl.syncDataToServer(requestOBJ, Authorization, jwtToken);
String s = getDataFromVanAndSyncToDBImpl.syncDataToServer(requestOBJ, Authorization);
if (s != null)
response.setResponse(s);
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@

import javax.sql.DataSource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

Expand All @@ -50,6 +53,8 @@ public class DataSyncRepository {
@Autowired
private SyncUtilityClassRepo syncutilityClassRepo;

private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());

private JdbcTemplate getJdbcTemplate() {
return new JdbcTemplate(dataSource);

Expand All @@ -64,7 +69,7 @@ public List<Map<String, Object>> getDataForGivenSchemaAndTable(String schema, St

if (table != null && table.equalsIgnoreCase("m_beneficiaryregidmapping")) {
baseQuery = " SELECT " + columnNames + " FROM " + schema + "." + table
+ " WHERE provisioned is true AND processed <> 'P' AND vanID is not null ";
+ " WHERE provisioned is true AND processed != 'P' AND vanID is not null ";
} else {
if (table != null && (table.equalsIgnoreCase("t_patientissue")
|| table.equalsIgnoreCase("t_physicalstockentry") || table.equalsIgnoreCase("t_stockadjustment")
Expand All @@ -75,30 +80,36 @@ public List<Map<String, Object>> getDataForGivenSchemaAndTable(String schema, St
|| table.equalsIgnoreCase("t_itemstockexit"))) {

baseQuery = " SELECT " + columnNames + " FROM " + schema + "." + table
+ " WHERE processed <> 'P' AND SyncFacilityID is not null ";
+ " WHERE processed != 'P' AND SyncFacilityID is not null ";

} else {
baseQuery = " SELECT " + columnNames + " FROM " + schema + "." + table
+ " WHERE processed <> 'P' AND vanID is not null ";
+ " WHERE processed != 'P' AND vanID is not null ";
}

}

resultSetList = jdbcTemplate.queryForList(baseQuery);
return resultSetList;
}



public int updateProcessedFlagInVan(String schemaName, String tableName, StringBuilder vanSerialNos,
String autoIncreamentColumn, String user) throws Exception {
jdbcTemplate = getJdbcTemplate();
String query = " UPDATE " + schemaName + "." + tableName
+ " SET processed = 'P' , SyncedDate = ?, Syncedby = ? WHERE " + autoIncreamentColumn
+ " IN (" + vanSerialNos + ")";
String query = "";

Timestamp syncedDate = new Timestamp(System.currentTimeMillis());
int updatedRows = jdbcTemplate.update(query, syncedDate, user);
if (tableName != null && tableName.toLowerCase().equals("i_ben_flow_outreach")) {
query = "UPDATE " + schemaName + "." + tableName
+ " SET created_date = ? , processed = 'P', SyncedDate = ?, Syncedby = ? "
+ "WHERE " + autoIncreamentColumn + " IN (" + vanSerialNos + ")";
} else {
query = "UPDATE " + schemaName + "." + tableName
+ " SET CreatedDate = ? , processed = 'P', SyncedDate = ?, Syncedby = ? "
+ "WHERE " + autoIncreamentColumn + " IN (" + vanSerialNos + ")";
}

Timestamp syncedDate = new Timestamp(System.currentTimeMillis());
int updatedRows = jdbcTemplate.update(query, syncedDate, syncedDate, user);
return updatedRows;

}
Expand All @@ -119,4 +130,4 @@ public int[] updateLatestMasterInLocal(String query, List<Object[]> syncDataList

// ---------------------------------- End of Download Repository

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,32 +243,8 @@ private void setResponseStatus(Map<String, String> groupIdStatus, int groupId, S
groupIdStatus.put("groupId", String.valueOf(groupId));
groupIdStatus.put("status", serverAcknowledgement);
responseStatus.add(groupIdStatus);
logger.info("Response from data sync: {}", responseStatus);
}

// private boolean setResponseStatus(Map<String, String> groupIdStatus, int groupId, String serverAcknowledgement,
// List<Map<String, String>> responseStatus, boolean isProgress) {
// if (serverAcknowledgement != null) {
// groupIdStatus.put("groupId", String.valueOf(groupId));
// groupIdStatus.put("status", serverAcknowledgement);
// responseStatus.add(groupIdStatus);
// logger.info("Response from data sync", responseStatus);
// } else if (isProgress) {
// groupIdStatus.put("groupId", String.valueOf(groupId));
// groupIdStatus.put("status", "pending");
// responseStatus.add(groupIdStatus);
// logger.info("Response from data sync", responseStatus);
// } else {
// isProgress = true;
// groupIdStatus.put("groupId", String.valueOf(groupId));
// groupIdStatus.put("status", "failed");
// responseStatus.add(groupIdStatus);
// logger.info("Response from data sync", responseStatus);
// }
// return isProgress;
//
// }

/**
*
* @param syncTableDetailsIDs
Expand Down Expand Up @@ -299,7 +275,6 @@ public List<SyncUtilityClass> getVanAndServerColumnList(Integer groupID) throws

private List<Map<String, Object>> getDataToSync(String schemaName, String tableName, String columnNames)
throws Exception {
logger.info("Fetching data to sync for schema: {}, table: {}, columns: {}", schemaName, tableName, columnNames);
List<Map<String, Object>> resultSetList = dataSyncRepository.getDataForGivenSchemaAndTable(schemaName,
tableName, columnNames);
if (resultSetList != null) {
Expand Down Expand Up @@ -343,14 +318,11 @@ private List<Map<String, Object>> getBatchOfAskedSizeDataToSync(List<Map<String,
public String syncDataToServer(int vanID, String schemaName, String tableName, String vanAutoIncColumnName,
String serverColumns, List<Map<String, Object>> dataToBesync, String user, String Authorization, String token)
throws Exception {
logger.debug(
"Entering syncDataToServer with vanID: {}, schemaName: '{}', tableName: '{}', vanAutoIncColumnName: '{}', serverColumns: '{}', user: '{}'",
vanID, schemaName, tableName, vanAutoIncColumnName, serverColumns, user);

RestTemplate restTemplate = new RestTemplate();


Integer facilityID = masterVanRepo.getFacilityID(vanID);
logger.debug("Fetched facilityID for vanID {}: {}", vanID, facilityID);

// serialize null
GsonBuilder gsonBuilder = new GsonBuilder();
Expand All @@ -368,33 +340,18 @@ public String syncDataToServer(int vanID, String schemaName, String tableName, S
dataMap.put("facilityID", facilityID);

String requestOBJ = gson.toJson(dataMap);

HttpEntity<Object> request = RestTemplateUtil.createRequestEntity(requestOBJ, Authorization,token);
logger.info("Before Data sync upload Url" + dataSyncUploadUrl);
HttpEntity<Object> request = RestTemplateUtil.createRequestEntity(requestOBJ, Authorization,"datasync");
ResponseEntity<String> response = restTemplate.exchange(dataSyncUploadUrl, HttpMethod.POST, request,
String.class);
logger.info("Received response from data sync URL: {}", response);
logger.info("Received response from data sync URL: {}", dataSyncUploadUrl);

logger.info("After Data sync upload Url" + dataSyncUploadUrl);
/**
* if data successfully synced then getVanSerialNo of synced data to update
* processed flag
*/

int i = 0;
if (response != null && response.hasBody()) {
JSONObject obj = new JSONObject(response.getBody());
if (obj != null && obj.has("statusCode") && obj.getInt("statusCode") == 200) {
StringBuilder vanSerialNos = getVanSerialNoListForSyncedData(vanAutoIncColumnName, dataToBesync);
logger.info(
"Updating processed flag for schemaName: {}, tableName: {}, vanSerialNos: {}, vanAutoIncColumnName: {}, user: {}",
schemaName, tableName, vanSerialNos.toString(), vanAutoIncColumnName, user);
// update table for processed flag = "P"
logger.info(schemaName + "|" + tableName + "|" + vanSerialNos.toString() + "|" + vanAutoIncColumnName
+ "|" + user);

i = dataSyncRepository.updateProcessedFlagInVan(schemaName, tableName, vanSerialNos,
vanAutoIncColumnName, user);
logger.debug("Updated processed flag in database. Records affected: {}", i);
}
}
if (i > 0)
Expand Down Expand Up @@ -435,4 +392,4 @@ public String getDataSyncGroupDetails() {
return null;
}

}
}
Loading