@@ -27,12 +27,14 @@ func startQuery(el *onet.Roster, proofs bool, sum []string, count bool, whereQue
27
27
28
28
surveyID , err := client .SendSurveyCreationQuery (el , servicesunlynx .SurveyID ("" ), nil , nbrDPs , proofs , true , sum , count , whereQueryValues , predicate , groupBy )
29
29
if err != nil {
30
- log .Fatal ("Service did not start." , err )
30
+ log .Error ("Service did not start." , err )
31
+ return
31
32
}
32
33
33
34
grp , aggr , err := client .SendSurveyResultsQuery (* surveyID )
34
35
if err != nil {
35
- log .Fatal ("Service could not output the results." , err )
36
+ log .Error ("Service could not output the results." , err )
37
+ return
36
38
}
37
39
38
40
// Print Output
@@ -44,7 +46,7 @@ func startQuery(el *onet.Roster, proofs bool, sum []string, count bool, whereQue
44
46
}
45
47
}
46
48
47
- func runUnLynx (c * cli.Context ) error {
49
+ func runUnLynx (c * cli.Context ) {
48
50
tomlFileName := c .String ("file" )
49
51
50
52
proofs := c .Bool ("proofs" )
@@ -58,13 +60,19 @@ func runUnLynx(c *cli.Context) error {
58
60
59
61
el , err := openGroupToml (tomlFileName )
60
62
if err != nil {
61
- return err
63
+ log .Error ("Could not open group toml:" , err )
64
+ return
65
+ }
66
+
67
+ sumFinal , countFinal , whereFinal , predicateFinal , groupByFinal , err := parseQuery (el , sum , count , whereQueryValues , predicate , groupBy )
68
+ if err != nil {
69
+ log .Error (err )
70
+ return
62
71
}
63
72
64
- sumFinal , countFinal , whereFinal , predicateFinal , groupByFinal := parseQuery (el , sum , count , whereQueryValues , predicate , groupBy )
65
73
startQuery (el , proofs , sumFinal , countFinal , whereFinal , predicateFinal , groupByFinal )
66
74
67
- return nil
75
+ return
68
76
}
69
77
70
78
func openGroupToml (tomlFileName string ) (* onet.Roster , error ) {
@@ -84,27 +92,24 @@ func openGroupToml(tomlFileName string) (*onet.Roster, error) {
84
92
return el .Roster , nil
85
93
}
86
94
87
- func checkRegex (input , expression , errorMessage string ) {
95
+ func checkRegex (input , expression string ) bool {
88
96
var aux = regexp .MustCompile (expression )
89
-
90
- correct := aux .MatchString (input )
91
-
92
- if ! correct {
93
- log .Fatal (errorMessage )
94
- }
97
+ return aux .MatchString (input )
95
98
}
96
99
97
- func parseQuery (el * onet.Roster , sum string , count bool , where , predicate , groupBy string ) ([]string , bool , []libunlynx.WhereQueryAttribute , string , []string ) {
100
+ func parseQuery (el * onet.Roster , sum string , count bool , where , predicate , groupBy string ) ([]string , bool , []libunlynx.WhereQueryAttribute , string , []string , error ) {
98
101
99
102
if sum == "" || (where != "" && predicate == "" ) || (where == "" && predicate != "" ) {
100
- log . Fatal ("Wrong query! Please check the sum, where and the predicate parameters" )
103
+ return nil , false , nil , "" , nil , errors . New ("Wrong query! Please check the sum, where and the predicate parameters" )
101
104
}
102
105
103
106
sumRegex := "{s[0-9]+(,\\ s*s[0-9]+)*}"
104
107
whereRegex := "{(w[0-9]+(,\\ s*[0-9]+))*(,\\ s*w[0-9]+(,\\ s*[0-9]+))*}"
105
108
groupByRegex := "{g[0-9]+(,\\ s*g[0-9]+)*}"
106
109
107
- checkRegex (sum , sumRegex , "Error parsing the sum parameter(s)" )
110
+ if ! checkRegex (sum , sumRegex ) {
111
+ return nil , false , nil , "" , nil , errors .New ("Error parsing the sum parameter(s)" )
112
+ }
108
113
sum = strings .Replace (sum , " " , "" , - 1 )
109
114
sum = strings .Replace (sum , "{" , "" , - 1 )
110
115
sum = strings .Replace (sum , "}" , "" , - 1 )
@@ -119,11 +124,13 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group
119
124
}
120
125
121
126
if ! check {
122
- log . Fatal ("No 'count' attribute in the sum variables" )
127
+ return nil , false , nil , "" , nil , errors . New ("No 'count' attribute in the sum variables" )
123
128
}
124
129
}
125
130
126
- checkRegex (where , whereRegex , "Error parsing the where parameter(s)" )
131
+ if ! checkRegex (where , whereRegex ) {
132
+ return nil , false , nil , "" , nil , errors .New ("Error parsing the where parameter(s)" )
133
+ }
127
134
where = strings .Replace (where , " " , "" , - 1 )
128
135
where = strings .Replace (where , "{" , "" , - 1 )
129
136
where = strings .Replace (where , "}" , "" , - 1 )
@@ -139,20 +146,22 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group
139
146
} else { // if it is a value
140
147
value , err := strconv .Atoi (tmp [i ])
141
148
if err != nil {
142
- log . Fatal ( err )
149
+ return nil , false , nil , "" , nil , err
143
150
}
144
151
145
152
whereFinal = append (whereFinal , libunlynx.WhereQueryAttribute {Name : variable , Value : * libunlynx .EncryptInt (el .Aggregate , int64 (value ))})
146
153
}
147
154
}
148
155
149
- checkRegex (groupBy , groupByRegex , "Error parsing the groupBy parameter(s)" )
156
+ if ! checkRegex (groupBy , groupByRegex ) {
157
+ return nil , false , nil , "" , nil , errors .New ("Error parsing the groupBy parameter(s)" )
158
+ }
150
159
groupBy = strings .Replace (groupBy , " " , "" , - 1 )
151
160
groupBy = strings .Replace (groupBy , "{" , "" , - 1 )
152
161
groupBy = strings .Replace (groupBy , "}" , "" , - 1 )
153
162
groupByFinal := strings .Split (groupBy , "," )
154
163
155
- return sumFinal , count , whereFinal , predicate , groupByFinal
164
+ return sumFinal , count , whereFinal , predicate , groupByFinal , nil
156
165
}
157
166
158
167
// CLIENT END: QUERIER ----------
0 commit comments