Subversion Repositories SmartDukaan

Rev

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

Rev 2362 Rev 2367
Line 1... Line 1...
1
package in.shop2020.util;
1
package in.shop2020.util;
-
 
2
import java.io.File;
-
 
3
import java.io.IOException;
2
import java.util.ArrayList;
4
import java.util.ArrayList;
3
import java.util.Date;
5
import java.util.Date;
-
 
6
import java.util.HashMap;
4
import java.util.LinkedHashMap;
7
import java.util.LinkedHashMap;
5
import java.util.List;
8
import java.util.List;
6
import java.util.Map;
9
import java.util.Map;
7
 
10
 
8
import in.shop2020.metamodel.core.Entity;
11
import in.shop2020.metamodel.core.Entity;
Line 12... Line 15...
12
import in.shop2020.metamodel.util.ExpandedEntity;
15
import in.shop2020.metamodel.util.ExpandedEntity;
13
import in.shop2020.model.v1.catalog.InventoryService.Client;
16
import in.shop2020.model.v1.catalog.InventoryService.Client;
14
import in.shop2020.model.v1.catalog.Item;
17
import in.shop2020.model.v1.catalog.Item;
15
import in.shop2020.model.v1.catalog.status;
18
import in.shop2020.model.v1.catalog.status;
16
import in.shop2020.thrift.clients.CatalogServiceClient;
19
import in.shop2020.thrift.clients.CatalogServiceClient;
-
 
20
import in.shop2020.ui.util.PriceInsertor;
17
import in.shop2020.ui.util.NewVUI;
21
import in.shop2020.ui.util.NewVUI;
18
 
22
 
19
import org.apache.commons.cli.*;
23
import org.apache.commons.cli.*;
20
 
24
 
21
 
25
 
22
 
26
 
