Example #1
0
    def deleteTariff(self,tariff_name):
	"""
	    delete a tariff using it's "tariff_name"
	"""	
	self.__deleteTariffCheckInput(tariff_name)
	tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
	self.__deleteTariffDB(tariff_obj.getTariffID())
	tariff_main.getLoader().unloadTariffByID(tariff_obj.getTariffID())
Example #2
0
    def updateTariff(self,tariff_id,tariff_name,comment):
	"""
	    update tariff with id tariff_id
	"""
	self.__updateTariffCheckInput(tariff_id,tariff_name,comment)
	self.__updateTariffDB(tariff_id,tariff_name,comment)
	tariff_main.getLoader().unloadTariffByID(tariff_id)
	tariff_main.getLoader().loadTariffByID(tariff_id)
Example #3
0
    def deletePrefix(self,tariff_name,prefix_codes):
	"""
	    prefix_codes(iterable object): prefix codes
	"""
	self.__delPrefixCheckInput(tariff_name,prefix_codes)
	tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
	self.__delPrefixDB(tariff_obj.getTariffID(),prefix_codes)
	tariff_main.getLoader().loadTariffByID(tariff_obj.getTariffID())
Example #4
0
 def __updateTariffCheckInput(self,tariff_id,tariff_name,comment):
     tariff_obj=tariff_main.getLoader().getTariffByID(tariff_id)
     if tariff_obj.getTariffName()!=tariff_name:
         if not isValidName(tariff_name):
             raise GeneralException(errorText("VOIP_TARIFF","BAD_TARIFF_NAME")%tariff_name)
     
         if tariff_main.getLoader().tariffNameExists(tariff_name):
             raise GeneralException(errorText("VOIP_TARIFF","TARIFF_NAME_ALREADY_EXISTS")%tariff_name)
Example #5
0
 def deletePrefix(self,tariff_name,prefix_codes):
     """
         prefix_codes(iterable object): prefix codes
     """
     self.__delPrefixCheckInput(tariff_name,prefix_codes)
     tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
     self.__delPrefixDB(tariff_obj.getTariffID(),prefix_codes)
     tariff_main.getLoader().loadTariffByID(tariff_obj.getTariffID())
Example #6
0
 def updateTariff(self,tariff_id,tariff_name,comment):
     """
         update tariff with id tariff_id
     """
     self.__updateTariffCheckInput(tariff_id,tariff_name,comment)
     self.__updateTariffDB(tariff_id,tariff_name,comment)
     tariff_main.getLoader().unloadTariffByID(tariff_id)
     tariff_main.getLoader().loadTariffByID(tariff_id)
Example #7
0
 def deleteTariff(self,tariff_name):
     """
         delete a tariff using it's "tariff_name"
     """     
     self.__deleteTariffCheckInput(tariff_name)
     tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
     self.__deleteTariffDB(tariff_obj.getTariffID())
     tariff_main.getLoader().unloadTariffByID(tariff_obj.getTariffID())
Example #8
0
    def __updateTariffCheckInput(self,tariff_id,tariff_name,comment):
	tariff_obj=tariff_main.getLoader().getTariffByID(tariff_id)
	if tariff_obj.getTariffName()!=tariff_name:
	    if not isValidName(tariff_name):
	        raise GeneralException(errorText("VOIP_TARIFF","BAD_TARIFF_NAME")%tariff_name)
	
	    if tariff_main.getLoader().tariffNameExists(tariff_name):
		raise GeneralException(errorText("VOIP_TARIFF","TARIFF_NAME_ALREADY_EXISTS")%tariff_name)
Example #9
0
 def addNewTariff(self,tariff_name,comment):
     """
         add new tariff
         tariff_name(str): name of new tariff
     """
     self.__addNewTariffCheckInput(tariff_name,comment)
     tariff_id=self.__getNewTariffID()
     self.__insertTariffDB(tariff_id,tariff_name,comment)
     tariff_main.getLoader().loadTariffByID(tariff_id)
     return tariff_id
Example #10
0
    def addNewTariff(self,tariff_name,comment):
	"""
	    add new tariff
	    tariff_name(str): name of new tariff
	"""
	self.__addNewTariffCheckInput(tariff_name,comment)
	tariff_id=self.__getNewTariffID()
	self.__insertTariffDB(tariff_id,tariff_name,comment)
	tariff_main.getLoader().loadTariffByID(tariff_id)
	return tariff_id
