Subversion Repositories SmartDukaan

Rev

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

Rev 5155 Rev 5227
Line 34... Line 34...
34
import org.apache.commons.cli.CommandLineParser;
34
import org.apache.commons.cli.CommandLineParser;
35
import org.apache.commons.cli.HelpFormatter;
35
import org.apache.commons.cli.HelpFormatter;
36
import org.apache.commons.cli.Options;
36
import org.apache.commons.cli.Options;
37
import org.apache.commons.cli.ParseException;
37
import org.apache.commons.cli.ParseException;
38
import org.apache.commons.cli.PosixParser;
38
import org.apache.commons.cli.PosixParser;
-
 
39
import org.apache.commons.lang.StringUtils;
39
import org.apache.commons.logging.Log;
40
import org.apache.commons.logging.Log;
40
import org.apache.commons.logging.LogFactory;
41
import org.apache.commons.logging.LogFactory;
41
 
42
 
42
import com.google.gson.Gson;
43
import com.google.gson.Gson;
43
 
44
 
Line 48... Line 49...
48
 
49
 
49
    private static final String   COMMAND_LINE                = "java ContentGenerationUtility.class -t { ALL | INCREMENTAL | ONE } -s { yyyy-MM-dd-HH-mm-ss } -u { CONTENT | CATALOG } -e {EntityId} ";
50
    private static final String   COMMAND_LINE                = "java ContentGenerationUtility.class -t { ALL | INCREMENTAL | ONE } -s { yyyy-MM-dd-HH-mm-ss } -u { CONTENT | CATALOG } -e {EntityId} ";
50
 
51
 
51
    private static Log            log                         = LogFactory
52
    private static Log            log                         = LogFactory
52
                                                                      .getLog(ContentGenerationUtility.class);
53
                                                                      .getLog(ContentGenerationUtility.class);
53
 
-
 
-
 
54
    private static long 			ONE_DAY					  = 24*60*60*1000;  	//milliseconds in a day						 	
54
    // Commandline options
55
    // Commandline options
55
    private static Options        options                     = null;
56
    private static Options        options                     = null;
56
    private static final String   GENERATION_TYPE_INCREMENTAL = "INCREMENTAL";
57
    private static final String   GENERATION_TYPE_INCREMENTAL = "INCREMENTAL";
57
    private static final String   GENERATION_TYPE_ALL         = "ALL";
58
    private static final String   GENERATION_TYPE_ALL         = "ALL";
58
    private static final String   GENERATION_TYPE_ONE         = "ONE";
59
    private static final String   GENERATION_TYPE_ONE         = "ONE";
Line 254... Line 255...
254
        lastGenerationTime = new Long(0);
255
        lastGenerationTime = new Long(0);