23
public class ContentGenerationUtility {
27
public class ContentGenerationUtility {
24
    private static Options options = null; // Command line options
28
    private static Options options = null; // Command line options
25
    
29
    
-
 
30
    private static final String UPDATE_TYPE_OPTION = "u";
26
    private static final String GENERATION_TYPE_OPTION = "t";
31
    private static final String GENERATION_TYPE_OPTION = "t";
27
    private static final String ENTITY_ID_OPTION = "e";
32
    private static final String ENTITY_ID_OPTION = "e";
28
    
33
    
-
 
34
    private static String UPDATE_TYPE = "CONTENT";
29
    private static String GENERATION_TYPE = "INCREMENTAL";
35
    private static String GENERATION_TYPE = "INCREMENTAL";
30
    private static String ENTITY_ID = "ALL";
36
    private static String ENTITY_ID = "ALL";
31
    Map<Long, Entity> entities;
37
    Map<Long, Entity> entities;
32
    List<Item> items;
38
    List<Item> items;
-
 
39
    List<Item> contentCompleteItems  = new ArrayList<Item>();
33
    List<Item> contentCompleteItems;
40
    List<Item> phasedOutItems;
34
    CatalogServiceClient csc;
41
    CatalogServiceClient csc;
35
    Client client;
42
    Client client;
36
    Map<Long, List<Item>> entityIdItemMap = new LinkedHashMap<Long, List<Item>>();
43
    Map<Long, List<Item>> entityIdItemMap = new LinkedHashMap<Long, List<Item>>();
37
    private CommandLine cmd = null; // Command Line arguments
44
    private CommandLine cmd = null; // Command Line arguments
38
    Long lastGenerationTime;
45
    Long lastGenerationTime;
39
    
46
    
40
    static{
47
    static{
41
        options = new Options();
48
        options = new Options();
42
        options.addOption(GENERATION_TYPE_OPTION, true, "Generation type");
49
        options.addOption(GENERATION_TYPE_OPTION, true, "Generation type");
-
 
50
        options.addOption(UPDATE_TYPE_OPTION, true, "Default is : " + UPDATE_TYPE);
43
        options.addOption(ENTITY_ID_OPTION, true, "all entities " + ENTITY_ID + " by default");
51
        options.addOption(ENTITY_ID_OPTION, true, "all entities " + ENTITY_ID + " by default");
44
        
-
 
45
    }
52
    }
46
    
53
    
47
    public ContentGenerationUtility() throws Exception{
54
    public ContentGenerationUtility() throws Exception{
48
        csc = new CatalogServiceClient();
55
        csc = new CatalogServiceClient();
49
        client = csc.getClient();
56
        client = csc.getClient();
50
    }
57
    }
51
    
58
    
-
 
59
 
52
    /**
60
    /**
53
     * @param args
61
     * @param args
54
     * @throws Exception 
62
     * @throws Exception 
55
     */
63
     */
56
    public static void main(String[] args) throws Exception {
64
    public static void main(String[] args) throws Exception {
57
        ContentGenerationUtility cgu = new ContentGenerationUtility();
65
        ContentGenerationUtility cgu = new ContentGenerationUtility();
-
 
66
        //Load arguments
58
        cgu.loadArgs(args);
67
        cgu.loadArgs(args);
-
 
68
        //Call method based on arguments
59
        cgu.generateContent();
69
        cgu.callMethod();
60
    }
70
    }
-
 
71
 
61
    
72
    
62
    /**
73
	/**
63
     * Validate and set command line arguments.
74
     * Validate and set command line arguments.
64
     * Exit after printing usage if anything is astray
75
     * Exit after printing usage if anything is astray
65
     * @param args String[] args as featured in public static void main()
76
     * @param args String[] args as featured in public static void main()
66
     */
77
     */
67
    private void loadArgs(String[] args){
78
    private void loadArgs(String[] args){
Line 74... Line 85...
74
            System.exit(1);
85
            System.exit(1);
75
        }
86
        }
76
        
87
        
77
        // Check for mandatory args
88
        // Check for mandatory args
78
        
89
        
79
        if (! cmd.hasOption(GENERATION_TYPE_OPTION)){
90
        if (!( cmd.hasOption(GENERATION_TYPE_OPTION)  &&  cmd.hasOption(UPDATE_TYPE_OPTION))){
80
            HelpFormatter formatter = new HelpFormatter();
91
            HelpFormatter formatter = new HelpFormatter();
81
            formatter.printHelp("java ContentGenerationUtility.class -t {ALL,INCREMENTAL,ONE} -e {EntityId} ", options);
92
            formatter.printHelp("java ContentGenerationUtility.class -t { ALL | INCREMENTAL | ONE } -u { CONTENT | CATALOG } -e {EntityId} ", options);
82
            System.exit(1);
93
            System.exit(1);
83
        }
94
        }
84
        
95
        
85
        GENERATION_TYPE = cmd.getOptionValue(GENERATION_TYPE_OPTION);
96
        GENERATION_TYPE = cmd.getOptionValue(GENERATION_TYPE_OPTION);
86
        // Look for optional args.
-
 
87
        
97
        
-
 
98
        UPDATE_TYPE = cmd.getOptionValue(UPDATE_TYPE_OPTION);
-
 
99
        
-
 
100
        // Look for optional args.
88
        if(GENERATION_TYPE.equals("ONE")){
101
        if(GENERATION_TYPE.equals("ONE")){
89
            if (cmd.hasOption(ENTITY_ID_OPTION)){
102
            if (cmd.hasOption(ENTITY_ID_OPTION)){
90
                ENTITY_ID = cmd.getOptionValue(ENTITY_ID_OPTION);
103
                ENTITY_ID = cmd.getOptionValue(ENTITY_ID_OPTION);
91
            }else{
104
            }else{
92
                HelpFormatter formatter = new HelpFormatter();
105
                HelpFormatter formatter = new HelpFormatter();
93
                formatter.printHelp("java ContentGenerationUtility.class -t {ALL,INCREMENTAL,ONE} -e {EntityId} ", options);
106
                formatter.printHelp("java ContentGenerationUtility.class -t { ALL | INCREMENTAL | ONE } -u { CONTENT | CATALOG } -e {EntityId} ", options);
94
                System.exit(1);
107
                System.exit(1);
95
            }
108
            }
96
        }
109
        }
-
 
110
    }
-
 
111
    
-
 
112
    /**
-
 
113
     * Call method based on arguments
-
 
114
     * @throws Exception
-
 
115
     */
-
 
116
    private void callMethod() throws Exception{
-
 
117
    	if(UPDATE_TYPE.equals("CONTENT")){
-
 
118
    		this.generateContent();	
-
 
119
    	}
-
 
120
    	
-
 
121
    	if(UPDATE_TYPE.equals("CATALOG")){
-
 
122
    		this.updatePrices();
-
 
123
    	}	
-
 
124
    }
-
 
125
    
-
 
126
 
-
 
127
    
-
 
128
	public boolean deleteDir(File dir) {
-
 
129
	    if (dir.isDirectory()) {
-
 
130
	        String[] children = dir.list();
-
 
131
	        for (int i=0; i<children.length; i++) {
-
 
132
	            boolean success = deleteDir(new File(dir, children[i]));
-
 
133
	            if (!success) {
-
 
134
	                return false;
-
 
135
	            }
-
 
136
	        }
-
 
137
	    }
-
 
138
	    // The directory is now empty so delete it
-
 
139
	    return dir.delete();
-
 
140
	}
-
 
141
	
-
 
142
	
-
 
143
	private void removeOldResources() throws IOException{
-
 
144
		File f = new File(Utils.EXPORT_SOLR_PATH);
-
 
145
		if(f.exists()){
-
 
146
			deleteDir(f);
-
 
147
		}
-
 
148
		f.createNewFile();
-
 
149
		f.mkdir();
-
 
150
		
-
 
151
		File f1 = new File(Utils.EXPORT_ENTITIES_PATH_LOCALHOST);
-
 
152
		if(f1.exists()){
-
 
153
			deleteDir(f1);
-
 
154
		}
-
 
155
		f1.createNewFile();
-
 
156
		f1.mkdir();
-
 
157
		
-
 
158
		File f2 = new File(Utils.EXPORT_ENTITIES_PATH_SAHOLIC);
-
 
159
		if(f2.exists()){
-
 
160
			deleteDir(f2);
-
 
161
		}
-
 
162
		f2.createNewFile();
-
 
163
		f2.mkdir();
-
 
164
		
-
 
165
		File f3 = new File(Utils.EXPORT_ENTITIES_PATH_SHOP2020);
-
 
166
		if(f3.exists()){
-
 
167
			deleteDir(f3);
-
 
168
		}
-
 
169
		f3.createNewFile();
-
 
170
		f3.mkdir();
-
 
171
	}
-
 
172
	
-
 
173
    /**
-
 
174
     * Update the prices in the generated content
-
 
175
     * @throws Exception
-
 
176
     */
-
 
177
    private void updatePrices() throws Exception {
-
 
178
    	lastGenerationTime = new Long(0);
-
 
179
        if(GENERATION_TYPE.equals("ONE")) {
-
 
180
            items = client.getItemsByCatalogId(Long.parseLong(ENTITY_ID));
-
 
181
        }else{
-
 
182
            items = client.getAllItemsByStatus(status.ACTIVE);
-
 
183
            items.addAll(client.getAllItemsByStatus(status.PAUSED));
-
 
184
            items.addAll(client.getAllItemsByStatus(status.CONTENT_COMPLETE));
-
 
185
 
-
 
186
            //Clean up the data from the solr directories.
-
 
187
            removeOldResources();
-
 
188
 
-
 
189
        }
-
 
190
        //this still needs to be evolved. Must not be used.
-
 
191
        if(GENERATION_TYPE.equals("INCREMENTAL")) {
-
 
192
        }
-
 
193
 
-
 
194
 
-
 
195
        
-
 
196
        //Populate the entityIdIemMap 
-
 
197
        populateEntityIdItemMap();
97
        
198
        
-
 
199
        PriceInsertor priceInserter = new PriceInsertor();
-
 
200
		
-
 
201
        for(Map.Entry<Long, List<Item>> entry: entityIdItemMap.entrySet()){
-
 
202
        	long entityId = entry.getKey();
-
 
203
        	List<Item> items = entry.getValue();
-
 
204
            //TODO Domain name and destination  directory should be read from properties file
-
 
205
        	priceInserter.insertPriceInHtml(items, entityId, "saholic.com", Utils.EXPORT_ENTITIES_PATH_SAHOLIC);
-
 
206
        	priceInserter.insertPriceInHtml(items, entityId, "shop2020.in", Utils.EXPORT_ENTITIES_PATH_SHOP2020);
-
 
207
        	priceInserter.insertPriceInHtml(items, entityId, "localhost:8090", Utils.EXPORT_ENTITIES_PATH_LOCALHOST);
-
 
208
        	priceInserter.insertPriceInSolrData(entityId, getMinPrice(items));
-
 
209
            // Mark content-complete items as active after the content has been generated
-
 
210
        	for(Item item: items){
-
 
211
        		if(item.getItemStatus()==status.CONTENT_COMPLETE){
-
 
212
                    item.setItemStatus(status.ACTIVE);
-
 
213
                    item.setStatus_description("This item is active");
-
 
214
                    client.updateItem(item);
-
 
215
        		}
-
 
216
        	}
-
 
217
        }
-
 
218
        
-
 
219
        //Generate partners and json objects for phones only
-
 
220
        if(!GENERATION_TYPE.equals("ONE")) {
-
 
221
        	ProductListGenerator generator = new ProductListGenerator(entityIdItemMap);
-
 
222
			generator.generateProductsListXML();
-
 
223
			generator.generateProductListJavascript();
-
 
224
        }
-
 
225
 
98
    }
226
    }
