Subversion Repositories SmartDukaan

Rev

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

Rev 8121 Rev 8168
Line 8... Line 8...
8
import java.util.Map;
8
import java.util.Map;
9
 
9
 
10
import javax.servlet.ServletContext;
10
import javax.servlet.ServletContext;
11
import javax.servlet.ServletRequest;
11
import javax.servlet.ServletRequest;
12
import javax.servlet.http.HttpServletRequest;
12
import javax.servlet.http.HttpServletRequest;
-
 
13
import javax.servlet.http.HttpServletResponse;
13
import javax.servlet.http.HttpSession;
14
import javax.servlet.http.HttpSession;
14
 
15
 
15
import in.shop2020.model.v1.catalog.Amazonlisted;
16
import in.shop2020.model.v1.catalog.Amazonlisted;
16
import in.shop2020.model.v1.catalog.CatalogServiceException;
17
import in.shop2020.model.v1.catalog.CatalogServiceException;
17
import in.shop2020.model.v1.catalog.Item;
18
import in.shop2020.model.v1.catalog.Item;
Line 31... Line 32...
31
 
32
 
32
import org.apache.commons.io.FileUtils;
33
import org.apache.commons.io.FileUtils;
33
import org.apache.commons.lang.xwork.StringUtils;
34
import org.apache.commons.lang.xwork.StringUtils;
34
import org.apache.poi.hssf.usermodel.HSSFSheet;
35
import org.apache.poi.hssf.usermodel.HSSFSheet;
35
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
36
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-
 
37
import org.apache.poi.ss.usermodel.Cell;
36
import org.apache.struts2.convention.annotation.InterceptorRef;
38
import org.apache.struts2.convention.annotation.InterceptorRef;
37
import org.apache.struts2.convention.annotation.InterceptorRefs;
39
import org.apache.struts2.convention.annotation.InterceptorRefs;
38
import org.apache.struts2.convention.annotation.Result;
40
import org.apache.struts2.convention.annotation.Result;
39
import org.apache.struts2.convention.annotation.Results;
41
import org.apache.struts2.convention.annotation.Results;
40
import org.apache.struts2.interceptor.ServletRequestAware;
42
import org.apache.struts2.interceptor.ServletRequestAware;
-
 
43
import org.apache.struts2.interceptor.ServletResponseAware;
-
 
44
import org.apache.struts2.util.ServletContextAware;
41
import org.apache.thrift.TException;
45
import org.apache.thrift.TException;
42
import org.apache.thrift.transport.TTransportException;
46
import org.apache.thrift.transport.TTransportException;
43
import org.slf4j.Logger;
47
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
48
import org.slf4j.LoggerFactory;
45
 
49
 
