@@ -54,15 +54,16 @@ func SwaggerJSON(app *Application) http.HandlerFunc {
54
54
// description: Callback request
55
55
// required: true
56
56
// schema:
57
- // $ref: '#/definitions/ApiCallbackRequest'
57
+ // $ref: '#/definitions/ApiCallbackRequest'
58
58
//
59
59
// Responses:
60
- // default:
61
- // schema:
62
- // $ref: '#/definitions/ApiResponseError'
63
- // 200:
64
- // schema:
65
- // $ref: '#/definitions/ApiCallbackRequest'
60
+ //
61
+ // default:
62
+ // schema:
63
+ // $ref: '#/definitions/ApiResponseError'
64
+ // 200:
65
+ // schema:
66
+ // $ref: '#/definitions/ApiCallbackRequest'
66
67
func SampleCallback (app * Application ) http.HandlerFunc {
67
68
return func (w http.ResponseWriter , r * http.Request ) {
68
69
var payload model.ApiCallbackRequest
@@ -85,9 +86,10 @@ func SampleCallback(app *Application) http.HandlerFunc {
85
86
//
86
87
// ---
87
88
// Responses:
88
- // default:
89
- // schema:
90
- // $ref: '#/definitions/ApiJobsResponse'
89
+ //
90
+ // default:
91
+ // schema:
92
+ // $ref: '#/definitions/ApiJobsResponse'
91
93
func GetJobs (app * Application ) http.HandlerFunc {
92
94
return func (w http.ResponseWriter , r * http.Request ) {
93
95
apiResponse := model.ApiJobsResponse {Jobs : app .queue .Jobs }
@@ -114,15 +116,16 @@ func GetJobs(app *Application) http.HandlerFunc {
114
116
// description: Description of a job
115
117
// required: true
116
118
// schema:
117
- // $ref: '#/definitions/ApiRequest'
119
+ // $ref: '#/definitions/ApiRequest'
118
120
//
119
121
// Responses:
120
- // default:
121
- // schema:
122
- // $ref: '#/definitions/ApiResponseError'
123
- // 200:
124
- // schema:
125
- // $ref: '#/definitions/ApiSingleJobResponse'
122
+ //
123
+ // default:
124
+ // schema:
125
+ // $ref: '#/definitions/ApiResponseError'
126
+ // 200:
127
+ // schema:
128
+ // $ref: '#/definitions/ApiSingleJobResponse'
126
129
func PostJob (app * Application ) http.HandlerFunc {
127
130
return func (w http.ResponseWriter , r * http.Request ) {
128
131
// Read the event log from the request body
@@ -142,7 +145,7 @@ func PostJob(app *Application) http.HandlerFunc {
142
145
}
143
146
_ = r .Body .Close ()
144
147
145
- job , err := model .NewJob (apiRequest .EventLogURL_ , apiRequest .CallbackEndpointURL_ , app .config .ResultsDir )
148
+ job , err := model .NewJob (apiRequest .EventLogURL_ , apiRequest .CallbackEndpointURL_ , apiRequest . ColumnMapping , app .config .ResultsDir )
146
149
if err != nil {
147
150
message := fmt .Sprintf ("cannot create a job; %s" , err )
148
151
reply (w , http .StatusBadRequest , model.ApiResponseError {Error : message }, app .logger )
@@ -168,7 +171,9 @@ func PostJob(app *Application) http.HandlerFunc {
168
171
169
172
func PostJobFromBody (app * Application ) http.HandlerFunc {
170
173
return func (w http.ResponseWriter , r * http.Request ) {
171
- job , err := app .newJobFromRequestBody (r .Body )
174
+ columnMapping := columnMappingFromRequest (r )
175
+
176
+ job , err := app .newJobFromRequestBody (r .Body , columnMapping )
172
177
if err != nil {
173
178
message := fmt .Sprintf ("failed to create a job from the request body; %s" , err )
174
179
reply (w , http .StatusBadRequest , model.ApiResponseError {Error : message }, app .logger )
@@ -198,12 +203,13 @@ func PostJobFromBody(app *Application) http.HandlerFunc {
198
203
//
199
204
// ---
200
205
// Responses:
201
- // default:
202
- // schema:
203
- // $ref: '#/definitions/ApiResponseError'
204
- // 200:
205
- // schema:
206
- // $ref: '#/definitions/ApiJobsResponse'
206
+ //
207
+ // default:
208
+ // schema:
209
+ // $ref: '#/definitions/ApiResponseError'
210
+ // 200:
211
+ // schema:
212
+ // $ref: '#/definitions/ApiJobsResponse'
207
213
func DeleteJobs (app * Application ) http.HandlerFunc {
208
214
return func (w http.ResponseWriter , r * http.Request ) {
209
215
err := app .queue .Clear ()
@@ -249,12 +255,13 @@ func DeleteJobs(app *Application) http.HandlerFunc {
249
255
// type: string
250
256
//
251
257
// Responses:
252
- // default:
253
- // schema:
254
- // $ref: '#/definitions/ApiResponseError'
255
- // 200:
256
- // schema:
257
- // $ref: '#/definitions/ApiSingleJobResponse'
258
+ //
259
+ // default:
260
+ // schema:
261
+ // $ref: '#/definitions/ApiResponseError'
262
+ // 200:
263
+ // schema:
264
+ // $ref: '#/definitions/ApiSingleJobResponse'
258
265
func GetJobByID (app * Application ) http.HandlerFunc {
259
266
return func (w http.ResponseWriter , r * http.Request ) {
260
267
var apiResponse model.ApiSingleJobResponse
@@ -292,12 +299,13 @@ func GetJobByID(app *Application) http.HandlerFunc {
292
299
// type: string
293
300
//
294
301
// Responses:
295
- // default:
296
- // schema:
297
- // $ref: '#/definitions/ApiResponseError'
298
- // 200:
299
- // schema:
300
- // $ref: '#/definitions/ApiSingleJobResponse'
302
+ //
303
+ // default:
304
+ // schema:
305
+ // $ref: '#/definitions/ApiResponseError'
306
+ // 200:
307
+ // schema:
308
+ // $ref: '#/definitions/ApiSingleJobResponse'
301
309
func CancelJobByID (app * Application ) http.HandlerFunc {
302
310
return func (w http.ResponseWriter , r * http.Request ) {
303
311
vars := mux .Vars (r )
@@ -345,3 +353,52 @@ func checkError(err error, message string, logger *log.Logger) {
345
353
}
346
354
logger .Printf ("%s; %s" , message , err )
347
355
}
356
+
357
+ func columnMappingFromRequest (r * http.Request ) map [string ]string {
358
+ vars := mapFromRawQuery (r .URL .RawQuery )
359
+
360
+ var (
361
+ caseID string
362
+ activity string
363
+ resource string
364
+ startTime string
365
+ endTime string
366
+ ok bool
367
+ )
368
+
369
+ columnMapping := make (map [string ]string )
370
+
371
+ caseID , ok = vars ["case" ]
372
+ if ok {
373
+ columnMapping ["case" ] = caseID
374
+ }
375
+ activity , ok = vars ["activity" ]
376
+ if ok {
377
+ columnMapping ["activity" ] = activity
378
+ }
379
+ resource , ok = vars ["resource" ]
380
+ if ok {
381
+ columnMapping ["resource" ] = resource
382
+ }
383
+ startTime , ok = vars ["start_timestamp" ]
384
+ if ok {
385
+ columnMapping ["start_timestamp" ] = startTime
386
+ }
387
+ endTime , ok = vars ["end_timestamp" ]
388
+ if ok {
389
+ columnMapping ["end_timestamp" ] = endTime
390
+ }
391
+
392
+ return columnMapping
393
+ }
394
+
395
+ func mapFromRawQuery (query string ) map [string ]string {
396
+ queryMap := make (map [string ]string )
397
+ for _ , pair := range strings .Split (query , "&" ) {
398
+ values := strings .Split (pair , "=" )
399
+ if len (values ) == 2 {
400
+ queryMap [values [0 ]] = values [1 ]
401
+ }
402
+ }
403
+ return queryMap
404
+ }
0 commit comments