99
    
227
    
-
 
228
    
100
    /**
229
    /**
-
 
230
     * 
-
 
231
     * @param items
-
 
232
     * @return the minimum price of the items
-
 
233
     */
-
 
234
	private double getMinPrice(List<Item> items){
-
 
235
        double minPrice = Double.MAX_VALUE;
-
 
236
        for(Item item: items){
-
 
237
            if(minPrice > item.getSellingPrice()){
-
 
238
                minPrice = item.getSellingPrice();
-
 
239
            }
-
 
240
        }
-
 
241
        return minPrice;
-
 
242
    }
-
 
243
 
-
 
244
 
-
 
245
	/**
101
     * Generates content for the specified entity embedding links to the
246
     * Generates content for the specified entity embedding links to the
102
     * specified domain name.
247
     * specified domain name.
103
     * 
248
     * 
104
     * The method updates the member variable problems in any of the following
249
     * The method will not generate content if one of the following conditions is met:
105
     * four cases:
-
 
106
     * <ol>
250
     * <ol>
107
     * <li>The entity is not ready.
251
     * <li>The entity is not ready.
108
     * <li>The category has not been updated yet. (Set to -1).
252
     * <li>The category has not been updated yet. (Set to -1).
109
     * <li>There are no items in the catalog corresponding to this entity.
-
 
110
     * <li>There are no active or content-complete items in the catalog
-
 
111
     * corresponding to this entity.
253
     * <li>The content has not been updated.
112
     * <li>Neither the items have been updated nor the content has been updated.
-
 
113
     * </ol>
254
     * </ol>
114
     * 
255
     *
115
     * @param entity
-
 
116
     *            - Entity for which the content has to be generated.
-
 
117
     * @param domain
-
 
118
     *            - The domain name to be used to serve static content.
-
 
119
     * @param exportPath
-
 
120
     *            - Local file system path where content has to be generated.
-
 
121
     * @return -True if content is generated successfully, False otherwise.
-
 
122
     * @throws Exception
256
     * @throws
123
     */
