Subversion Repositories SmartDukaan

Rev

Rev 22228 | Rev 22230 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 22228 Rev 22229
Line 38... Line 38...
38
	private static final Logger LOGGER = LoggerFactory.getLogger(ExcelUtils.class);
38
	private static final Logger LOGGER = LoggerFactory.getLogger(ExcelUtils.class);
39
	
39
	
40
	public static void main(String[] args) throws Throwable{
40
	public static void main(String[] args) throws Throwable{
41
		parse(null);
41
		parse(null);
42
	}
42
	}
43
	public static List<TagListingModel> parse(InputStream inputStream) throws ProfitMandiBusinessException{
43
	public static List<TagListingModel> parse(InputStream inputStream) throws ProfitMandiBusinessException {
44
		
44
		
45
		List<TagListingModel> tagListings = new ArrayList<>();
45
		List<TagListingModel> tagListings = new ArrayList<>();
46
		XSSFWorkbook myWorkBook = null;
46
		XSSFWorkbook myWorkBook = null;
47
		try{
47
		try{
48
			//FileInputStream fileInputStream = new FileInputStream("/home/ashikali/tag_listing1.xlsx");
48
			//FileInputStream fileInputStream = new FileInputStream("/home/ashikali/tag_listing1.xlsx");
Line 97... Line 97...
97
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(TAG_LISTING, "", "TGLSTNG_VE_1012");
97
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(TAG_LISTING, "", "TGLSTNG_VE_1012");
98
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
98
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
99
					throw profitMandiBusinessException;
99
					throw profitMandiBusinessException;
100
					// missing headers in first row
100
					// missing headers in first row
101
				}
101
				}
102
				LOGGER.info("rowNumber {}", rowNumber);
102
				//LOGGER.info("rowNumber {}", rowNumber);
103
				LOGGER.info("row {}", row);
103
				LOGGER.info("row {}", row);
104
				LOGGER.info("row {}", row.getLastCellNum());
104
				//LOGGER.info("row {}", row.getLastCellNum());
105
				if(rowNumber > 0 && row != null && row.getLastCellNum() == 11){
105
				if(rowNumber > 0 && row != null && row.getLastCellNum() == 11){
106
					TagListingModel tagListing = new TagListingModel();
106
					TagListingModel tagListing = new TagListingModel();
107
					if(row.getCell(0) != null && row.getCell(0).getCellTypeEnum() == CellType.NUMERIC){
107
					if(row.getCell(0) != null && row.getCell(0).getCellTypeEnum() == CellType.NUMERIC){
108
						tagListing.setTagId((Double.valueOf(row.getCell(0).getNumericCellValue())).intValue());
108
						tagListing.setTagId((Double.valueOf(row.getCell(0).getNumericCellValue())).intValue());
109
					}else{
109
					}else{
110
						ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(TAG_ID, row.getCell(0).toString(), "TGLSTNG_VE_1010");
110
						ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(TAG_ID, row.getCell(0).toString(), "TGLSTNG_VE_1010");
111
						//LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
111
						LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
112
						throw profitMandiBusinessException;
112
						throw profitMandiBusinessException;
113
					}
113
					}
114
					
114
					
115
					
115
					
116
					if(row.getCell(2) != null && row.getCell(2).getCellTypeEnum() == CellType.NUMERIC){
116
					if(row.getCell(2) != null && row.getCell(2).getCellTypeEnum() == CellType.NUMERIC){
117
						tagListing.setItemId(Double.valueOf(row.getCell(2).toString()).intValue());
117
						tagListing.setItemId(Double.valueOf(row.getCell(2).toString()).intValue());
118
					}else{
118
					}else{
119
						ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(ITEM_ID, row.getCell(2).toString(), "TGLSTNG_VE_1010");
119
						ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(ITEM_ID, row.getCell(2).toString(), "TGLSTNG_VE_1010");
120
						//LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
120
						LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
121
						throw profitMandiBusinessException;
121
						throw profitMandiBusinessException;
122
					}
122
					}
123
 
123
 
124
					if(row.getCell(7) != null && row.getCell(7).getCellTypeEnum() == CellType.NUMERIC){
124
					if(row.getCell(7) != null && row.getCell(7).getCellTypeEnum() == CellType.NUMERIC){
125
						tagListing.setSellingPrice(Double.valueOf(row.getCell(7).toString()).floatValue());
125
						tagListing.setSellingPrice(Double.valueOf(row.getCell(7).toString()).floatValue());
126
					}else{
126
					}else{
127
						ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(SELLING_PRICE, row.getCell(7), "TGLSTNG_VE_1010");
127
						ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(SELLING_PRICE, row.getCell(7), "TGLSTNG_VE_1010");
128
						//LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
128
						LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
129
						throw profitMandiBusinessException;
129
						throw profitMandiBusinessException;
130
					}
130
					}
131
					if(row.getCell(8) != null && row.getCell(8).getCellTypeEnum() == CellType.NUMERIC){
131
					if(row.getCell(8) != null && row.getCell(8).getCellTypeEnum() == CellType.NUMERIC){
132
						tagListing.setMop(Double.valueOf(row.getCell(8).toString()).floatValue());
132
						tagListing.setMop(Double.valueOf(row.getCell(8).toString()).floatValue());
133
					}else{
133
					}else{
134
						ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(MOP, row.getCell(7), "TGLSTNG_VE_1010");
134
						ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(MOP, row.getCell(7), "TGLSTNG_VE_1010");
135
						//LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
135
						LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
136
						throw profitMandiBusinessException;
136
						throw profitMandiBusinessException;
137
					}
137
					}
138
					if(row.getCell(9) != null && row.getCell(9).getCellTypeEnum() == CellType.NUMERIC){
138
					if(row.getCell(9) != null && row.getCell(9).getCellTypeEnum() == CellType.NUMERIC){
139
						tagListing.setSupportPrice(Double.valueOf(row.getCell(8).toString()).floatValue());
139
						tagListing.setSupportPrice(Double.valueOf(row.getCell(8).toString()).floatValue());
140
					}else{
140
					}else{
141
						ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(SUPPORT_PRICE, row.getCell(8).toString(), "TGLSTNG_VE_1010");
141
						ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(SUPPORT_PRICE, row.getCell(8).toString(), "TGLSTNG_VE_1010");
142
						//LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
142
						LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
143
						throw profitMandiBusinessException;
143
						throw profitMandiBusinessException;
144
					}
144
					}
145
					if(row.getCell(10) != null && HSSFDateUtil.isCellDateFormatted(row.getCell(10))){
145
					if(row.getCell(10) != null && HSSFDateUtil.isCellDateFormatted(row.getCell(10))){
146
						Date date = row.getCell(10).getDateCellValue();
146
						Date date = row.getCell(10).getDateCellValue();
147
						LocalDateTime startDate = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
147
						LocalDateTime startDate = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
148
						tagListing.setStartDate(startDate);
148
						tagListing.setStartDate(startDate);
149
					}else{
149
					}else{
150
						ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(START_DATE, row.getCell(9).toString(), "TGLSTNG_VE_1010");
150
						ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(START_DATE, row.getCell(9).toString(), "TGLSTNG_VE_1010");
151
						//LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
151
						LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
152
						throw  profitMandiBusinessException;
152
						throw  profitMandiBusinessException;
153
					}
153
					}
154
					tagListings.add(tagListing);
154
					tagListings.add(tagListing);
155
				} else {
155
				} else {
156
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(TAG_LISTING, "", "TGLSTNG_VE_1012");
156
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(TAG_LISTING, "", "TGLSTNG_VE_1012");