added unique id to actions and action trigger

This commit is contained in:
Radu Ioan Fericean
2012-08-16 12:59:32 +03:00
parent e60ff7bc79
commit d5dc2d242c
6 changed files with 32 additions and 21 deletions

View File

@@ -29,6 +29,7 @@ import (
Structure to be filled for each tariff plan with the bonus value for received calls minutes.
*/
type Action struct {
Id string
ActionType string
BalanceId string
Direction string
@@ -184,6 +185,7 @@ func (apl ActionPriotityList) Sort() {
Serializes the action for the storage. Used for key-value storages.
*/
func (a *Action) store() (result string) {
result += a.Id + "|"
result += a.ActionType + "|"
result += a.BalanceId + "|"
result += a.Direction + "|"
@@ -201,13 +203,14 @@ De-serializes the action for the storage. Used for key-value storages.
*/
func (a *Action) restore(input string) {
elements := strings.Split(input, "|")
a.ActionType = elements[0]
a.BalanceId = elements[1]
a.Direction = elements[2]
a.Units, _ = strconv.ParseFloat(elements[3], 64)
a.Weight, _ = strconv.ParseFloat(elements[4], 64)
if len(elements) == 6 {
a.Id = elements[0]
a.ActionType = elements[1]
a.BalanceId = elements[2]
a.Direction = elements[3]
a.Units, _ = strconv.ParseFloat(elements[4], 64)
a.Weight, _ = strconv.ParseFloat(elements[5], 64)
if len(elements) == 7 {
a.MinuteBucket = &MinuteBucket{}
a.MinuteBucket.restore(elements[5])
a.MinuteBucket.restore(elements[6])
}
}

View File

@@ -35,7 +35,7 @@ const (
)
type ActionTiming struct {
Id string // identify the timing
Id string // uniquely identify the timing
Tag string // informative purpos only
UserBalanceIds []string
Timing *Interval

View File

@@ -26,6 +26,7 @@ import (
)
type ActionTrigger struct {
Id string // uniquely identify the timing
BalanceId string
Direction string
ThresholdValue float64
@@ -82,6 +83,7 @@ func (atpl ActionTriggerPriotityList) Sort() {
Serializes the action trigger for the storage. Used for key-value storages.
*/
func (at *ActionTrigger) store() (result string) {
result += at.Id + ";"
result += at.BalanceId + ";"
result += at.Direction + ";"
result += at.DestinationId + ";"
@@ -97,14 +99,15 @@ De-serializes the action timing for the storage. Used for key-value storages.
*/
func (at *ActionTrigger) restore(input string) {
elements := strings.Split(input, ";")
if len(elements) != 7 {
if len(elements) != 8 {
return
}
at.BalanceId = elements[0]
at.Direction = elements[1]
at.DestinationId = elements[2]
at.ActionsId = elements[3]
at.ThresholdValue, _ = strconv.ParseFloat(elements[4], 64)
at.Weight, _ = strconv.ParseFloat(elements[5], 64)
at.Executed, _ = strconv.ParseBool(elements[6])
at.Id = elements[0]
at.BalanceId = elements[1]
at.Direction = elements[2]
at.DestinationId = elements[3]
at.ActionsId = elements[4]
at.ThresholdValue, _ = strconv.ParseFloat(elements[5], 64)
at.Weight, _ = strconv.ParseFloat(elements[6], 64)
at.Executed, _ = strconv.ParseBool(elements[7])
}

View File

@@ -59,6 +59,7 @@ func TestActionTimingStoreRestore(t *testing.T) {
func TestActionTriggerStoreRestore(t *testing.T) {
at := &ActionTrigger{
Id: "some_uuid",
BalanceId: CREDIT,
Direction: OUTBOUND,
ThresholdValue: 100.0,
@@ -67,7 +68,7 @@ func TestActionTriggerStoreRestore(t *testing.T) {
ActionsId: "Commando",
}
r := at.store()
if string(r) != "MONETARY;OUT;NAT;Commando;100;10;false" {
if string(r) != "some_uuid;MONETARY;OUT;NAT;Commando;100;10;false" {
t.Errorf("Error serializing action trigger: %v", string(r))
}
o := &ActionTrigger{}
@@ -751,6 +752,7 @@ func TestUUID(t *testing.T) {
func TestActionTriggerLogging(t *testing.T) {
at := &ActionTrigger{
Id: "some_uuid",
BalanceId: CREDIT,
Direction: OUTBOUND,
ThresholdValue: 100.0,
@@ -763,7 +765,7 @@ func TestActionTriggerLogging(t *testing.T) {
t.Error("Error getting actions for the action timing: ", err)
}
storageGetter.LogActionTrigger("rif", at, as)
expected := "rif*MONETARY;OUT;NAT;TEST_ACTIONS;100;10;false*TOPUP|MONETARY|OUT|10|0"
expected := "rif*some_uuid;MONETARY;OUT;NAT;TEST_ACTIONS;100;10;false*|TOPUP|MONETARY|OUT|10|0"
var key string
for k, v := range storageGetter.(*MapStorage).dict {
if strings.Contains(k, LOG_PREFIX) && strings.Contains(string(v), expected) {
@@ -802,7 +804,7 @@ func TestActionTimingLogging(t *testing.T) {
t.Error("Error getting actions for the action trigger: ", err)
}
storageGetter.LogActionTiming(at, as)
expected := "some uuid|test|one,two,three|;1,2,3,4,5,6,7,8,9,10,11,12;1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31;1,2,3,4,5;18:00:00;00:00:00;10;0;1;60;1|10|TEST_ACTIONS*TOPUP|MONETARY|OUT|10|0"
expected := "some uuid|test|one,two,three|;1,2,3,4,5,6,7,8,9,10,11,12;1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31;1,2,3,4,5;18:00:00;00:00:00;10;0;1;60;1|10|TEST_ACTIONS*|TOPUP|MONETARY|OUT|10|0"
var key string
for k, v := range storageGetter.(*MapStorage).dict {
if strings.Contains(k, LOG_PREFIX) && strings.Contains(string(v), expected) {

View File

@@ -379,6 +379,7 @@ func (csvr *CSVReader) LoadActions(fn string, comma rune) (err error) {
return errors.New(fmt.Sprintf("Could not parse action weight: %v", err))
}
a = &Action{
Id: GenUUID(),
ActionType: record[1],
BalanceId: record[2],
Direction: record[3],
@@ -466,6 +467,7 @@ func (csvr *CSVReader) LoadActionTriggers(fn string, comma rune) (err error) {
return errors.New(fmt.Sprintf("Could not parse action trigger weight: %v", err))
}
at := &ActionTrigger{
Id: GenUUID(),
BalanceId: record[1],
Direction: record[2],
ThresholdValue: value,

View File

@@ -53,6 +53,7 @@ func TestUserBalanceStoreRestore(t *testing.T) {
MinuteBuckets: []*MinuteBucket{&MinuteBucket{Weight: 20, Price: 1, DestinationId: "NAT"}, &MinuteBucket{Weight: 10, Price: 10, Percent: 0, DestinationId: "RET"}},
}
at := &ActionTrigger{
Id: "some_uuid",
BalanceId: CREDIT,
Direction: OUTBOUND,
ThresholdValue: 100.0,
@@ -69,8 +70,8 @@ func TestUserBalanceStoreRestore(t *testing.T) {
ActionTriggers: ActionTriggerPriotityList{at, at, at},
}
r := ub.store()
if string(r) != "rif|postpaid|SMSOUT:14#INTERNETOUT:1024|0;20;1;0;NAT#0;10;10;0;RET|OUT/SMS/100/0;20;1;0;NAT,0;10;10;0;RET#OUT/SMS/100/0;20;1;0;NAT,0;10;10;0;RET|MONETARY;OUT;NAT;Commando;100;10;false#MONETARY;OUT;NAT;Commando;100;10;false#MONETARY;OUT;NAT;Commando;100;10;false" &&
string(r) != "rif|postpaid|INTERNETOUT:1024#SMSOUT:14|0;20;1;0;NAT#0;10;10;0;RET|OUT/SMS/100/0;20;1;0;NAT,0;10;10;0;RET#OUT/SMS/100/0;20;1;0;NAT,0;10;10;0;RET|MONETARY;OUT;NAT;Commando;100;10;false#MONETARY;OUT;NAT;Commando;100;10;false#MONETARY;OUT;NAT;Commando;100;10;false" {
if string(r) != "rif|postpaid|SMSOUT:14#INTERNETOUT:1024|0;20;1;0;NAT#0;10;10;0;RET|OUT/SMS/100/0;20;1;0;NAT,0;10;10;0;RET#OUT/SMS/100/0;20;1;0;NAT,0;10;10;0;RET|some_uuid;MONETARY;OUT;NAT;Commando;100;10;false#some_uuid;MONETARY;OUT;NAT;Commando;100;10;false#some_uuid;MONETARY;OUT;NAT;Commando;100;10;false" &&
string(r) != "rif|postpaid|INTERNETOUT:1024#SMSOUT:14|0;20;1;0;NAT#0;10;10;0;RET|OUT/SMS/100/0;20;1;0;NAT,0;10;10;0;RET#OUT/SMS/100/0;20;1;0;NAT,0;10;10;0;RET|some_uuid;MONETARY;OUT;NAT;Commando;100;10;false#some_uuid;MONETARY;OUT;NAT;Commando;100;10;false#some_uuid;MONETARY;OUT;NAT;Commando;100;10;false" {
t.Errorf("Error serializing action timing: %v", string(r))
}
o := &UserBalance{}