-
 
124
 
-
 
125
    /**
-
 
126
     * 
-
 
127
     */
257
     */
128
    private void generateContent() throws Exception{
258
    private void generateContent() throws Exception{
-
 
259
        if(GENERATION_TYPE.equals("ALL")) {
-
 
260
        	entities = CreationUtils.getEntities();
-
 
261
            lastGenerationTime = new Long(0);
129
        if(GENERATION_TYPE.equals("ALL") || GENERATION_TYPE.equals("ONE")) {
262
        }else if(GENERATION_TYPE.equals("ONE")) {
-
 
263
        	entities = new HashMap<Long, Entity>();
-
 
264
        	entities.put(Long.parseLong(ENTITY_ID), CreationUtils.getEntity(Long.parseLong(ENTITY_ID)));
130
            lastGenerationTime = new Long(0);   
265
            lastGenerationTime = new Long(0);   
131
        }else{
266
        }else{
-
 
267
        	entities = CreationUtils.getEntities();
132
            lastGenerationTime = CreationUtils.getLastContentGenerationTime();
268
            lastGenerationTime = CreationUtils.getLastContentGenerationTime();
133
            if(lastGenerationTime==null){
269
            if(lastGenerationTime==null){
134
                lastGenerationTime = new Long(0);
270
                lastGenerationTime = new Long(0);
135
            }    
271
            }    
136
        }
272
        }
137
        
-
 
138
        if(GENERATION_TYPE.equals("ONE")) {
273
        //Filter invalid entities here
139
            items = client.getItemsByCatalogId(Long.parseLong(ENTITY_ID));
-
 
140
            contentCompleteItems = new ArrayList<Item>();
274
        List<Entity> validEntities = new ArrayList<Entity>();
141
            for(Item item: items){
275
        for(long entityID: entities.keySet()){
142
                if(item.getItemStatus() == status.CONTENT_COMPLETE){
-
 
143
                    contentCompleteItems.add(item);
276
        	if(isValidEntity(entities.get(entityID))){
144
                }
-
 
145
                
-
 
146
            }
-
 
147
        }else{
-
 
148
            contentCompleteItems = client.getAllItemsByStatus(status.CONTENT_COMPLETE);
-
 
149
            items = client.getAllItemsByStatus(status.ACTIVE);
-
 
150
            items.addAll(client.getAllItemsByStatus(status.PAUSED));
-
 
151
            items.addAll(contentCompleteItems);
277
        		validEntities.add(entities.get(entityID));
152
        }
278
        	}
153
        //If non incremental content needs to be generated
-
 
154
        if(GENERATION_TYPE.equals("INCREMENTAL")) {
-
 
155
            
-
 
156
        }
279
        }
157
        
-
 
158
        removeInvalidItems();
280
        //Calculate comparison scores
159
        
-
 
160
        NewCMP cmp = new NewCMP(entityIdItemMap);
281
        NewCMP cmp = new NewCMP(validEntities);
161
        Map<Long, Map<Long, Double>> slideScoresByEntity = cmp.getSlideScores();
282
        Map<Long, Map<Long, Double>> slideScoresByEntity = cmp.getSlideScores();
162
//        Utils.info("slideScoresByEntity=" + slideScoresByEntity);
-
 
163
        
-
 
164
        CreationUtils.storeSlideScores(slideScoresByEntity);
283
        CreationUtils.storeSlideScores(slideScoresByEntity);
165
 
284
        
166
        NewVUI vui = new NewVUI(lastGenerationTime);
285
        NewVUI vui = new NewVUI(lastGenerationTime);
167
        for(long entityID: entityIdItemMap.keySet()){
286
        for(Entity entity: validEntities){
168
            //TODO Domain name and destination  directory should be read from properties file 
-
 
169
            vui.generateHtmlForOneEntity(CreationUtils.getEntity(entityID), "saholic.com", Utils.EXPORT_ENTITIES_PATH_SAHOLIC, entityIdItemMap.get(entityID));
287
        		vui.generateHtmlForOneEntity(entity, Utils.EXPORT_VELOCITY_PATH);
170
            vui.generateHtmlForOneEntity(CreationUtils.getEntity(entityID), "shop2020.in", Utils.EXPORT_ENTITIES_PATH_SHOP2020, entityIdItemMap.get(entityID));
-
 
171
            vui.generateHtmlForOneEntity(CreationUtils.getEntity(entityID), "localhost:8090", Utils.EXPORT_ENTITIES_PATH_LOCALHOST, entityIdItemMap.get(entityID));
-
 
172
        }
-
 
173
 
-
 
174
        // Mark content-complete items as active after the content has been
-
 
175
        // generated
-
 
176
        long todate = new Date().getTime();
-
 
177
        for(Item item:contentCompleteItems){
-
 
178
        	if(item.getStartDate() > todate)
-
 
179
        		continue;
-
 
180
            item.setItemStatus(status.ACTIVE);
-
 
181
            item.setStatus_description("This item is active");
-
 
182
            client.updateItem(item);
-
 
183
        }
288
        }
-
 
289
        CreationUtils.storeLastContentGenerationTime((new Date()).getTime());
-
 
290
        
184
 
291
        
185
        NewIR ir = new NewIR(entityIdItemMap);
292
        NewIR ir = new NewIR(validEntities);
186
        ir.exportIRData();
293
        ir.exportIRData();
187
        ir.transformIrDataXMLtoSolrXML();
294
        //ir.transformIrDataXMLtoSolrXML();
188
        ir.exportIRMetaData();
295
        ir.exportIRMetaData();
189
        ir.transformIrMetaDataXMLSolrSchemaXML();
296
        ir.transformIrMetaDataXMLSolrSchemaXML();
190
 
297
 
191
    }
298
    }