Example #11
0
 def listTariffs(self,request):
     """
         return a list of tariff infos in format [{"tariff_name":,"tariff_id":,"comment":}]
         note that prefixes aren't included
     """
     request.needAuthType(request.ADMIN)
     request.getAuthNameObj().canDo("SEE VOIP TARIFF")
     tariffs=map(lambda tariff_name:tariff_main.getLoader().getTariffByName(tariff_name).getInfo(),
                tariff_main.getLoader().getAllTariffNames())
     sorted=SortedList(tariffs)
     sorted.sortByValueDicKey("tariff_name",False)
     return sorted.getList()
Example #12
0
    def listTariffs(self,request):
	"""
	    return a list of tariff infos in format [{"tariff_name":,"tariff_id":,"comment":}]
	    note that prefixes aren't included
	"""
	request.needAuthType(request.ADMIN)
	request.getAuthNameObj().canDo("SEE VOIP TARIFF")
	tariffs=map(lambda tariff_name:tariff_main.getLoader().getTariffByName(tariff_name).getInfo(),
		   tariff_main.getLoader().getAllTariffNames())
	sorted=SortedList(tariffs)
	sorted.sortByPostText("['tariff_name']",False)
	return sorted.getList()
Example #13
0
    def __delPrefixCheckInput(self,tariff_name,prefix_codes):
	tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
	if not len(prefix_codes):
	    raise GeneralException(errorText("VOIP_TARIFF","NO_PREFIX_TO_DELETE"))
	for code in prefix_codes:
	    if not tariff_obj.hasPrefixCode(code):
		raise GeneralException(errorText("VOIP_TARIFF","TARIFF_DOESNT_HAVE_PREFIX_CODE")%(tariff_obj.getTariffName(),code))
Example #14
0
 def __delPrefixCheckInput(self,tariff_name,prefix_codes):
     tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
     if not len(prefix_codes):
         raise GeneralException(errorText("VOIP_TARIFF","NO_PREFIX_TO_DELETE"))
     for code in prefix_codes:
         if not tariff_obj.hasPrefixCode(code):
             raise GeneralException(errorText("VOIP_TARIFF","TARIFF_DOESNT_HAVE_PREFIX_CODE")%(tariff_obj.getTariffName(),code))
Example #15
0
    def getTariffInfo(self,request):
	"""
	    return informations of voip tariff, including prefixes
	"""
	request.needAuthType(request.ADMIN)
	request.getAuthNameObj().canDo("SEE VOIP TARIFF")
    	request.checkArgs("tariff_name","include_prefixes")
	return tariff_main.getLoader().getTariffByName(request["tariff_name"]).getInfo(request["include_prefixes"])
Example #16
0
 def getTariffInfo(self,request):
     """
         return informations of voip tariff, including prefixes if selected
     """
     request.needAuthType(request.ADMIN)
     request.getAuthNameObj().canDo("SEE VOIP TARIFF")
     request.checkArgs("tariff_name","include_prefixes","name_regex")
     return tariff_main.getLoader().getTariffByName(request["tariff_name"]).getInfo(request["include_prefixes"],request["name_regex"])
Example #17
0
    def addVoIPChargeRule(self,charge_name,start_time,end_time,day_of_weeks,tariff_name,ras_id,ports):
	start_time,end_time,day_of_weeks=self.__chargeRuleTimesCheck(start_time,end_time,day_of_weeks)
	self.__voipChargeRuleCheckInput(charge_name,tariff_name,ras_id,ports)
	charge_obj=charge_main.getLoader().getChargeByName(charge_name)
	day_of_weeks_container=self.__createDayOfWeekContainer(day_of_weeks)
	tariff_id=tariff_main.getLoader().getTariffByName(tariff_name).getTariffID()
	rule_obj=self.__createVoIPChargeRuleObject(charge_obj,start_time,end_time,day_of_weeks_container,\
				tariff_id,ras_id,ports)
        self.__checkRuleConflict(charge_obj,rule_obj)
        self.__addVoIPChargeRuleToDB(rule_obj)
        charge_main.getLoader().loadCharge(charge_obj.getChargeID())
