Subversion Repositories SmartDukaan

Rev

Rev 4058 | Rev 4099 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2171 rajveer 1
package in.shop2020.util;
3929 mandeep.dh 2
 
2171 rajveer 3
import in.shop2020.metamodel.core.Entity;
4
import in.shop2020.metamodel.core.EntityState;
5
import in.shop2020.metamodel.core.EntityStatus;
6
import in.shop2020.metamodel.util.CreationUtils;
7
import in.shop2020.metamodel.util.ExpandedEntity;
8
import in.shop2020.model.v1.catalog.InventoryService.Client;
9
import in.shop2020.model.v1.catalog.Item;
3560 rajveer 10
import in.shop2020.model.v1.catalog.Source;
2171 rajveer 11
import in.shop2020.model.v1.catalog.status;
3127 rajveer 12
import in.shop2020.thrift.clients.CatalogClient;
3083 vikas 13
import in.shop2020.ui.util.CatalogUploderToGAE;
2733 rajveer 14
import in.shop2020.ui.util.ComparisonStatsFetcher;
3083 vikas 15
import in.shop2020.ui.util.NewVUI;
2367 rajveer 16
import in.shop2020.ui.util.PriceInsertor;
2838 mandeep.dh 17
import in.shop2020.ui.util.SpecialPageJSONConvertor;
3464 rajveer 18
import in.shop2020.utils.GmailUtils;
2171 rajveer 19
 
3083 vikas 20
import java.io.File;
21
import java.io.IOException;
4098 anupam.sin 22
import java.text.SimpleDateFormat;
3083 vikas 23
import java.util.ArrayList;
24
import java.util.Calendar;
25
import java.util.Date;
26
import java.util.HashMap;
27
import java.util.LinkedHashMap;
28
import java.util.List;
29
import java.util.Map;
2171 rajveer 30
 
3464 rajveer 31
import javax.mail.MessagingException;
32
 
3083 vikas 33
import org.apache.commons.cli.CommandLine;
34
import org.apache.commons.cli.CommandLineParser;
35
import org.apache.commons.cli.HelpFormatter;
36
import org.apache.commons.cli.Options;
37
import org.apache.commons.cli.ParseException;
38
import org.apache.commons.cli.PosixParser;
3929 mandeep.dh 39
import org.apache.commons.logging.Log;
40
import org.apache.commons.logging.LogFactory;
2171 rajveer 41
 
3929 mandeep.dh 42
public class ContentGenerationUtility {
43
    private static final String   UPDATE_TYPE_CATALOG         = "CATALOG";
2171 rajveer 44
 
3929 mandeep.dh 45
    private static final String   UPDATE_TYPE_CONTENT         = "CONTENT";
3083 vikas 46
 
4098 anupam.sin 47
    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} ";
3929 mandeep.dh 48
 
49
    private static Log            log                         = LogFactory
50
                                                                      .getLog(ContentGenerationUtility.class);
51
 
52
    // Commandline options
53
    private static Options        options                     = null;
54
    private static final String   GENERATION_TYPE_INCREMENTAL = "INCREMENTAL";
55
    private static final String   GENERATION_TYPE_ALL         = "ALL";
56
    private static final String   GENERATION_TYPE_ONE         = "ONE";
57
    private static final String   UPDATE_TYPE_OPTION          = "u";
58
    private static final String   GENERATION_TYPE_OPTION      = "t";
59
    private static final String   ENTITY_ID_OPTION            = "e";
4098 anupam.sin 60
    private static final String   TIMESTAMP_OPTION            = "s";
3929 mandeep.dh 61
 
62
    // Default values of cmdline options
63
    private static String         UPDATE_TYPE                 = UPDATE_TYPE_CONTENT;
64
    private static String         GENERATION_TYPE             = GENERATION_TYPE_INCREMENTAL;
65
    private static String         ENTITY_ID                   = "ALL";
66
 
4098 anupam.sin 67
    private Date 				  timeStamp			  		  = null;
3929 mandeep.dh 68
    private CommandLine           cmd                         = null;
69
    private Map<Long, List<Item>> entityIdItemMap             = new LinkedHashMap<Long, List<Item>>();
70
    private Long                  lastGenerationTime          = 0l;
71
    private Map<Long, Entity>     entities;
4098 anupam.sin 72
    private Map<Long, Entity>     dbg_entities;
3929 mandeep.dh 73
    private List<Item>            items;