Line 52... Line 56...
52
})
56
})
53
@Results({
57
@Results({
54
	@Result(name = "redirect", location = "${url}", type = "redirect"),
58
	@Result(name = "redirect", location = "${url}", type = "redirect"),
55
	@Result(name="authsuccess", type="redirectAction", params = {"actionName" , "reports"})
59
	@Result(name="authsuccess", type="redirectAction", params = {"actionName" , "reports"})
56
})
60
})
57
public class AmazonListController extends ValidationAwareSupport implements ServletRequestAware {
61
public class AmazonListController extends ValidationAwareSupport implements ServletRequestAware ,ServletResponseAware, ServletContextAware{
58
 
62
 
59
	private static Logger logger = LoggerFactory.getLogger(AmazonListController.class);
63
	private static Logger logger = LoggerFactory.getLogger(AmazonListController.class);
60
 
64
 
61
	private HttpServletRequest request;
65
	private HttpServletRequest request;
62
	private HttpSession session;
66
	private HttpSession session;
Line 75... Line 79...
75
	private String customHandlingTime;
79
	private String customHandlingTime;
76
	private String holdInventory;
80
	private String holdInventory;
77
	private String defaultInventory;
81
	private String defaultInventory;
78
	private String fileUploadFileName;
82
	private String fileUploadFileName;
79
	private String fileUploadContentType;
83
	private String fileUploadContentType;
-
 
84
	private String suppressMfnPriceUpdate;
-
 
85
	private String suppressFbaPriceUpdate;
80
	private File file;
86
	private File file;
81
 
87
 
82
	public String index() {
88
	public String index() {
83
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath())) {
89
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath())) {
84
			return "authfail";
90
			return "authfail";
Line 103... Line 109...
103
 
109
 
104
 
110
 
105
 
111
 
106
	public String update() throws NumberFormatException, TException{
112
	public String update() throws NumberFormatException, TException{
107
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
113
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
108
			boolean flag=false;
114
		boolean flag=false;
-
 
115
		boolean commit=false;
109
			long delay = Long.valueOf(customHandlingTime);
116
		long delay = Long.valueOf(customHandlingTime);
110
			if ( Boolean.valueOf(isTime)) {
117
		if ( Boolean.valueOf(isTime)) {
111
				flag = true;
118
			flag = true;
112
			}
119
		}
113
			changeItemInventory();
120
		changeItemInventory();
-
 
121
		Amazonlisted amazonlisted = CatalogClient.getAmazonItemDetails(Long.valueOf(itemId));
-
 
122
		if (amazonlisted.getSellingPrice()!=Double.valueOf(sellingPrice)){
-
 
123
			amazonlisted.setSellingPrice(Double.valueOf(sellingPrice));
-
 
124
			commit=true;
-
 
125
		}
-
 
126
		if (amazonlisted.getFbaPrice()!=Double.valueOf(fbaPrice)){
-
 
127
			amazonlisted.setFbaPrice(Double.valueOf(fbaPrice));
-
 
128
			commit=true;
-
 
129
		}
-
 
130
		if (amazonlisted.isIsFba()!=Boolean.valueOf(isFba)){
-
 
131
			amazonlisted.setIsFba(Boolean.valueOf(isFba));
-
 
132
			commit=true;
-
 
133
		}
-
 
134
		if (amazonlisted.isIsNonFba()!=Boolean.valueOf(isNonFba)){
-
 
135
			amazonlisted.setIsNonFba(Boolean.valueOf(isNonFba));
-
 
136
			commit=true;
-
 
137
		}
-
 
138
		if (amazonlisted.isIsCustomTime()!=flag){
-
 
139
			amazonlisted.setIsCustomTime(flag);
-
 
140
			commit=true;
-
 
141
		}
-
 
142
		if (amazonlisted.getHandlingTime()!=delay){
-
 
143
			amazonlisted.setHandlingTime(delay);
-
 
144
			commit=true;
-
 
145
		}
114
			CatalogClient.updateAmazonItemDetails(Long.valueOf(itemId),Double.valueOf(fbaPrice),Double.valueOf(sellingPrice),Boolean.valueOf(isFba),Boolean.valueOf(isNonFba),Boolean.valueOf(isInventoryOverride),delay,flag);
146
		if(amazonlisted.isIsInventoryOverride()!=Boolean.valueOf(isInventoryOverride)){
-
 
147
			amazonlisted.setIsInventoryOverride(Boolean.valueOf(isInventoryOverride));
-
 
148
			commit=true;
-
 
149
		}
-
 
150
		if(amazonlisted.isSuppressMfnPriceUpdate()!=Boolean.valueOf(suppressMfnPriceUpdate)){
-
 
151
			amazonlisted.setSuppressMfnPriceUpdate(Boolean.valueOf(suppressMfnPriceUpdate));
-
 
152
			commit=true;
-
 
153
		}
-
 
154
		if(amazonlisted.isSuppressFbaPriceUpdate()!=Boolean.valueOf(suppressFbaPriceUpdate)){
-
 
155
			amazonlisted.setSuppressFbaPriceUpdate(Boolean.valueOf(suppressFbaPriceUpdate));
-
 
156
			commit=true;
-
 
157
		}
-
 
158
		if(commit){
-
 
159
			CatalogClient.updateAmazonItemDetails(amazonlisted);
-
 
160
		}
-
 
161
		else{
-
 
162
			logger.info("Nothing new to commit");
-
 
163
		}
115
		//setUrl("/amazon-list/");
164
		//setUrl("/amazon-list/");
116
		return "index";
165
		return "index";
117
 
166
 
118
	}
167
	}
119
 
168
 
120
	public String upload() throws IOException, TException {
169
	public void upload() throws IOException, TException {
121
		File fileToCreate = new File("/tmp/", "Amazon-shipping.xls");
170
		File fileToCreate = new File("/tmp/", "Amazon-shipping.xls");
122
		FileUtils.copyFile(this.file, fileToCreate);
171
		FileUtils.copyFile(this.file, fileToCreate);
123
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
172
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
124
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
173
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
125
		HSSFSheet sheet = workbook.getSheetAt(0);
174
		HSSFSheet sheet = workbook.getSheetAt(0);
Line 135... Line 184...
135
				}
184
				}
136
			}
185
			}
