In my TypeScript code, I am making a call to an API method in a Java class that returns a list of maps.
The TypeScript file includes the code snippet below. When attempting to retrieve data from dataBody
, it displays as [Object Object]. I need assistance with modifying the TypeScript code to properly extract the dataset from the Java class.
*public populatePeople(hyperfindId: number) {
this.getGridInstance()
//this.peopleList= [];
this.personIds = [];
this.personNameById = new Map<string, string>();
this.pokerEntryService.getPeopleByHyperfind(hyperfindId, this.tbSite, this.tbDivision, this.tbDepartment).subscribe((data)=>{
let dataBody = JSON.parse(JSON.stringify(data.body));
//Need to retrieve data here.
if(dataBody.maxExceeded === true){
this.showError = true;
this.alertService.createAlert('WARNING', this.edapLocaleConvertor.convertLocaleMessage('peopleEditor.maxPeopleExceeded'));
}
},
err => {
this.showErrorMessage(err);
});
}**
Java class:
public List<Map<String,String>> getPeople(Long hyperfindId, String site, String division, String
department, LocalDate startDate, LocalDate endDate, String tenantId, String transactionId) {
Map<String, String> headersMap = new HashMap<String, String>();
headersMap.put("Authorization", edapRequestContextService.getAccessToken());
headersMap.put("appKey", GamingPropertiesLoader.getTenantPropertyValue(tenantId,PropertyConstants.APP_KEY, transactionId));
headersMap.put("Content-Type", EdapConstants.CONTENT_TYPE_JSON);
//String buildPrimaryOrg = "/Organization/"+site+"/"+division+"/"+department;
String buildPrimaryOrg = "Organization/United States/Metropolitan Plant/Shipping";
String debugMsg = "buildPrimaryOrg...." + buildPrimaryOrg;
logger.error(TenantContext.getTenantId(), debugMsg, Constants.TOKE_POOL, transactionId);
String requestBody = "{"
+ "\"select\": "
+ "["
+ "{\"alias\": \"PersonId\",\"key\": \"PEOPLE_PERSON_ID\"},"
+ "{\"alias\": \"PersonNum\",\"key\": \"PEOPLE_PERSON_NUMBER\"},"
+ "{\"alias\": \"CoreOrgJob\",\"key\": \"EMP_COMMON_PRIMARY_ORG\"},"
+ "{\"alias\&\quot;primary job\",\"key\": \"EMP_COMMON_PRIMARY_JOB\"}"
+ "],"
+ "\"where\": "
+ "[{\"key\": \"EMP_COMMON_PRIMARY_ORG\",\"alias\": \"CoreOrgJob\","
+ "\"operator\": \"IN\","
+ "\"values\" : [\""+buildPrimaryOrg+ "\"}],"
+ "\"from\": {"
+ "\"view\": \"EMP\","
+ "\"employeeSet\": {"
+ "\"dateRange\": "
+ "{"
+ "\"symbolicPeriod\": {\"id\": \"1\"}"
+ "},"
+ "\"hyperfind\": "
+ "{"
+ "\"id\": \"2\""
+ "}"
+ "}"
+ "}"
+ "}";
ResponseEntity<?> response = gamingRestService
.doPost(tenantId, GamingPropertiesLoader.getTenantPropertyValue(tenantId, PropertyConstants.WFD_API_HOST, transactionId)
+ Constants.PERSON_MULTI_READ_COMMONS_URI, headersMap, requestBody, String.class, GamingPropertyConstants.REST_GET_PEOPLE_BY_HYPERFIND_ID, transactionId);
List<Map<String,String>> peopleList = new ArrayList<>();
JSONObject json = new JSONObject(response.getBody().toString());
json = json.getJSONObject("data");
JSONArray jsonArray = json.getJSONArray("children");
for(int i=0; i<jsonArray.length(); i++) {
JSONObject attributesData = jsonArray.getJSONObject(i);
JSONArray attributesArray = attributesData.getJSONArray("attributes");
Map<String,String> m1 = new HashMap<String,String>();
for(int j=0; j<attributesArray.length(); j++) {
JSONObject pData = attributesArray.getJSONObject(j);
debugMsg = "personData:...." + pData.getString("value");
logger.error(TenantContext.getTenantId(), debugMsg, Constants.TOKE_POOL,
transactionId);
m1.put(pData.getString("key"), pData.getString("value"));
peopleList.add(m1);
}
}
debugMsg = "peopleList size:...." + peopleList.size();
logger.error(TenantContext.getTenantId(), debugMsg, Constants.TOKE_POOL, transactionId);
return peopleList;
}