PageRenderTime 86ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/MercerPoC/src/in/lnt/validations/FormValidator.java

https://bitbucket.org/jwala/mercer_api_local
Java | 2512 lines | 1978 code | 263 blank | 271 comment | 675 complexity | a168ad3c8668fa6947a214598daffffa MD5 | raw file
  1. package in.lnt.validations;
  2. import java.io.ByteArrayInputStream;
  3. import java.io.IOException;
  4. import java.io.UnsupportedEncodingException;
  5. import java.sql.SQLException;
  6. import java.text.SimpleDateFormat;
  7. import java.util.ArrayList;
  8. import java.util.Calendar;
  9. import java.util.Date;
  10. import java.util.HashMap;
  11. import java.util.HashSet;
  12. import java.util.Iterator;
  13. import java.util.LinkedHashMap;
  14. import java.util.List;
  15. import java.util.Map;
  16. import java.util.Map.Entry;
  17. import java.util.Set;
  18. import java.util.UUID;
  19. import java.util.regex.Matcher;
  20. import java.util.regex.Pattern;
  21. import org.apache.commons.lang3.EnumUtils;
  22. import org.apache.commons.lang3.StringUtils;
  23. import org.json.JSONArray;
  24. import org.json.JSONException;
  25. import org.json.JSONObject;
  26. import org.slf4j.Logger;
  27. import org.slf4j.LoggerFactory;
  28. import com.fasterxml.jackson.core.JsonParseException;
  29. import com.fasterxml.jackson.core.JsonProcessingException;
  30. import com.fasterxml.jackson.databind.JsonMappingException;
  31. import com.fasterxml.jackson.databind.JsonNode;
  32. import com.fasterxml.jackson.databind.ObjectMapper;
  33. import com.fasterxml.jackson.databind.node.ArrayNode;
  34. import com.fasterxml.jackson.databind.node.JsonNodeFactory;
  35. import com.fasterxml.jackson.databind.node.JsonNodeType;
  36. import com.fasterxml.jackson.databind.node.NullNode;
  37. import com.fasterxml.jackson.databind.node.ObjectNode;
  38. import com.lti.mosaic.function.def.InversionAndRangeCheckFunctions;
  39. import com.lti.mosaic.parser.driver.ExpressionEvalutionDriver;
  40. import com.lti.mosaic.parser.utils.ExpressionBuilderConstants;
  41. import in.lnt.constants.Constants;
  42. import in.lnt.enums.ValidationTypes;
  43. import in.lnt.exceptions.CustomStatusException;
  44. import in.lnt.ml.MachineLearningRestClient;
  45. import in.lnt.parser.CSVParser;
  46. import in.lnt.service.db.DBUtils;
  47. import in.lnt.utility.constants.CacheConstats;
  48. import in.lnt.utility.constants.ErrorCacheConstant;
  49. import in.lnt.utility.general.Cache;
  50. import in.lnt.utility.general.DataUtility;
  51. import in.lnt.utility.general.JsonUtils;
  52. import in.lnt.validations.evaluator.APIExpressionEvaluator;
  53. import in.lti.mosaic.api.mongo.MongoObject;
  54. import in.lti.mosaic.api.mongo.MongoThread;
  55. public class FormValidator {
  56. private static final Logger logger = LoggerFactory.getLogger(FormValidator.class);
  57. static ObjectMapper mapper = new ObjectMapper();
  58. ArrayList<String> paramValueList=null;
  59. static Pattern VALID_EMAIL_ADDRESS_REGEX =
  60. Pattern.compile("^(.+)@(.+)$", Pattern.CASE_INSENSITIVE);
  61. static Pattern VALID_PHONE_NUMBER_REGEX =
  62. Pattern.compile("^(\\(?\\+?[0-9]*\\)?)?[0-9_\\- \\(\\)]*$", Pattern.CASE_INSENSITIVE);
  63. // ^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$
  64. private static String MONGODB_ARCHIVE_FLAG = Cache
  65. .getMLProperty(in.lnt.utility.constants.CacheConstats.MONGODUMP_FLAG);
  66. public JsonNode parseAndValidate(String entitiesJson, String csvJsonString, boolean isAggregateRequest,
  67. Map<String, String> xslJsonMap, String firstSheetName, boolean isMultiPartRequest) throws Exception {
  68. JsonNode resultNode = null;
  69. //Generating UUID for a Request and Response
  70. final String uuid = UUID.randomUUID().toString().replace("-", "");
  71. JsonNode entitiesNodeResponse = preparingL1Input(entitiesJson, csvJsonString, isAggregateRequest, xslJsonMap,
  72. firstSheetName, isMultiPartRequest, null);
  73. //Adding Request into MongoDB
  74. dumpToMongo(uuid, mapper.writeValueAsString(entitiesNodeResponse), Constants.REQUEST);
  75. if (isAggregateRequest) {
  76. resultNode = performValidateAggregateRequest(entitiesNodeResponse, isAggregateRequest, isMultiPartRequest);
  77. } else
  78. resultNode = perform_L1_L2Validations(entitiesNodeResponse, isAggregateRequest, isMultiPartRequest);
  79. //Adding Response into MongoDB
  80. dumpToMongo(uuid, mapper.writeValueAsString(resultNode), Constants.RESPONSE);
  81. return resultNode;
  82. }
  83. /**
  84. * @param uuid
  85. * @param data
  86. * @throws JsonProcessingException
  87. * @author Vivek Kasadwar
  88. */
  89. public static void dumpToMongo(final String uuid, String data,String type){
  90. if (StringUtils.equals(MONGODB_ARCHIVE_FLAG,Constants.YES)) {
  91. MongoObject mongoObject = new MongoObject();
  92. mongoObject.setRequestId(uuid);
  93. mongoObject.setObjectType(type);
  94. mongoObject.setObjectJson(data);
  95. mongoObject.setTimeStamp(Calendar.getInstance().getTime());
  96. MongoThread.addToQueue(mongoObject);
  97. }
  98. }
  99. public HashMap<String, JsonNode> parseJsonObjectMap(String key, JsonNode value, HashMap<String, JsonNode> map,
  100. String datakey, JsonNode columnListJson,List<String> otherAndContextKeys) throws Exception { // PE-7056
  101. Iterator<Map.Entry<String, JsonNode>> it = value.fields();
  102. Map.Entry<String, JsonNode> entry = null;
  103. try {
  104. while (it.hasNext()) {
  105. entry = it.next();
  106. if (entry.getValue().getNodeType() != JsonNodeType.OBJECT) {
  107. if (datakey != null) {
  108. map.put((datakey + "." + key + "." + entry.getKey()).trim(), entry.getValue());
  109. if(otherAndContextKeys!=null)
  110. otherAndContextKeys.add((datakey + "." + key + "." + entry.getKey()).trim());
  111. } else {
  112. map.put((key + "." + entry.getKey()).trim(), entry.getValue());
  113. if(otherAndContextKeys!=null)
  114. otherAndContextKeys.add((key + "." + entry.getKey()).trim());
  115. }
  116. } else {
  117. parseJsonObjectMap(key + "." + entry.getKey(), entry.getValue(), map, datakey, columnListJson,otherAndContextKeys);
  118. }
  119. }
  120. } finally {
  121. it=null;
  122. if(null!=entry) entry=null;
  123. }
  124. return map;
  125. }
  126. public JsonNode validate(HashMap<String, JsonNode> dataMap, ArrayList<JsonNode> columnNodeList, JsonNode dataNode,
  127. APIExpressionEvaluator apiExpressionEvaluator, boolean isAggregateRequest,
  128. HashMap<String, String> columnMappingMap,HashMap<String, JsonNode> dimMap, List<String> metaDataColumnsOnly,
  129. boolean mlAutoCoorect) throws Exception {
  130. logger.debug("validate >> ExpressionEvaluatorDriver Cache : {}",
  131. apiExpressionEvaluator.getExpressionEvaluatorDriver().getAggregateFunctionCache());
  132. JsonNode validationNode = null;
  133. ObjectNode obj = null;
  134. ArrayList<ObjectNode> predefinedObjList = null;
  135. List<ObjectNode> rangeOrSeqObjList = null;
  136. String code = null;
  137. String mappedColumnName = null;
  138. ArrayNode arr = null;
  139. JsonNode nodeDTObject = null;
  140. JsonNode dnCodeObject = null;
  141. Boolean flag = null;
  142. String result = null;
  143. String skip = null;
  144. JsonNode validationObjNode = null;
  145. ObjectNode jobInversionObjNode = null;
  146. ArrayNode jobInversionArr = null;
  147. // PE-5643 by default true because for true type do not fire validations.
  148. boolean isOptionType = true;
  149. String countryCode = null;
  150. String __COMPENSATION = null;
  151. String jobInvParameter = null;
  152. // PE-5691
  153. boolean isEmtpyRecord = false;
  154. // PE - 7257
  155. ArrayNode datePatternArray = null;
  156. ArrayNode numberPatternArray = null;
  157. String columnName = null;
  158. JsonNode tempOriginalValue = null;
  159. // 8421 code changes.
  160. Map<String, String> incorrectDataType = new HashMap<>();
  161. JsonNode questionType = null; // Added for 8916 Remove %
  162. String dataType = null;
  163. if (columnNodeList != null && !columnNodeList.isEmpty()) {
  164. arr = mapper.createArrayNode();
  165. if (!JsonUtils.isNullOrBlankOrNullNode(dataMap.get(Constants.CONTEXTDATAKEY+Constants.CONTEXTDATA_DATEFORMAT))){
  166. datePatternArray = (ArrayNode)dataMap.get(Constants.CONTEXTDATAKEY+Constants.CONTEXTDATA_DATEFORMAT);
  167. }
  168. if (!JsonUtils.isNullOrBlankOrNullNode(dataMap.get(Constants.CONTEXTDATAKEY+Constants.CONTEXTDATA_NUMBERFORMAT))){
  169. numberPatternArray = (ArrayNode)dataMap.get(Constants.CONTEXTDATAKEY+Constants.CONTEXTDATA_NUMBERFORMAT);
  170. }
  171. // If request is AggregateRequest
  172. // L3A - Inversion/Aggregate Request Starts Here
  173. if (isAggregateRequest) {
  174. // PE - 7257
  175. for (JsonNode node : columnNodeList) {
  176. if (node.get(Constants.VALIDATIONS) != null && node.get(Constants.VALIDATIONS).size() > 0) {
  177. for (int i = 0; i < node.get(Constants.VALIDATIONS).size(); i++) {
  178. validationNode = node.get(Constants.VALIDATIONS).get(i);
  179. // For Inversion
  180. obj = apiExpressionEvaluator.expressionEvaluator(dataMap, validationNode, node,
  181. dataNode,isAggregateRequest, columnMappingMap, columnNodeList, metaDataColumnsOnly);
  182. if (obj != null) {
  183. arr.add(obj);
  184. obj = null;
  185. }
  186. }
  187. }
  188. }
  189. // PE-4843 Append JobInversion Object
  190. InversionAndRangeCheckFunctions invAndRangeChkFuncObj
  191. = new InversionAndRangeCheckFunctions(CSVParser.dataForAggregation, apiExpressionEvaluator.getExpressionEvaluatorDriver().getOtherData());
  192. Map<String, Object> requestMap = invAndRangeChkFuncObj.jobInversion(); // Changed by Nikhil
  193. if (requestMap.containsKey(ExpressionBuilderConstants.CONST_INVERSION_JSON_ARRAY)
  194. && null != requestMap.get(ExpressionBuilderConstants.CONST_INVERSION_JSON_ARRAY)) {
  195. jobInversionArr = (ArrayNode) mapper.readTree(
  196. requestMap.get(ExpressionBuilderConstants.CONST_INVERSION_JSON_ARRAY).toString());
  197. }
  198. if(requestMap.containsKey(ExpressionBuilderConstants.CONST_COUNTRYCODE)
  199. && null!=requestMap.get(ExpressionBuilderConstants.CONST_COUNTRYCODE)) {
  200. countryCode = requestMap.get(ExpressionBuilderConstants.CONST_COUNTRYCODE).toString();
  201. }
  202. logger.info("Creating JobInversion object...");
  203. jobInversionObjNode = mapper.createObjectNode();
  204. if(requestMap.containsKey(ExpressionBuilderConstants.CONST_COMPENSATION)
  205. && null!=requestMap.get(ExpressionBuilderConstants.CONST_COMPENSATION)) {
  206. __COMPENSATION = requestMap.get(ExpressionBuilderConstants.CONST_COMPENSATION).toString();
  207. if(__COMPENSATION.equals(ExpressionBuilderConstants.SALARY_TYPE_TOTAL_GUARANTEED_CASH)) {
  208. __COMPENSATION = ExpressionBuilderConstants.COL_TOTAL_GUARANTEED_CASH;
  209. jobInvParameter = ExpressionBuilderConstants.SALARY_TYPE_MSG_TOTAL_GUARANTEED_CASH;
  210. //PE-8454
  211. jobInversionObjNode.put(Constants.MESSAGE_KEY, Constants.JOB_INVERSION_ERROR_TOTAL_CASH);
  212. } else {
  213. __COMPENSATION = ExpressionBuilderConstants.COL_ANNUAL_BASE;
  214. jobInvParameter = ExpressionBuilderConstants.SALARY_TYPE_MSG_REGULAR;
  215. //PE-8454
  216. jobInversionObjNode.put(Constants.MESSAGE_KEY, Constants.JOB_INVERSION_ERROR_BASE_SALARY);
  217. }
  218. }
  219. jobInversionObjNode.put(Constants.ERROR_GROUP, Constants.PERSONAL);
  220. jobInversionObjNode.put(Constants.ERROR_TYPE, Constants.ERROR);
  221. jobInversionObjNode.put(Constants.VALIDATION_TYPE, Constants.EXPRESSION);
  222. jobInversionObjNode.put(Constants.FIELD, __COMPENSATION);
  223. jobInversionObjNode.put(Constants.CATEGORY, Constants.JOB_INVERSION);
  224. jobInversionObjNode.put(Constants.PARAMETER, jobInvParameter);
  225. jobInversionObjNode.putArray(Constants.DATA).addAll(jobInversionArr);
  226. arr.add(jobInversionObjNode);
  227. return mapper.convertValue(arr, JsonNode.class);
  228. }
  229. // L3A - Inversion/Aggregate Request Ends Here
  230. for (JsonNode node : columnNodeList) {
  231. JsonNode currentDataMapCol = null;
  232. isEmtpyRecord=false;
  233. if (node.get(Constants.CODE) != null)
  234. code = node.get(Constants.CODE).asText();
  235. if (node.get(Constants.SKIP) != null)
  236. skip = node.get(Constants.SKIP).asText();
  237. if (node.get(Constants.MAPPED_COLUMN_NAME) != null)
  238. mappedColumnName = node.get(Constants.MAPPED_COLUMN_NAME).asText();
  239. if ( dataNode != null || (dataNode!=null && dataNode.get(mappedColumnName) != null)) {
  240. //Following code written for Mercer JIRA Story PE-5691
  241. if(skip==null ) {
  242. if(code !=null && mappedColumnName!=null && JsonUtils.isNullOrBlankOrNullNode(dataNode.get(code))
  243. && JsonUtils.isNullOrBlankOrNullNode(dataNode.get(mappedColumnName)))
  244. {
  245. isEmtpyRecord = true;
  246. }
  247. if(code !=null && mappedColumnName ==null && JsonUtils.isNullOrBlankOrNullNode(dataNode.get(code)) )
  248. {
  249. isEmtpyRecord = true;
  250. }
  251. if(mappedColumnName !=null && code==null &&JsonUtils.isNullOrBlankOrNullNode(dataNode.get(mappedColumnName)))
  252. {
  253. isEmtpyRecord = true;
  254. }
  255. if(isEmtpyRecord)
  256. {
  257. ((ObjectNode)dataNode).set(code, JsonNodeFactory.instance.nullNode()) ;
  258. }
  259. }
  260. //PE-5691 End.
  261. flag = false;
  262. if ((mappedColumnName != null && dataNode.get(mappedColumnName) != null)
  263. && (null != code && mappedColumnName != null && !code.equals(mappedColumnName))) {
  264. // Changing logic
  265. ((ObjectNode) (dataNode)).set(code, dataMap.get(mappedColumnName));
  266. ((ObjectNode) (dataNode)).remove(mappedColumnName);
  267. }
  268. if (skip != null && (skip.equals("true") || Boolean.parseBoolean(skip) == true)) {
  269. if (code != null && !code.equals(""))
  270. ((ObjectNode) (dataNode)).remove(code);
  271. else
  272. ((ObjectNode) (dataNode)).remove(mappedColumnName);
  273. skip = null;
  274. continue;
  275. }
  276. // Validate the data type object block starts here.
  277. if(null != node.get(Constants.DATA_TYPE)){
  278. dataType = node.get(Constants.DATA_TYPE).asText();
  279. }
  280. if (dataType != null) {
  281. logger.info("Check if dataType is not empty");
  282. nodeDTObject = node.get(Constants.DATA_TYPE);
  283. if (dataNode.get(code) != null)
  284. dnCodeObject = dataNode.get(code);
  285. else if (dataNode.get(mappedColumnName) != null)
  286. dnCodeObject = dataNode.get(mappedColumnName);
  287. validationObjNode = node.get(Constants.VALIDATIONS);
  288. if ( StringUtils.isEmpty(mappedColumnName)) {
  289. columnName = code;
  290. }else {
  291. columnName = mappedColumnName;
  292. }
  293. if(null != dataMap && !JsonUtils.isNullOrBlankOrNullNode(dataMap.get(columnName))){
  294. currentDataMapCol = dataMap.get(columnName);
  295. }
  296. //Added for 8916 Remove %
  297. questionType = node.get(Constants.QUESTION_TYPE);
  298. if(null != currentDataMapCol && dataNode.get(columnName) != null
  299. && !JsonUtils.isNullOrBlankOrNullNode(questionType) && questionType.asText().equals(Constants.PERCENTAGE) ){
  300. String percentageValue = currentDataMapCol.asText().trim();
  301. if(!percentageValue.isEmpty() && percentageValue.endsWith("%")){
  302. percentageValue = percentageValue.substring(0, percentageValue.length()-1);
  303. dataMap.put(columnName,
  304. mapper.readValue(mapper.writeValueAsString(percentageValue),JsonNode.class));
  305. ((ObjectNode) dataNode).put(code, percentageValue);
  306. dnCodeObject = dataNode.get(columnName);
  307. }
  308. }
  309. // If data node is not empty then do data type validation
  310. if (!isAggregateRequest && !JsonUtils.isNullOrBlankOrNullNode(dnCodeObject)
  311. && !isEmtpyRecord && !StringUtils.isEmpty(dnCodeObject.asText().trim())) { //PE-9268
  312. //8421 code changes.
  313. incorrectDataType = dataTypeCheck(dataMap, dataNode, columnName, nodeDTObject, dnCodeObject, flag,
  314. datePatternArray, numberPatternArray);
  315. flag = Boolean.parseBoolean(incorrectDataType.get("dataTypeFlag"));
  316. } else {
  317. flag = true;
  318. }
  319. } else { // if data node is empty then skip data type validations.
  320. flag = true;
  321. }
  322. //PE -5216 and PE-5643 Check for drop down options exist in metadata or in database.
  323. // PE-5643 : Required this functionality at /uploadMulttipleFile also. (Mentioned by Alex)
  324. if (questionType != null
  325. && ( questionType.asText().equals(Constants.DROPDOWN) ||
  326. questionType.asText().equals(Constants.RADIO_BUTTONS) )) {
  327. // PE-8070 Clear & Prepare outputJson for dimensions
  328. if( !JsonUtils.isNullOrBlankOrNullNode(dataNode.get(code))
  329. && dataNode.get(code).getNodeType()==JsonNodeType.OBJECT) {
  330. Iterator<String> iter = dataNode.get(code).fieldNames();
  331. String dimensionKey = null;
  332. while(null!=iter && iter.hasNext() ) {
  333. dimensionKey = iter.next();
  334. isOptionType = FormValidator_CSC.checkAnswerExists(node, dataNode.get(code).get(dimensionKey));
  335. if ( ! isOptionType ) {
  336. // PE-8397
  337. // // Implementation start PE : 5643
  338. // // Clear the value anyways if checkAnswerExists==false
  339. //
  340. // // Implementation end PE : 5643
  341. // Generate error for dimension in format : Question1.Dimension1
  342. obj = APIExpressionEvaluator.prepareOutputJson(null, null, null, ValidationTypes.DROPDOWN,
  343. code+"."+dimensionKey, null, null,node.has(Constants.DISPLAYLABEL) ? node.get(Constants.DISPLAYLABEL).asText() : null);
  344. }
  345. if (obj != null) {
  346. arr.add(obj);
  347. obj = null;
  348. }
  349. }
  350. // Clear & Prepare outputJson for non-dimensional questions (i.e. simple values)
  351. } else {
  352. // PE-6524 ML Integration works start
  353. if(mlAutoCoorect )
  354. {
  355. isOptionType = FormValidator_CSC.checkAnswerExists(node, dataMap.get(code));
  356. }
  357. else
  358. {
  359. isOptionType = FormValidator_CSC.checkAnswerExists(node, dataNode.get(code));
  360. }
  361. // PE-6524 ML Integration works end
  362. if ( ! isOptionType ) {
  363. obj = APIExpressionEvaluator.prepareOutputJson(null, null, null, ValidationTypes.DROPDOWN,
  364. code, null, null,JsonUtils.isNullOrBlankOrNullNode(node.get(Constants.DISPLAYLABEL))? "":node.get(Constants.DISPLAYLABEL).asText() );
  365. }
  366. if (obj != null) {
  367. arr.add(obj);
  368. obj = null;
  369. }
  370. // PE-6254 ML Integration works end
  371. }
  372. }
  373. //PE-9490 Round off upto 2 precison places for money question type
  374. if(!JsonUtils.isNullOrBlankOrNullNode(questionType) && questionType.asText().equals(Constants.MONEY) && flag
  375. && null != dataMap && !JsonUtils.isNullOrBlankOrNullNode(currentDataMapCol) && dataNode.get(columnName) != null) {
  376. String colStringVal = currentDataMapCol.asText().trim();
  377. double colDoubleVal = currentDataMapCol.asDouble();
  378. if(colStringVal.contains(".")) {
  379. //RoundOff the value and return error object if it has more than 2 precison places
  380. obj = DataUtility.roundOffMoneyQuestionType(dataMap, dataNode, obj, code, dataType, colStringVal, colDoubleVal);
  381. }
  382. }
  383. tempOriginalValue = dataNode.get(code);
  384. if(mlAutoCoorect && !isAggregateRequest)
  385. {
  386. if(!JsonUtils.isNullOrBlankOrNullNode(dataNode.get(code+Constants.UNDERSCORE_ACFLAG)) && dataNode.get(code+Constants.UNDERSCORE_ACFLAG).asText().equalsIgnoreCase("R"))
  387. {
  388. arr.add(prepareMLAutocorrectObject(code,"validationType",tempOriginalValue));
  389. if( !JsonUtils.isNullOrBlankOrNullNode(dataMap.get(code)) ) { // Handled NullPointerExc
  390. ((ObjectNode) (dataNode)).put(code,dataMap.get(code).asText());
  391. } else {
  392. ((ObjectNode) (dataNode)).putNull(code);
  393. }
  394. }
  395. }
  396. if (node.get(Constants.VALIDATIONS) != null && node.get(Constants.VALIDATIONS).size() > 0
  397. && flag) { // Aggregate
  398. for (int i = 0; i < node.get(Constants.VALIDATIONS).size(); i++) {
  399. validationNode = node.get(Constants.VALIDATIONS).get(i);
  400. if (validationNode.get(Constants.VALIDATION_TYPE) != null
  401. && EnumUtils.isValidEnum(ValidationTypes.class,
  402. validationNode.get(Constants.VALIDATION_TYPE).asText().toUpperCase() )) {
  403. switch (ValidationTypes.valueOf(validationNode.get(Constants.VALIDATION_TYPE).asText().toUpperCase())) {
  404. case REQUIRED:
  405. // PE - 7241
  406. predefinedObjList = validatePredefinedValidation(dataNode,node,validationNode,dataMap,mappedColumnName,Constants.REQUIRED);
  407. break;
  408. case ONEOF:
  409. obj = apiExpressionEvaluator.checkValidationTypeOneOf(dataMap, code, node,
  410. validationNode, mappedColumnName);
  411. break;
  412. case RANGE:
  413. rangeOrSeqObjList = apiExpressionEvaluator.prepareRangeObject(dataMap, validationNode, node,
  414. dataNode);
  415. break;
  416. case RANGEVALIDATIONREFTABLE:
  417. rangeOrSeqObjList = apiExpressionEvaluator.prepareRefernceRangeObject(dataMap, validationNode,
  418. node, dataNode);
  419. break;
  420. case ELIGIBILITY:
  421. // Last Parameter is weather request of MDA
  422. arr.addAll(apiExpressionEvaluator.checkValidity(dataMap, validationNode, node,
  423. dataNode,false,metaDataColumnsOnly));
  424. break;
  425. case PHONE:
  426. // PE - 7241
  427. predefinedObjList = validatePredefinedValidation(dataNode,node,validationNode,null,mappedColumnName,Constants.PHONE);
  428. break;
  429. case EMAIL:
  430. // PE - 7241
  431. predefinedObjList = validatePredefinedValidation(dataNode,node,validationNode,null,mappedColumnName,Constants.EMAIL);
  432. break;
  433. case EXPRESSION:
  434. obj = apiExpressionEvaluator.expressionEvaluator(dataMap, validationNode, node, dataNode,
  435. isAggregateRequest, columnMappingMap, columnNodeList, metaDataColumnsOnly);
  436. break;
  437. /**
  438. * @author Akhileshwar
  439. * PE-7045
  440. **/
  441. case SEQUENTIALCHECK://PE-7989 metaDataColumnsOnly added in method signature
  442. rangeOrSeqObjList = apiExpressionEvaluator.performSequentialCheck(dataMap, validationNode, node,
  443. dataNode, dimMap,apiExpressionEvaluator.getColumnDataTypeMapping(), true, metaDataColumnsOnly);
  444. break;
  445. default:
  446. }
  447. }else {
  448. result = Constants.MANDATORY_VALIDATIONTYPE;
  449. obj = APIExpressionEvaluator.prepareOutputJson(null, null, result, null, null, null,
  450. null, null);
  451. }
  452. if (obj != null) {
  453. arr.add(obj);
  454. obj = null;
  455. }
  456. if(rangeOrSeqObjList!=null)
  457. {
  458. for(int j=0;j<rangeOrSeqObjList.size();j++)
  459. {
  460. arr.add(rangeOrSeqObjList.get(j));
  461. }
  462. rangeOrSeqObjList=null;
  463. }
  464. if((null != predefinedObjList) && (predefinedObjList.size() > 0)){
  465. arr.addAll(predefinedObjList);
  466. predefinedObjList = null;
  467. }
  468. }
  469. } else if (!isAggregateRequest && flag == false) {
  470. logger.info("{}","Check if flag is false");
  471. //8421 code changes.
  472. if(null != dataType && !incorrectDataType.containsKey(dataType)){
  473. if(Constants.INT.equals(dataType)){
  474. result = Cache.getPropertyFromError(ErrorCacheConstant.ERR_061);
  475. }else if(Constants.DOUBLE.equals(dataType)){
  476. result = Cache.getPropertyFromError(ErrorCacheConstant.ERR_062);
  477. }else if(Constants.DATE.equals(dataType)){
  478. result = Cache.getPropertyFromError(ErrorCacheConstant.ERR_063);
  479. }else{
  480. result = Cache.getPropertyFromError(ErrorCacheConstant.ERR_043);
  481. }
  482. }
  483. if (null != nodeDTObject && null != dnCodeObject) {
  484. obj = APIExpressionEvaluator.prepareOutputJson(validationObjNode, node, result,
  485. ValidationTypes.DATATYPEERROR, dnCodeObject.asText(), nodeDTObject.asText(),
  486. nodeDTObject.asText(), null);
  487. }
  488. if (obj != null) {
  489. arr.add(obj);
  490. obj = null;
  491. }
  492. }
  493. // PE-6874 : Fixed by shifting this code down here
  494. //Following code written for Mercer JIRA Story PE-5691
  495. // If data node code value is not present then set to Blank and Data map also.
  496. // PE-7071 : Remove CODE if there is no validation OR validation_errorType != "AUTOCORRECT"
  497. if(isEmtpyRecord &&
  498. (validationNode==null ||
  499. (null!=validationNode && !JsonUtils.isNullOrBlankOrNullNode(validationNode.get(Constants.ERROR_TYPE))
  500. && !(validationNode.get(Constants.ERROR_TYPE).asText()).equalsIgnoreCase("AUTOCORRECT")))) {
  501. ((ObjectNode)dataNode).remove(code);
  502. }
  503. //PE-5691 End.
  504. // PE : 2449 to create auto-correct object for missing EEID
  505. if ((code!=null &&code.equalsIgnoreCase(Constants.EMPLOYEE_EEID)) ||
  506. (mappedColumnName !=null && mappedColumnName.equalsIgnoreCase(Constants.EMPLOYEE_EEID)))
  507. obj = prepareEeidAutoCorrectObject(code, dataMap, dataNode,columnMappingMap);
  508. if (obj != null) {
  509. arr.add(obj);
  510. obj = null;
  511. }
  512. if (node.get("questionType") != null
  513. && node.get("questionType").asText().equals("checkboxes")) {
  514. buildCheckboxArray(dataNode,code, mappedColumnName);
  515. }
  516. }
  517. code = null;
  518. validationNode = null;
  519. }
  520. // PE-6254 ML Integration work
  521. if(mlAutoCoorect && !isAggregateRequest)
  522. {
  523. removeDataNodeACFields(dataNode);
  524. }
  525. if ((arr != null && arr.size() > 0)) {
  526. if (!isAggregateRequest) {
  527. /*
  528. * if(dataNode.get(k).get(code)!=null) ((ObjectNode)
  529. * (dataNode.get(k))).set(code, dataNode.get(k).get(code));
  530. */
  531. ((ObjectNode) (dataNode)).set(Constants.VALIDATION_ERRORS, arr);
  532. arr = null;
  533. } else { // Aggregate
  534. JsonNode objectNode = mapper.convertValue(arr, JsonNode.class);
  535. return objectNode;
  536. }
  537. }
  538. }
  539. return dataNode;
  540. }
  541. /**
  542. * @param dataNode
  543. * @param mappedColumnName
  544. * @param nodeDTObject
  545. * @param dnCodeObject
  546. * @param flag
  547. * @param datePatternArray
  548. * @param numberPatternArray
  549. * @return
  550. */
  551. protected Map<String,String> dataTypeCheck(HashMap<String, JsonNode> dataMap, JsonNode dataNode, String mappedColumnName, JsonNode nodeDTObject,
  552. JsonNode dnCodeObject, Boolean flag, ArrayNode datePatternArray, ArrayNode numberPatternArray) {
  553. String dnObjetText;
  554. Map<String,String> incorrectDataTypeMap = new HashMap<>();
  555. boolean isNullNode = NullNode.class.equals(dnCodeObject.getClass());
  556. if (!isNullNode) {
  557. dnObjetText = dnCodeObject.asText();
  558. }else {
  559. dnObjetText = null;
  560. }
  561. boolean dataTypeFlag = flag;
  562. String incorrectintegerDataType = "";
  563. boolean isDateArray = false;
  564. boolean isNumberArray = false;
  565. // 7257 For Multi-part request check following arrays
  566. if ( null != datePatternArray && datePatternArray.size() > 0 ) {
  567. isDateArray = true ;
  568. }
  569. if ( null != numberPatternArray && numberPatternArray.size() > 0 ) {
  570. isNumberArray = true;
  571. }
  572. // Check for integer,boolean,double ,date and string data type object.
  573. if ("int".equalsIgnoreCase(nodeDTObject.asText()) && (StringUtils.isEmpty(dnObjetText) || isNullNode
  574. || (isNumberArray ? DataUtility.isNumeric(dnObjetText, numberPatternArray)
  575. : (DataUtility.isNumeric(dnObjetText)||DataUtility.isDecimal(dnObjetText)) ))) {
  576. //8421 code changes.
  577. dataTypeFlag = true;
  578. incorrectintegerDataType = "integer";
  579. // PE-9689 : If the value is string integer("45"), then convert it to integer(45).
  580. // PE-9708 : If the value is string integer("45.0" or "45.7"), then convert it to integer(45).
  581. if(dnCodeObject.asText().matches(Constants.INT_PATTERN) || dnCodeObject.asText().matches(Constants.DATATYPE_DOUBLE_PATTERN)) {
  582. ((ObjectNode) dataNode).set(mappedColumnName, JsonNodeFactory.instance.numberNode(dnCodeObject.asInt()));
  583. dataMap.put(mappedColumnName,dataNode.get(mappedColumnName));
  584. // Else if Dataformat is defined, convert it to appropriate string.
  585. } else if (isNumberArray && !dnCodeObject.isNumber() && !StringUtils.isEmpty(dnObjetText)) {
  586. ((ObjectNode) dataNode).put(mappedColumnName, DataUtility.toNumber(dnObjetText, numberPatternArray));
  587. //PE-8731
  588. dataMap.put(mappedColumnName,dataNode.get(mappedColumnName));
  589. }
  590. } else if ("boolean".equalsIgnoreCase(nodeDTObject.asText()) && ("false".equalsIgnoreCase(dnObjetText)
  591. || isNullNode || StringUtils.isEmpty(dnObjetText) || "true".equalsIgnoreCase(dnObjetText))) {
  592. //8421 code changes.
  593. dataTypeFlag = true;
  594. incorrectintegerDataType = "boolean";
  595. ((ObjectNode) dataNode).put(mappedColumnName, DataUtility.toNumber(dnObjetText, numberPatternArray));
  596. } else if ("date".equalsIgnoreCase(nodeDTObject.asText()) && (StringUtils.isEmpty(dnObjetText) || isNullNode
  597. || (isDateArray ? DataUtility.isValidDate(dnObjetText, datePatternArray)
  598. : DataUtility.isValidDate(dnObjetText)))) {
  599. //8421 code changes.
  600. dataTypeFlag = true;
  601. incorrectintegerDataType = "date";
  602. // PE-9689 : If the value is string long("45454545"), then convert it to integer(45454545).
  603. if(dnCodeObject.asText().matches(Constants.LONG_PATTERN)) {
  604. ((ObjectNode) dataNode).set(mappedColumnName, JsonNodeFactory.instance.numberNode(Long.parseLong(dnCodeObject.asText())));
  605. dataMap.put(mappedColumnName,dataNode.get(mappedColumnName));
  606. // Else if Dateformat is defined, convert it to appropriate string.
  607. // Convert to ISO-8601 Format
  608. } else if (isDateArray && !StringUtils.isEmpty(dnObjetText)) {
  609. ((ObjectNode) dataNode).put(mappedColumnName, DataUtility.customDateConvertor(dnObjetText,datePatternArray));
  610. }
  611. } else if ("double".equalsIgnoreCase(nodeDTObject.asText()) && (StringUtils.isEmpty(dnObjetText) || isNullNode
  612. || (isNumberArray ? DataUtility.isDecimal(dnObjetText, numberPatternArray)
  613. : DataUtility.isDecimal(dnObjetText)))) {
  614. dataTypeFlag = true;
  615. incorrectintegerDataType = "double";
  616. // PE-9689 Note : If user passes integer(454545) while the dataype="double", it will get converted to double(454545.0)
  617. // If the value is string long("4545.45"), then convert it to integer(4545.45).
  618. if(dnCodeObject.asText().matches(Constants.DATATYPE_DOUBLE_PATTERN)) {
  619. ((ObjectNode) dataNode).set(mappedColumnName, JsonNodeFactory.instance.numberNode(Double.parseDouble(dnCodeObject.asText())));
  620. dataMap.put(mappedColumnName, dataNode.get(mappedColumnName));
  621. // Else if Dataformat is defined, convert it to appropriate string.
  622. //Convert to java decimal
  623. } else if (isNumberArray && !StringUtils.isEmpty(dnObjetText)) {
  624. ((ObjectNode) dataNode).put(mappedColumnName, DataUtility.toDecimal(dnObjetText, numberPatternArray));
  625. //PE-8731
  626. dataMap.put(mappedColumnName,dataNode.get(mappedColumnName));
  627. }
  628. } else if (StringUtils.isEmpty(dnObjetText) || isNullNode || "string".equalsIgnoreCase(nodeDTObject.asText())) {
  629. dataTypeFlag = true;
  630. }
  631. //8421 code changes.
  632. incorrectDataTypeMap.put("dataTypeFlag", Boolean.toString(dataTypeFlag));
  633. incorrectDataTypeMap.put("datatype", incorrectintegerDataType);
  634. return incorrectDataTypeMap;
  635. }
  636. public ArrayNode findAndMerge(JsonNode dataNode, ArrayNode csvNode, String uniqueIdColumnCode) {
  637. Iterator<String> it = null;
  638. String key = "";
  639. boolean isMerged = false;
  640. if (dataNode != null && dataNode.size() > 0) {
  641. for (int i = 0; i < dataNode.size(); i++) {
  642. isMerged = false;
  643. if (dataNode.get(i).get(uniqueIdColumnCode) != null)
  644. {
  645. for (int j = 0; j < csvNode.size(); j++) {
  646. if (csvNode.get(j).get(uniqueIdColumnCode) != null && csvNode.get(j).get(uniqueIdColumnCode)
  647. .equals(dataNode.get(i).get(uniqueIdColumnCode))) {
  648. it = dataNode.get(i).fieldNames();
  649. while (it != null && it.hasNext()) {
  650. key = it.next();
  651. if (JsonUtils.isNullOrBlankOrNullNode(csvNode.get(j).get(key)) || csvNode.get(j).get(key).asText().equals("")) {
  652. ((ObjectNode) csvNode.get(j)).set(key, dataNode.get(i).get(key));
  653. }
  654. }
  655. isMerged = true;
  656. }
  657. }
  658. if (!isMerged) {
  659. csvNode.add(dataNode.get(i));
  660. }
  661. }
  662. }
  663. }
  664. return csvNode;
  665. }
  666. public void buildCheckboxArray(JsonNode dataNode,String code, String mappedColumnName) {
  667. if (code == null || code.equals("")) {
  668. code = mappedColumnName;
  669. }
  670. if (dataNode.get(code) != null)
  671. {
  672. if (dataNode.get(code).getNodeType() != JsonNodeType.OBJECT
  673. && dataNode.get(code).getNodeType() != JsonNodeType.ARRAY) {
  674. ArrayNode arrNode = mapper.createArrayNode();
  675. // PE-7795 Array was giving arrayName["null"] wrong array.
  676. // Below changes will give arraName[null] requires correct array.
  677. if( !JsonUtils.isNullNode(dataNode.get(code))) {
  678. String arr1[] = dataNode.get(code).asText().split(",");
  679. if (arr1 != null && arr1.length > 0) {
  680. for (int i = 0; i < arr1.length; i++) {
  681. arrNode.add(arr1[i]);
  682. }
  683. }
  684. }
  685. ((ObjectNode) (dataNode)).set(code, arrNode);
  686. } else {
  687. Iterator<Map.Entry<String, JsonNode>> it = dataNode.get(code).fields();
  688. Map.Entry<String, JsonNode> entry = null;
  689. while (it != null && it.hasNext()) {
  690. entry = it.next();
  691. ArrayNode arrNode = mapper.createArrayNode();
  692. switch (entry.getValue().getNodeType()) {
  693. case ARRAY:
  694. for (final JsonNode objNode : entry.getValue()) {
  695. arrNode.add(objNode);
  696. }
  697. break;
  698. case STRING:
  699. String[] arr1 = entry.getValue().asText().split(",");
  700. if (arr1 != null && arr1.length > 0) {
  701. for (int i = 0; i < arr1.length; i++) {
  702. arrNode.add(arr1[i]);
  703. }
  704. }
  705. break;
  706. default:
  707. break;
  708. }
  709. ((ObjectNode) (dataNode.get(code))).set(entry.getKey(), arrNode);
  710. }
  711. }
  712. }
  713. }
  714. /**
  715. *
  716. * @param header
  717. * @param entitiesJson
  718. * @return
  719. * @throws JsonParseException
  720. * @throws JsonMappingException
  721. * @throws IOException
  722. */
  723. @SuppressWarnings("unchecked")
  724. public HashMap<String, Object> compareFields(List<HashMap<String, String>> records,List<String> header, String entitiesJson,
  725. HashMap<String, Object> xlsxMap,Object eeidColFlag) throws Exception {
  726. ArrayNode entitiesNode = mapper.readValue(entitiesJson, ArrayNode.class);
  727. JsonNode columnNode = null;
  728. ArrayNode arr = null;
  729. int columnNodeSize = 0;
  730. boolean found = false;
  731. boolean multiSheetExcel=false;
  732. ObjectNode resultNode = null;
  733. HashMap<String, Object> resultMap = new HashMap<String, Object>();
  734. String entityCode = null;
  735. JsonNode skip = null;
  736. String mappedColName = null;
  737. boolean sheetMatchingFlag = true;
  738. String sheetName = "";
  739. JsonNode dataNode = null;
  740. String currentHeaderCol = null;//PE-8247 duplicate cols validation
  741. Set<String> set = null;//PE-8247
  742. HashMap<String, List<String>> headerMap=null;
  743. if(xlsxMap!=null)
  744. {
  745. headerMap = (HashMap<String, List<String>>)xlsxMap.get(Constants.XLSXHEADERMAP);
  746. }
  747. if (entitiesNode != null && xlsxMap != null && headerMap != null) {
  748. if(headerMap.size() > 1 )
  749. multiSheetExcel=true;
  750. if (entitiesNode.size() < headerMap.size()) {
  751. sheetMatchingFlag = false;
  752. } else {
  753. for (int i = 0; i < entitiesNode.size(); i++) {
  754. sheetName = entitiesNode.get(i).get(Constants.CONTEXTDATAKEY).get(Constants.COMPANYNAME).asText() + "_"
  755. + entitiesNode.get(i).get(Constants.CONTEXTDATAKEY).get(Constants.CTRYCDOE).asText();
  756. if (headerMap.get(sheetName) == null) {
  757. sheetMatchingFlag = false;
  758. }
  759. break;
  760. }
  761. }
  762. }
  763. if(xlsxMap!=null && (records !=null || !multiSheetExcel) && entitiesNode.size()> 1)
  764. {
  765. HashMap<String, Object> map = new HashMap<>();
  766. if(records !=null)
  767. {
  768. map.put("data", records);
  769. map.put(Constants.COLUMNS,header );
  770. }
  771. else
  772. {
  773. map.put("data", ((HashMap<String, List<HashMap<String, String>>>)xlsxMap.get(Constants.XLSXDATAMAP)).get(xlsxMap.get(Constants.FIRSTSHEETNAME)));
  774. map.put(Constants.COLUMNS,headerMap.get(xlsxMap.get(Constants.FIRSTSHEETNAME)) );
  775. }
  776. dataNode = mapper.readValue(mapper.writeValueAsString(map), JsonNode.class);
  777. resultMap.put(Constants.RESULTNODE, dataNode);
  778. return resultMap;
  779. }
  780. for (int i = 0; i < entitiesNode.size(); i++) {
  781. set = new HashSet<>();
  782. dataNode = mapper.createObjectNode();
  783. columnNode = entitiesNode.get(i).get(Constants.SECTION_STRUCTURE).get(Constants.COLUMNS);
  784. if (entitiesNode.get(i).get(Constants.CONTEXTDATAKEY).get(Constants.COMPANYNAME) != null
  785. && entitiesNode.get(i).get(Constants.CONTEXTDATAKEY).get(Constants.CTRYCDOE) != null) {
  786. sheetName = entitiesNode.get(i).get(Constants.CONTEXTDATAKEY).get(Constants.COMPANYNAME).asText() + "_"
  787. + entitiesNode.get(i).get(Constants.CONTEXTDATAKEY).get(Constants.CTRYCDOE).asText();
  788. }
  789. columnNodeSize = (columnNode).size();
  790. if (xlsxMap != null && xlsxMap.get("xlsxHeaderMap") != null) {
  791. if (!sheetMatchingFlag) {
  792. header = headerMap.get(xlsxMap.get(Constants.FIRSTSHEETNAME));
  793. } else {
  794. header = headerMap.get(sheetName);
  795. }
  796. }
  797. resultNode = mapper.createObjectNode();
  798. if (header != null) {
  799. for (int j = 0; j < header.size(); j++) {
  800. //PE-8247 Duplicate Cols Validation
  801. if(!set.add(header.get(j).trim())){
  802. throw new CustomStatusException(Constants.HTTPSTATUS_400,
  803. in.lnt.utility.general.Cache.getPropertyFromError(ErrorCacheConstant.ERR_065));
  804. }
  805. }
  806. for (int j = 0; j < header.size(); j++) {
  807. currentHeaderCol = header.get(j);
  808. found = false;
  809. for (int k = 0; k < columnNodeSize; k++) {
  810. skip = columnNode.get(k).get(Constants.SKIP);
  811. if (null != columnNode.get(k).get("code")) {
  812. entityCode = columnNode.get(k).get("code").asText();
  813. }
  814. if (null != columnNode.get(k).get(Constants.MAPPED_COLUMN_NAME)) {
  815. mappedColName = columnNode.get(k).get(Constants.MAPPED_COLUMN_NAME).asText();
  816. }
  817. //Code modified to skip mapping in case of skip=true in request PE : 6858
  818. if(skip!=null && skip.asText().equals("true"))
  819. {
  820. if(currentHeaderCol.equals(entityCode) || currentHeaderCol.equals(mappedColName))
  821. {
  822. found = true;
  823. break;
  824. }
  825. else
  826. {
  827. continue;
  828. }
  829. }
  830. if ((!StringUtils.isEmpty(entityCode)|| !StringUtils.isEmpty(mappedColName)) && skip==null && (currentHeaderCol.equals(entityCode) || currentHeaderCol.equals(mappedColName))) {
  831. found = true;
  832. break;
  833. }
  834. }
  835. if (!found) {
  836. break;
  837. }
  838. }
  839. }
  840. if (!found) {
  841. break;
  842. }
  843. }
  844. if (!found || (xlsxMap!=null &&((Integer)xlsxMap.get(Constants.EEIDINHEADER)!= (headerMap.size()))) ) {
  845. if(!multiSheetExcel)
  846. {
  847. HashMap<String, Object> map = new HashMap<String, Object>();
  848. if(xlsxMap!=null)
  849. {
  850. if(!sheetMatchingFlag)
  851. {
  852. map.put("data", ((HashMap<String, List<HashMap<String, String>>>)xlsxMap.get(Constants.XLSXDATAMAP)).get(xlsxMap.get(Constants.FIRSTSHEETNAME)));
  853. }
  854. else{
  855. map.put("data", ((HashMap<String, List<HashMap<String, String>>>)xlsxMap.get(Constants.XLSXDATAMAP)).get(sheetName));
  856. }
  857. }
  858. else if(records!=null)
  859. {
  860. map.put("data", records);
  861. }
  862. if((boolean)eeidColFlag)
  863. {
  864. map.put(Constants.COLUMNS,header );
  865. }
  866. else
  867. {
  868. header.remove(header.size() - 1);
  869. map.put(Constants.COLUMNS,header);
  870. }
  871. dataNode = mapper.readValue(mapper.writeValueAsString(map), JsonNode.class);
  872. resultMap.put(Constants.RESULTNODE, dataNode);
  873. }
  874. else
  875. {
  876. resultMap.put(Constants.RESULTNODE, ErrorCacheConstant.ERR_055);
  877. }
  878. } else {
  879. resultMap.put(Constants.RESULTNODE, null);
  880. if (sheetMatchingFlag == false) {
  881. resultMap.put("sheetMatchingFlag",
  882. null != xlsxMap.get(Constants.FIRSTSHEETNAME) ? xlsxMap.get(Constants.FIRSTSHEETNAME) : "");
  883. }
  884. return resultMap;
  885. }
  886. if (sheetMatchingFlag == false) {
  887. resultMap.put("sheetMatchingFlag",
  888. null != xlsxMap.get(Constants.FIRSTSHEETNAME) ? xlsxMap.get(Constants.FIRSTSHEETNAME) : "");
  889. }
  890. return resultMap;
  891. }
  892. @SuppressWarnings("unchecked")
  893. public HashMap<String, Object> convertXlsxToMap(Map<String, Object> workBookMap,String empIdColumn) throws Exception {
  894. HashMap<String, Object> map = null;
  895. List<String> headerList = null;
  896. List<ArrayList<String>> dataList = null;
  897. HashMap<String, List<HashMap<String, String>>> xlsxDataMap = null;
  898. HashMap<String, List<String>> xlsxHeaderMap = null;
  899. HashMap<String, Object> xlsxMap = null;
  900. xlsxDataMap = new HashMap<>();
  901. xlsxHeaderMap = new HashMap<>();
  902. Set<Object> eeidSet = null;
  903. List<HashMap<String, String>> allRecords = null;
  904. HashMap<String, String> record = null;
  905. boolean eeidFlag = true;
  906. //PE-8933
  907. boolean eeidMissingFlag = false;
  908. String tempDataListRecord ;
  909. String tempHeaderListRecord;
  910. int eeIdInHeader=0;
  911. if (workBookMap != null && workBookMap.size() > 0) {
  912. xlsxMap = new HashMap<>();
  913. //Iterate through each xlsx tab.
  914. for (Entry<String, Object> entry : workBookMap.entrySet()) {
  915. eeidSet = new HashSet<>();
  916. if (entry.getKey().equals(Constants.FIRSTSHEETNAME)) {
  917. xlsxMap.put(Constants.FIRSTSHEETNAME, entry.getValue());
  918. continue;
  919. }
  920. allRecords = new ArrayList<>();
  921. map = (HashMap<String, Object>) entry.getValue();
  922. headerList = (List<String>) map.get("header");
  923. dataList = (List<ArrayList<String>>) map.get("data");
  924. //Iterate through data records from each xlsx tab.
  925. for (int i = 0; i < dataList.size(); i++) {
  926. record = new HashMap<>();
  927. //Iterate through each header from each tab.
  928. for (int j = 0; j < headerList.size(); j++) {
  929. tempDataListRecord = dataList.get(i).get(j);
  930. tempHeaderListRecord = headerList.get(j);
  931. if (tempHeaderListRecord.equalsIgnoreCase(Constants.EMPLOYEE_EEID) || (empIdColumn!=null
  932. && !empIdColumn.equals("") && tempHeaderListRecord.equals(empIdColumn))) {
  933. try {
  934. if(i==0)
  935. {
  936. eeIdInHeader++;
  937. }
  938. if (tempDataListRecord != null && !tempDataListRecord.equals(""))
  939. eeidFlag = eeidSet.add(tempDataListRecord);
  940. else {
  941. // PE-8933
  942. eeidMissingFlag = true;
  943. }
  944. } catch (IndexOutOfBoundsException e) {
  945. eeidFlag = true;
  946. }
  947. }
  948. if (eeidFlag) {
  949. try {
  950. boolean isNotBlankEEID = !StringUtils.isEmpty(tempDataListRecord);
  951. record.put(tempHeaderListRecord,
  952. (isNotBlankEEID ? tempDataListRecord : Constants.BLANK));
  953. } catch (IndexOutOfBoundsException e) {
  954. record.put(tempHeaderListRecord, Constants.BLANK);
  955. }
  956. } else {
  957. xlsxMap.put("isEeidDuplicate", "true");
  958. eeidSet=null;
  959. //PE-8933
  960. if(eeidMissingFlag)
  961. xlsxMap.put(Constants.MISSING_EEID, true);
  962. else
  963. xlsxMap.put(Constants.MISSING_EEID, false);
  964. return xlsxMap;
  965. }
  966. }
  967. allRecords.add(record);
  968. //Clean up block
  969. record = null;
  970. }
  971. xlsxDataMap.put(entry.getKey(), allRecords);
  972. xlsxHeaderMap.put(entry.getKey(), headerList);
  973. xlsxMap.put(Constants.XLSXHEADERMAP, xlsxHeaderMap);
  974. xlsxMap.put(Constants.XLSXDATAMAP, xlsxDataMap);
  975. //PE-8933
  976. if(eeidMissingFlag)
  977. xlsxMap.put(Constants.MISSING_EEID, true);
  978. else
  979. xlsxMap.put(Constants.MISSING_EEID, false);
  980. //Clean up records
  981. allRecords = null;
  982. }
  983. xlsxMap.put(Constants.EEIDINHEADER, eeIdInHeader);
  984. }
  985. eeidSet = null;
  986. //logger.info(String.format("%s %s", Constants.EXIT ,Constants.LOG_CONVERXLSXTOMAP));
  987. return xlsxMap;
  988. }
  989. @SuppressWarnings("unchecked")
  990. public LinkedHashMap<String, String> prepareJsonString(HashMap<String, Object> xslsMap) throws Exception{
  991. HashMap<String, Object> map = new HashMap<String, Object>();
  992. HashMap<String, List<HashMap<String, String>>> xlsxDataMap = null;
  993. String csvJsonString = "";
  994. LinkedHashMap<String, String> xslJsonMap = new LinkedHashMap<String, String>();
  995. HashMap<String, List<HashMap<String, String>>> xlsxDataMap_Temp = null;
  996. if (xslsMap != null && xslsMap.size() > 0) {
  997. xlsxDataMap_Temp = (HashMap<String, List<HashMap<String, String>>>) xslsMap.get(Constants.XLSXDATAMAP); //PE-9452 Empty cols removal
  998. xlsxDataMap = RemoveColsWithNoValue(xlsxDataMap_Temp); //PE-9452 Empty cols removal
  999. for (Entry<String, List<HashMap<String, String>>> entry : xlsxDataMap.entrySet()) {
  1000. map.put("data", entry.getValue());
  1001. ObjectMapper objmapper = new ObjectMapper();
  1002. csvJsonString = objmapper.writeValueAsString(map);
  1003. xslJsonMap.put(entry.getKey(), csvJsonString);
  1004. }
  1005. }
  1006. return xslJsonMap;
  1007. }
  1008. //Method added to remove cols having no values PE-9452
  1009. public HashMap<String, List<HashMap<String, String>>> RemoveColsWithNoValue(HashMap<String, List<HashMap<String, String>>> xlsxDataMap) throws Exception{
  1010. List<HashMap<String, String>> xslJsonMapEntry = null;;
  1011. HashMap<String, List<HashMap<String, String>>> xlsxDataMapWithoutEmptyCols = new HashMap<String, List<HashMap<String, String>>>();
  1012. HashMap<String, String> hm = null;
  1013. for (Entry<String, List<HashMap<String, String>>> entry : xlsxDataMap.entrySet()) {
  1014. xslJsonMapEntry = new ArrayList<HashMap<String, String>>();
  1015. for(HashMap<String, String> hm1 : entry.getValue()){
  1016. hm = new HashMap<String, String>();
  1017. for(Entry<String,String> entry1 : hm1.entrySet()){
  1018. if(entry1.getValue().length() == 0){
  1019. //hm.remove(entry.getKey());
  1020. }else{
  1021. hm.put(entry1.getKey(), entry1.getValue());
  1022. }
  1023. }
  1024. xslJsonMapEntry.add(hm);
  1025. }
  1026. xlsxDataMapWithoutEmptyCols.put(entry.getKey(),xslJsonMapEntry);
  1027. }
  1028. return xlsxDataMapWithoutEmptyCols;
  1029. }
  1030. // PE : 2449 to check duplication of EEID start in case of entity data in
  1031. // request body
  1032. public Map<String,String> checkUniqueNessForEEID(String enetityJson,String dataAsJson) throws Exception{
  1033. //logger.info(String.format("%s %s", Constants.INTIATE ,Constants.LOG_CHECKUNIQUENESSFOREEID));
  1034. @SuppressWarnings("unchecked")
  1035. Map<String,String> empIdMap= new HashMap<>();
  1036. empIdMap.put(Constants.ISUNIQUE, "true");
  1037. JsonNode entityNode = null;
  1038. boolean flag = false;
  1039. String code = "";
  1040. JsonNode sectionStructureNode = null;
  1041. String empIdColumn="";
  1042. ArrayList<JsonNode> columnNodeList = null;
  1043. columnNodeList = new ArrayList<JsonNode>();
  1044. JsonNode entittiesNode = mapper.readValue(enetityJson, JsonNode.class);
  1045. Set<String> eeidSet = null;
  1046. if (entittiesNode != null) {
  1047. for (int i = 0; i < entittiesNode.size(); i++) {
  1048. eeidSet = new HashSet<>();
  1049. entityNode = entittiesNode.get(i);
  1050. sectionStructureNode = entityNode.get(Constants.SECTION_STRUCTURE);
  1051. for (int j = 0; j < sectionStructureNode.get(Constants.COLUMNS).size(); j++) {
  1052. columnNodeList.add(sectionStructureNode.get(Constants.COLUMNS).get(j));
  1053. }
  1054. if (columnNodeList != null && columnNodeList.size() > 0) {
  1055. for (JsonNode node : columnNodeList) {
  1056. if (node.get(Constants.CODE) != null)
  1057. code = node.get(Constants.CODE).asText();
  1058. if (code.equals(Constants.EMPLOYEE_EEID))
  1059. {
  1060. flag = true;
  1061. if(node.get(Constants.MAPPED_COLUMN_NAME)!=null && !node.get(Constants.MAPPED_COLUMN_NAME).asText().equals(""))
  1062. {
  1063. empIdColumn = node.get(Constants.MAPPED_COLUMN_NAME).asText();
  1064. empIdMap.put("empIdColumn", empIdColumn);
  1065. }
  1066. }
  1067. }
  1068. }
  1069. if (flag) {
  1070. JsonNode dataNode = entittiesNode.get(i).get(Constants.DATA);
  1071. if (dataNode != null) {
  1072. for (int k = 0; k < dataNode.size(); k++) {
  1073. if (dataNode.get(k).get(Constants.EMPLOYEE_EEID) != null
  1074. && !dataNode.get(k).get(Constants.EMPLOYEE_EEID).asText().equals("")) {
  1075. String eeId = dataNode.get(k).get(Constants.EMPLOYEE_EEID).asText();
  1076. if (!eeidSet.add(eeId)) {
  1077. eeidSet.clear();
  1078. empIdMap.put(Constants.ISUNIQUE,Constants.DUPLICATE);
  1079. return empIdMap;
  1080. }
  1081. } else {
  1082. empIdMap.put(Constants.ISUNIQUE,Constants.MISSING);
  1083. return empIdMap;
  1084. }
  1085. }
  1086. }
  1087. if(dataAsJson!=null)
  1088. {
  1089. empIdMap = DataUtility.checkUniqueEEIDForRequestDataJson(dataAsJson,empIdMap);
  1090. return empIdMap;
  1091. }
  1092. }
  1093. }
  1094. }
  1095. return empIdMap;
  1096. }
  1097. // PE : 2449 to prepare auto-correct validation object in case of missing EEID..
  1098. public ObjectNode prepareEeidAutoCorrectObject(String code, HashMap<String, JsonNode> dataMap, JsonNode dataNode,
  1099. HashMap<String, String> columnMappingMap) throws Exception {
  1100. ObjectNode obj = null;
  1101. if (dataMap != null && ((!JsonUtils.isNullOrBlankOrNullNode(dataMap.get(Constants.EMPLOYEE_EEID))
  1102. && !JsonUtils.isBlankTextNode(dataMap.get(Constants.EMPLOYEE_EEID)) )
  1103. || (!JsonUtils.isNullOrBlankOrNullNode(dataMap.get(columnMappingMap.get(code)))
  1104. && !JsonUtils.isBlankTextNode(dataMap.get(columnMappingMap.get(code))) )))
  1105. {
  1106. return obj;
  1107. } else {
  1108. String eeId = generateUniqueEeid();
  1109. obj = APIExpressionEvaluator.prepareOutputJson(null, null, eeId, ValidationTypes.EEIDAUTOCORRECT, code,
  1110. null, null, null);
  1111. ((ObjectNode) (dataNode)).put(code, eeId);
  1112. }
  1113. return obj;
  1114. }
  1115. public static synchronized String generateUniqueEeid() throws Exception {
  1116. Date d1 = new Date();
  1117. SimpleDateFormat sdf = new SimpleDateFormat(Constants.EEID_FORMAT2);
  1118. String tmpNanoTime = String.valueOf(System.nanoTime()); // Duplicate EEID occurred at millisec-level. Found in PE-8616.
  1119. return sdf.format(d1)+ tmpNanoTime.substring(tmpNanoTime.length()-5, tmpNanoTime.length());
  1120. }
  1121. public static ArrayNode removeMlNode(JsonNode jsonNode) throws Exception {
  1122. JsonNode mlNode = null;
  1123. JsonNode entityNode = null;
  1124. Iterator<Entry<String, JsonNode>> mlItr = null;
  1125. ArrayNode mlJsonDataArray = (ArrayNode) jsonNode.get(Constants.ENTITIES);
  1126. Map.Entry<String, JsonNode> entry = null;
  1127. for (int i = 0; i < mlJsonDataArray.size(); i++) {
  1128. entityNode = mlJsonDataArray.get(i);
  1129. mlNode = entityNode.get(Constants.DATA);
  1130. for (int k = 0; k < mlNode.size(); k++) {
  1131. mlItr = mlNode.get(k).fields();
  1132. while (mlItr.hasNext()) {
  1133. entry = mlItr.next();
  1134. if (entry.getKey().contains(Constants.UNDERSCORE_REPLACE) || entry.getKey().contains(Constants.UNDERSCORE_ACFLAG)) {
  1135. ((ObjectNode) mlNode.get(k)).remove(entry.getKey());
  1136. }
  1137. }
  1138. }
  1139. }
  1140. return mlJsonDataArray;
  1141. }
  1142. public void performL0Validation(String entitiesJson, String csvJsonString, boolean isAggregateRequest,
  1143. HashMap<String, String> xslJsonMap, String FirstSheetName) throws Exception
  1144. {
  1145. JsonNode sectionStructureNode = null;
  1146. JsonNode contextDataNode = null;
  1147. JsonNode csvNode = null;
  1148. JsonNode entityNode = null;
  1149. long startTime=0;
  1150. long stopTime=0;
  1151. Set<String> xslJsonSheets = null;
  1152. String code = "";
  1153. JsonNode validationNode = null;
  1154. String returnValue="";
  1155. Pattern pattern = Pattern.compile(Constants.EXP_PATTERN);
  1156. boolean columnMissflag = true;
  1157. Map<String,String> mappedColumnMap = new HashMap<String,String>();
  1158. // 8395 JP
  1159. String field=null;
  1160. ArrayNode entitiesNode = mapper.readValue(entitiesJson, ArrayNode.class);
  1161. if (xslJsonMap != null) {
  1162. xslJsonSheets = new HashSet<String>(xslJsonMap.keySet());
  1163. }
  1164. for (int i = 0; i < entitiesNode.size(); i++) {
  1165. entityNode = entitiesNode.get(i);
  1166. if(entitiesNode.get(i).get(Constants.DATA)!=null && entitiesNode.get(i).get(Constants.DATA).size()>0)
  1167. {
  1168. break;
  1169. }
  1170. sectionStructureNode = entityNode.get(Constants.SECTION_STRUCTURE);
  1171. contextDataNode = entityNode.get(Constants.CONTEXTDATAKEY);
  1172. if (csvJsonString != null && !csvJsonString.equals("")) {
  1173. csvNode = mapper.readValue(csvJsonString, JsonNode.class);
  1174. } else if (xslJsonMap != null && xslJsonMap.size() > 0) {
  1175. String coName_CtryCode = contextDataNode.get(Constants.COMPANYNAME).asText() + "_"
  1176. + contextDataNode.get(Constants.CTRYCDOE).asText();
  1177. if (FirstSheetName != null) {
  1178. csvNode = mapper.readValue(xslJsonMap.get(FirstSheetName), JsonNode.class);
  1179. } else if (xslJsonMap.get(coName_CtryCode) != null) {
  1180. if (xslJsonSheets.contains(coName_CtryCode)) {
  1181. csvNode = mapper.readValue(xslJsonMap.get(coName_CtryCode), JsonNode.class);
  1182. }
  1183. } else if (xslJsonMap.get(coName_CtryCode) == null) {
  1184. /*throw new CustomStatusException(Constants.HTTPSTATUS_400,
  1185. String.format(Constants.ERROR_SHEET_NOT_FOUND, coName_CtryCode));*/
  1186. paramValueList = new ArrayList<String>();
  1187. paramValueList.add(""+coName_CtryCode);
  1188. throw new CustomStatusException(Constants.HTTPSTATUS_400,Cache.getPropertyFromError(ErrorCacheConstant.ERR_035),
  1189. Cache.getPropertyFromError(ErrorCacheConstant.ERR_035+Constants.UNDERSCORE_PARAMS),paramValueList);
  1190. }
  1191. }
  1192. if (!JsonUtils.isNullOrBlankOrNullNode(csvNode)
  1193. && csvNode.get(Constants.DATA).size() > 0 ) {
  1194. sectionStructureNode = entityNode.get(Constants.SECTION_STRUCTURE);
  1195. ArrayList<JsonNode> columnNodeList = new ArrayList<>();
  1196. for (int j = 0; j < sectionStructureNode.get(Constants.COLUMNS).size(); j++) {
  1197. columnNodeList.add(sectionStructureNode.get(Constants.COLUMNS).get(j));
  1198. //Code added for 8395
  1199. /*if(null != columnNodeList.get(j).get(Constants.CODE) && null != columnNodeList.get(j).get(Constants.MAPPED_COLUMN_NAME)){
  1200. mappedColumnMap.put(columnNodeList.get(j).get(Constants.CODE).asText(), columnNodeList.get(j).get(Constants.MAPPED_COLUMN_NAME).asText());
  1201. }
  1202. if(null != columnNodeList.get(j).get(Constants.CODE)) {
  1203. metaDataColumnsSet.add(columnNodeList.get(j).get(Constants.CODE).asText());
  1204. }*/
  1205. //8395 JP
  1206. if (null != columnNodeList.get(j).get(Constants.CODE)) {
  1207. mappedColumnMap.put(columnNodeList.get(j).get(Constants.CODE).asText(),columnNodeList.get(j).get(Constants.CODE).asText());
  1208. if (null != columnNodeList.get(j).get(Constants.MAPPED_COLUMN_NAME)) {
  1209. mappedColumnMap.put(columnNodeList.get(j).get(Constants.CODE).asText(),
  1210. columnNodeList.get(j).get(Constants.MAPPED_COLUMN_NAME).asText());
  1211. }
  1212. }
  1213. }
  1214. if (columnNodeList != null && columnNodeList.size() > 0) {
  1215. for (JsonNode node : columnNodeList) {
  1216. if (node.get(Constants.CODE) != null)
  1217. code = node.get(Constants.CODE).asText();
  1218. if (node.get(Constants.VALIDATIONS) != null
  1219. && node.get(Constants.VALIDATIONS).size() > 0) {
  1220. for (int k = 0; k < node.get(Constants.VALIDATIONS).size(); k++) {
  1221. validationNode = node.get(Constants.VALIDATIONS).get(k);
  1222. columnMissflag = true;
  1223. if (validationNode != null && validationNode.get("category") != null
  1224. && validationNode.get("category").asText().equalsIgnoreCase("file_acceptance")) {
  1225. if (validationNode.get(Constants.EXPRESSION) != null && validationNode
  1226. .get(Constants.EXPRESSION).asText().contains("ISBLANK")) {
  1227. Matcher matcher = pattern.matcher(validationNode.get(Constants.EXPRESSION).asText()
  1228. .replaceAll(Constants.CURLY_BRACES, ""));
  1229. List<String> fields = new ArrayList<String>();
  1230. while (matcher.find()) {
  1231. // 8395 JP
  1232. field=matcher.group().replace("this.", "").trim();
  1233. if(mappedColumnMap.containsKey(field)) {
  1234. fields.add(field);
  1235. }
  1236. }
  1237. /* for (int fieldSize = 0; fieldSize < fields.size(); fieldSize++) {
  1238. // if(csvNode.get(Constants.DATA).get(0).has(fields.get(fieldSize))){
  1239. if (csvNode.get(Constants.DATA).get(0)
  1240. .has(mappedColumnMap.get(fields.get(fieldSize)))) {
  1241. // if (csvNode.get(Constants.DATA).get(0).get(fields.get(fieldSize)) !=
  1242. // null) {
  1243. columnMissflag = false;
  1244. break;
  1245. }
  1246. }*/
  1247. //if (!columnMissflag) {
  1248. startTime = System.currentTimeMillis();
  1249. //Code added for 8395
  1250. columnMissflag = checkforBlank(fields, csvNode,mappedColumnMap);
  1251. stopTime = System.currentTimeMillis();
  1252. //logger.info(String.format("Time taken for checkforBlank() in FormValidator..%d", (stopTime-startTime)));
  1253. //}
  1254. if (columnMissflag) {
  1255. paramValueList = new ArrayList<>();
  1256. paramValueList.add(validationNode.get("_id").asText());
  1257. paramValueList.add(code);
  1258. throw new CustomStatusException(Constants.HTTPSTATUS_400,
  1259. Cache.getPropertyFromError(ErrorCacheConstant.ERR_060),
  1260. Cache.getPropertyFromError(ErrorCacheConstant.ERR_060 + Constants.UNDERSCORE_PARAMS),
  1261. paramValueList);
  1262. }
  1263. }
  1264. }
  1265. }
  1266. }
  1267. }
  1268. }
  1269. }
  1270. }
  1271. //return returnValue;
  1272. }
  1273. public boolean checkforBlank(List<String> fields,JsonNode csvNode,Map<String,String> mappedColumn)throws Exception
  1274. {
  1275. boolean returnValue = true;
  1276. JsonNode dataNode = csvNode.get(Constants.DATA);
  1277. for (String field : fields) {
  1278. if (returnValue == false)
  1279. break;
  1280. JsonNode dataNodeValue = null;
  1281. for (int i = 0; i < dataNode.size(); i++) {
  1282. dataNodeValue = dataNode.get(i);
  1283. //Code added for 8395
  1284. if ((dataNodeValue != null && !JsonUtils.isNullOrBlankOrNullNode(dataNodeValue.get(field))
  1285. && dataNodeValue.get(field).asText() != null && !dataNodeValue.get(field).asText().trim().equals("")) ||
  1286. ((dataNodeValue != null && !JsonUtils.isNullOrBlankOrNullNode(dataNodeValue.get(mappedColumn.get(field)))
  1287. && dataNodeValue.get(mappedColumn.get(field)).asText() != null && !dataNodeValue.get(mappedColumn.get(field)).asText().trim().equals("")))
  1288. /*(mappedColumn.get(dataNode.get(i)) != null)*/) {
  1289. returnValue = false;
  1290. break;
  1291. }
  1292. }
  1293. }
  1294. return returnValue;
  1295. }
  1296. // PE-7241 Changes
  1297. public static ArrayList<ObjectNode> validatePredefinedValidation(JsonNode dataNode, JsonNode columnNode,
  1298. JsonNode validationNode, HashMap<String, JsonNode> dataMap, String mappedColumnName, String errorType)
  1299. throws Exception {
  1300. ArrayList<ObjectNode> emailObjList = new ArrayList<ObjectNode>();
  1301. // Get Regex depending upon error Type
  1302. Pattern COMMON_REGEX_PATTERN = null;
  1303. switch (errorType) {
  1304. case Constants.EMAIL:
  1305. COMMON_REGEX_PATTERN = VALID_EMAIL_ADDRESS_REGEX;
  1306. break;
  1307. case Constants.PHONE:
  1308. COMMON_REGEX_PATTERN = VALID_PHONE_NUMBER_REGEX;
  1309. break;
  1310. case Constants.REQUIRED:
  1311. break;
  1312. default:
  1313. break;
  1314. }
  1315. boolean checkCode = false;
  1316. // Mapped Columns matching
  1317. if(columnNode.has(Constants.CODE) && !JsonUtils.isNullOrBlankOrNullNode(columnNode.get(Constants.CODE))){
  1318. checkCode = true;
  1319. }
  1320. // Dimensions
  1321. if (columnNode.has(Constants.DIMENSIONS) && !JsonUtils.isNullNode(columnNode.get(Constants.DIMENSIONS))) {
  1322. JsonNode dimensionNode = dataNode.get(checkCode ? columnNode.get(Constants.CODE).asText() : mappedColumnName);
  1323. // PE-8463 NULL Handling
  1324. if (!JsonUtils.isNullOrBlankOrNullNode(dimensionNode)) {
  1325. dimensionNode = dimensionNode.deepCopy();
  1326. }
  1327. else {
  1328. // PE-8814 - No data for dimension
  1329. dimensionNode = createNullNodesForDimension(columnNode.get(Constants.CODE).asText(),
  1330. columnNode.get(Constants.DIMENSIONS));
  1331. //PE-8814
  1332. }
  1333. if(!JsonUtils.isNullOrBlankOrNullNode(dimensionNode)){
  1334. // PE-8463 NULL Handling
  1335. for (JsonNode dimensionAttribute : columnNode.get(Constants.DIMENSIONS)) {
  1336. if (dimensionNode.has(dimensionAttribute.asText())) {
  1337. switch (dimensionNode.get(dimensionAttribute.asText()).getNodeType()) {
  1338. case OBJECT:
  1339. // No object Expected
  1340. return emailObjList;
  1341. // For Checkbox Array
  1342. case ARRAY:
  1343. for (final JsonNode checkBoxObj : dimensionNode.get(dimensionAttribute.asText())) {
  1344. String inputValue = checkInputNodeType(checkBoxObj);
  1345. ObjectNode objNode = buildValidationObjectForPredefinedValidation(COMMON_REGEX_PATTERN,
  1346. inputValue, dimensionAttribute, columnNode, validationNode, dataMap,checkCode,
  1347. errorType);
  1348. if (objNode.size() > 0) {
  1349. emailObjList.add(objNode);
  1350. }
  1351. }
  1352. break;
  1353. case STRING:
  1354. case BINARY:
  1355. case BOOLEAN:
  1356. case MISSING:
  1357. case NULL:
  1358. case NUMBER:
  1359. case POJO:
  1360. // For Normal Values / CheckBox String
  1361. if (!JsonUtils.isNullOrBlankOrNullNode(dimensionNode.get(dimensionAttribute.asText()))) {
  1362. String[] splitValues = dimensionNode.get(dimensionAttribute.asText()).asText().split(",");
  1363. for (String splitValue : splitValues) {
  1364. /*emailObjList.add(new APIExpressionEvaluator().prepareOutputJson(validationNode, columnNode,
  1365. null, ValidationTypes.expression, null, null, null, null));*/
  1366. ObjectNode objNode = buildValidationObjectForPredefinedValidation(COMMON_REGEX_PATTERN,
  1367. splitValue, dimensionAttribute, columnNode, validationNode, dataMap,checkCode, errorType);
  1368. if (objNode.size() > 0) {
  1369. emailObjList.add(objNode);
  1370. }
  1371. }
  1372. break;
  1373. }else{
  1374. ObjectNode objNode = buildValidationObjectForPredefinedValidation(COMMON_REGEX_PATTERN,
  1375. null, dimensionAttribute, columnNode, validationNode, dataMap,checkCode, errorType);
  1376. if (objNode.size() > 0) {
  1377. emailObjList.add(objNode);
  1378. }
  1379. }
  1380. }
  1381. }
  1382. // Dimension not found and Validation is required
  1383. else if (errorType.equals(Constants.REQUIRED)) {
  1384. ObjectNode objNode = APIExpressionEvaluator.prepareOutputJson(validationNode, dimensionAttribute, null,
  1385. ValidationTypes.PREDEFINEDVALIDATIONS,
  1386. checkCode ? columnNode.get(Constants.CODE).asText() : mappedColumnName, null, null, null);
  1387. if (objNode.size() > 0) {
  1388. emailObjList.add(objNode);
  1389. }
  1390. }
  1391. }
  1392. }
  1393. } else if ((columnNode.has(Constants.QUESTION_TYPE)
  1394. && (!JsonUtils.isNullNode(columnNode.get(Constants.QUESTION_TYPE))
  1395. && columnNode.get(Constants.QUESTION_TYPE).asText().equals(Constants.CHECKBOXES)))
  1396. && (!JsonUtils.isNullNode(
  1397. dataNode.get(checkCode ?
  1398. columnNode.get(Constants.CODE).asText() :
  1399. mappedColumnName)))) {
  1400. JsonNode checkBoxData = dataNode.get(checkCode ? columnNode.get(Constants.CODE).asText() : mappedColumnName);
  1401. if (!JsonUtils.isNullOrBlankOrNullNode(checkBoxData)) {
  1402. switch (checkBoxData.getNodeType()) {
  1403. case ARRAY:
  1404. if(checkBoxData.size()==0) {
  1405. ObjectNode objNode = buildValidationObjectForPredefinedValidation(COMMON_REGEX_PATTERN,
  1406. null, null, columnNode, validationNode, dataMap, checkCode, errorType);
  1407. if (objNode.size() > 0) {
  1408. emailObjList.add(objNode);
  1409. }
  1410. }else {
  1411. for (final JsonNode checkBoxObj : checkBoxData) {
  1412. String inputValue = checkInputNodeType(checkBoxObj);
  1413. ObjectNode objNode = buildValidationObjectForPredefinedValidation(COMMON_REGEX_PATTERN,
  1414. inputValue, null, columnNode, validationNode, dataMap, checkCode, errorType);
  1415. if (objNode.size() > 0) {
  1416. emailObjList.add(objNode);
  1417. }
  1418. }
  1419. }
  1420. break;
  1421. case STRING:
  1422. case BINARY:
  1423. case BOOLEAN:
  1424. case MISSING:
  1425. case NULL:
  1426. case NUMBER:
  1427. case POJO:
  1428. // String Value (Comma Separated)
  1429. if (!JsonUtils.isNullOrBlankOrNullNode(
  1430. dataNode.get(checkCode ? columnNode.get(Constants.CODE).asText() : mappedColumnName))) {
  1431. String[] splitValues = dataNode
  1432. .get(checkCode ? columnNode.get(Constants.CODE).asText() : mappedColumnName).asText()
  1433. .split(",");
  1434. for (String splitValue : splitValues) {
  1435. /*emailObjList.add(new APIExpressionEvaluator().prepareOutputJson(validationNode, columnNode,
  1436. null, ValidationTypes.expression, null, null, null, null));*/
  1437. ObjectNode objNode = buildValidationObjectForPredefinedValidation(COMMON_REGEX_PATTERN,
  1438. splitValue, null, columnNode, validationNode, dataMap, checkCode, errorType);
  1439. if (objNode.size() > 0) {
  1440. emailObjList.add(objNode);
  1441. }
  1442. }
  1443. } else {
  1444. ObjectNode objNode = buildValidationObjectForPredefinedValidation(COMMON_REGEX_PATTERN, dataNode
  1445. .get(checkCode ? columnNode.get(Constants.CODE).asText() : mappedColumnName).asText(),
  1446. null, columnNode, validationNode, dataMap, checkCode, errorType);
  1447. if (objNode.size() > 0) {
  1448. emailObjList.add(objNode);
  1449. }
  1450. }
  1451. break;
  1452. default:
  1453. break;
  1454. }
  1455. }
  1456. } else {
  1457. /*emailObjList.add(new APIExpressionEvaluator().prepareOutputJson(validationNode, columnNode,
  1458. null, ValidationTypes.expression, null, null, null, null));*/
  1459. ObjectNode objNode = buildValidationObjectForPredefinedValidation(COMMON_REGEX_PATTERN,
  1460. (!JsonUtils.isNullOrBlankOrNullNode(dataNode.get(checkCode ? columnNode.get(Constants.CODE).asText() : mappedColumnName)) ? dataNode.get(checkCode ? columnNode.get(Constants.CODE).asText() : mappedColumnName).asText() : null), null,
  1461. columnNode, validationNode, dataMap, checkCode, errorType);
  1462. if (objNode.size() > 0) {
  1463. emailObjList.add(objNode);
  1464. }
  1465. }
  1466. return emailObjList;
  1467. }
  1468. private static JsonNode createNullNodesForDimension(String code, JsonNode dimensions) {
  1469. ObjectNode dimensionsObject = mapper.createObjectNode();
  1470. for (JsonNode dimensionNode : dimensions) {
  1471. dimensionsObject.set(dimensionNode.asText(),NullNode.getInstance());
  1472. }
  1473. return mapper.createObjectNode().set(code, dimensionsObject);
  1474. }
  1475. static String checkInputNodeType(JsonNode node) {
  1476. String inputValue = node.asText();
  1477. switch (node.getNodeType()) {
  1478. case STRING:
  1479. case BINARY:
  1480. case BOOLEAN:
  1481. break;
  1482. case MISSING:
  1483. case NULL:
  1484. inputValue = null;
  1485. break;
  1486. case NUMBER:
  1487. case POJO:
  1488. break;
  1489. default:
  1490. break;
  1491. }
  1492. return inputValue;
  1493. }
  1494. static ObjectNode buildValidationObjectForPredefinedValidation(Pattern COMMON_REGEX_PATTERN, String inputValue,
  1495. JsonNode dimensionAttribute, JsonNode columnNode, JsonNode validationNode, HashMap<String, JsonNode> dataMap, boolean checkCode, String errorType)
  1496. throws Exception {
  1497. ObjectNode errorObjNode = mapper.createObjectNode();
  1498. switch (errorType) {
  1499. case Constants.EMAIL:
  1500. case Constants.PHONE:
  1501. // (null == inputValue)
  1502. if (!StringUtils.isBlank(inputValue) && (null != COMMON_REGEX_PATTERN)
  1503. && !COMMON_REGEX_PATTERN.matcher(inputValue).find()) {
  1504. if ((null != dimensionAttribute) && !JsonUtils.isNullNode(dimensionAttribute)) {
  1505. ((ObjectNode) validationNode).put("dimension", dimensionAttribute.asText());
  1506. }
  1507. switch (validationNode.get(Constants.ERROR_TYPE).asText().toUpperCase() ) {
  1508. case Constants.ENHANCEMENT:
  1509. case Constants.ALERT:
  1510. case Constants.ERROR:
  1511. errorObjNode = APIExpressionEvaluator.prepareOutputJson(validationNode,
  1512. columnNode, null, ValidationTypes.EXPRESSION, null, null, null, null);
  1513. break;
  1514. case Constants.AUTOCORRECT:
  1515. /*((ObjectNode) validationNode).set("OriginalValue", dimensionNode.get(jsonNode.asText()));
  1516. ((ObjectNode) (dimensionNode)).put(jsonNode.asText(), result);
  1517. ((ObjectNode) validationNode).put("dimension", jsonNode.asText());
  1518. emailObjList.add(prepareOutputJson(validationNode, columnNode, result, ValidationTypes.expression, null,
  1519. null, null, null));*/
  1520. break;
  1521. default :
  1522. break;
  1523. }
  1524. }
  1525. break;
  1526. case Constants.REQUIRED:
  1527. /*ObjectNode requiredObjNode = new APIExpressionEvaluator().checkMandatoryFields(dataMap, code,
  1528. columnNode.get(Constants.DATA_TYPE).asText(), mappedColumnName);*/
  1529. //return new APIExpressionEvaluator().checkRequiredField(inputValue, code, columnNode.get(Constants.DATA_TYPE).asText());
  1530. if (StringUtils.isBlank(inputValue)) {
  1531. String code = null;
  1532. if (checkCode) {
  1533. code = columnNode.get(Constants.CODE).asText();
  1534. } else {
  1535. code = columnNode.get(Constants.MAPPED_COLUMN_NAME).asText();
  1536. }
  1537. errorObjNode = APIExpressionEvaluator.prepareOutputJson(validationNode, dimensionAttribute, null,
  1538. ValidationTypes.PREDEFINEDVALIDATIONS, code, inputValue, null, null);
  1539. }
  1540. break;
  1541. default:
  1542. break;
  1543. }
  1544. return errorObjNode;
  1545. }
  1546. public JsonNode preparyCompanyWiseData(JsonNode dataNode,JsonNode contextDataNode)
  1547. {
  1548. String comppany_Column=null;
  1549. String country_Column=null;
  1550. JsonNode mappedCompany=null;
  1551. JsonNode node=null;
  1552. JsonNode companyDataNode = mapper.createObjectNode();;
  1553. boolean found=false;
  1554. ArrayNode arr = mapper.createArrayNode();
  1555. HashMap<String,String> nodeMap=null;
  1556. List<HashMap<String,String>> companyList= new ArrayList<HashMap<String,String>>();
  1557. if(!JsonUtils.isNullOrBlankOrNullNode(contextDataNode))
  1558. {
  1559. if (!JsonUtils.isNullOrBlankOrNullNode(contextDataNode.get(Constants.ENTITY_NAME_COLUMN_CODE))
  1560. && JsonUtils.isStringExist(contextDataNode.get(Constants.ENTITY_NAME_COLUMN_CODE).asText())) {
  1561. comppany_Column=contextDataNode.get(Constants.ENTITY_NAME_COLUMN_CODE).asText();
  1562. if (!JsonUtils.isNullOrBlankOrNullNode(contextDataNode.get(Constants.MAPPED_COMPANY))) {
  1563. mappedCompany=contextDataNode.get(Constants.MAPPED_COMPANY);
  1564. Iterator<JsonNode> it=mappedCompany.iterator();
  1565. while(it.hasNext())
  1566. {
  1567. node=(JsonNode)it.next();
  1568. nodeMap=new HashMap<String,String>();
  1569. nodeMap.put("name",(!JsonUtils.isNullOrBlankOrNullNode(node.get("name"))? node.get("name").asText():""));
  1570. nodeMap.put(Constants.COUNTRY,(!JsonUtils.isNullOrBlankOrNullNode(node.get(Constants.COUNTRY))? node.get(Constants.COUNTRY).asText():"")); // check null poiter here
  1571. companyList.add(nodeMap);
  1572. }
  1573. }
  1574. }
  1575. if (!JsonUtils.isNullOrBlankOrNullNode(contextDataNode.get(Constants.ENTITY_COUNTRY_COLUMN_CODE))
  1576. && JsonUtils.isStringExist(contextDataNode.get(Constants.ENTITY_COUNTRY_COLUMN_CODE).asText())) {
  1577. country_Column=contextDataNode.get(Constants.ENTITY_COUNTRY_COLUMN_CODE).asText();
  1578. }
  1579. }
  1580. if(!JsonUtils.isNullOrBlankOrNullNode(dataNode) && JsonUtils.isStringExist(comppany_Column) && !JsonUtils.isNullOrBlankOrNullNode(mappedCompany))
  1581. {
  1582. for(JsonNode data:dataNode)
  1583. {
  1584. found=false;
  1585. if(!JsonUtils.isNullOrBlankOrNullNode(data.get(comppany_Column)))
  1586. {
  1587. for(HashMap<String,String> map:companyList)
  1588. {
  1589. if(!map.get(Constants.COUNTRY).equals(""))
  1590. {
  1591. if(data.get(country_Column).asText().equals(map.get(Constants.COUNTRY)) && data.get(comppany_Column).asText().equals(map.get("name")))
  1592. {
  1593. found=true;
  1594. break;
  1595. }
  1596. }
  1597. else if(data.get(comppany_Column).asText().equals(map.get("name")))
  1598. {
  1599. found=true;
  1600. break;
  1601. }
  1602. }
  1603. if(found)
  1604. {
  1605. arr.add(data);
  1606. }
  1607. }
  1608. }
  1609. ((ObjectNode) (companyDataNode)).set(Constants.DATA, arr);
  1610. }
  1611. else
  1612. {
  1613. return ((ObjectNode) (companyDataNode)).set(Constants.DATA, dataNode);
  1614. }
  1615. return companyDataNode;
  1616. }
  1617. public HashMap<String, JsonNode> updateDataMapWithEmptyDimension(HashMap<String, JsonNode> dataMap ,HashMap<String, JsonNode> dimMap)
  1618. {
  1619. JsonNode value=null;
  1620. String code="";
  1621. String key="";
  1622. if(dimMap!=null && dimMap.size()>0)
  1623. {
  1624. for (Map.Entry<String, JsonNode> entry : dimMap.entrySet())
  1625. {
  1626. code = entry.getKey();
  1627. value = entry.getValue();
  1628. for(JsonNode dim : value)
  1629. {
  1630. key=code+"."+dim.asText();
  1631. if(JsonUtils.isNullOrBlankOrNullNode(dataMap.get(key)))
  1632. {
  1633. dataMap.put(key, JsonNodeFactory.instance.nullNode());
  1634. }
  1635. }
  1636. //use key and value
  1637. }
  1638. }
  1639. return dataMap;
  1640. }
  1641. /**
  1642. *
  1643. * @param entitiesJson
  1644. * @param csvJsonString
  1645. * @param isAggregateRequest
  1646. * @param xslJsonMap
  1647. * @param firstSheetName
  1648. * @param isMultiPartRequest
  1649. * @param isEEIDMissingInAsyncL0
  1650. * @return
  1651. * @throws IOException
  1652. * @throws CustomStatusException
  1653. * @throws Exception
  1654. */
  1655. public JsonNode preparingL1Input(String entitiesJson, String csvJsonString, boolean isAggregateRequest,
  1656. Map<String, String> xslJsonMap, String firstSheetName, boolean isMultiPartRequest,Object isEEIDMissingInAsyncL0) throws IOException, CustomStatusException {
  1657. JsonNode resultNode = null;
  1658. ArrayNode entityArr = null;
  1659. Set<String> xslJsonSheets = null;
  1660. JsonNode resultEntiryNode = null;
  1661. JsonNode sectionStructureNode = null;
  1662. JsonNode dataNode = null;
  1663. JsonNode otherSecDataNode = null;
  1664. JsonNode contextDataNode = null;
  1665. JsonNode csvNode = null;
  1666. String uniqueIdColumnCode = "";
  1667. JsonNode entityNode = null;
  1668. resultNode = mapper.createObjectNode();
  1669. entityArr = mapper.createArrayNode();
  1670. Iterator<String> fieldIter=null;
  1671. ArrayNode entitiesNode = mapper.readValue(entitiesJson, ArrayNode.class);
  1672. StringBuffer coName_CtryCode = new StringBuffer();
  1673. String countryCode = null;
  1674. ArrayList<String> fieldList=new ArrayList<>();
  1675. JsonNode companyDataNode = null;
  1676. ArrayNode objNode=null;
  1677. String fieldName=null;
  1678. String code="";
  1679. String mappedCode="";
  1680. // For .xlsx data
  1681. if (xslJsonMap != null) {
  1682. xslJsonSheets = new HashSet<String>(xslJsonMap.keySet());
  1683. }
  1684. JsonNode colNode = null;
  1685. HashMap<String,String> metaDataCodes=new HashMap<>();
  1686. for (int i = 0; i < entitiesNode.size(); i++) {
  1687. countryCode = "";
  1688. entityNode = entitiesNode.get(i);
  1689. resultEntiryNode = mapper.createObjectNode();
  1690. sectionStructureNode = entityNode.get(Constants.SECTION_STRUCTURE);
  1691. dataNode = entityNode.get(Constants.DATA);
  1692. otherSecDataNode = entityNode.get(Constants.OTHERSECTIONDATAKEY);
  1693. contextDataNode = entityNode.get(Constants.CONTEXTDATAKEY);
  1694. colNode = sectionStructureNode.get(Constants.COLUMNS);
  1695. // PE: 8976 Start
  1696. for (JsonNode col : colNode) {
  1697. if (!JsonUtils.isNullOrBlankOrNullNode(col.get(Constants.MAPPED_COLUMN_NAME))) {
  1698. mappedCode = col.get(Constants.MAPPED_COLUMN_NAME).asText();
  1699. }
  1700. if (!JsonUtils.isNullOrBlankOrNullNode(col.get("code"))) {
  1701. code = col.get("code").asText();
  1702. }
  1703. if(mappedCode.length() > 0 )
  1704. {
  1705. if (!JsonUtils.isNullOrBlankOrNullNode(col.get("skip"))) {
  1706. metaDataCodes.put(mappedCode, "skipEnabled");
  1707. } else if (code.length() > 0) {
  1708. metaDataCodes.put(mappedCode, code);
  1709. }
  1710. }
  1711. }
  1712. // PE: 8976 End
  1713. // Added uniqueIdColumnCode for PE: 8315 . Following line is
  1714. // assigned for merging.
  1715. uniqueIdColumnCode = contextDataNode.get("uniqueIdColumnCode").asText();
  1716. if (!contextDataNode.isNull() && contextDataNode.has(Constants.CTRYCDOE)) {
  1717. countryCode = contextDataNode.get(Constants.CTRYCDOE).asText();
  1718. }
  1719. if (csvJsonString != null && !csvJsonString.equals("")) {
  1720. csvNode = mapper.readValue(csvJsonString, JsonNode.class);
  1721. } else if (xslJsonMap != null && xslJsonMap.size() > 0) {
  1722. coName_CtryCode.delete(0, coName_CtryCode.length());
  1723. coName_CtryCode.append(contextDataNode.get(Constants.COMPANYNAME).asText());
  1724. coName_CtryCode.append("_");
  1725. coName_CtryCode.append(countryCode);
  1726. // Default condition - Need to check usage of FirstSheetName !!
  1727. if (firstSheetName != null) {
  1728. csvNode = mapper.readValue(xslJsonMap.get(firstSheetName), JsonNode.class);
  1729. // If sheet is found
  1730. } else if (xslJsonMap.get(coName_CtryCode.toString()) != null) {
  1731. // If sheet not previously used
  1732. if (xslJsonSheets.contains(coName_CtryCode.toString())) {
  1733. csvNode = mapper.readValue(xslJsonMap.get(coName_CtryCode.toString()), JsonNode.class);
  1734. xslJsonSheets.remove(coName_CtryCode.toString());
  1735. // If sheet previously used
  1736. } else {
  1737. paramValueList = new ArrayList<String>();
  1738. paramValueList.add("" + contextDataNode.get(Constants.COMPANYNAME).asText());
  1739. paramValueList.add("" + countryCode );
  1740. throw new CustomStatusException(Constants.HTTPSTATUS_400,
  1741. Cache.getPropertyFromError(ErrorCacheConstant.ERR_034),
  1742. Cache.getPropertyFromError(ErrorCacheConstant.ERR_034 + Constants.UNDERSCORE_PARAMS),
  1743. paramValueList);
  1744. }
  1745. // If sheet not found
  1746. } else if (xslJsonMap.get(coName_CtryCode.toString()) == null) {
  1747. paramValueList = new ArrayList<String>();
  1748. paramValueList.add("" + coName_CtryCode.toString());
  1749. throw new CustomStatusException(Constants.HTTPSTATUS_400,
  1750. Cache.getPropertyFromError(ErrorCacheConstant.ERR_035),
  1751. Cache.getPropertyFromError(ErrorCacheConstant.ERR_035 + Constants.UNDERSCORE_PARAMS), paramValueList);
  1752. }
  1753. }
  1754. if (csvNode != null) {
  1755. companyDataNode = preparyCompanyWiseData(csvNode.get("data"), contextDataNode);
  1756. dataNode = findAndMerge(dataNode, (ArrayNode) companyDataNode.get("data"), uniqueIdColumnCode);
  1757. }
  1758. // L0 Validations Ends Here
  1759. // Returning Input Json for L1 Validation
  1760. // PE 8976 Start : To send column code in the L0response
  1761. if (metaDataCodes.size() > 0) {
  1762. fieldIter = dataNode.get(0).fieldNames();
  1763. while (fieldIter != null && fieldIter.hasNext()) {
  1764. fieldName = fieldIter.next();
  1765. if (null != metaDataCodes.get(fieldName) && !metaDataCodes.get(fieldName).equals("skipEnabled")) {
  1766. fieldList.add(fieldName);
  1767. }
  1768. }
  1769. if (metaDataCodes.keySet().containsAll(fieldList)) {
  1770. objNode = mapper.createArrayNode();
  1771. JsonNode node = null;
  1772. for (JsonNode data : dataNode) {
  1773. node = mapper.createObjectNode();
  1774. for (String field : fieldList) {
  1775. if (metaDataCodes.get(field) != null) {
  1776. ((ObjectNode) node).set(metaDataCodes.get(field), (data.get(field)!=null)?data.get(field):data.get(metaDataCodes.get(field)));
  1777. }
  1778. }
  1779. objNode.add(node);
  1780. }
  1781. }
  1782. }
  1783. // PE 8976 End
  1784. //PE-8933 - Starts
  1785. if (null != isEEIDMissingInAsyncL0) {
  1786. if ((boolean) isEEIDMissingInAsyncL0) {
  1787. ((ObjectNode) (contextDataNode)).put(Constants.MISSING_EEID, true);
  1788. } else {
  1789. ((ObjectNode) (contextDataNode)).put(Constants.MISSING_EEID, false);
  1790. }
  1791. ((ObjectNode) (entityNode)).set(Constants.CONTEXTDATAKEY, contextDataNode);
  1792. }
  1793. //PE-8933 - Ends
  1794. resultEntiryNode = entityNode;
  1795. if(null!=objNode && objNode.size()>0)
  1796. {
  1797. ((ObjectNode) (resultEntiryNode)).set(Constants.DATA, objNode);
  1798. }
  1799. else
  1800. {
  1801. ((ObjectNode) (resultEntiryNode)).set(Constants.DATA, dataNode);
  1802. }
  1803. entityArr.add(resultEntiryNode);
  1804. metaDataCodes.clear();
  1805. }
  1806. resultNode = mapper.createObjectNode().set(Constants.ENTITIES, entityArr);
  1807. return resultNode;
  1808. }
  1809. public JsonNode perform_L1_L2Validations(JsonNode entitiesNodeResponse, boolean isAggregateRequest,
  1810. boolean isMultiPartRequest) throws Exception {
  1811. JsonNode dataNode = null;
  1812. HashMap<String, String> columnMappingMap = null;
  1813. JsonNode sectionStructureNode = null;
  1814. HashMap<String, JsonNode> dimMap = new HashMap<String, JsonNode>();
  1815. String countryCode = null;
  1816. JsonNode otherSecDataNode = null;
  1817. JsonNode contextDataNode = null;
  1818. JsonNode resultNode = null;
  1819. JsonNode mlNode = null;
  1820. ArrayNode entityArr = null;
  1821. ArrayNode arr = null;
  1822. JsonNode entityNode = null;
  1823. JsonNode resultEntiryNode = null;
  1824. Map.Entry<String, JsonNode> entry = null;
  1825. Map.Entry<String, JsonNode> entry1 = null;
  1826. List<String> otherAndContextKeys = new ArrayList<>();
  1827. String tempArrayName = null;
  1828. entityArr = mapper.createArrayNode();
  1829. ArrayNode entitiesNode = (ArrayNode) entitiesNodeResponse.get(Constants.ENTITIES);
  1830. boolean mlAutoCoorect=false;
  1831. JsonNode mLdataNode = null;
  1832. // Making csv out of JSON single level
  1833. for (int i = 0; i < entitiesNode.size(); i++) {
  1834. //Creating a ExpressionEvalutionDriver at a request level(Per Entity (Eg. Employee section))
  1835. ExpressionEvalutionDriver expressionEvalutionDriver = new ExpressionEvalutionDriver();
  1836. logger.debug(
  1837. "perform_L1_L2Validations >> ExpressionEvalutionDriver Cache Initialized");
  1838. countryCode = "";
  1839. arr = mapper.createArrayNode();
  1840. entityNode = entitiesNode.get(i);
  1841. resultEntiryNode = mapper.createObjectNode();
  1842. sectionStructureNode = entityNode.get(Constants.SECTION_STRUCTURE);
  1843. dataNode = entityNode.get(Constants.DATA);
  1844. otherSecDataNode = entityNode.get(Constants.OTHERSECTIONDATAKEY);
  1845. contextDataNode = entityNode.get(Constants.CONTEXTDATAKEY);
  1846. // Before L1 for File upload ML Auto-correction API call will be executed.
  1847. // PE-6254 ML Integration works only for File upload case.
  1848. // Check flag from config file located in API_HOME
  1849. if ( isMultiPartRequest
  1850. && "Y".equalsIgnoreCase(Cache.getMLProperty(CacheConstats.IS_AUTOCORRECTION).trim()) ) {
  1851. mlNode = MachineLearningRestClient.callMLRestAPI(entityNode);
  1852. if( null != mlNode) {
  1853. dataNode = mlNode;
  1854. mlAutoCoorect=true;
  1855. }
  1856. }
  1857. //PE-6254 ML End.
  1858. if (null != contextDataNode && contextDataNode.has(Constants.CTRYCDOE)) {
  1859. countryCode = contextDataNode.get(Constants.CTRYCDOE).asText();
  1860. }
  1861. HashMap<String, JsonNode> dataMap = new HashMap<>();
  1862. contextAndOtherSectionDataToMap(dataMap, otherSecDataNode, contextDataNode, otherAndContextKeys, entry,
  1863. entry1, tempArrayName, isMultiPartRequest);
  1864. //PE-8552
  1865. HashMap<String, JsonNode> contextDataAndOtherDataMap = new HashMap<String, JsonNode>(dataMap);
  1866. ArrayList<JsonNode> columnNodeList = new ArrayList<JsonNode>();
  1867. columnMappingMap = new HashMap<String, String>();
  1868. APIExpressionEvaluator apiExpressionEvaluator = new APIExpressionEvaluator(expressionEvalutionDriver);
  1869. String uuid = setColumnMappingAndDataForAggregation(apiExpressionEvaluator, columnNodeList,
  1870. otherAndContextKeys, columnMappingMap, sectionStructureNode, dataMap, dimMap, dataNode,
  1871. countryCode);
  1872. // Added by Nikhil
  1873. // Start PE-7056 Expression should not executed if columns are not
  1874. // present in MetaData.
  1875. List<String> metaDataColumnsOnly = null;
  1876. metaDataColumnsOnly = DataUtility.extractColumnsFromMetaData(apiExpressionEvaluator);
  1877. if (!otherAndContextKeys.isEmpty()) {
  1878. metaDataColumnsOnly.addAll(otherAndContextKeys);
  1879. }
  1880. // End PE-7056
  1881. Iterator<Map.Entry<String, JsonNode>> iterator = null;
  1882. for (int k = 0; k < dataNode.size(); k++) {
  1883. if(mlAutoCoorect)
  1884. {
  1885. mLdataNode = dataNode.get(k);
  1886. }
  1887. iterator = dataNode.get(k).fields();
  1888. while (iterator.hasNext()) {
  1889. entry = iterator.next();
  1890. //8552
  1891. JsonNode value = JsonUtils.isNullNode(entry.getValue()) ? null : entry.getValue();
  1892. if (entry.getValue().getNodeType() != JsonNodeType.OBJECT) {
  1893. // PE-6254 ML Integration works start
  1894. if(mlAutoCoorect)
  1895. {
  1896. if(entry.getKey().trim().contains(Constants.UNDERSCORE_ACFLAG)
  1897. || entry.getKey().trim().contains(Constants.UNDERSCORE_REPLACE))
  1898. {
  1899. continue;
  1900. }
  1901. else
  1902. {
  1903. if(mLdataNode.get(entry.getKey()+Constants.UNDERSCORE_ACFLAG).asText().equalsIgnoreCase("R"))
  1904. {
  1905. dataMap.put(entry.getKey().trim(), mLdataNode.get(entry.getKey()+Constants.UNDERSCORE_REPLACE));
  1906. }
  1907. else
  1908. {
  1909. dataMap.put(entry.getKey().trim(), value);
  1910. }
  1911. }
  1912. }
  1913. // PE-6254 ML Integration works end
  1914. else
  1915. {
  1916. dataMap.put(entry.getKey().trim(), value);
  1917. }
  1918. } else {
  1919. dataMap = parseJsonObjectMap(entry.getKey(), value, dataMap, null,
  1920. mapper.valueToTree(columnNodeList), null); // PE-7605 (2)
  1921. }
  1922. }
  1923. dataMap = updateDataMapWithEmptyDimension(dataMap, dimMap);
  1924. // logger.debug(String.format("dataMap..%s", dataMap));
  1925. resultNode = validate(dataMap, columnNodeList, dataNode.get(k), apiExpressionEvaluator, false,
  1926. columnMappingMap, dimMap, metaDataColumnsOnly,mlAutoCoorect);
  1927. arr.add(resultNode);
  1928. // logger.debug(String.format("resultNode..%s", resultNode));
  1929. //tempMetaDataColumn.removeAll(dataNodeColumnsOnly);
  1930. /*if (tempMetaDataColumn != null && tempMetaDataColumn.size() > 0) {
  1931. for (String key : tempMetaDataColumn) {
  1932. dataMap.remove(key);
  1933. }
  1934. }*/
  1935. dataMap = new HashMap<String, JsonNode>(contextDataAndOtherDataMap);
  1936. }
  1937. ((ObjectNode) (resultEntiryNode)).set(Constants.DATA, arr);
  1938. if (null != contextDataNode)
  1939. ((ObjectNode) (resultEntiryNode)).set(Constants.CONTEXTDATAKEY, contextDataNode);
  1940. entityArr.add(resultEntiryNode);
  1941. // removing csv from expression evaluator
  1942. // added by Nikhil
  1943. apiExpressionEvaluator.getExpressionEvaluatorDriver().removeCsvData(uuid);
  1944. logger.debug(
  1945. "perform_L1_L2Validations >> ExpressionEvalutionDriver Cache Destroyed");
  1946. }
  1947. resultNode = mapper.createObjectNode().set(Constants.ENTITIES, entityArr);
  1948. // logger.info(String.format("%s %s", Constants.EXIT ,Constants.LOG_PARSEANDVALIDATE));
  1949. return resultNode;
  1950. }
  1951. private String setColumnMappingAndDataForAggregation(APIExpressionEvaluator apiExpressionEvaluator, ArrayList<JsonNode> columnNodeList,
  1952. List<String> otherAndContextKeys, HashMap<String, String> columnMappingMap, JsonNode sectionStructureNode,
  1953. HashMap<String, JsonNode> dataMap, HashMap<String, JsonNode> dimMap, JsonNode dataNode,
  1954. String countryCode) throws UnsupportedEncodingException, JSONException {
  1955. if (sectionStructureNode.has(Constants.COLUMNS)) {
  1956. for (int j = 0; j < sectionStructureNode.get(Constants.COLUMNS).size(); j++) {
  1957. columnNodeList.add(sectionStructureNode.get(Constants.COLUMNS).get(j));
  1958. if (!JsonUtils.isNullOrBlankOrNullNode(
  1959. sectionStructureNode.get(Constants.COLUMNS).get(j).get(Constants.MAPPED_COLUMN_NAME))
  1960. && !sectionStructureNode.get(Constants.COLUMNS).get(j).get(Constants.MAPPED_COLUMN_NAME).equals(""))
  1961. if (!JsonUtils
  1962. .isNullOrBlankOrNullNode(sectionStructureNode.get(Constants.COLUMNS).get(j).get("code")))
  1963. columnMappingMap.put(sectionStructureNode.get(Constants.COLUMNS).get(j).get("code").asText(),
  1964. sectionStructureNode.get(Constants.COLUMNS).get(j).get(Constants.MAPPED_COLUMN_NAME).asText());
  1965. }
  1966. }
  1967. if (!JsonUtils.isNullOrBlankOrNullNode(dataNode)) {
  1968. JSONArray myArr = new JSONArray(dataNode.toString());
  1969. Set<String> keyList = new HashSet<>();
  1970. for (int j = 0; j < myArr.length(); j++) {
  1971. JSONObject json = myArr.getJSONObject(j);
  1972. Iterator<String> keys = json.keys();
  1973. while (keys.hasNext()) {
  1974. keyList.add(keys.next());
  1975. }
  1976. }
  1977. logger.info("FormValidator >> setColumnMappingAndDataForAggregation() >> CSVParser.parseFile : start");
  1978. long startTImeForCSVParseFile = System.currentTimeMillis();
  1979. CSVParser.parseFile(new ByteArrayInputStream(
  1980. (JsonUtils.rowToString(new JSONArray(keyList)) + JsonUtils.toString(new JSONArray(keyList), myArr))
  1981. .toString().getBytes("UTF-8")));
  1982. logger.info("FormValidator >> setColumnMappingAndDataForAggregation() >> CSVParser.parseFile : end. Took : "
  1983. + (System.currentTimeMillis() - startTImeForCSVParseFile) + " msec");
  1984. }
  1985. // Set Column - data type mapping - PE
  1986. apiExpressionEvaluator.setColumnDataTypeMapping(new HashMap<String, String>());
  1987. APIExpressionEvaluator.df.setMaximumFractionDigits(16);
  1988. APIExpressionEvaluator.df.setMinimumFractionDigits(1);
  1989. /**
  1990. * @author Vivek Kasadwar
  1991. */
  1992. for (JsonNode columnNode : columnNodeList) {
  1993. if ((!JsonUtils.isNullOrBlankOrNullNode(columnNode.get(Constants.CODE))
  1994. && !StringUtils.isBlank(columnNode.get(Constants.CODE).asText()))
  1995. && (null != columnNode.get(Constants.DATA_TYPE))) {
  1996. apiExpressionEvaluator.getColumnDataTypeMapping().put(columnNode.get(Constants.CODE).asText(),
  1997. columnNode.get(Constants.DATA_TYPE).asText());
  1998. // PE-9734
  1999. if (columnNode.get(Constants.CODE).asText().equalsIgnoreCase(Constants.COLUMN_EMP047)) {
  2000. autoCorrectionUsingDB(dataMap, dataNode, columnNode);
  2001. }
  2002. /**
  2003. * @author Akhileshwar
  2004. * @throws Exception
  2005. * PE-7045
  2006. */
  2007. if (!JsonUtils.isNullOrBlankOrNullNode(columnNode.get(Constants.DIMENSIONS))) {
  2008. for (JsonNode dimensioNode : columnNode.get(Constants.DIMENSIONS)) {
  2009. apiExpressionEvaluator.getColumnDataTypeMapping().put(
  2010. columnNode.get(Constants.CODE).asText() + Constants.DOT + dimensioNode.asText(),
  2011. columnNode.get(Constants.DATA_TYPE).asText());
  2012. }
  2013. dimMap.put(columnNode.get(Constants.CODE).asText(), columnNode.get(Constants.DIMENSIONS));
  2014. }
  2015. }
  2016. }
  2017. HashMap<String, Object> otherParams = null;
  2018. if (!StringUtils.isEmpty(countryCode)) {
  2019. otherParams = new HashMap<String, Object>();
  2020. otherParams.put("countryCode", countryCode);
  2021. }
  2022. String uuid = apiExpressionEvaluator.getExpressionEvaluatorDriver().setCsvData(CSVParser.dataForAggregation, otherParams);
  2023. return uuid;
  2024. }
  2025. void contextAndOtherSectionDataToMap(HashMap<String, JsonNode> dataMap, JsonNode otherSecDataNode,
  2026. JsonNode contextDataNode, List<String> otherAndContextKeys, Entry<String, JsonNode> entry,
  2027. Entry<String, JsonNode> entry1, String tempArrayName, boolean isMultiPartRequest) throws Exception {
  2028. // Other Section data iterator
  2029. if (!JsonUtils.isNullOrBlankOrNullNode(otherSecDataNode) && !otherSecDataNode.toString().equals("")) {
  2030. Iterator<Map.Entry<String, JsonNode>> osdIt = otherSecDataNode.fields();
  2031. while (osdIt.hasNext()) {
  2032. entry = osdIt.next();
  2033. if (entry.getValue().getNodeType() != JsonNodeType.OBJECT) {
  2034. dataMap.put(Constants.OTHERSECTIONDATAKEY + "." + entry.getKey().trim(), entry.getValue());
  2035. // PE-7056
  2036. otherAndContextKeys.add(Constants.OTHERSECTIONDATAKEY + "." + entry.getKey().trim());
  2037. } else {
  2038. dataMap = parseJsonObjectMap(entry.getKey().trim(), entry.getValue(), dataMap,
  2039. Constants.OTHERSECTIONDATAKEY, null, otherAndContextKeys);
  2040. }
  2041. }
  2042. entry = null;
  2043. }
  2044. // Context data node iterator
  2045. // Populate dataMap with values from "contextDataNode"
  2046. if (!JsonUtils.isNullOrBlankOrNullNode(contextDataNode) && !contextDataNode.toString().equals("")) {
  2047. Iterator<Map.Entry<String, JsonNode>> contextIt = contextDataNode.fields();
  2048. while (contextIt.hasNext()) {
  2049. entry = contextIt.next();
  2050. if (entry.getValue().getNodeType() != JsonNodeType.OBJECT
  2051. && entry.getValue().getNodeType() != JsonNodeType.ARRAY) {
  2052. dataMap.put(Constants.CONTEXTDATAKEY + "." + entry.getKey().trim(), entry.getValue());
  2053. // PE-7056
  2054. otherAndContextKeys.add(Constants.CONTEXTDATAKEY + "." + entry.getKey().trim());
  2055. } else if (entry.getValue().getNodeType() == JsonNodeType.ARRAY && (entry.getValue().size() > 0)) {
  2056. Iterator<Map.Entry<String, JsonNode>> arrIt = contextDataNode.fields();
  2057. tempArrayName = entry.getKey();
  2058. // PE - 7257
  2059. if (entry.getValue().getNodeType() == JsonNodeType.ARRAY && isMultiPartRequest) {
  2060. dataMap.put(Constants.CONTEXTDATAKEY + "." + entry.getKey().trim(), entry.getValue());
  2061. // PE-7056
  2062. otherAndContextKeys.add(Constants.CONTEXTDATAKEY + "." + entry.getKey().trim());
  2063. } else {
  2064. if (entry.getValue().size() > 0) {
  2065. arrIt = entry.getValue().get(0).fields();
  2066. while (arrIt.hasNext()) {
  2067. entry1 = arrIt.next();
  2068. dataMap.put(
  2069. Constants.CONTEXTDATAKEY + "." + tempArrayName + "." + entry1.getKey().trim(),
  2070. entry1.getValue());
  2071. // PE-7056
  2072. otherAndContextKeys.add(
  2073. Constants.CONTEXTDATAKEY + "." + tempArrayName + "." + entry1.getKey().trim());
  2074. }
  2075. }
  2076. }
  2077. } else {
  2078. dataMap = parseJsonObjectMap(entry.getKey(), entry.getValue(), dataMap, Constants.CONTEXTDATAKEY,
  2079. null, otherAndContextKeys);
  2080. }
  2081. }
  2082. entry = null;
  2083. }
  2084. }
  2085. public JsonNode performValidateAggregateRequest(JsonNode entitiesNodeResponse, boolean isAggregateRequest, boolean isMultiPartRequest) throws Exception {
  2086. JsonNode dataNode = null;
  2087. HashMap<String, String> columnMappingMap = null;
  2088. JsonNode sectionStructureNode = null;
  2089. HashMap<String, JsonNode> dimMap = new HashMap<String, JsonNode>();
  2090. String countryCode = null;
  2091. JsonNode otherSecDataNode = null;
  2092. JsonNode contextDataNode = null;
  2093. JsonNode resultNode = null;
  2094. ArrayNode entityArr = null;
  2095. JsonNode entityNode = null;
  2096. JsonNode resultEntiryNode = null;
  2097. Map.Entry<String, JsonNode> entry = null;
  2098. Map.Entry<String, JsonNode> entry1 = null;
  2099. List<String> otherAndContextKeys = new ArrayList<>();
  2100. String tempArrayName = null;
  2101. entityArr = mapper.createArrayNode();
  2102. ArrayNode entitiesNode = (ArrayNode) entitiesNodeResponse.get(Constants.ENTITIES);
  2103. // Making csv out of JSON single level
  2104. for (int i = 0; i < entitiesNode.size(); i++) {
  2105. countryCode = "";
  2106. entityNode = entitiesNode.get(i);
  2107. resultEntiryNode = mapper.createObjectNode();
  2108. if (entityNode.has(Constants.SECTION_STRUCTURE)) {
  2109. sectionStructureNode = entityNode.get(Constants.SECTION_STRUCTURE);
  2110. }
  2111. if (entityNode.has(Constants.DATA)) {
  2112. dataNode = entityNode.get(Constants.DATA);
  2113. }
  2114. if (entityNode.has(Constants.OTHERSECTIONDATAKEY)) {
  2115. otherSecDataNode = entityNode.get(Constants.OTHERSECTIONDATAKEY);
  2116. }
  2117. if (entityNode.has(Constants.CONTEXTDATAKEY)) {
  2118. contextDataNode = entityNode.get(Constants.CONTEXTDATAKEY);
  2119. }
  2120. if (null != contextDataNode && contextDataNode.has(Constants.CTRYCDOE)) {
  2121. countryCode = contextDataNode.get(Constants.CTRYCDOE).asText();
  2122. }
  2123. HashMap<String, JsonNode> dataMap = new HashMap<>();
  2124. contextAndOtherSectionDataToMap(dataMap, otherSecDataNode, contextDataNode, otherAndContextKeys, entry,
  2125. entry1, tempArrayName, isMultiPartRequest);
  2126. ArrayList<JsonNode> columnNodeList = new ArrayList<JsonNode>();
  2127. columnMappingMap = new HashMap<>();
  2128. //Creating a ExpressionEvalutionDriver at a request level(Per Entity (Eg. Employee section))
  2129. ExpressionEvalutionDriver expressionEvalutionDriver = new ExpressionEvalutionDriver();
  2130. logger.debug("performValidateAggregateRequest >> expressionEvalutionDriver Cache : {}",
  2131. expressionEvalutionDriver.getAggregateFunctionCache());
  2132. APIExpressionEvaluator apiExpressionEvaluator = new APIExpressionEvaluator(expressionEvalutionDriver);
  2133. String uuid = setColumnMappingAndDataForAggregation(apiExpressionEvaluator, columnNodeList,
  2134. otherAndContextKeys, columnMappingMap, sectionStructureNode, dataMap, dimMap, dataNode,
  2135. countryCode);
  2136. // Added by Nikhil
  2137. // Start PE-7056 Expression should not executed if columns are not
  2138. // present in MetaData.
  2139. List<String> metaDataColumnsOnly = null;
  2140. metaDataColumnsOnly = DataUtility.extractColumnsFromMetaData(apiExpressionEvaluator);
  2141. if (!otherAndContextKeys.isEmpty()) {
  2142. metaDataColumnsOnly.addAll(otherAndContextKeys);
  2143. }
  2144. // End PE-7056
  2145. // PE : 2449 to update datamap with entity data which was
  2146. // missing in case of aggregate
  2147. Iterator<Map.Entry<String, JsonNode>> iterator = null;
  2148. if(dataNode.isArray() && dataNode.size()!=0) { // Remove NullPointer when there is no object in data-node.
  2149. iterator = dataNode.get(0).fields();
  2150. while (iterator.hasNext()) {
  2151. entry = iterator.next();
  2152. JsonNode value = JsonUtils.isNullNode(entry.getValue()) ? null : entry.getValue();
  2153. if (entry.getValue().getNodeType() != JsonNodeType.OBJECT) {
  2154. dataMap.put(entry.getKey().trim(), value);
  2155. } else {
  2156. dataMap = parseJsonObjectMap(entry.getKey(), value, dataMap, null, null, null);
  2157. }
  2158. }
  2159. }
  2160. resultNode = validate(dataMap, columnNodeList, dataNode.get(0), apiExpressionEvaluator, true,
  2161. columnMappingMap, dimMap, metaDataColumnsOnly,false);
  2162. ((ObjectNode) (resultEntiryNode)).set(Constants.VALIDATION_RESULTS, resultNode);
  2163. if (null != contextDataNode)
  2164. ((ObjectNode) (resultEntiryNode)).set(Constants.CONTEXTDATAKEY, contextDataNode);
  2165. entityArr.add(resultEntiryNode);
  2166. apiExpressionEvaluator.getExpressionEvaluatorDriver().removeCsvData(uuid);
  2167. }
  2168. resultNode = mapper.createObjectNode().set(Constants.ENTITIES, entityArr);
  2169. // logger.info(String.format("%s %s", Constants.EXIT ,Constants.LOG_PARSEANDVALIDATE));
  2170. return resultNode;
  2171. }
  2172. // PE-6254 ML Integration works start
  2173. public ObjectNode prepareMLAutocorrectObject(String field,String validationType,JsonNode originalvalue)
  2174. {
  2175. ObjectNode validation = mapper.createObjectNode();
  2176. validation.put(Constants.FIELD, field);
  2177. validation.put(Constants.ERROR_TYPE, Constants.AUTOCORRECT);
  2178. // validation.put(Constants.MESSAGE, result);
  2179. validation.put(Constants.MESSAGE_KEY,
  2180. in.lnt.utility.general.Cache.getPropertyFromError(ErrorCacheConstant.ERR_059));
  2181. if(!JsonUtils.isNullOrBlankOrNullNode((originalvalue)))
  2182. validation.put(Constants.ORIGINAL_VALUE,originalvalue.asText());
  2183. else
  2184. validation.put(Constants.ORIGINAL_VALUE,"");
  2185. return validation;
  2186. }
  2187. public void removeDataNodeACFields(JsonNode dataNode)
  2188. {
  2189. Iterator<Map.Entry<String, JsonNode>> iterator = null;
  2190. iterator = dataNode.fields();
  2191. //dataNode.
  2192. List<String> fieldsToDelete=new ArrayList<String>();
  2193. Map.Entry<String, JsonNode> entry = null;
  2194. while (iterator.hasNext()) {
  2195. entry = iterator.next();
  2196. if(entry.getKey().trim().contains(Constants.UNDERSCORE_ACFLAG) || entry.getKey().trim().contains(Constants.UNDERSCORE_REPLACE))
  2197. {}
  2198. else{
  2199. fieldsToDelete.add(entry.getKey());
  2200. }
  2201. }
  2202. ((ObjectNode)dataNode).retain(fieldsToDelete);
  2203. }
  2204. // PE-6254 ML Integration works end
  2205. /**
  2206. * @param dataMap
  2207. * @param dataNode
  2208. * @param columnNode
  2209. * @return
  2210. */
  2211. // PE-9734
  2212. public void autoCorrectionUsingDB(Map<String, JsonNode> dataMap, JsonNode dataNode, JsonNode columnNode) {
  2213. String replacedOption = null;
  2214. String originalValue = null;
  2215. StringBuilder runTimeQuery = new StringBuilder();
  2216. for (JsonNode node : dataNode) {
  2217. runTimeQuery.setLength(0);
  2218. runTimeQuery = new StringBuilder(" SELECT REPLACEMENT FROM region_lookup WHERE \"MATCH\" = ");
  2219. runTimeQuery.append("'");
  2220. if (!JsonUtils.isNullOrBlankOrNullNode(node.get(Constants.COLUMN_EMP047))) {
  2221. originalValue = node.get(Constants.COLUMN_EMP047).asText();
  2222. runTimeQuery.append(originalValue);
  2223. } else {
  2224. continue;
  2225. }
  2226. runTimeQuery.append("'");
  2227. if (!JsonUtils.isNullOrBlankOrNullNode(dataMap.get(Constants.COTEXT_COUNTRY_CODE))) {
  2228. runTimeQuery.append(" AND CTX_CTRY_CODE = ");
  2229. runTimeQuery.append("'");
  2230. runTimeQuery.append(dataMap.get(Constants.COTEXT_COUNTRY_CODE).asText());
  2231. runTimeQuery.append("'");
  2232. }
  2233. try {
  2234. replacedOption = DBUtils.getDataFromDerbyTable(runTimeQuery.toString());
  2235. } catch (SQLException ex) {
  2236. logger.error("Exception occured in getRangeDetails..{}", ex);
  2237. replacedOption = null;
  2238. }
  2239. if (null != replacedOption && !StringUtils.equalsIgnoreCase(replacedOption, originalValue)) {
  2240. ((ObjectNode) node).put(Constants.COLUMN_EMP047 + Constants.UNDERSCORE_REPLACE,
  2241. FormValidator_CSC.getOptionFromDropDown(columnNode, replacedOption));
  2242. ((ObjectNode) node).put(Constants.COLUMN_EMP047 + Constants.UNDERSCORE_ACFLAG, "R");
  2243. } else {
  2244. ((ObjectNode) node).put(Constants.COLUMN_EMP047 + Constants.UNDERSCORE_REPLACE, originalValue);
  2245. ((ObjectNode) node).put(Constants.COLUMN_EMP047 + Constants.UNDERSCORE_ACFLAG, "O");
  2246. }
  2247. }
  2248. }
  2249. }