74
    private List<Source>          sources;
75
    private CatalogClient         csc;
76
    private Client                client;
77
 
78
    private long                  newLastGenerationTime;
79
 
80
    static {
2171 rajveer 81
        options = new Options();
82
        options.addOption(GENERATION_TYPE_OPTION, true, "Generation type");
3929 mandeep.dh 83
        options.addOption(UPDATE_TYPE_OPTION, true, "Default is : "
84
                + UPDATE_TYPE);
85
        options.addOption(ENTITY_ID_OPTION, true, "all entities " + ENTITY_ID
86
                + " by default");
4098 anupam.sin 87
        options.addOption(TIMESTAMP_OPTION, true, "Manual timestamp");
88
 
2171 rajveer 89
    }
3929 mandeep.dh 90
 
91
    public ContentGenerationUtility() throws Exception {
3127 rajveer 92
        csc = new CatalogClient();
2171 rajveer 93
        client = csc.getClient();
3573 rajveer 94
        sources = client.getAllSources();
2171 rajveer 95
    }
2367 rajveer 96
 
2171 rajveer 97
    /**
98
     * @param args
3929 mandeep.dh 99
     * @throws Exception
2171 rajveer 100
     */
3929 mandeep.dh 101
    public static void main(String[] args) throws Exception {
2171 rajveer 102
        ContentGenerationUtility cgu = new ContentGenerationUtility();
3929 mandeep.dh 103
 
104
        // Load arguments
2171 rajveer 105
        cgu.loadArgs(args);
3929 mandeep.dh 106
 
107
        // Call method based on arguments
2367 rajveer 108
        cgu.callMethod();
2171 rajveer 109
    }
2367 rajveer 110
 
3929 mandeep.dh 111
    /**
112
     * Validate and set command line arguments. Exit after printing usage if
113
     * anything is astray
114
     * 
115
     * @param args
116
     *            String[] args as featured in public static void main()
2171 rajveer 117
     */
3929 mandeep.dh 118
    private void loadArgs(String[] args) {
2171 rajveer 119
        CommandLineParser parser = new PosixParser();
3929 mandeep.dh 120
 
2171 rajveer 121
        try {
122
            cmd = parser.parse(options, args);
123
        } catch (ParseException e) {
3929 mandeep.dh 124
            log.error("Error parsing arguments", e);
2171 rajveer 125
            System.exit(1);
126
        }
3929 mandeep.dh 127
 
2171 rajveer 128
        // Check for mandatory args
3929 mandeep.dh 129
        if (!(cmd.hasOption(GENERATION_TYPE_OPTION) && cmd
130
                .hasOption(UPDATE_TYPE_OPTION))) {
2171 rajveer 131
            HelpFormatter formatter = new HelpFormatter();
3929 mandeep.dh 132
            formatter.printHelp(COMMAND_LINE, options);
2171 rajveer 133
            System.exit(1);
134
        }
4098 anupam.sin 135
 
136
 
2171 rajveer 137
        GENERATION_TYPE = cmd.getOptionValue(GENERATION_TYPE_OPTION);
4098 anupam.sin 138
 
2367 rajveer 139
        UPDATE_TYPE = cmd.getOptionValue(UPDATE_TYPE_OPTION);
3929 mandeep.dh 140
 
2171 rajveer 141
        // Look for optional args.
3929 mandeep.dh 142
        if (GENERATION_TYPE.equals(GENERATION_TYPE_ONE)) {
143
            if (cmd.hasOption(ENTITY_ID_OPTION)) {
2171 rajveer 144
                ENTITY_ID = cmd.getOptionValue(ENTITY_ID_OPTION);
3929 mandeep.dh 145
            } else {
2171 rajveer 146
                HelpFormatter formatter = new HelpFormatter();
3929 mandeep.dh 147
                formatter.printHelp(COMMAND_LINE, options);
2171 rajveer 148
                System.exit(1);
149
            }
150
        }
4098 anupam.sin 151
 
152
        if (GENERATION_TYPE_INCREMENTAL.equals(GENERATION_TYPE))
153
        	if (cmd.hasOption(TIMESTAMP_OPTION)) {
154
        		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
155
        		try {
156
        		    timeStamp = df.parse(cmd.getOptionValue(TIMESTAMP_OPTION));
157
        		} catch(Exception e) {
158
        			HelpFormatter formatter = new HelpFormatter();
159
                    formatter.printHelp(COMMAND_LINE, options);
160
                    System.exit(1);
161
        		}
162
        	}
2367 rajveer 163
    }