137
		}
186
		}
138
		TransactionClient tcl = new TransactionClient();
187
		TransactionClient tcl = new TransactionClient();
139
		tcl.getClient().updateTimestampForAmazonOrder(amazonOrderMap);
188
		tcl.getClient().updateTimestampForAmazonOrder(amazonOrderMap);
140
		return "authsuccess";
-
 
141
	}
189
	}
142
 
190
 
143
	private void changeItemInventory() throws NumberFormatException, TException {
191
	private void changeItemInventory() throws NumberFormatException, TException {
144
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
192
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
145
 
193
 
Line 217... Line 265...
217
		for (Item o : itemList) {
265
		for (Item o : itemList) {
218
			itemMap.put((Long) o.getId(), o);
266
			itemMap.put((Long) o.getId(), o);
219
		}
267
		}
220
		return itemMap;
268
		return itemMap;
221
	}
269
	}
222
	
-
 
223
	 public String runAsinJob() throws IOException, InterruptedException {
-
 
224
         ProcessBuilder testProcess = new ProcessBuilder("/bin/bash");
-
 
225
         String[] command = {"/bin/bash", "-c", "sudo /root/code/trunk/AmazonFeeds/Test.sh"};
-
 
226
     testProcess.command(command);
-
 
227
     logger.info(testProcess.command().toString());
-
 
228
     Process process = testProcess.start();
-
 
229
     process.waitFor();
-
 
230
     logger.info(String.valueOf(process.exitValue()));
-
 
231
     return "asinjob";
-
 
232
 
270
 
-
 
271
	public String runAsinJob() throws IOException, InterruptedException {
-
 
272
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
-
 
273
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
-
 
274
			return "authfail";
-
 
275
		}
-
 
276
		ProcessBuilder testProcess = new ProcessBuilder("/bin/bash");
-
 
277
		String[] command = {"/bin/bash", "-c", "sudo /root/code/trunk/AmazonFeeds/Test.sh"};
-
 
278
		testProcess.command(command);
-
 
279
		logger.info(testProcess.command().toString());
-
 
280
		Process process = testProcess.start();
-
 
281
		process.waitFor();
-
 
282
		logger.info(String.valueOf(process.exitValue()));
-
 
283
		return "asinjob";
-
 
284
 
-
 
285
	}
-
 
286
 
-
 
287
	public void uploadBulkFile() throws IOException, TException{
-
 
288
		File fileToCreate = new File("/tmp/", "Amazon-bulk-upload.xls");
-
 
289
		FileUtils.copyFile(this.file, fileToCreate);
-
 
290
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
-
 
291
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
-
 
292
		HSSFSheet sheet = workbook.getSheetAt(0);
-
 
293
		Map<Long,Amazonlisted> amazonBulkUpdate = new HashMap<Long,Amazonlisted>();
-
 
294
		Client CatalogClient=null;
-
 
295
		try {
-
 
296
			CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
-
 
297
		} catch (TTransportException e) {
-
 
298
			// TODO Auto-generated catch block
-
 
299
			e.printStackTrace();
-
 
300
		}
-
 
301
		for (int iterator=(sheet.getFirstRowNum()+1);iterator<=sheet.getLastRowNum();iterator++){
-
 
302
			Amazonlisted amazonlisted =null;
-
 
303
			Long sku;
-
 
304
			if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
-
 
305
				continue;
-
 
306
			}
-
 
307
			else {
-
 
308
				sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
-
 
309
				amazonlisted = CatalogClient.getAmazonItemDetails(sku);
-
 
310
			}
-
 
311
 
-
 
312
			if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
-
 
313
				double mfnPrice = sheet.getRow(iterator).getCell(1).getNumericCellValue();
-
 
314
				amazonlisted.setSellingPrice(mfnPrice);
-
 
315
			}
