Subversion Repositories SmartDukaan

Rev

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

Rev 3872 Rev 3924
Line 20... Line 20...
20
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
20
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
21
from shop2020.model.v1.catalog.impl.CategoryManager import CategoryManager
21
from shop2020.model.v1.catalog.impl.CategoryManager import CategoryManager
22
from sqlalchemy.sql.expression import and_, or_, distinct, func
22
from sqlalchemy.sql.expression import and_, or_, distinct, func
23
from string import Template
23
from string import Template
24
from shop2020.clients.HelperClient import HelperClient
24
from shop2020.clients.HelperClient import HelperClient
-
 
25
import urllib2
-
 
26
from urllib2 import HTTPBasicAuthHandler
-
 
27
from shop2020.config.client.ConfigClient import ConfigClient
25
 
28
 
26
def initialize():
29
def initialize():
27
    DataService.initialize()
30
    DataService.initialize()
28
 
31
 
29
def get_all_items_by_status(status, offset=0, limit=None):
32
def get_all_items_by_status(status, offset=0, limit=None):
Line 71... Line 74...
71
        if item.risky and availability <= 0 and item.status == status.ACTIVE:
74
        if item.risky and availability <= 0 and item.status == status.ACTIVE:
72
            add_status_change_log(item, status.PAUSED_BY_RISK)
75
            add_status_change_log(item, status.PAUSED_BY_RISK)
73
            item.status = status.PAUSED_BY_RISK
76
            item.status = status.PAUSED_BY_RISK
74
            item.status_description = "This item is currently out of stock"
77
            item.status_description = "This item is currently out of stock"
75
            session.commit()
78
            session.commit()
-
 
79
            #This will clear cache from tomcat
-
 
80
            __clear_homepage_cache()
76
        t_item_shipping_info.isActive = (item.status == status.ACTIVE)
81
        t_item_shipping_info.isActive = (item.status == status.ACTIVE)
77
        t_item_shipping_info.quantity = availability
82
        t_item_shipping_info.quantity = availability
78
    except InventoryServiceException:
83
    except InventoryServiceException:
79
        print "[ERROR] Unexpected error:", sys.exc_info()[0]
84
        print "[ERROR] Unexpected error:", sys.exc_info()[0]
80
    return t_item_shipping_info
85
    return t_item_shipping_info
Line 429... Line 434...
429
    item.status = new_status
434
    item.status = new_status
430
    if item.status == status.PHASED_OUT:
435
    if item.status == status.PHASED_OUT:
431
        item.status_description = "This item has been phased out"
436
        item.status_description = "This item has been phased out"
432
    elif item.status == status.DELETED:
437
    elif item.status == status.DELETED:
433
        item.status_description = "This item has been deleted"
438
        item.status_description = "This item has been deleted"
-
 
439
    elif item.status == status.PAUSED:
-
 
440
        item.status_description = "This item is currently out of stock"      
434
    elif item.status == status.PAUSED or item.status == status.PAUSED_BY_RISK:
441
    elif item.status == status.PAUSED_BY_RISK:
435
        item.status_description = "This item is currently out of stock"        
442
        item.status_description = "This item is currently out of stock"
-
 
443
        #This will clear cache from tomcat
-
 
444
        __clear_homepage_cache()  
436
    elif item.status == status.ACTIVE:
445
    elif item.status == status.ACTIVE:
437
        item.status_description = "This item is active"
446
        item.status_description = "This item is active"
438
    elif item.status == status.IN_PROCESS:
447
    elif item.status == status.IN_PROCESS:
439
        item.status_description = "This item is in process"
448
        item.status_description = "This item is in process"
440
    elif item.status == status.CONTENT_COMPLETE:
449
    elif item.status == status.CONTENT_COMPLETE:
Line 1183... Line 1192...
1183
 
1192
 
1184
    query = query.filter(or_(*query_clause))
1193
    query = query.filter(or_(*query_clause))
1185
    
1194
    
1186
    return query.count()
1195
    return query.count()
1187
 
1196
 
-
 
1197
def __clear_homepage_cache():
-
 
1198
    try:
-
 
1199
        # create a password manager
-
 
1200
        password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
-
 
1201
        # Add the username and password.
-
 
1202
        configclient = ConfigClient()
-
 
1203
        ips = configclient.get_property("production_servers_public_ips");
-
 
1204
        ips = ips.split(" ")
-
 
1205
        
-
 
1206
        for ip in ips:
-
 
1207
            top_level_url = "http://" + ip + ":8080/"
-
 
1208
            password_mgr.add_password(None, top_level_url, "saholic", "shop2020")
-
 
1209
            handler = urllib2.HTTPBasicAuthHandler(password_mgr)
-
 
1210
            
-
 
1211
            opener = urllib2.build_opener(handler)
-
 
1212
    
-
 
1213
            # use the opener to fetch a URL
-
 
1214
            res = opener.open(top_level_url + "cache-admin/HomePageSnippets?_method=delete")
-
 
1215
            print "Successfully cleared home page cache" + res.read()
-
 
1216
    except:
-
 
1217
        print "Unable to clear cache, still should continue with other operations"
-
 
1218
    
1188
def close_session():
1219
def close_session():
1189
    if session.is_active:
1220
    if session.is_active:
1190
        print "session is active. closing it."
1221
        print "session is active. closing it."
1191
        session.close()
1222
        session.close()
1192
 
1223