3929 mandeep.dh 164
 
2367 rajveer 165
    /**
166
     * Call method based on arguments
3929 mandeep.dh 167
     * 
2367 rajveer 168
     * @throws Exception
169
     */
3929 mandeep.dh 170
    private void callMethod() {
171
        boolean isSuccess = false;
172
        String logfile = "/tmp/content-from-cms.log";
173
        if (UPDATE_TYPE.equals(UPDATE_TYPE_CONTENT)) {
174
            logfile = "/tmp/content-from-cms.log";
175
            try {
176
                this.generateContent();
177
                isSuccess = true;
178
            } catch (Exception e) {
179
                log.error("Error generating content", e);
180
            }
181
        }
182
 
183
        if (UPDATE_TYPE.equals(UPDATE_TYPE_CATALOG)) {
184
            logfile = "/tmp/content-from-catalog.log";
185
            try {
186
                this.updatePrices();
187
                isSuccess = true;
188
            } catch (Exception e) {
189
                log.error("Error updating prices", e);
190
            }
191
        }
192
 
4098 anupam.sin 193
//        GmailUtils gm = new GmailUtils();
194
//        String[] sendTo = { "chandranshu.s@shop2020.in",
195
//                "rajveer.singh@shop2020.in", "mandeep.dhir@shop2020.in" };
196
//
197
//        try {
198
//            gm.sendSSLMessage(sendTo, "Content Generation Successful ? : "
199
//                    + isSuccess, "Content generation completed at time : "
200
//                    + Calendar.getInstance().getTime().toString(),
201
//                    "build@shop2020.in", "shop2020", logfile);
202
//        } catch (MessagingException e) {
203
//            log.error("Could not send status mail", e);
204
//        }
2367 rajveer 205
    }
206
 
3929 mandeep.dh 207
    public boolean cleanDir(File dir, boolean deleteSelf) {
208
        if (dir.isDirectory()) {
209
            String[] children = dir.list();
210
            for (int i = 0; i < children.length; i++) {
211
                boolean success = cleanDir(new File(dir, children[i]), true);
212
                if (!success) {
213
                    return false;
214
                }
215
            }
216
        }
217
 
218
        // The directory is now empty so delete it
219
        if (deleteSelf) {
220
            return dir.delete();
221
        }
222
 
223
        return true;
224
    }
225
 
226
    private void removeOldResources() throws IOException {
227
        File f = new File(Utils.EXPORT_SOLR_PATH);
228
        if (f.exists()) {
229
            cleanDir(f, false);
230
        }
231
 
232
        File f1 = new File(Utils.EXPORT_ENTITIES_PATH_LOCALHOST);
233
        if (f1.exists()) {
234
            cleanDir(f1, false);
235
        }
236
 
237
        File f2 = new File(Utils.EXPORT_ENTITIES_PATH_SAHOLIC);
238
        if (f2.exists()) {
239
            cleanDir(f2, false);
240
        }
241
 
242
        File f3 = new File(Utils.EXPORT_ENTITIES_PATH_SHOP2020);
243
        if (f3.exists()) {
244
            cleanDir(f3, false);
245
        }
246
    }
247
 
2367 rajveer 248
    /**
249
     * Update the prices in the generated content
3929 mandeep.dh 250
     * 
2367 rajveer 251
     * @throws Exception
252
     */