Example #18
0
    def addPrefix(self,tariff_name,prefix_codes,prefix_names,cpms,free_seconds,min_durations,round_tos):
	"""
	    add a prefix to tariff with name "tariff_name"
	    prefix_codes(list of str): list of prefix codes
	    prefix_names(list of str): list of prefix names
	    cpms(list of float): list of charge per minutes
	    free_seconds(list of int): list of free seconds of calls
	    min_durations(list of int): list of minimum durations of call in seconds
	    round_tos(list of int): round calls to this amount of seconds
	    
	    WARNING: All lists should have same length
	    
	    return a dictionary in format {"success":bool,"errs":list of errs}
	"""
	errs=self.__addPrefixCheckInput(tariff_name,prefix_codes,prefix_names,cpms,free_seconds,min_durations,round_tos)
	if errs: return {"errs":errs,"success":False}
	tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
	prefix_ids=map(lambda x:self.__getNewPrefixID(),xrange(len(prefix_codes)))
	self.__addPrefixDB(tariff_obj.getTariffID(),prefix_ids,prefix_codes,prefix_names,cpms,free_seconds,min_durations,round_tos)
	tariff_main.getLoader().loadTariffByID(tariff_obj.getTariffID())
	return {"errs":[],"success":True}
Example #19
0
 def addPrefix(self,tariff_name,prefix_codes,prefix_names,cpms,free_seconds,min_durations,round_tos,min_chargable_durations):
     """
         add a prefix to tariff with name "tariff_name"
         prefix_codes(list of str): list of prefix codes
         prefix_names(list of str): list of prefix names
         cpms(list of float): list of charge per minutes
         free_seconds(list of int): list of free seconds of calls
         min_durations(list of int): list of minimum durations of call in seconds
         round_tos(list of int): round calls to this amount of seconds
         min_chargable_durations(list of int): list of minimum chargable durations
         
         WARNING: All lists should have same length
         
         return a dictionary in format {"success":bool,"errs":list of errs}
     """
     errs=self.__addPrefixCheckInput(tariff_name,prefix_codes,prefix_names,cpms,free_seconds,min_durations,round_tos,min_chargable_durations)
     if errs: return {"errs":errs,"success":False}
     tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
     prefix_ids=map(lambda x:self.__getNewPrefixID(),xrange(len(prefix_codes)))
     self.__addPrefixDB(tariff_obj.getTariffID(),prefix_ids,prefix_codes,prefix_names,cpms,free_seconds,min_durations,round_tos,min_chargable_durations)
     tariff_main.getLoader().loadTariffByID(tariff_obj.getTariffID())
     return {"errs":[],"success":True}
Example #20
0
    def __updatePrefixCheckInput(self,tariff_name,prefix_id,prefix_code,prefix_name,cpm,free_second,min_duration,round_to,min_chargable_duration):
        tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
        
        if not tariff_obj.hasPrefixID(prefix_id):
            raise GeneralException(errorText("VOIP_TARIFF","TARIFF_DOESNT_HAVE_PREFIX_ID")%(tariff_obj.getTariffName(),prefix_id))

        if tariff_obj.getPrefixByID(prefix_id).getPrefixCode()!=prefix_code and tariff_obj.hasPrefixCode(prefix_code):
            raise GeneralException(errorText("VOIP_TARIFF","PREFIX_CODE_ALREADY_EXIST")%(prefix_code,tariff_obj.getTariffName()))
                
        errs=[]
        self.__checkPrefix(prefix_code,prefix_name,cpm,free_second,min_duration,round_to,min_chargable_duration,errs,1)
        if errs:
            raise GeneralException("\n".join(errs))
Example #21
0
    def __updatePrefixCheckInput(self,tariff_name,prefix_id,prefix_code,prefix_name,cpm,free_second,min_duration,round_to):
	tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
	
	if not tariff_obj.hasPrefixID(prefix_id):
	    raise GeneralException(errorText("VOIP_TARIFF","TARIFF_DOESNT_HAVE_PREFIX_ID")%(tariff_obj.getTariffName(),prefix_id))

	if tariff_obj.getPrefixByID(prefix_id).getPrefixCode()!=prefix_code and tariff_obj.hasPrefixCode(prefix_code):
	    raise GeneralException(errorText("VOIP_TARIFF","PREFIX_CODE_ALREADY_EXIST")%(prefix_code,tariff_obj.getTariffName()))
		
	errs=[]
	self.__checkPrefix(prefix_code,prefix_name,cpm,free_second,min_duration,round_to,errs,1)
	if errs:
	    raise GeneralException("\n".join(errs))