-
 
316
 
-
 
317
			if (!checkEmptyString(sheet.getRow(iterator).getCell(2))){
-
 
318
				double fbaSellingPrice = sheet.getRow(iterator).getCell(2).getNumericCellValue();
-
 
319
				amazonlisted.setFbaPrice(fbaSellingPrice);
-
 
320
			}
-
 
321
 
-
 
322
			if (!checkEmptyString(sheet.getRow(iterator).getCell(3))){
-
 
323
				if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==1){
-
 
324
					amazonlisted.setIsNonFba(true);
-
 
325
				}
-
 
326
				if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==0){
-
 
327
					amazonlisted.setIsNonFba(false);
-
 
328
				}
-
 
329
			}
-
 
330
 
-
 
331
			if (!checkEmptyString(sheet.getRow(iterator).getCell(4))){
-
 
332
				if ((long)sheet.getRow(iterator).getCell(4).getNumericCellValue()==1){
-
 
333
					amazonlisted.setIsFba(true);
-
 
334
				}
-
 
335
				if ((long)sheet.getRow(iterator).getCell(4).getNumericCellValue()==0){
-
 
336
					amazonlisted.setIsFba(false);
-
 
337
				}
-
 
338
			}
-
 
339
			if (!checkEmptyString(sheet.getRow(iterator).getCell(5))){
-
 
340
				if ((long)sheet.getRow(iterator).getCell(5).getNumericCellValue()==1){
-
 
341
					amazonlisted.setIsInventoryOverride(true);
-
 
342
				}
-
 
343
				if ((long)sheet.getRow(iterator).getCell(5).getNumericCellValue()==0){
-
 
344
					amazonlisted.setIsInventoryOverride(false);
-
 
345
				}
-
 
346
			}
-
 
347
			if (!checkEmptyString(sheet.getRow(iterator).getCell(6))){
-
 
348
				if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==1){
-
 
349
					amazonlisted.setSuppressMfnPriceUpdate(true);
-
 
350
				}
-
 
351
				if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==0){
-
 
352
					amazonlisted.setSuppressMfnPriceUpdate(false);
-
 
353
				}
-
 
354
			}
-
 
355
 
-
 
356
			if (!checkEmptyString(sheet.getRow(iterator).getCell(7))){
-
 
357
				if ((long)sheet.getRow(iterator).getCell(7).getNumericCellValue()==1){
-
 
358
					amazonlisted.setSuppressFbaPriceUpdate(true);
-
 
359
				}
-
 
360
				if ((long)sheet.getRow(iterator).getCell(7).getNumericCellValue()==0){
-
 
361
					amazonlisted.setSuppressFbaPriceUpdate(false);
-
 
362
				}
-
 
363
			}
-
 
364
			amazonBulkUpdate.put(sku, amazonlisted);
-
 
365
		}
-
 
366
		logger.info("Amazon Bulk Map "+amazonBulkUpdate.toString());
-
 
367
		CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
-
 
368
		CatalogClient.updateAmazonAttributesInBulk(amazonBulkUpdate);
-
 
369
	}
-
 
370
 
-
 
371
 
-
 
372
	public boolean checkEmptyString(Cell cell){
-
 
373
		if (cell==null){
-
 
374
			return true;
-
 
375
		}
-
 
376
		return false;
-
 
377
	}