253
    private void updatePrices() throws Exception {
3929 mandeep.dh 254
        lastGenerationTime = new Long(0);
255
        if (GENERATION_TYPE.equals(GENERATION_TYPE_ONE)) {
2367 rajveer 256
            items = client.getItemsByCatalogId(Long.parseLong(ENTITY_ID));
3929 mandeep.dh 257
        } else {
2367 rajveer 258
            items = client.getAllItemsByStatus(status.ACTIVE);
259
            items.addAll(client.getAllItemsByStatus(status.PAUSED));
260
 
3929 mandeep.dh 261
            // Clean up the data from the solr directories.
2367 rajveer 262
            removeOldResources();
263
 
264
        }
3929 mandeep.dh 265
 
266
        // this still needs to be evolved. Must not be used.
267
        if (GENERATION_TYPE.equals(GENERATION_TYPE_INCREMENTAL)) {
2367 rajveer 268
        }
269
 
3929 mandeep.dh 270
        // Populate the entityIdIemMap
271
        populateEntityIdItemMap();
2367 rajveer 272
 
273
        PriceInsertor priceInserter = new PriceInsertor();
274
 
3929 mandeep.dh 275
        for (Map.Entry<Long, List<Item>> entry : entityIdItemMap.entrySet()) {
276
            long entityId = entry.getKey();
277
            List<Item> items = entry.getValue();
278
            // TODO Domain name and destination directory should be read from
279
            // properties file
280
            double minPrice = priceInserter.insertPriceInHtml(items, entityId,
281
                    "saholic.com", Utils.EXPORT_ENTITIES_PATH_SAHOLIC, null);
282
            priceInserter.insertPriceInHtml(items, entityId, "shop2020.in",
283
                    Utils.EXPORT_ENTITIES_PATH_SHOP2020, null);
284
            priceInserter.insertPriceInHtml(items, entityId, "localhost:8090",
285
                    Utils.EXPORT_ENTITIES_PATH_LOCALHOST, null);
286
            StringBuilder priceString = new StringBuilder(
287
                    "<field name=\"F_50002\">" + minPrice + "</field>");
288
 
289
            if (sources != null) {
290
                for (Source source : sources) {
291
                    minPrice = priceInserter.insertPriceInHtml(items, entityId,
292
                            "saholic.com", Utils.EXPORT_ENTITIES_PATH_SAHOLIC,
293
                            source);
294
                    priceInserter.insertPriceInHtml(items, entityId,
295
                            "shop2020.in", Utils.EXPORT_ENTITIES_PATH_SHOP2020,
296
                            source);
297
                    priceInserter.insertPriceInHtml(items, entityId,
298
                            "localhost:8090",
299
                            Utils.EXPORT_ENTITIES_PATH_LOCALHOST, source);
300
                    priceString.append("<field name=\"F_50002_"
301
                            + source.getId() + "\">" + minPrice + "</field>");
302
                }
2367 rajveer 303
            }
3929 mandeep.dh 304
 
305
            priceInserter.insertPriceInSolrData(entityId,
306
                    priceString.toString());
2367 rajveer 307
        }
3929 mandeep.dh 308
 
4058 rajveer 309
        priceInserter.copySolrSchemaFiles();
310
 
3929 mandeep.dh 311
        // Generate partners and json objects for phones only
312
        if (!GENERATION_TYPE.equals(GENERATION_TYPE_ONE)) {
313
            ProductListGenerator generator = new ProductListGenerator(
314
                    entityIdItemMap);
315
            generator.generateProductsListXML();
316
            generator.generateProductListJavascript();
317
        }
2367 rajveer 318
    }
319
 
3929 mandeep.dh 320
    /**
2171 rajveer 321
     * Generates content for the specified entity embedding links to the
322
     * specified domain name.
323
     * 
3929 mandeep.dh 324
     * The method will not generate content if one of the following conditions
325
     * is met:
2171 rajveer 326
     * <ol>
327
     * <li>The entity is not ready.
328
     * <li>The category has not been updated yet. (Set to -1).
2367 rajveer 329
     * <li>The content has not been updated.
2171 rajveer 330
     * </ol>
3929 mandeep.dh 331
     * 
2367 rajveer 332
     * @throws
2171 rajveer 333
     */
