/MercerPoC/src/in/lnt/validations/FormValidator.java
Java | 2381 lines | 1859 code | 207 blank | 315 comment | 640 complexity | 17eeaa7c46418656d542ba51425f132e MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- package in.lnt.validations;
-
- import java.io.ByteArrayInputStream;
- import java.io.IOException;
- import java.io.UnsupportedEncodingException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.Iterator;
- import java.util.LinkedHashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Map.Entry;
- import java.util.Set;
- import java.util.UUID;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
-
- import org.apache.commons.lang3.EnumUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
-
- import com.fasterxml.jackson.core.JsonParseException;
- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.fasterxml.jackson.databind.JsonMappingException;
- import com.fasterxml.jackson.databind.JsonNode;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.fasterxml.jackson.databind.node.ArrayNode;
- import com.fasterxml.jackson.databind.node.JsonNodeFactory;
- import com.fasterxml.jackson.databind.node.JsonNodeType;
- import com.fasterxml.jackson.databind.node.NullNode;
- import com.fasterxml.jackson.databind.node.ObjectNode;
- import com.lti.mosaic.function.def.InversionAndRangeCheckFunctions;
- import com.lti.mosaic.parser.utils.ExpressionBuilderConstants;
- import com.mongodb.util.JSON;
- import com.rabbitmq.tools.json.JSONUtil;
-
- import in.lnt.constants.Constants;
- import in.lnt.enums.ValidationTypes;
- import in.lnt.exceptions.CustomStatusException;
- import in.lnt.ml.MachineLearningRestClient;
- import in.lnt.parser.CSVParser;
- import in.lnt.utility.constants.CacheConstats;
- import in.lnt.utility.constants.ErrorCacheConstant;
- import in.lnt.utility.general.Cache;
- import in.lnt.utility.general.DataUtility;
- import in.lnt.utility.general.JsonUtils;
- import in.lnt.validations.evaluator.APIExpressionEvaluator;
- import in.lti.mosaic.api.mongo.MongoObject;
- import in.lti.mosaic.api.mongo.MongoThread;
-
- public class FormValidator {
- private static final Logger logger = LoggerFactory.getLogger(FormValidator.class);
- static ObjectMapper mapper = new ObjectMapper();
- ArrayList<String> paramValueList=null;
- static Pattern VALID_EMAIL_ADDRESS_REGEX =
- Pattern.compile("^(.+)@(.+)$", Pattern.CASE_INSENSITIVE);
- static Pattern VALID_PHONE_NUMBER_REGEX =
- Pattern.compile("^(\\(?\\+?[0-9]*\\)?)?[0-9_\\- \\(\\)]*$", Pattern.CASE_INSENSITIVE);
- // ^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$
-
- private static String MONGODB_ARCHIVE_FLAG = Cache
- .getMLProperty(in.lnt.utility.constants.CacheConstats.MONGODUMP_FLAG);
-
- public JsonNode parseAndValidate(String entitiesJson, String csvJsonString, boolean isAggregateRequest,
- HashMap<String, String> xslJsonMap, String firstSheetName, boolean isMultiPartRequest) throws Exception {
- // logger.info(String.format("%s %s", Constants.INTIATE ,Constants.LOG_PARSEANDVALIDATE));
- JsonNode resultNode = null;
-
- //Generating UUID for a Request and Response
- final String uuid = UUID.randomUUID().toString().replace("-", "");
-
- JsonNode entitiesNodeResponse = preparingL1Input(entitiesJson, csvJsonString, isAggregateRequest, xslJsonMap,
- firstSheetName, isMultiPartRequest, null);
-
- //Adding Request into MongoDB
- dumpToMongo(uuid, mapper.writeValueAsString(entitiesNodeResponse), Constants.REQUEST);
-
- if (isAggregateRequest) {
- resultNode = performValidateAggregateRequest(entitiesNodeResponse, isAggregateRequest, isMultiPartRequest);
- } else
- resultNode = perform_L1_L2Validations(entitiesNodeResponse, isAggregateRequest, isMultiPartRequest);
-
- //Adding Response into MongoDB
- dumpToMongo(uuid, mapper.writeValueAsString(resultNode), Constants.RESPONSE);
-
- return resultNode;
- }
-
- /**
- * @param uuid
- * @param data
- * @throws JsonProcessingException
- * @author Vivek Kasadwar
- */
- public static void dumpToMongo(final String uuid, String data,String type){
- if (StringUtils.equals(MONGODB_ARCHIVE_FLAG,Constants.YES)) {
- MongoObject mongoObject = new MongoObject();
- mongoObject.setRequestId(uuid);
- mongoObject.setObjectType(type);
- mongoObject.setObjectJson(data);
- mongoObject.setTimeStamp(Calendar.getInstance().getTime());
- MongoThread.addToQueue(mongoObject);
- }
- }
-
- public HashMap<String, JsonNode> parseJsonObjectMap(String key, JsonNode value, HashMap<String, JsonNode> map,
- String datakey, JsonNode columnListJson,List<String> otherAndContextKeys) throws Exception { // PE-7056
- Iterator<Map.Entry<String, JsonNode>> it = value.fields();
- Map.Entry<String, JsonNode> entry = null;
- try {
- while (it.hasNext()) {
- entry = it.next();
- if (entry.getValue().getNodeType() != JsonNodeType.OBJECT) {
- if (datakey != null) {
- map.put((datakey + "." + key + "." + entry.getKey()).trim(), entry.getValue());
- if(otherAndContextKeys!=null)
- otherAndContextKeys.add((datakey + "." + key + "." + entry.getKey()).trim());
- // addDimensionsInDatamap(datakey+"."+key, map, columnListJson);
- } else {
- map.put((key + "." + entry.getKey()).trim(), entry.getValue());
- if(otherAndContextKeys!=null)
- otherAndContextKeys.add((key + "." + entry.getKey()).trim());
- //addDimensionsInDatamap(key, map, columnListJson); // TODO Take this outside while.
- }
- } else {
- parseJsonObjectMap(key + "." + entry.getKey(), entry.getValue(), map, datakey, columnListJson,otherAndContextKeys);
- }
- }
- } finally {
- if(null!=it) it=null;
- if(null!=entry) entry=null;
- }
- return map;
- }
-
- /*
- * PE-7506 Populate all undefined dimensions to null.
- */
- /*public static HashMap<String, JsonNode> addDimensionsInDatamap(String key, HashMap<String, JsonNode> map, JsonNode columnListJson) {
- ArrayNode dimensionArray = null;
- if(null!=columnListJson) {
- for(int i=0; i<columnListJson.size(); i++) {
-
- if(!JsonUtils.isNullOrBlankOrNullNode(columnListJson.get(i).get(Constants.CODE))) {
- if(key.equals(columnListJson.get(i).get(Constants.CODE).asText())) {
-
- if(!JsonUtils.isNullOrBlankOrNullNode(columnListJson.get(i).get(Constants.DIMENSIONS))) {
- dimensionArray = (ArrayNode) columnListJson.get(i).get(Constants.DIMENSIONS);
- for(int j = 0; j<dimensionArray.size(); j++) {
- if(!JsonUtils.isNullOrBlankOrNullNode(dimensionArray.get(j))) {
- String key_dimension = dimensionArray.get(j).asText();
- if(!map.containsKey((key+"."+key_dimension).trim())) {
- map.put((key+"."+key_dimension).trim(), null);
- }
- key_dimension = null;
- }
- }
- dimensionArray = null;
- break;
- }
- }
- }
- }
- }
- return map;
- }*/
-
- public JsonNode validate(HashMap<String, JsonNode> dataMap, ArrayList<JsonNode> columnNodeList, JsonNode dataNode,
- APIExpressionEvaluator apiExpressionEvaluator, boolean isAggregateRequest,
- HashMap<String, String> columnMappingMap,HashMap<String, JsonNode> dimMap, List<String> metaDataColumnsOnly,
- boolean mlAutoCoorect) throws Exception {
- //logger.info(String.format("%s %s", Constants.INTIATE ,Constants.LOG_VALIDATE));
- JsonNode validationNode = null;
- ObjectNode obj = null;
- ArrayList<ObjectNode> predefinedObjList = null;
- List<ObjectNode> rangeOrSeqObjList = null;
- String code = null;
- String mappedColumnName = null;
- ArrayNode arr = null;
- JsonNode nodeDTObject = null;
- JsonNode dnCodeObject = null;
- Boolean flag = null;
- String result = null;
- String skip = null;
- JsonNode validationObjNode = null;
- ObjectNode jobInversionObjNode = null;
- ArrayNode jobInversionArr = null;
- // PE-5643 by default true because for true type do not fire validations.
- boolean isOptionType = true;
- String countryCode = null;
- String __COMPENSATION = null;
- String jobInvParameter = null;
-
- // PE-5691
- boolean isEmtpyRecord = false;
-
- // PE - 7257
- ArrayNode datePatternArray = null;
- ArrayNode numberPatternArray = null;
- String columnName = null;
- JsonNode tempOriginalValue = null;
- // 8421 code changes.
- Map<String, String> incorrectDataType = new HashMap<>();
- JsonNode questionType = null; // Added for 8916 Remove %
- String dataType = null;
- if (columnNodeList != null && columnNodeList.size() > 0) {
- arr = mapper.createArrayNode();
- if (!JsonUtils.isNullOrBlankOrNullNode(dataMap.get(Constants.CONTEXTDATAKEY+Constants.CONTEXTDATA_DATEFORMAT))){
- datePatternArray = (ArrayNode)dataMap.get(Constants.CONTEXTDATAKEY+Constants.CONTEXTDATA_DATEFORMAT);
- }if (!JsonUtils.isNullOrBlankOrNullNode(dataMap.get(Constants.CONTEXTDATAKEY+Constants.CONTEXTDATA_NUMBERFORMAT))){
- numberPatternArray = (ArrayNode)dataMap.get(Constants.CONTEXTDATAKEY+Constants.CONTEXTDATA_NUMBERFORMAT);
- }
-
- // If request is AggregateRequest
- // L3A - Inversion/Aggregate Request Starts Here
- if (isAggregateRequest) {
- // PE - 7257
- for (JsonNode node : columnNodeList) {
- if (node.get(Constants.VALIDATIONS) != null && node.get(Constants.VALIDATIONS).size() > 0) {
-
- for (int i = 0; i < node.get(Constants.VALIDATIONS).size(); i++) {
-
- validationNode = node.get(Constants.VALIDATIONS).get(i);
-
- // For Inversion
- obj = apiExpressionEvaluator.expressionEvaluator(dataMap, validationNode, node,
- dataNode,isAggregateRequest, columnMappingMap, columnNodeList, metaDataColumnsOnly);
- if (obj != null) {
- arr.add(obj);
- obj = null;
- }
- }
- }
- }
-
- // PE-4843 Append JobInversion Object
-
- //logger.info("Before calling JobInversion.jobInversion()...");
-
- InversionAndRangeCheckFunctions invAndRangeChkFuncObj
- = new InversionAndRangeCheckFunctions(CSVParser.dataForAggregation, apiExpressionEvaluator.getExpressionEvaluatorDriver().getOtherData());
- Map<String, Object> requestMap = invAndRangeChkFuncObj.jobInversion(); // Changed by Nikhil
-
- if (requestMap.containsKey(ExpressionBuilderConstants.CONST_INVERSION_JSON_ARRAY)
- && null != requestMap.get(ExpressionBuilderConstants.CONST_INVERSION_JSON_ARRAY)) {
- jobInversionArr = (ArrayNode) mapper.readTree(
- requestMap.get(ExpressionBuilderConstants.CONST_INVERSION_JSON_ARRAY).toString());
- }
-
- if(requestMap.containsKey(ExpressionBuilderConstants.CONST_COUNTRYCODE)
- && null!=requestMap.get(ExpressionBuilderConstants.CONST_COUNTRYCODE)) {
- countryCode = requestMap.get(ExpressionBuilderConstants.CONST_COUNTRYCODE).toString();
- }
-
- if(requestMap.containsKey(ExpressionBuilderConstants.CONST___COMPENSATION)
- && null!=requestMap.get(ExpressionBuilderConstants.CONST___COMPENSATION)) {
- __COMPENSATION = requestMap.get(ExpressionBuilderConstants.CONST___COMPENSATION).toString();
-
- if(__COMPENSATION.equals(ExpressionBuilderConstants.SALARY_TYPE_TOTAL_GUARANTEED_CASH)) {
- __COMPENSATION = ExpressionBuilderConstants.COL_TOTAL_GUARANTEED_CASH;
- jobInvParameter = ExpressionBuilderConstants.SALARY_TYPE_MSG_TOTAL_GUARANTEED_CASH;
- } else {
- __COMPENSATION = ExpressionBuilderConstants.COL_ANNUAL_BASE;
- jobInvParameter = ExpressionBuilderConstants.SALARY_TYPE_MSG_REGULAR;
- }
- }
-
- logger.info("Creating JobInversion object...");
- jobInversionObjNode = mapper.createObjectNode();
- jobInversionObjNode.put(Constants.ERROR_GROUP, Constants.PERSONAL);
- jobInversionObjNode.put(Constants.ERROR_TYPE, Constants.ERROR);
- jobInversionObjNode.put(Constants.VALIDATION_TYPE, Constants.EXPRESSION);
- jobInversionObjNode.put(Constants.MESSAGE, Constants.JOB_INVERSION_ERRORS);
- jobInversionObjNode.put(Constants.FIELD, __COMPENSATION);
- jobInversionObjNode.put(Constants.CATEGORY, Constants.JOB_INVERSION);
- jobInversionObjNode.put(Constants.PARAMETER, jobInvParameter);
-
- jobInversionObjNode.putArray(Constants.DATA).addAll(jobInversionArr);
-
- arr.add(jobInversionObjNode);
-
- JsonNode objectNode = mapper.convertValue(arr, JsonNode.class);
- return objectNode;
- }
-
- // L3A - Inversion/Aggregate Request Ends Here
-
- for (JsonNode node : columnNodeList) {
- isEmtpyRecord=false;
- if (node.get(Constants.CODE) != null)
- code = node.get(Constants.CODE).asText();
- if (node.get(Constants.SKIP) != null)
- skip = node.get(Constants.SKIP).asText();
- if (node.get(Constants.MAPPED_COLUMN_NAME) != null)
- mappedColumnName = node.get(Constants.MAPPED_COLUMN_NAME).asText();
-
- if ( dataNode != null || (dataNode!=null && dataNode.get(mappedColumnName) != null)) {
-
- //Following code written for Mercer JIRA Story PE-5691
-
- if(skip==null ) {
- if(code !=null && mappedColumnName!=null && JsonUtils.isNullOrBlankOrNullNode(dataNode.get(code))
- && JsonUtils.isNullOrBlankOrNullNode(dataNode.get(mappedColumnName)))
- {
- //((ObjectNode)dataNode).put(code, JsonNodeFactory.instance.nullNode()) ;
- isEmtpyRecord = true;
- }
- if(code !=null && mappedColumnName ==null && JsonUtils.isNullOrBlankOrNullNode(dataNode.get(code)) )
- {
- isEmtpyRecord = true;
- }
- if(mappedColumnName !=null && code==null &&JsonUtils.isNullOrBlankOrNullNode(dataNode.get(mappedColumnName)))
- {
- isEmtpyRecord = true;
- }
- if(isEmtpyRecord)
- {
- ((ObjectNode)dataNode).set(code, JsonNodeFactory.instance.nullNode()) ;
- }
- // Modified to prepare datamap correctly in case of Dimensions in datanode
- // if(isEmtpyRecord) // Code is reverting the ML values to original value. Commenting as per discussed with Jwala
- // {
- // it = dataNode.fields();
- // while (it.hasNext()) {
- // entry = it.next();
- // if (entry.getValue().getNodeType() != JsonNodeType.OBJECT) {
- // dataMap.put(entry.getKey().trim(), entry.getValue());
- // } else {
- // dataMap = parseJsonObjectMap(entry.getKey(), entry.getValue(), dataMap, null, null,null);
- // }
- // }
- // }
-
- }
- //PE-5691 End.
- flag = false;
- if ((mappedColumnName != null && dataNode.get(mappedColumnName) != null)
- && (null != code && mappedColumnName != null && !code.equals(mappedColumnName))) {
- // Changing logic
- ((ObjectNode) (dataNode)).set(code, dataMap.get(mappedColumnName));
- ((ObjectNode) (dataNode)).remove(mappedColumnName);
- }
- if (skip != null && (skip.equals("true") || Boolean.parseBoolean(skip) == true)) {
- if (code != null && !code.equals(""))
- ((ObjectNode) (dataNode)).remove(code);
- else
- ((ObjectNode) (dataNode)).remove(mappedColumnName);
- skip = null;
- continue;
- }
- // Validate the data type object block starts here.
- if(null != node.get(Constants.DATA_TYPE)){
- dataType = node.get(Constants.DATA_TYPE).asText();
- }
- if (dataType != null) {
- logger.info("Check if dataType is not empty");
- nodeDTObject = node.get(Constants.DATA_TYPE);
- if (dataNode.get(code) != null)
- dnCodeObject = dataNode.get(code);
- else if (dataNode.get(mappedColumnName) != null)
- dnCodeObject = dataNode.get(mappedColumnName);
-
- validationObjNode = node.get(Constants.VALIDATIONS);
-
- if ( StringUtils.isEmpty(mappedColumnName)) {
- columnName = code;
- }else {
- columnName = mappedColumnName;
- }
- //Added for 8916 Remove %
- questionType = node.get(Constants.QUESTION_TYPE);
- if(!JsonUtils.isNullOrBlankOrNullNode(questionType) && questionType.asText().equals(Constants.PERCENTAGE)){
- if (null != dataMap && !JsonUtils.isNullOrBlankOrNullNode(dataMap.get(columnName)) && dataNode.get(columnName) != null) {
- String percentageValue = dataMap.get(columnName).asText().trim();
- if(!percentageValue.isEmpty() && percentageValue.endsWith("%")){
- percentageValue = percentageValue.substring(0, percentageValue.length()-1);
- dataMap.put(columnName, mapper.readTree(percentageValue));
- ((ObjectNode) dataNode).put(code, mapper.readTree(percentageValue));
- dnCodeObject = dataNode.get(columnName);
- }
- }
- }
- // If data node is not empty then do data type validation
- if (!isAggregateRequest && !JsonUtils.isNullOrBlankOrNullNode(dnCodeObject)
- && !isEmtpyRecord && !StringUtils.isEmpty(dnCodeObject.asText().trim())) { //PE-9268
- //8421 code changes.
- incorrectDataType = dataTypeCheck(dataMap, dataNode, columnName, nodeDTObject, dnCodeObject, flag,
- datePatternArray, numberPatternArray);
- flag = Boolean.parseBoolean(incorrectDataType.get("dataTypeFlag"));
- } else {
- flag = true;
- }
- } else { // if data node is empty then skip data type validations.
- flag = true;
- }
-
- //PE -5216 and PE-5643 Check for drop down options exist in metadata or in database.
- // PE-5643 : Required this functionality at /uploadMulttipleFile also. (Mentioned by Alex)
- if (questionType != null
- && ( questionType.asText().equals(Constants.DROPDOWN) ||
- questionType.asText().equals(Constants.RADIO_BUTTONS) )) {
- //logger.info(String.format("Question type is..%s", node.get("questionType").asText()));
-
- // PE-8070 Clear & Prepare outputJson for dimensions
- if( !JsonUtils.isNullOrBlankOrNullNode(dataNode.get(code)) && dataNode.get(code).getNodeType()==JsonNodeType.OBJECT) {
- Iterator<String> iter = dataNode.get(code).fieldNames();
- String dimensionKey = null;
- while(null!=iter && iter.hasNext() ) {
- dimensionKey = iter.next();
- isOptionType = FormValidator_CSC.checkAnswerExists(node, dataNode.get(code).get(dimensionKey));
-
- // TODO Further task (Make it a function)
- if ( ! isOptionType ) {
-
- // PE-8397
- // // Implementation start PE : 5643
- // // Clear the value anyways if checkAnswerExists==false
- // ((ObjectNode) (dataNode.get(code))).put(dimensionKey, "");
- // // Implementation end PE : 5643
-
- // Generate error for dimension in format : Question1.Dimension1
- obj = apiExpressionEvaluator.prepareOutputJson(null, null, null, ValidationTypes.dropDown,
- code+"."+dimensionKey, null, null,node.has("displayLabel") ? node.get("displayLabel").asText() : null);
- }
- if (obj != null) {
- arr.add(obj);
- obj = null;
- }
- }
-
- // Clear & Prepare outputJson for non-dimensional questions (ie. simple values)
- } else {
- // PE-6254 ML Integration works start
- if(mlAutoCoorect )
- {
- isOptionType = FormValidator_CSC.checkAnswerExists(node, dataMap.get(code));
- }
- else
- {
- isOptionType = FormValidator_CSC.checkAnswerExists(node, dataNode.get(code));
- }
-
- // PE-6254 ML Integration works end
- if ( ! isOptionType ) {
-
- // PE-8397
- // // Implementation start PE : 5643
- // // Clear the value anyways if checkAnswerExists==false
- // ((ObjectNode) (dataNode)).put(code, "");
-
- obj = apiExpressionEvaluator.prepareOutputJson(null, null, null, ValidationTypes.dropDown,
- code, null, null,JsonUtils.isNullOrBlankOrNullNode(node.get("displayLabel"))? "":node.get("displayLabel").asText() );
- }
-
- if (obj != null) {
- arr.add(obj);
- obj = null;
- }
- // PE-6254 ML Integration works start
- /*if(mlAutoCoorect && !isAggregateRequest)
- {
- if(!JsonUtils.isNullOrBlankOrNullNode(dataNode.get(code+"_ACflag")) && dataNode.get(code+"_ACflag").asText().equalsIgnoreCase("R"))
- {
- arr.add(prepareMLAutocorrectObject(code,"validationType",tempOriginalValue));
- ((ObjectNode) (dataNode)).put(code,dataMap.get(code).asText());
- }
- }*/
- // PE-6254 ML Integration works end
- }
- }
- tempOriginalValue = dataNode.get(code);
- if(mlAutoCoorect && !isAggregateRequest)
- {
- if(!JsonUtils.isNullOrBlankOrNullNode(dataNode.get(code+"_ACflag")) && dataNode.get(code+"_ACflag").asText().equalsIgnoreCase("R"))
- {
- arr.add(prepareMLAutocorrectObject(code,"validationType",tempOriginalValue));
- if( !JsonUtils.isNullOrBlankOrNullNode(dataMap.get(code)) ) { // Handled NullPointerExc
- ((ObjectNode) (dataNode)).put(code,dataMap.get(code).asText());
- } else {
- ((ObjectNode) (dataNode)).putNull(code);
- }
- }
- }
-
- if (node.get(Constants.VALIDATIONS) != null && node.get(Constants.VALIDATIONS).size() > 0
- && flag) { // Aggregate
- for (int i = 0; i < node.get(Constants.VALIDATIONS).size(); i++) {
-
- validationNode = node.get(Constants.VALIDATIONS).get(i);
- if (validationNode.get(Constants.VALIDATION_TYPE) != null
- && EnumUtils.isValidEnum(ValidationTypes.class,
- validationNode.get(Constants.VALIDATION_TYPE).asText())) {
-
- switch (ValidationTypes.valueOf(validationNode.get(Constants.VALIDATION_TYPE).asText())) {
- case required:
- // PE - 7241
- predefinedObjList = validatePredefinedValidation(dataNode,node,validationNode,dataMap,mappedColumnName,Constants.REQUIRED);
- break;
- case oneOf:
- obj = apiExpressionEvaluator.checkValidationTypeOneOf(dataMap, code, node,
- validationNode, mappedColumnName);
- break;
- case range:
- rangeOrSeqObjList = apiExpressionEvaluator.prepareRangeObject(dataMap, validationNode, node,
- dataNode);
- break;
- case rangeValidationRefTable:
- rangeOrSeqObjList = apiExpressionEvaluator.prepareRefernceRangeObject(dataMap, validationNode,
- node, dataNode);
- break;
- case eligibility:
- // Last Parameter is weather request of MDA
- arr.addAll(apiExpressionEvaluator.checkValidity(dataMap, validationNode, node,
- dataNode,false,metaDataColumnsOnly));
- break;
- case phone:
- // PE - 7241
- predefinedObjList = validatePredefinedValidation(dataNode,node,validationNode,null,mappedColumnName,Constants.PHONE);
- break;
- case email:
- // PE - 7241
- predefinedObjList = validatePredefinedValidation(dataNode,node,validationNode,null,mappedColumnName,Constants.EMAIL);
- break;
- case expression:
- obj = apiExpressionEvaluator.expressionEvaluator(dataMap, validationNode, node, dataNode,
- isAggregateRequest, columnMappingMap, columnNodeList, metaDataColumnsOnly);
- //logger.info(String.format("obj..%s", obj));
- break;
-
- /**
- * @author Akhileshwar
- * PE-7045
- **/
- case sequentialCheck://PE-7989 metaDataColumnsOnly added in method signature
- rangeOrSeqObjList = apiExpressionEvaluator.performSequentialCheck(dataMap, validationNode, node,
- dataNode, dimMap,apiExpressionEvaluator.getColumnDataTypeMapping(), true, metaDataColumnsOnly);
- break;
- default:
- }
- }else {
- result = Constants.MANDATORY_VALIDATIONTYPE;
- obj = apiExpressionEvaluator.prepareOutputJson(null, null, result, null, null, null,
- null, null);
- }
- if (obj != null) {
- arr.add(obj);
- obj = null;
- }
- if(rangeOrSeqObjList!=null)
- {
- for(int j=0;j<rangeOrSeqObjList.size();j++)
- {
- arr.add(rangeOrSeqObjList.get(j));
- }
- rangeOrSeqObjList=null;
- }
- if((null != predefinedObjList) && (predefinedObjList.size() > 0)){
- arr.addAll(predefinedObjList);
- predefinedObjList = null;
- }
- }
- } else if (!isAggregateRequest && flag == false) {
- logger.info("Check if flag is false");
- //8421 code changes.
- if(null != dataType && !incorrectDataType.containsKey(dataType)){
- if(Constants.INT.equals(dataType)){
- result = Cache.getPropertyFromError(ErrorCacheConstant.ERR_061);
- }else if(Constants.DOUBLE.equals(dataType)){
- result = Cache.getPropertyFromError(ErrorCacheConstant.ERR_062);
- }else if(Constants.DATE.equals(dataType)){
- result = Cache.getPropertyFromError(ErrorCacheConstant.ERR_063);
- }else{
- //result = Constants.INVALID_DATATYPE_FOR_ERROR;
- result = Cache.getPropertyFromError(ErrorCacheConstant.ERR_043);
- }
- }
-
- if (null != nodeDTObject && null != dnCodeObject) {
- obj = apiExpressionEvaluator.prepareOutputJson(validationObjNode, node, result,
- ValidationTypes.dataTypeError, dnCodeObject.asText(), nodeDTObject.asText(),
- nodeDTObject.asText(), null);
- //logger.info(String.format("Value of object is..%s", obj));
- }
-
- if (obj != null) {
- arr.add(obj);
- obj = null;
- }
-
- }
-
- // PE-6874 : Fixed by shifting this code down here
- //Following code written for Mercer JIRA Story PE-5691
- // If data node code value is not present then set to Blank and Data map also.
- // PE-7071 : Remove CODE if there is no validation OR validation_errorType != "AUTOCORRECT"
- if(isEmtpyRecord &&
- (validationNode==null ||
- (null!=validationNode && !JsonUtils.isNullOrBlankOrNullNode(validationNode.get(Constants.ERROR_TYPE))
- && !(validationNode.get(Constants.ERROR_TYPE).asText()).equalsIgnoreCase("AUTOCORRECT")))) {
- ((ObjectNode)dataNode).remove(code);
- }
- //PE-5691 End.
-
- // PE : 2449 to create auto-correct object for missing EEID
-
- if ((code!=null &&code.equalsIgnoreCase(Constants.EMPLOYEE_EEID)) ||
- (mappedColumnName !=null && mappedColumnName.equalsIgnoreCase(Constants.EMPLOYEE_EEID)))
- obj = prepareEeidAutoCorrectObject(code, dataMap, dataNode,columnMappingMap);
-
- if (obj != null) {
- arr.add(obj);
- obj = null;
- }
-
- if (node.get("questionType") != null
- && node.get("questionType").asText().equals("checkboxes")) {
- buildCheckboxArray(dataNode,code, mappedColumnName);
- }
-
- }
-
- code = null;
- validationNode = null;
- }
- // PE-6254 ML Integration work
- if(mlAutoCoorect && !isAggregateRequest)
- {
- removeDataNodeACFields(dataNode);
- }
- if ((arr != null && arr.size() > 0)) {
- if (!isAggregateRequest) {
- /*
- * if(dataNode.get(k).get(code)!=null) ((ObjectNode)
- * (dataNode.get(k))).set(code, dataNode.get(k).get(code));
- */
-
- ((ObjectNode) (dataNode)).set(Constants.VALIDATION_ERRORS, arr);
- arr = null;
- } else { // Aggregate
- JsonNode objectNode = mapper.convertValue(arr, JsonNode.class);
- return objectNode;
- }
- }
-
- }
- //logger.info(String.format("%s %s", Constants.EXIT ,Constants.LOG_VALIDATE));
- return dataNode;
- }
-
- /**
- * @param dataNode
- * @param mappedColumnName
- * @param nodeDTObject
- * @param dnCodeObject
- * @param flag
- * @param datePatternArray
- * @param numberPatternArray
- * @return
- */
- protected Map<String,String> dataTypeCheck(HashMap<String, JsonNode> dataMap, JsonNode dataNode, String mappedColumnName, JsonNode nodeDTObject,
- JsonNode dnCodeObject, Boolean flag, ArrayNode datePatternArray, ArrayNode numberPatternArray) {
-
- String dnObjetText;
- Map<String,String> incorrectDataTypeMap = new HashMap<>();
- boolean isNullNode = NullNode.class.equals(dnCodeObject.getClass());
- if (!isNullNode) {
- dnObjetText = dnCodeObject.asText();
- }else {
- dnObjetText = null;
- }
- boolean dataTypeFlag = flag;
- String incorrectintegerDataType = "";
-
- boolean isDateArray = false;
- boolean isNumberArray = false;
-
- // 7257 For Multi-part request check following arrays
- if ( null != datePatternArray && datePatternArray.size() > 0 ) {
- isDateArray = true ;
- }
-
- if ( null != numberPatternArray && numberPatternArray.size() > 0 ) {
- isNumberArray = true;
- }
- // Check for integer,boolean,double ,date and string data type object.
- if ("int".equalsIgnoreCase(nodeDTObject.asText()) && (StringUtils.isEmpty(dnObjetText) || isNullNode
- || (isNumberArray ? DataUtility.isNumeric(dnObjetText, numberPatternArray)
- : DataUtility.isNumeric(dnObjetText)))) {
- //8421 code changes.
- dataTypeFlag = true;
- incorrectintegerDataType = "integer";
-
- if (isNumberArray && !StringUtils.isEmpty(dnObjetText)) {
- ((ObjectNode) dataNode).put(mappedColumnName, DataUtility.toNumber(dnObjetText, numberPatternArray));
- //PE-8731
- dataMap.put(mappedColumnName,dataNode.get(mappedColumnName));
- }
- } else if ("boolean".equalsIgnoreCase(nodeDTObject.asText()) && ("false".equalsIgnoreCase(dnObjetText)
- || isNullNode || StringUtils.isEmpty(dnObjetText) || "true".equalsIgnoreCase(dnObjetText))) {
- //8421 code changes.
- dataTypeFlag = true;
-
- incorrectintegerDataType = "boolean";
- ((ObjectNode) dataNode).put(mappedColumnName, DataUtility.toNumber(dnObjetText, numberPatternArray));
- } else if ("date".equalsIgnoreCase(nodeDTObject.asText()) && (StringUtils.isEmpty(dnObjetText) || isNullNode
- || (isDateArray ? DataUtility.isValidDate(dnObjetText, datePatternArray)
- : DataUtility.isValidDate(dnObjetText)))) {
- //8421 code changes.
- dataTypeFlag = true;
- incorrectintegerDataType = "date";
-
- // Convert to ISO-8601 Format
- if (isDateArray && !StringUtils.isEmpty(dnObjetText)) {
- ((ObjectNode) dataNode).put(mappedColumnName, DataUtility.customDateConvertor(dnObjetText,datePatternArray));
- }
- } else if ("double".equalsIgnoreCase(nodeDTObject.asText()) && (StringUtils.isEmpty(dnObjetText) || isNullNode
- || (isNumberArray ? DataUtility.isDecimal(dnObjetText, numberPatternArray)
- : DataUtility.isDecimal(dnObjetText)))) {
- dataTypeFlag = true;
- incorrectintegerDataType = "double";
-
- //Convert to java decimal
- if (isNumberArray && !StringUtils.isEmpty(dnObjetText)) {
- ((ObjectNode) dataNode).put(mappedColumnName, DataUtility.toDecimal(dnObjetText, numberPatternArray));
- //PE-8731
- dataMap.put(mappedColumnName,dataNode.get(mappedColumnName));
- }
- } else if (StringUtils.isEmpty(dnObjetText) || isNullNode || "string".equalsIgnoreCase(nodeDTObject.asText())) {
- dataTypeFlag = true;
-
- }
- //8421 code changes.
- incorrectDataTypeMap.put("dataTypeFlag", Boolean.toString(dataTypeFlag));
- incorrectDataTypeMap.put("datatype", incorrectintegerDataType);
- return incorrectDataTypeMap;
- }
-
- public ArrayNode findAndMerge(JsonNode dataNode, ArrayNode csvNode, String uniqueIdColumnCode) throws Exception {
-
- Iterator<String> it = null;
- String key = "";
- boolean isMerged = false;
- if (dataNode != null && dataNode.size() > 0) {
- for (int i = 0; i < dataNode.size(); i++) {
- isMerged = false;
- if (dataNode.get(i).get(uniqueIdColumnCode) != null)
- {
- for (int j = 0; j < csvNode.size(); j++) {
- if (csvNode.get(j).get(uniqueIdColumnCode) != null && csvNode.get(j).get(uniqueIdColumnCode)
- .equals(dataNode.get(i).get(uniqueIdColumnCode))) {
- it = dataNode.get(i).fieldNames();
- while (it != null && it.hasNext()) {
- key = it.next();
- if (csvNode.get(j).get(key) == null || csvNode.get(j).get(key).equals("")) {
- ((ObjectNode) csvNode.get(j)).set(key, dataNode.get(i).get(key));
- }
- }
- isMerged = true;
- }
- }
- if (!isMerged) {
- csvNode.add(dataNode.get(i));
- }
- }
- }
- }
- return csvNode;
- }
-
- public void buildCheckboxArray(JsonNode dataNode,String code, String mappedColumnName) {
- if (code == null || code.equals("")) {
- code = mappedColumnName;
- }
- if (dataNode.get(code) != null)
-
- {
- if (dataNode.get(code).getNodeType() != JsonNodeType.OBJECT
- && dataNode.get(code).getNodeType() != JsonNodeType.ARRAY) {
- ArrayNode arrNode = mapper.createArrayNode();
- // PE-7795 Array was giving arrayName["null"] wrong array.
- // Below changes will give arraName[null] requires correct array.
- if( !JsonUtils.isNullNode(dataNode.get(code))) {
- String arr1[] = dataNode.get(code).asText().split(",");
- if (arr1 != null && arr1.length > 0) {
- for (int i = 0; i < arr1.length; i++) {
- arrNode.add(arr1[i]);
- }
- }
- }
- ((ObjectNode) (dataNode)).set(code, arrNode);
-
- } else {
- Iterator<Map.Entry<String, JsonNode>> it = dataNode.get(code).fields();
- Map.Entry<String, JsonNode> entry = null;
- while (it != null && it.hasNext()) {
- entry = it.next();
- ArrayNode arrNode = mapper.createArrayNode();
- switch (entry.getValue().getNodeType()) {
- case ARRAY:
- for (final JsonNode objNode : entry.getValue()) {
- arrNode.add(objNode);
- }
- break;
- case STRING:
- String[] arr1 = entry.getValue().asText().split(",");
- if (arr1 != null && arr1.length > 0) {
- for (int i = 0; i < arr1.length; i++) {
- arrNode.add(arr1[i]);
- }
- }
- break;
- }
- ((ObjectNode) (dataNode.get(code))).set(entry.getKey(), arrNode);
- }
- }
- }
- }
-
- /**
- *
- * @param header
- * @param entitiesJson
- * @return
- * @throws JsonParseException
- * @throws JsonMappingException
- * @throws IOException
- */
- @SuppressWarnings("unchecked")
- public HashMap<String, Object> compareFields(List<HashMap<String, String>> records,List<String> header, String entitiesJson,
- HashMap<String, Object> xlsxMap,Object eeidColFlag) throws Exception {
- ArrayNode entitiesNode = mapper.readValue(entitiesJson, ArrayNode.class);
- JsonNode columnNode = null;
- ArrayNode arr = null;
- int columnNodeSize = 0;
- boolean found = false;
- boolean multiSheetExcel=false;
- ObjectNode resultNode = null;
- HashMap<String, Object> resultMap = new HashMap<String, Object>();
- String entityCode = null;
- JsonNode skip = null;
- String mappedColName = null;
- boolean sheetMatchingFlag = true;
- String sheetName = "";
- JsonNode dataNode = null;
- if (entitiesNode != null && xlsxMap != null && xlsxMap.get("xlsxHeaderMap") != null) {
- if((((HashMap<String, List<String>>) xlsxMap.get("xlsxHeaderMap")).size()) > 1 )
- multiSheetExcel=true;
- if (entitiesNode.size() < ((HashMap<String, List<String>>) xlsxMap.get("xlsxHeaderMap")).size()) {
- sheetMatchingFlag = false;
- } else {
- for (int i = 0; i < entitiesNode.size(); i++) {
- sheetName = entitiesNode.get(i).get(Constants.CONTEXTDATAKEY).get("companyName").asText() + "_"
- + entitiesNode.get(i).get(Constants.CONTEXTDATAKEY).get("ctryCode").asText();
- if (((HashMap<String, List<String>>) xlsxMap.get("xlsxHeaderMap")).get(sheetName) == null) {
- sheetMatchingFlag = false;
- }
- break;
- }
-
- }
- //logger.info(String.format("nodetype...%s", entitiesNode.size()));
- }
-
- //if((!multiSheetExcel && entitiesNode.size()> 1 ) || (records !=null && entitiesNode.size()> 1))
- if(entitiesNode.size()> 1 && (records !=null || !multiSheetExcel))
- {
- HashMap<String, Object> map = new HashMap<String, Object>();
- if(records !=null)
- {
- map.put("data", records);
- map.put("columns",header );
- }
- else
- {
- map.put("data", ((HashMap<String, List<HashMap<String, String>>>)xlsxMap.get("xlsxDataMap")).get(xlsxMap.get("FirstSheetName")));
- map.put("columns",((HashMap<String, List<String>>) xlsxMap.get("xlsxHeaderMap")).get(xlsxMap.get("FirstSheetName")) );
- }
- dataNode = mapper.readValue(mapper.writeValueAsString(map), JsonNode.class);
- resultMap.put("resultNode", dataNode);
- return resultMap;
- }
-
- for (int i = 0; i < entitiesNode.size(); i++) {
-
- dataNode = mapper.createObjectNode();
- columnNode = entitiesNode.get(i).get(Constants.SECTION_STRUCTURE).get(Constants.COLUMNS);
- if (entitiesNode.get(i).get(Constants.CONTEXTDATAKEY).get("companyName") != null
- && entitiesNode.get(i).get(Constants.CONTEXTDATAKEY).get("ctryCode") != null) {
- sheetName = entitiesNode.get(i).get(Constants.CONTEXTDATAKEY).get("companyName").asText() + "_"
- + entitiesNode.get(i).get(Constants.CONTEXTDATAKEY).get("ctryCode").asText();
- }
- columnNodeSize = (columnNode).size();
- if (xlsxMap != null && xlsxMap.get("xlsxHeaderMap") != null) {
- if (!sheetMatchingFlag) {
- header = ((HashMap<String, List<String>>) xlsxMap.get("xlsxHeaderMap"))
- .get(xlsxMap.get("FirstSheetName"));
- } else {
- header = ((HashMap<String, List<String>>) xlsxMap.get("xlsxHeaderMap")).get(sheetName);
- }
- }
- resultNode = mapper.createObjectNode();
- if (header != null) {
- for (int j = 0; j < header.size(); j++) {
- found = false;
- for (int k = 0; k < columnNodeSize; k++) {
- skip = columnNode.get(k).get(Constants.SKIP);
- if (null != columnNode.get(k).get("code")) {
- entityCode = columnNode.get(k).get("code").asText();
- }
- if (null != columnNode.get(k).get("mappedColumnName")) {
- mappedColName = columnNode.get(k).get("mappedColumnName").asText();
- }
- //Code modified to skip mapping in case of skip=true in request PE : 6858
- if(skip!=null && skip.asText().equals("true"))
- {
- if(header.get(j).equals(entityCode) || header.get(j).equals(mappedColName))
- {
- found = true;
- break;
- }
- else
- {
- continue;
- }
-
- }
- if ((!StringUtils.isEmpty(entityCode)|| !StringUtils.isEmpty(mappedColName)) && skip==null) {
- if (header.get(j).equals(entityCode) || header.get(j).equals(mappedColName)) {
- found = true;
- break;
- }
- }
- }
- if (!found) {
- break;
- }
- }
- }
- if (!found) {
- break;
- }
-
- }
- if (!found ) {
- if(!multiSheetExcel)
- {
- HashMap<String, Object> map = new HashMap<String, Object>();
- if(xlsxMap!=null)
- {
- if(!sheetMatchingFlag)
- {
- map.put("data", ((HashMap<String, List<HashMap<String, String>>>)xlsxMap.get("xlsxDataMap")).get(xlsxMap.get("FirstSheetName")));
- }
- else{
- map.put("data", ((HashMap<String, List<HashMap<String, String>>>)xlsxMap.get("xlsxDataMap")).get(sheetName));
- }
-
- }
- else if(records!=null)
- {
- map.put("data", records);
- }
- if((boolean)eeidColFlag)
- {
- map.put("columns",header );
- }
- else
- {
- header.remove(header.size() - 1);
- map.put("columns",header);
- }
- dataNode = mapper.readValue(mapper.writeValueAsString(map), JsonNode.class);
- resultMap.put("resultNode", dataNode);
- }
- else
- {
- resultMap.put("resultNode", ErrorCacheConstant.ERR_055);
- }
- } else {
- resultMap.put("resultNode", null);
- if (sheetMatchingFlag == false) {
- resultMap.put("sheetMatchingFlag",
- null != xlsxMap.get("FirstSheetName") ? xlsxMap.get("FirstSheetName") : "");
- }
- return resultMap;
- }
- if (sheetMatchingFlag == false) {
- resultMap.put("sheetMatchingFlag",
- null != xlsxMap.get("FirstSheetName") ? xlsxMap.get("FirstSheetName") : "");
- }
- return resultMap;
- }
-
- @SuppressWarnings("unchecked")
- public HashMap<String, Object> convertXlsxToMap(Map<String, Object> workBookMap,String empIdColumn) throws Exception {
- //logger.info(String.format("%s %s", Constants.INTIATE ,Constants.LOG_CONVERXLSXTOMAP));
- HashMap<String, Object> map = null;
- List<String> headerList = null;
- List<ArrayList<String>> dataList = null;
- HashMap<String, List<HashMap<String, String>>> xlsxDataMap = null;
- HashMap<String, List<String>> xlsxHeaderMap = null;
- HashMap<String, Object> xlsxMap = null;
- xlsxDataMap = new HashMap<>();
- xlsxHeaderMap = new HashMap<>();
- Set<Object> eeidSet = null;
- List<HashMap<String, String>> allRecords = null;
- HashMap<String, String> record = null;
- boolean eeidFlag = true;
- //PE-8933
- boolean eeidMissingFlag = false;
-
-
- String tempDataListRecord ;
- String tempHeaderListRecord;
- try {
- if (workBookMap != null && workBookMap.size() > 0) {
- xlsxMap = new HashMap<>();
- //Iterate through each xlsx tab.
- for (Entry<String, Object> entry : workBookMap.entrySet()) {
- eeidSet = new HashSet<>();
- if (entry.getKey().equals("FirstSheetName")) {
- xlsxMap.put("FirstSheetName", entry.getValue());
- continue;
- }
- allRecords = new ArrayList<>();
- map = (HashMap<String, Object>) entry.getValue();
- headerList = (List<String>) map.get("header");
- dataList = (List<ArrayList<String>>) map.get("data");
-
- //Iterate through data records from each xlsx tab.
- for (int i = 0; i < dataList.size(); i++) {
- record = new HashMap<>();
-
- //Iterate through each header from each tab.
- for (int j = 0; j < headerList.size(); j++) {
-
- tempDataListRecord = dataList.get(i).get(j);
- tempHeaderListRecord = headerList.get(j);
- if (tempHeaderListRecord.equalsIgnoreCase(Constants.EMPLOYEE_EEID) || (empIdColumn!=null
- && !empIdColumn.equals("") && tempHeaderListRecord.equals(empIdColumn))) {
- try {
- if (tempDataListRecord != null && !tempDataListRecord.equals(""))
- eeidFlag = eeidSet.add(tempDataListRecord);
- else {
- // PE-8933
- eeidMissingFlag = true;
- }
- } catch (IndexOutOfBoundsException e) {
- eeidFlag = true;
- }
- }
- if (eeidFlag) {
- try {
- boolean isNotBlankEEID = !StringUtils.isEmpty(tempDataListRecord);
- record.put(tempHeaderListRecord,
- (isNotBlankEEID ? tempDataListRecord : Constants.BLANK));
- } catch (IndexOutOfBoundsException e) {
- record.put(tempHeaderListRecord, Constants.BLANK);
- }
- } else {
- xlsxMap.put("isEeidDuplicate", "true");
- eeidSet = null;
- //PE-8933
- if(eeidMissingFlag)
- xlsxMap.put(Constants.MISSING_EEID, true);
- else
- xlsxMap.put(Constants.MISSING_EEID, false);
-
- return xlsxMap;
- }
- }
- allRecords.add(record);
-
- //Clean up block
- record = null;
- }
- xlsxDataMap.put(entry.getKey(), allRecords);
- xlsxHeaderMap.put(entry.getKey(), headerList);
- xlsxMap.put("xlsxHeaderMap", xlsxHeaderMap);
- xlsxMap.put("xlsxDataMap", xlsxDataMap);
-
- //PE-8933
- if(eeidMissingFlag)
- xlsxMap.put(Constants.MISSING_EEID, true);
- else
- xlsxMap.put(Constants.MISSING_EEID, false);
-
- //Clean up records
- allRecords = null;
- }
- }
- }finally {
-
- }
- eeidSet = null;
- //logger.info(String.format("%s %s", Constants.EXIT ,Constants.LOG_CONVERXLSXTOMAP));
- return xlsxMap;
- }
-
- @SuppressWarnings("unchecked")
- public LinkedHashMap<String, String> prepareJsonString(HashMap<String, Object> xslsMap) throws Exception{
-
- HashMap<String, Object> map = new HashMap<String, Object>();
- HashMap<String, List<HashMap<String, String>>> xlsxDataMap = null;
- String csvJsonString = "";
- LinkedHashMap<String, String> xslJsonMap = new LinkedHashMap<String, String>();
- if (xslsMap != null && xslsMap.size() > 0) {
- xlsxDataMap = (HashMap<String, List<HashMap<String, String>>>) xslsMap.get("xlsxDataMap");
- for (Entry<String, List<HashMap<String, String>>> entry : xlsxDataMap.entrySet()) {
- map.put("data", entry.getValue());
- ObjectMapper mapper = new ObjectMapper();
- csvJsonString = mapper.writeValueAsString(map);
- xslJsonMap.put(entry.getKey(), csvJsonString);
-
- }
- }
- return xslJsonMap;
- }
-
- // PE : 2449 to check duplication of EEID start in case of entity data in
- // request body
- public HashMap<String,String> checkUniqueNessForEEID(String enetityJson) throws Exception{
- //logger.info(String.format("%s %s", Constants.INTIATE ,Constants.LOG_CHECKUNIQUENESSFOREEID));
- @SuppressWarnings("unchecked")
- HashMap<String,String> empIdMap= new HashMap<String,String>();
- empIdMap.put("isUnique", "true");
- JsonNode entityNode = null;
- boolean flag = false;
- String code = "";
- JsonNode sectionStructureNode = null;
- String empIdColumn="";
- ArrayList<JsonNode> columnNodeList = null;
- columnNodeList = new ArrayList<JsonNode>();
- JsonNode entittiesNode = mapper.readValue(enetityJson, JsonNode.class);
- HashSet<String> eeidSet = null;
- if (entittiesNode != null) {
- for (int i = 0; i < entittiesNode.size(); i++) {
- eeidSet = new HashSet<String>();
- entityNode = entittiesNode.get(i);
- sectionStructureNode = entityNode.get(Constants.SECTION_STRUCTURE);
-
- for (int j = 0; j < sectionStructureNode.get(Constants.COLUMNS).size(); j++) {
- columnNodeList.add(sectionStructureNode.get(Constants.COLUMNS).get(j));
-
- }
- if (columnNodeList != null && columnNodeList.size() > 0) {
-
- for (JsonNode node : columnNodeList) {
- if (node.get(Constants.CODE) != null)
- code = node.get(Constants.CODE).asText();
- if (code.equals(Constants.EMPLOYEE_EEID))
- {
- flag = true;
- if(node.get(Constants.MAPPED_COLUMN_NAME)!=null && !node.get(Constants.MAPPED_COLUMN_NAME).equals(""))
- {
- empIdColumn = node.get(Constants.MAPPED_COLUMN_NAME).asText();
- empIdMap.put("empIdColumn", empIdColumn);
- }
- }
-
- }
- }
-
- if (flag) {
- JsonNode dataNode = entittiesNode.get(i).get(Constants.DATA);
- if (dataNode != null) {
- for (int k = 0; k < dataNode.size(); k++) {
-
- if (dataNode.get(k).get(Constants.EMPLOYEE_EEID) != null
- && !dataNode.get(k).get(Constants.EMPLOYEE_EEID).asText().equals("")) {
- String eeId = dataNode.get(k).get(Constants.EMPLOYEE_EEID).asText();
- if (!eeidSet.add(eeId)) {
- eeidSet = null;
- empIdMap.put("isUnique",Constants.DUPLICATE);
- return empIdMap;
- }
- } else {
- empIdMap.put("isUnique",Constants.MISSING);
- return empIdMap;
- }
- }
- }
- }
- }
- }
- //logger.info(String.format("%s %s", Constants.EXIT ,Constants.LOG_CHECKUNIQUENESSFOREEID));
- return empIdMap;
-
- }
-
- // PE : 2449 to prepare auto-correct validation object in case of missing EEID..
- public ObjectNode prepareEeidAutoCorrectObject(String code, HashMap<String, JsonNode> dataMap, JsonNode dataNode,
- HashMap<String, String> columnMappingMap) throws Exception {
- //logger.info(String.format("%s %s", Constants.INTIATE ,Constants.LOG_PREPAREEEIDAUTOCORRECTOBJECT));
- ObjectNode obj = null;
-
- if (dataMap != null && ((!JsonUtils.isNullOrBlankOrNullNode(dataMap.get(Constants.EMPLOYEE_EEID))
- && !JsonUtils.isBlankTextNode(dataMap.get(Constants.EMPLOYEE_EEID)) )
- || (!JsonUtils.isNullOrBlankOrNullNode(dataMap.get(columnMappingMap.get(code)))
- && !JsonUtils.isBlankTextNode(dataMap.get(columnMappingMap.get(code))) )))
- {
- return obj;
- } else {
- String eeId = generateUniqueEeid();
- //logger.info(String.format("eeid generated..%s", eeId));
- APIExpressionEvaluator apiExpressionEvaluator = new APIExpressionEvaluator();
- obj = apiExpressionEvaluator.prepareOutputJson(null, null, eeId, ValidationTypes.eeIdAutoCorrect, code,
- null, null, null);
- ((ObjectNode) (dataNode)).put(code, eeId);
- }
- //logger.info(String.format("%s %s", Constants.EXIT ,Constants.LOG_PREPAREEEIDAUTOCORRECTOBJECT));
- return obj;
- }
-
- public static synchronized String generateUniqueEeid() throws Exception {
- //logger.info(String.format("%s %s", Constants.INTIATE ,Constants.LOG_GENERATEUNIQUEEID));
- Date d1 = new Date();
- SimpleDateFormat sdf = new SimpleDateFormat(Constants.EEID_FORMAT2);
- //logger.info(String.format("%s %s", Constants.EXIT ,Constants.LOG_GENERATEUNIQUEEID));
- String tmpNanoTime = String.valueOf(System.nanoTime()); // Duplicate EEID occurred at millisec-level. Found in PE-8616.
- return sdf.format(d1)+ tmpNanoTime.substring(tmpNanoTime.length()-5, tmpNanoTime.length());
-
- }
-
- public static ArrayNode removeMlNode(JsonNode jsonNode) throws Exception {
- JsonNode mlNode = null;
- JsonNode entityNode = null;
- Iterator<Entry<String, JsonNode>> mlItr = null;
- ArrayNode mlJsonDataArray = (ArrayNode) jsonNode.get("entities");
- Map.Entry<String, JsonNode> entry = null;
-
- for (int i = 0; i < mlJsonDataArray.size(); i++) {
-
- entityNode = mlJsonDataArray.get(i);
- mlNode = entityNode.get(Constants.DATA);
-
- for (int k = 0; k < mlNode.size(); k++) {
-
- …
Large files files are truncated, but you can click here to view the full file