Example #22
0
 def __addPrefixCheckInput(self,tariff_name,prefix_codes,prefix_names,cpms,free_seconds,min_durations,round_tos,min_chargable_durations):
     tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
     if not len(prefix_codes)==len(prefix_names)==len(cpms)==len(free_seconds)==len(min_durations)==len(round_tos)==len(min_chargable_durations):
         raise GeneralException(errorText("VOIP_TARIFF","PREFIX_COUNT_NOT_EQUAL"))
     errs=[]
     line=1
     for code,name,cpm,free_sec,min_duration,round_to,min_chargable_duration in itertools.izip(prefix_codes,prefix_names,cpms,free_seconds,min_durations,round_tos,min_chargable_durations):
         cpm,free_sec,min_duration,round_to,min_chargable_duration=self.__convertToInt(cpm,free_sec,min_duration,round_to,min_chargable_duration,errs,line)
         self.__checkPrefix(code,name,cpm,free_sec,min_duration,round_to,min_chargable_duration,errs,line)
         self.__checkCodeExistence(code,tariff_obj,errs,line)
         self.__checkCodeDuplicates(prefix_codes,line-1,errs,line)
         line+=1
     
     return errs
Example #23
0
    def __addPrefixCheckInput(self,tariff_name,prefix_codes,prefix_names,cpms,free_seconds,min_durations,round_tos):
	tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
	if not len(prefix_codes)==len(prefix_names)==len(cpms)==len(free_seconds)==len(min_durations)==len(round_tos):
	    raise GeneralException(errorText("VOIP_TARIFF","PREFIX_COUNT_NOT_EQUAL"))
	errs=[]
	line=1
	for code,name,cpm,free_sec,min_duration,round_to in itertools.izip(prefix_codes,prefix_names,cpms,free_seconds,min_durations,round_tos):
	    cpm,free_sec,min_duration,round_to=self.__convertToInt(cpm,free_sec,min_duration,round_to,errs,line)
	    self.__checkPrefix(code,name,cpm,free_sec,min_duration,round_to,errs,line)
	    self.__checkCodeExistence(code,tariff_obj,errs,line)
	    self.__checkCodeDuplicates(prefix_codes,line-1,errs,line)
	    line+=1
	
	return errs
Example #24
0
 def addVoIPChargeRule(self, charge_name, start_time, end_time,
                       day_of_weeks, tariff_name, ras_id, ports):
     start_time, end_time, day_of_weeks = self.__chargeRuleTimesCheck(
         start_time, end_time, day_of_weeks)
     self.__voipChargeRuleCheckInput(charge_name, tariff_name, ras_id,
                                     ports)
     charge_obj = charge_main.getLoader().getChargeByName(charge_name)
     day_of_weeks_container = self.__createDayOfWeekContainer(day_of_weeks)
     tariff_id = tariff_main.getLoader().getTariffByName(
         tariff_name).getTariffID()
     rule_obj=self.__createVoIPChargeRuleObject(charge_obj,start_time,end_time,day_of_weeks_container,\
                             tariff_id,ras_id,ports)
     self.__checkRuleConflict(charge_obj, rule_obj)
     self.__addVoIPChargeRuleToDB(rule_obj)
     charge_main.getLoader().loadCharge(charge_obj.getChargeID())
Example #25
0
    def updateVoIPChargeRule(self,charge_name,charge_rule_id,start_time,end_time,day_of_weeks,tariff_name,ras_id,ports):
	"""
	    add a charge rule to charge with id "charge_id" and reload the charge
	    it will add charge_rule and it's ports to db too
	"""
	start_time,end_time,day_of_weeks=self.__chargeRuleTimesCheck(start_time,end_time,day_of_weeks)
	charge_rule_id=self.__updateVoIPChargeRuleCheckInput(charge_name,charge_rule_id,start_time,end_time,day_of_weeks,tariff_name,ras_id,ports)
	charge_obj=charge_main.getLoader().getChargeByName(charge_name)
	day_of_weeks_container=self.__createDayOfWeekContainer(day_of_weeks)
	tariff_id=tariff_main.getLoader().getTariffByName(tariff_name).getTariffID()
	rule_obj=self.__createVoIPChargeRuleObject(charge_obj,start_time,end_time,day_of_weeks_container,\
		    				   tariff_id,ras_id,ports,charge_rule_id)
        self.__checkRuleConflict(charge_obj,rule_obj,[charge_rule_id])
        self.__updateVoIPChargeRuleDB(rule_obj)
        charge_main.getLoader().loadCharge(charge_obj.getChargeID())