3929 mandeep.dh 334
    private void generateContent() throws Exception {
335
        if (GENERATION_TYPE.equals(GENERATION_TYPE_ALL)) {
336
            entities = CreationUtils.getEntities();
2367 rajveer 337
            lastGenerationTime = new Long(0);
3929 mandeep.dh 338
        } else if (GENERATION_TYPE.equals(GENERATION_TYPE_ONE)) {
339
            entities = new HashMap<Long, Entity>();
4098 anupam.sin 340
            dbg_entities = CreationUtils.getEntities();
3929 mandeep.dh 341
            entities.put(Long.parseLong(ENTITY_ID),
342
                    CreationUtils.getEntity(Long.parseLong(ENTITY_ID)));
343
            lastGenerationTime = new Long(0);
344
        } else {
4098 anupam.sin 345
        	entities = CreationUtils.getEntities();
346
            //  When we read lastGenerationTime from database
347
            //  then only we should mark the 
348
            //	current time as newLastGenerationTime
349
            if(timeStamp == null) {
350
            	newLastGenerationTime = new Date().getTime();
351
            	lastGenerationTime = CreationUtils.getLastContentGenerationTime();
352
            } else {
353
            	lastGenerationTime = timeStamp.getTime();
354
            }
355
 
3929 mandeep.dh 356
            log.info("lastGenerationTime: " + lastGenerationTime);
357
            if (lastGenerationTime == null) {
2171 rajveer 358
                lastGenerationTime = new Long(0);
3929 mandeep.dh 359
            }
4098 anupam.sin 360
        } 
3929 mandeep.dh 361
 
362
        // Filter invalid entities here
2367 rajveer 363
        List<Entity> validEntities = new ArrayList<Entity>();
3929 mandeep.dh 364
        for (long entityID : entities.keySet()) {
365
            if (isValidEntity(entities.get(entityID))) {
366
                validEntities.add(entities.get(entityID));
367
            }
2171 rajveer 368
        }
3929 mandeep.dh 369
 
370
        // Calculate comparison scores
371
        log.info("Calculating comparison scores");
2367 rajveer 372
        NewCMP cmp = new NewCMP(validEntities);
2171 rajveer 373
        Map<Long, Map<Long, Double>> slideScoresByEntity = cmp.getSlideScores();
2367 rajveer 374
        CreationUtils.storeSlideScores(slideScoresByEntity);
2658 rajveer 375
 
3516 rajveer 376
        // Fetch comparison statistics everyday and store them in BDB
3929 mandeep.dh 377
        log.info("Fetching comparison statistics");
3516 rajveer 378
        ComparisonStatsFetcher csf = new ComparisonStatsFetcher();
379
        csf.fetchAndStoreComparisonStats();
3929 mandeep.dh 380
 
381
        // Upload catalog to Google App Engine.
382
        if (GENERATION_TYPE.equals(GENERATION_TYPE_ALL)) {
383
            log.info("Uploading Catalog to Google app engine");
3083 vikas 384
            List<Item> allItems = client.getAllItems(false);
385
            allItems.addAll(client.getAllItems(true));
386
            CatalogUploderToGAE catalogUploaderToGAE = new CatalogUploderToGAE();
387
            catalogUploaderToGAE.uploadItems(allItems);
388
        }
3929 mandeep.dh 389
 
2726 rajveer 390
        items = client.getAllItemsByStatus(status.ACTIVE);
391
        items.addAll(client.getAllItemsByStatus(status.PAUSED));
392
        items.addAll(client.getAllItemsByStatus(status.CONTENT_COMPLETE));
393
        populateEntityIdItemMap();
3929 mandeep.dh 394
 
395
        log.info("Finding accessories");
2726 rajveer 396
        AccessoriesFinder af = new AccessoriesFinder(entityIdItemMap.keySet());
3929 mandeep.dh 397
        Map<Long, Map<Long, List<Long>>> relatedAccessories = af.findAccessories();
398
        CreationUtils.storeRelatedAccessories(relatedAccessories);
2838 mandeep.dh 399
 
3929 mandeep.dh 400
        log.info("Writing JSON file for special pages");
2838 mandeep.dh 401
        SpecialPageJSONConvertor bjc = new SpecialPageJSONConvertor();
3929 mandeep.dh 402
        bjc.writeToJSONFile(new File(Utils.EXPORT_JAVASCRIPT_CONTENT_PATH
403
                + "special-pages.json"));
2838 mandeep.dh 404
 
3929 mandeep.dh 405
        log.info("Generating velocity templates, images, documents etc.");
2171 rajveer 406
        NewVUI vui = new NewVUI(lastGenerationTime);
3929 mandeep.dh 407
        for (Entity entity : validEntities) {
408
            log.info("Processing Entityid: " + entity.getID());
409
            vui.generateContentForOneEntity(entity, Utils.EXPORT_VELOCITY_PATH);
2171 rajveer 410
        }
3929 mandeep.dh 411
 
412
        // Generate synonyms list. This will be used in PriceComparisonTool to
413
        // resolve the product names.
414
        log.info("Generating synonyms");
415
        SynonymExporter sx = new SynonymExporter(validEntities);
416
        sx.storeSynonyms();
417
 
418
        if (newLastGenerationTime != 0) {
419
            CreationUtils.storeLastContentGenerationTime(newLastGenerationTime);
420
        }
421
 
422
 
423
        log.info("Generating Solr files");
2367 rajveer 424
        NewIR ir = new NewIR(validEntities);
2227 rajveer 425
        ir.exportIRData();
3929 mandeep.dh 426
        // ir.transformIrDataXMLtoSolrXML();
2227 rajveer 427
        ir.exportIRMetaData();
4057 rajveer 428
        ir.transformIrMetaDataXMLtoSolrSchemaXML();
429
        ir.transformIrMetaDataXMLtoSolrCatchAllXML();
2227 rajveer 430
 
3929 mandeep.dh 431
        for (Map.Entry<Long, List<Item>> entry : entityIdItemMap.entrySet()) {
432
            List<Item> items = entry.getValue();
433
            for (Item item : items) {
434
                if (item.getItemStatus() == status.CONTENT_COMPLETE) {
2493 rajveer 435
                    item.setItemStatus(status.ACTIVE);
436
                    item.setStatus_description("This item is active");
437
                    client.updateItem(item);
3929 mandeep.dh 438
                }
439
            }
2493 rajveer 440
        }
2171 rajveer 441
    }