-
 
299
 
192
    
300
    
193
    /**
301
    /**
194
     * Iterate through all candidate items and remove item if one of following conditions met.
302
     * Checks weather entity is valid or not. Entity will be invalid in one of these cases:
-
 
303
     * <ol>
195
     * <li> If item is not in one  of three states ( ACTIVE, CONTENT_COMPLETE, PAUSED)
304
     * <li>The entity is not ready.
196
     * <li> If Entity is invalid 
305
     * <li>The category has not been updated yet. (Set to -1).
197
     * <li> If neither content nor item is updated after last content generation
306
     * <li>Content has not been updated after last content generation timestamp.
-
 
307
     * </ol>
198
     *   
308
     * 
199
     * @throws Exception 
309
     * @param entity
200
     *   
310
     * @return
-
 
311
     * @throws Exception
201
     */
312
     */
202
    private void removeInvalidItems() throws Exception{
313
    private boolean isValidEntity(Entity entity) throws Exception{
-
 
314
        ExpandedEntity expEntity = new ExpandedEntity(entity);
203
        entities =  CreationUtils.getEntities();
315
        EntityState state = CreationUtils.getEntityState(entity.getID());
-
 
316
        long categoryID = expEntity.getCategoryID();
-
 
317
        
-
 
318
        if(state.getStatus() != EntityStatus.READY ||  categoryID == -1){
-
 
319
            return false;
-
 
320
        }
-
 
321
        if(state.getMerkedReadyOn().getTime() < this.lastGenerationTime){
-
 
322
            return false;
-
 
323
        }
-
 
324
        return true;
-
 
325
    }
-
 
326
 
-
 
327
    
-
 
328
    private void populateEntityIdItemMap(){
204
        Date todate = new Date();
329
        Date todate = new Date();
205
        for(Item item: items){            
330
        for(Item item: items){
206
            List<Item> itemList = entityIdItemMap.get(item.getCatalogItemId());
-
 
207
            //TODO Can be removed as we are checking in calling function
331
            //TODO Can be removed as we are checking in calling function
208
            if(!(item.getItemStatus()==status.ACTIVE || item.getItemStatus()==status.CONTENT_COMPLETE || item.getItemStatus() == status.PAUSED)){
332
            if(!(item.getItemStatus()==status.ACTIVE || item.getItemStatus()==status.CONTENT_COMPLETE || item.getItemStatus() == status.PAUSED)){
209
                continue;
333
                continue;
210
            }
334
            }
211
            if(todate.getTime() < item.getStartDate()){
335
            if(todate.getTime() < item.getStartDate()){
212
                continue;
336
                continue;
213
            }
337
            }
-
 
338
            List<Item> itemList = entityIdItemMap.get(item.getCatalogItemId());
214
            if(itemList == null){
339
            if(itemList == null){
215
                
-
 
216
                if(!isValidEntity(entities.get(item.getCatalogItemId()))){
-
 
217
                    continue;
-
 
218
                }
-
 
219
                itemList = new ArrayList<Item>();
340
                itemList = new ArrayList<Item>();
220
            }
341
            }
221
            itemList.add(item);
342
            itemList.add(item);
222
            entityIdItemMap.put(item.getCatalogItemId(), itemList);
343
            entityIdItemMap.put(item.getCatalogItemId(), itemList);
223
        }
344
        }
224
        
345
 
225
        /**
-
 
226
         * Remove all items which have not been updated ever.
346
        //Remove all items which have not been updated since last content generation.
227
         */
-
 
228
        List<Long> removeEntities = new ArrayList<Long>();
347
        List<Long> removeEntities = new ArrayList<Long>();
229
        for(Long entityId:entityIdItemMap.keySet()){
348
        for(Long entityId:entityIdItemMap.keySet()){
230
            boolean isValidEntity = false;
349
            boolean isValidEntity = false;
231
            //If any one of the items has been updated since last generation timestamp, than we generate content for whole entity
350
            //If any one of the items has been updated before current timestamp, than we generate content for whole entity
232
            for(Item item: entityIdItemMap.get(entityId)){
351
            for(Item item: entityIdItemMap.get(entityId)){
233
                if(item.getUpdatedOn() > this.lastGenerationTime){
352
                if(item.getUpdatedOn() > lastGenerationTime){
234
                    isValidEntity = true;
353
                    isValidEntity = true;
235
                }
354
                }
236
            }
355
            }
237
            if(!isValidEntity){
356
            if(!isValidEntity){
238
                removeEntities.add(entityId);
357
                removeEntities.add(entityId);
239
            }
358
            }
240
        }
359
        }
241
        for(Long entityId: removeEntities){
360
        for(Long entityId: removeEntities){
242
            entityIdItemMap.remove(entityId);
361
            entityIdItemMap.remove(entityId);
243
        }
362
        }
244
 
-
 
245
        
-
 
246
    }
363
    }
247
    
364
    
248
    /**
-
 
249
     * Checks weather entity is valid or not. Entity will be invalid in one of these cases:
-
 
250
     * <ol>
-
 
251
     * <li>The entity is not ready.
-
 
252
     * <li>The category has not been updated yet. (Set to -1).
-
 
253
     * <li>Content has not been updated after last content generation timestamp.
-
 
254
     * </ol>
-
 
255
     * 
-
 
256
     * @param entity
-
 
257
     * @return
-
 
258
     * @throws Exception
-
 
259
     */
-
 
260
    private boolean isValidEntity(Entity entity) throws Exception{
-
 
261
        ExpandedEntity expEntity = new ExpandedEntity(entity);
-
 
262
        EntityState state = CreationUtils.getEntityState(entity.getID());
-
 
263
        long categoryID = expEntity.getCategoryID();
-
 
264
        
-
 
265
        if(state.getStatus() != EntityStatus.READY ||  categoryID == -1){
-
 
266
            return false;
-
 
267
        }
-
 
268
        if(state.getMerkedReadyOn().getTime() < this.lastGenerationTime){
-
 
269
            return false;
-
 
270
        }
-
 
271
        return true;
-
 
272
    }
-
 
273
        
-
 
274
}
365
}