Example #26
0
 def updateVoIPChargeRule(self, charge_name, charge_rule_id, start_time,
                          end_time, day_of_weeks, tariff_name, ras_id,
                          ports):
     """
         add a charge rule to charge with id "charge_id" and reload the charge
         it will add charge_rule and it's ports to db too
     """
     start_time, end_time, day_of_weeks = self.__chargeRuleTimesCheck(
         start_time, end_time, day_of_weeks)
     charge_rule_id = self.__updateVoIPChargeRuleCheckInput(
         charge_name, charge_rule_id, start_time, end_time, day_of_weeks,
         tariff_name, ras_id, ports)
     charge_obj = charge_main.getLoader().getChargeByName(charge_name)
     day_of_weeks_container = self.__createDayOfWeekContainer(day_of_weeks)
     tariff_id = tariff_main.getLoader().getTariffByName(
         tariff_name).getTariffID()
     rule_obj=self.__createVoIPChargeRuleObject(charge_obj,start_time,end_time,day_of_weeks_container,\
                                                tariff_id,ras_id,ports,charge_rule_id)
     self.__checkRuleConflict(charge_obj, rule_obj, [charge_rule_id])
     self.__updateVoIPChargeRuleDB(rule_obj)
     charge_main.getLoader().loadCharge(charge_obj.getChargeID())
Example #27
0
 def __deleteTariffCheckInput(self,tariff_name):
     tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
     self.__tariffUsedInCharge(tariff_obj.getTariffID())
Example #28
0
 def __voipChargeRuleCheckInput(self, charge_name, tariff_name, ras_id,
                                ports):
     self.__chargeRuleCheckInput(charge_name, "VoIP", ras_id, ports)
     tariff_main.getLoader().getTariffByName(tariff_name)
Example #29
0
    def updatePrefix(self,tariff_name,prefix_id,prefix_code,prefix_name,cpm,free_second,min_duration,round_to):
	self.__updatePrefixCheckInput(tariff_name,prefix_id,prefix_code,prefix_name,cpm,free_second,min_duration,round_to)
	tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
	self.__updatePrefixDB(tariff_obj.getTariffID(),prefix_id,prefix_code,prefix_name,cpm,free_second,min_duration,round_to)
	tariff_main.getLoader().loadTariffByID(tariff_obj.getTariffID())
Example #30
0
    def getTariffObj(self):
	return tariff_main.getLoader().getTariffByID(self.tariff_id)
Example #31
0
 def updatePrefix(self,tariff_name,prefix_id,prefix_code,prefix_name,cpm,free_second,min_duration,round_to,min_chargable_duration):
     self.__updatePrefixCheckInput(tariff_name,prefix_id,prefix_code,prefix_name,cpm,free_second,min_duration,round_to,min_chargable_duration)
     tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
     self.__updatePrefixDB(tariff_obj.getTariffID(),prefix_id,prefix_code,prefix_name,cpm,free_second,min_duration,round_to,min_chargable_duration)
     tariff_main.getLoader().loadTariffByID(tariff_obj.getTariffID())
Example #32
0
 def __addNewTariffCheckInput(self,tariff_name,comment):
     if not isValidName(tariff_name):
         raise GeneralException(errorText("VOIP_TARIFF","BAD_TARIFF_NAME")%tariff_name)
     
     if tariff_main.getLoader().tariffNameExists(tariff_name):
         raise GeneralException(errorText("VOIP_TARIFF","TARIFF_NAME_ALREADY_EXISTS")%tariff_name)
Example #33
0
    def __deleteTariffCheckInput(self,tariff_name):
	tariff_obj=tariff_main.getLoader().getTariffByName(tariff_name)
	self.__tariffUsedInCharge(tariff_obj.getTariffID())
Example #34
0
 def getTariffObj(self):
     return tariff_main.getLoader().getTariffByID(self.tariff_id)
Example #35
0
    def __addNewTariffCheckInput(self,tariff_name,comment):
	if not isValidName(tariff_name):
	    raise GeneralException(errorText("VOIP_TARIFF","BAD_TARIFF_NAME")%tariff_name)
	
	if tariff_main.getLoader().tariffNameExists(tariff_name):
	    raise GeneralException(errorText("VOIP_TARIFF","TARIFF_NAME_ALREADY_EXISTS")%tariff_name)
Example #36
0
    def __voipChargeRuleCheckInput(self,charge_name,tariff_name,ras_id,ports):
	self.__chargeRuleCheckInput(charge_name,"VoIP",ras_id,ports)
	tariff_main.getLoader().getTariffByName(tariff_name)