255
        if (GENERATION_TYPE.equals(GENERATION_TYPE_ONE)) {
256
        if (GENERATION_TYPE.equals(GENERATION_TYPE_ONE)) {
256
            items = client.getItemsByCatalogId(Long.parseLong(ENTITY_ID));
257
            items = client.getItemsByCatalogId(Long.parseLong(ENTITY_ID));
257
        } else {
258
        } else {
258
            items = client.getAllItemsByStatus(status.ACTIVE);
259
            items = client.getAllItemsByStatus(status.ACTIVE);
-
 
260
            items.addAll(client.getAllItemsByStatus(status.COMING_SOON));
259
            items.addAll(client.getAllItemsByStatus(status.PAUSED));
261
            items.addAll(client.getAllItemsByStatus(status.PAUSED));
260
            try {
262
            try {
261
                //Generate prices and availability data for amazon
263
                //Generate prices and availability data for amazon
262
                AmazonSCDataGenerator.generatePricesAndAvailability();
264
                AmazonSCDataGenerator.generatePricesAndAvailability();
263
            } catch (Exception e) {
265
            } catch (Exception e) {
Line 399... Line 401...
399
        }
401
        }
400
 
402
 
401
        items = client.getAllItemsByStatus(status.ACTIVE);
403
        items = client.getAllItemsByStatus(status.ACTIVE);
402
        items.addAll(client.getAllItemsByStatus(status.PAUSED));
404
        items.addAll(client.getAllItemsByStatus(status.PAUSED));
403
        items.addAll(client.getAllItemsByStatus(status.CONTENT_COMPLETE));
405
        items.addAll(client.getAllItemsByStatus(status.CONTENT_COMPLETE));
-
 
406
        items.addAll(client.getAllItemsByStatus(status.COMING_SOON));
404
        populateEntityIdItemMap();
407
        populateEntityIdItemMap();
405
 
408
 
406
        //FIXME Avoiding the finding of accesories, as list of categories for which we need to find accessories is hardocoded in code. 
409
        //FIXME Avoiding the finding of accesories, as list of categories for which we need to find accessories is hardocoded in code. 
407
        // We need to make that configurable. Also creating ticket to improve it.
410
        // We need to make that configurable. Also creating ticket to improve it.
408
        try{
411
        try{
Line 469... Line 472...
469
        ir.transformIrMetaDataXMLtoSolrCatchAllXML();
472
        ir.transformIrMetaDataXMLtoSolrCatchAllXML();
470
 
473
 
471
        for (Map.Entry<Long, List<Item>> entry : entityIdItemMap.entrySet()) {
474
        for (Map.Entry<Long, List<Item>> entry : entityIdItemMap.entrySet()) {
472
            List<Item> items = entry.getValue();
475
            List<Item> items = entry.getValue();
473
            for (Item item : items) {
476
            for (Item item : items) {
474
                if (item.getItemStatus() == status.CONTENT_COMPLETE) {
477
                if (item.getItemStatus() == status.CONTENT_COMPLETE || item.getItemStatus() == status.COMING_SOON) {
-
 
478
                	if(item.getStartDate() <= new Date().getTime()){
475
                    item.setItemStatus(status.ACTIVE);
479
                		item.setItemStatus(status.ACTIVE);
476
                    item.setStatus_description("This item is active");
480
                		item.setStatus_description("This item is active");
-
 
481
                	} else {
-
 
482
                		item.setItemStatus(status.COMING_SOON);
-
 
483
                		String productName = getProductName(item);
-
 
484
                		String statusDescription = productName + " is coming soon.";
-
 
485
                		if(item.getExpectedArrivalDate()>new Date().getTime() + ONE_DAY){
-
 
486
                			statusDescription = productName + " will be available by " 
-
 
487
                			+ new SimpleDateFormat("dd/MM/yy").format(new Date(item.getExpectedArrivalDate()));
-
 
488
                		}
-
 
489
                		item.setStatus_description(statusDescription);
-
 
490
                	}
477
                    client.updateItem(item);
491
                    client.updateItem(item);
478
                }
492
                }
479
            }
493
            }
480
        }
494
        }
481
        try {
495
        try {
Line 485... Line 499...
485
        	e.printStackTrace();
499
        	e.printStackTrace();
486
            log.info("Could not generate Amazon data", e);
500
            log.info("Could not generate Amazon data", e);
487
        }
501
        }
488
    }
502
    }
489
 
503
 
-
 
504
    private String getProductName(Item item) {
-
 
505
    	String brand = item.getBrand();
-
 
506
		String modelName = item.getModelName();
-
 
507
		String modelNumber = item.getModelNumber();
-
 
508
		String product = "";
-
 
509
		if(StringUtils.isEmpty(modelName)){
-
 
510
			product = brand + " " + modelNumber;
-
 
511
		}else {
-
 
512
			product = brand + " " + modelName + " " + modelNumber;
-
 
513
		}
-
 
514
		return product;
-
 
515
	}
-
 
516
 
490
    /**
517
    /**
491
     * Checks weather entity is valid or not. Entity will be invalid in one of
518
     * Checks weather entity is valid or not. Entity will be invalid in one of
492
     * these cases:
519
     * these cases:
493
     * <ol>
520
     * <ol>
494
     * <li>The entity is not ready.
521
     * <li>The entity is not ready.
Line 520... Line 547...
520
        for (Item item : items) {
547
        for (Item item : items) {
521
            Utils.info(item.getId() + ":" + item.getItemStatus() + ":" + item.getCatalogItemId());
548
            Utils.info(item.getId() + ":" + item.getItemStatus() + ":" + item.getCatalogItemId());
522
            // TODO Can be removed as we are checking in calling function
549
            // TODO Can be removed as we are checking in calling function
523
            if (!(item.getItemStatus() == status.ACTIVE
550
            if (!(item.getItemStatus() == status.ACTIVE
524
                    || item.getItemStatus() == status.CONTENT_COMPLETE || item
551
                    || item.getItemStatus() == status.CONTENT_COMPLETE || item
525
                    .getItemStatus() == status.PAUSED)) {
552
                    .getItemStatus() == status.PAUSED || item.getItemStatus() == status.COMING_SOON)) {
526
                continue;
553
                continue;
527
            }
554
            }
528
            Utils.info(item.getStartDate() + ":" + item.getSellingPrice());
555
            Utils.info(item.getStartDate() + ":" + item.getSellingPrice());
-
 
556
            
529
            if (todate.getTime() < item.getStartDate()
557
			if (todate.getTime() < item.getStartDate()
-
 
558
					&& (!item.isSetExpectedArrivalDate() || todate.getTime() < item.getComingSoonStartDate()) 
530
                    || item.getSellingPrice() == 0) {
559
					|| item.getSellingPrice() == 0) {
531
                continue;
560
				continue;
532
            }
561
			}
533
            Utils.info(item.getId() + " Item is adding");
562
            Utils.info(item.getId() + " Item is adding");
534
            List<Item> itemList = entityIdItemMap.get(item.getCatalogItemId());
563
            List<Item> itemList = entityIdItemMap.get(item.getCatalogItemId());
535
            if (itemList == null) {
564
            if (itemList == null) {
536
                itemList = new ArrayList<Item>();
565
                itemList = new ArrayList<Item>();
537
            }
566
            } 
538
            itemList.add(item);
567
            itemList.add(item);
539
            entityIdItemMap.put(item.getCatalogItemId(), itemList);
568
            entityIdItemMap.put(item.getCatalogItemId(), itemList);
540
        }
569
        }
541
 
570
 
542
        Utils.info("Processing " + entityIdItemMap.size() + " entities");
571
        Utils.info("Processing " + entityIdItemMap.size() + " entities");
Line 546... Line 575...
546
        for (Long entityId : entityIdItemMap.keySet()) {
575
        for (Long entityId : entityIdItemMap.keySet()) {
547
            boolean isValidEntity = false;
576
            boolean isValidEntity = false;
548
            // If any one of the items has been updated before current
577
            // If any one of the items has been updated before current
549
            // timestamp, than we generate content for whole entity
578
            // timestamp, than we generate content for whole entity
550
            for (Item item : entityIdItemMap.get(entityId)) {
579
            for (Item item : entityIdItemMap.get(entityId)) {
551
                if (item.getUpdatedOn() > lastGenerationTime) {
580
                if (item.getUpdatedOn() > lastGenerationTime || item.getItemStatus()==status.COMING_SOON) {
552
                    isValidEntity = true;
581
                    isValidEntity = true;
553
                }
582
                }
554
            }
583
            }
555
            if (!isValidEntity) {
584
            if (!isValidEntity) {
556
                removeEntities.add(entityId);
585
                removeEntities.add(entityId);