@Override public Map<String, Object> uploadFixedActiveSplit(String nexiRefId, MultipartFile uploadedFile, String employeeId) { // TODO Auto-generated method stub LOG.info("FixedActiveSplitService | uploadFixedActiveSplit | invoked"); String MCAFEE_FILE_PATH = new DynamicStringProperty("MCAFEE_UPLOAD",NexisLinkMasterConstant.MCAFEE_DIR).get(); Map<String, Object> returnMap = new HashMap<>(); boolean validInput = true; List<AddFixedWonLineDTO> addFixedWonLineDTOs = new ArrayList<>(); if(nexiRefId!=null && !nexiRefId.trim().isEmpty() && uploadedFile!=null && UtxNexisUtility.validateInputString(nexiRefId)) { try(XSSFWorkbook workbook = new XSSFWorkbook(uploadedFile.getInputStream())) { String[] fileName = uploadedFile.getOriginalFilename().split("\\."); String extension = fileName[fileName.length-1]; if(extension==null || (!"xls".equalsIgnoreCase(extension) && !"xlsx".equalsIgnoreCase(extension))) { returnMap.put(NexisLinkMasterConstant.RESPONSE_ERROR, NexisLinkMasterConstant.INVALID_FILE_EXTENSION); LOG.info(FIXED_ACTIVE_LEAVING); return returnMap; } // String newFilePath = NexisLinkMasterConstant.MCAFEE_DIR + "/" + employeeId + "_" + uploadedFile.getOriginalFilename(); String newFilePath = MCAFEE_FILE_PATH + employeeId + "_" + uploadedFile.getOriginalFilename(); //normalize path String path = FilenameUtils.normalize(newFilePath); File newFile = new File(path); write(uploadedFile, newFilePath); boolean virusStatus = UtxNexisUtility.scanFile(newFilePath, employeeId); if(newFile.exists()) { newFile.delete(); } if(!virusStatus){ returnMap.put(NexisLinkMasterConstant.RESPONSE_ERROR, NexisLinkMasterConstant.VIRUS_FOUND); LOG.info(FIXED_ACTIVE_LEAVING); return returnMap; } List<String> projectNoList = new ArrayList<>(); XSSFSheet worksheet = workbook.getSheetAt(0); int rowIndex=1; XSSFRow row = worksheet.getRow(rowIndex); while(row!=null) { //Condition where Project No exist but bandwidth is blank if(row.getCell(0)!=null && !row.getCell(0).toString().trim().isEmpty() && (row.getCell(1)==null || row.getCell(1).toString().trim().isEmpty())) { List<String> projects; if(returnMap.containsKey(NexisLinkMasterConstant.MISSING_BANDWIDTH_DATA)) { projects = (List<String>) returnMap.get(NexisLinkMasterConstant.MISSING_BANDWIDTH_DATA); } else { projects = new ArrayList<>(); } projectNoList.add(row.getCell(0).toString().split("\\.")[0].trim()); projects.add(row.getCell(0).toString().split("\\.")[0].trim()); returnMap.put(NexisLinkMasterConstant.MISSING_BANDWIDTH_DATA, projects); validInput = false; } //Checking if bandwidth is decimal and converting to DTO accordingly else if(row.getCell(1)!=null && !row.getCell(1).toString().trim().isEmpty()){ AddFixedWonLineDTO addFixedWonLineDTO = new AddFixedWonLineDTO(); if(row.getCell(0)!=null && !row.getCell(0).toString().trim().isEmpty()) { String projectNoTemp = row.getCell(0).toString().trim(); addFixedWonLineDTO.setIsBuffer(false); BigInteger number = new BigInteger("0"); try { number = new BigDecimal(row.getCell(0).toString().replaceAll("\\s*", "")).toBigInteger(); String project = number.toString().trim(); projectNoTemp = project; }catch(NumberFormatException ex) { LOG.info("FixedActiveSplitService | uploadFixedActiveSplit | project no contains alphabate"); } if(UtxNexisUtility.validateInputString(projectNoTemp)){ addFixedWonLineDTO.setProjectId(projectNoTemp); projectNoList.add(projectNoTemp); } else{ List<String> projects; if(returnMap.containsKey(NexisLinkMasterConstant.INVALID_PROJECT_DATA)) { projects = (List<String>) returnMap.get(NexisLinkMasterConstant.INVALID_PROJECT_DATA); } else { projects = new ArrayList<>(); } projects.add(row.getCell(0).toString().trim()); returnMap.put(NexisLinkMasterConstant.INVALID_PROJECT_DATA, projects); validInput = false; } } else{ addFixedWonLineDTO.setIsBuffer(true); } try { BigDecimal bandwidth = new BigDecimal(row.getCell(1).toString().trim()); if(bandwidth.compareTo(new BigDecimal(0))<=0) { throw new NumberFormatException(); } addFixedWonLineDTO.setBandwidth(bandwidth); addFixedWonLineDTOs.add(addFixedWonLineDTO); } catch(NumberFormatException ex) { List<String> bandwidths; if(returnMap.containsKey(NexisLinkMasterConstant.INVALID_BANDWIDTH_DATA)) { bandwidths = (List<String>) returnMap.get(NexisLinkMasterConstant.INVALID_BANDWIDTH_DATA); } else { bandwidths = new ArrayList<>(); } bandwidths.add(row.getCell(1).toString()); returnMap.put(NexisLinkMasterConstant.INVALID_BANDWIDTH_DATA, bandwidths); validInput = false; } } else { //Do Nothing } rowIndex++; row = worksheet.getRow(rowIndex); } returnMap.putAll(validateProjectUtility.validateProjectDtls(projectNoList)); } catch(IOException ex) { ExceptionUtils.getStackTrace("IOException in uploadFixedActiveSplit", ex); LOG.debug("FixedActiveSplitService | uploadFixedActiveSplit | IOException"); validInput=false; } } else { validInput=false; } if(validInput && returnMap.containsKey(NexisLinkMasterConstant.RESPONSE_SUCCESS) && addFixedWonLineDTOs!=null && !addFixedWonLineDTOs.isEmpty()) { returnMap = fixedActiveSplitDao.addFixedActiveSplit(nexiRefId, addFixedWonLineDTOs, employeeId); } else { returnMap.remove(NexisLinkMasterConstant.RESPONSE_SUCCESS); returnMap.put(NexisLinkMasterConstant.RESPONSE_ERROR, NexisLinkMasterConstant.INVALID_INPUT); } LOG.info(FIXED_ACTIVE_LEAVING); return returnMap; } private static void write(MultipartFile file, String newFilePath) throws IOException{ String path = FilenameUtils.normalize(newFilePath); try(OutputStream os = new FileOutputStream(new File(path))){ os.write(file.getBytes()); } }