2367 rajveer 442
 
2171 rajveer 443
    /**
3929 mandeep.dh 444
     * Checks weather entity is valid or not. Entity will be invalid in one of
445
     * these cases:
2367 rajveer 446
     * <ol>
447
     * <li>The entity is not ready.
448
     * <li>The category has not been updated yet. (Set to -1).
449
     * <li>Content has not been updated after last content generation timestamp.
450
     * </ol>
451
     * 
452
     * @param entity
453
     * @return
454
     * @throws Exception
2171 rajveer 455
     */
3929 mandeep.dh 456
    private boolean isValidEntity(Entity entity) throws Exception {
2367 rajveer 457
        ExpandedEntity expEntity = new ExpandedEntity(entity);
458
        EntityState state = CreationUtils.getEntityState(entity.getID());
459
        long categoryID = expEntity.getCategoryID();
3929 mandeep.dh 460
 
461
        if (state.getStatus() != EntityStatus.READY || categoryID == -1) {
2367 rajveer 462
            return false;
463
        }
3929 mandeep.dh 464
        if (state.getMerkedReadyOn().getTime() < this.lastGenerationTime) {
2367 rajveer 465
            return false;
466
        }
467
        return true;
468
    }
469
 
3929 mandeep.dh 470
    private void populateEntityIdItemMap() {
2171 rajveer 471
        Date todate = new Date();
3929 mandeep.dh 472
        for (Item item : items) {
473
            // TODO Can be removed as we are checking in calling function
474
            if (!(item.getItemStatus() == status.ACTIVE
475
                    || item.getItemStatus() == status.CONTENT_COMPLETE || item
476
                    .getItemStatus() == status.PAUSED)) {
2171 rajveer 477
                continue;
478
            }
3929 mandeep.dh 479
            if (todate.getTime() < item.getStartDate()
480
                    || item.getSellingPrice() == 0) {
2171 rajveer 481
                continue;
482
            }
2367 rajveer 483
            List<Item> itemList = entityIdItemMap.get(item.getCatalogItemId());
3929 mandeep.dh 484
            if (itemList == null) {
2171 rajveer 485
                itemList = new ArrayList<Item>();
486
            }
487
            itemList.add(item);
488
            entityIdItemMap.put(item.getCatalogItemId(), itemList);
489
        }
2367 rajveer 490
 
3929 mandeep.dh 491
        // Remove all items which have not been updated since last content
492
        // generation.
2171 rajveer 493
        List<Long> removeEntities = new ArrayList<Long>();
3929 mandeep.dh 494
        for (Long entityId : entityIdItemMap.keySet()) {
2171 rajveer 495
            boolean isValidEntity = false;
3929 mandeep.dh 496
            // If any one of the items has been updated before current
497
            // timestamp, than we generate content for whole entity
498
            for (Item item : entityIdItemMap.get(entityId)) {
499
                if (item.getUpdatedOn() > lastGenerationTime) {
2171 rajveer 500
                    isValidEntity = true;
501
                }
502
            }
3929 mandeep.dh 503
            if (!isValidEntity) {
2171 rajveer 504
                removeEntities.add(entityId);
505
            }
506
        }
3929 mandeep.dh 507
        for (Long entityId : removeEntities) {
2171 rajveer 508
            entityIdItemMap.remove(entityId);
509
        }
510
    }
511
}