-
 
378
 
-
 
379
	public String uploadSheet(){
-
 
380
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
-
 
381
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
-
 
382
			return "authfail";
-
 
383
		}
-
 
384
		return "amazon-shipping-upload";
-
 
385
	}
-
 
386
 
-
 
387
	public String uploadBulkSheet(){
-
 
388
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
-
 
389
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
-
 
390
			return "authfail";
-
 
391
		}
-
 
392
		return "amazon-bulk-upload";
233
 }
393
	}
234
 
394
 
235
 
395
 
236
	public String edit() {
396
	public String edit() {
237
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
397
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
238
			return "authfail";
398
			return "authfail";
239
		}
399
		}
240
		return "edit";
400
		return "edit";
241
	}
401
	}
242
 
402
 
243
	public String show() {
403
	public String show() {
-
 
404
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
-
 
405
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1]);
-
 
406
			return "authfail";
-
 
407
		}
-
 
408
 
-
 
409
		if (StringUtils.equals(id, "options")){
-
 
410
			return "options";
-
 
411
		}
244
		return "show";
412
		return "id";
245
	}
413
	}
246
 
414
 
247
	public String editNew() {
415
	public String editNew() {
248
		return "editNew";
416
		return "editNew";
249
	}
417
	}	
250
 
418
 
251
	public void setId(String id) {
419
	public void setId(String id) {
-
 
420
		logger.info(id);
252
		this.id = id;
421
		this.id = id;
253
	}
422
	}
254
 
423
 
255
	public void setUrl(String url) {
424
	public void setUrl(String url) {
256
		this.url = url;
425
		this.url = url;
Line 333... Line 502...
333
	}
502
	}
334
 
503
 
335
	public String getHandlingTime(){
504
	public String getHandlingTime(){
336
		return handlingTime;
505
		return handlingTime;
337
	}
506
	}
338
	
507
 
339
	public void setCustomHandlingTime(String customHandlingTime){
508
	public void setCustomHandlingTime(String customHandlingTime){
340
		this.customHandlingTime = customHandlingTime;
509
		this.customHandlingTime = customHandlingTime;
341
	}
510
	}
342
 
511
 
343
	public String getCustomHandlingTime(){
512
	public String getCustomHandlingTime(){
Line 391... Line 560...
391
 
560
 
392
	public static void main(String[] args) throws NumberFormatException, InventoryServiceException, TException, IOException {
561
	public static void main(String[] args) throws NumberFormatException, InventoryServiceException, TException, IOException {
393
		AmazonListController call = new AmazonListController();
562
		AmazonListController call = new AmazonListController();
394
		//System.out.println(call.runAsinJob());
563
		//System.out.println(call.runAsinJob());
395
	}
564
	}
-
 
565
 
-
 
566
	@Override
-
 
567
	public void setServletContext(ServletContext arg0) {
-
 
568
		// TODO Auto-generated method stub
-
 
569
 
-
 
570
	}
-
 
571
 
-
 
572
	@Override
-
 
573
	public void setServletResponse(HttpServletResponse arg0) {
-
 
574
		// TODO Auto-generated method stub
-
 
575
 
-
 
576
	}
-
 
577
 
-
 
578
	public void setSuppressMfnPriceUpdate(String suppressMfnPriceUpdate) {
-
 
579
		this.suppressMfnPriceUpdate = suppressMfnPriceUpdate;
-
 
580
	}
-
 
581
 
-
 
582
	public String getSuppressMfnPriceUpdate() {
-
 
583
		return suppressMfnPriceUpdate;
-
 
584
	}
-
 
585
 
-
 
586
	public void setSuppressFbaPriceUpdate(String suppressFbaPriceUpdate) {
-
 
587
		this.suppressFbaPriceUpdate = suppressFbaPriceUpdate;
-
 
588
	}
-
 
589
 
-
 
590
	public String getSuppressFbaPriceUpdate() {
-
 
591
		return suppressFbaPriceUpdate;
-
 
592
	}
396
}
593
}