Skip to content

Commit daa7453

Browse files
committed
Merge branch 'Issue_179_HOTFIX'
2 parents a991e4c + bbc0d22 commit daa7453

File tree

6 files changed

+59
-23
lines changed

6 files changed

+59
-23
lines changed

config/default.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ module.exports = {
2222
KAFKA_ERROR_TOPIC: process.env.KAFKA_ERROR_TOPIC || 'error.notification',
2323
KAFKA_AGGREGATE_TOPIC: process.env.KAFKA_AGGREGATE_TOPIC || 'submission.notification.aggregate',
2424
CHALLENGEAPI_URL: process.env.CHALLENGEAPI_URL || 'https://api.topcoder-dev.com/v4/challenges',
25+
CHALLENGEAPI_V5_URL: process.env.CHALLENGEAPI_V5_URL || 'https://api.topcoder-dev.com/v5/challenges',
2526
AUTH0_URL: process.env.AUTH0_URL, // Auth0 credentials for Submission Service
2627
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE || 'https://www.topcoder.com',
2728
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME,
2829
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
2930
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
3031
esConfig: {
31-
HOST: process.env.ES_HOST,
32+
HOST: process.env.ES_HOST || 'localhost:9200',
3233
API_VERSION: process.env.ES_API_VERSION || '6.3',
3334
ES_INDEX: process.env.ES_INDEX || 'submission',
3435
ES_TYPE: process.env.ES_TYPE || '_doc' // ES 6.x accepts only 1 Type per index and it's mandatory to define it

docs/swagger.yaml

+5-11
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ paths:
9494
challengeId: 'a12a4180-65aa-42ec-a945-5fd21dec0502'
9595
legacySubmissionId: 'a12a4180-65aa-42ec-a945-5fd21dec0502'
9696
legacyUploadId: 'a12a4180-65aa-42ec-a945-5fd21dec0502'
97-
submissionPhaseId: 'a12a4180-65aa-42ec-a945-5fd21dec0502'
97+
submissionPhaseId: 764567
9898
created: '2018-05-20T07:00:30.123Z'
9999
updated: '2018-06-01T07:36:28.178Z'
100100
createdBy: 'topcoder user'
@@ -106,7 +106,7 @@ paths:
106106
challengeId: 'a12a4180-65aa-42ec-a945-5fd21dec0502'
107107
legacySubmissionId: 'a12a4180-65aa-42ec-a945-5fd21dec0502'
108108
legacyUploadId: 'a12a4180-65aa-42ec-a945-5fd21dec0502'
109-
submissionPhaseId: 'a12a4180-65aa-42ec-a945-5fd21dec0502'
109+
submissionPhaseId: 764567
110110
created: '2018-05-20T08:00:30.000Z'
111111
updated: '2018-06-01T09:23:00.178Z'
112112
createdBy: 'topcoder user'
@@ -260,9 +260,7 @@ paths:
260260
description: Legacy Submission Id
261261
- in: formData
262262
name: submissionPhaseId
263-
oneOf:
264-
- type: string
265-
- type: integer
263+
type: integer
266264
description: Submission Phase Id
267265
responses:
268266
201:
@@ -1599,9 +1597,7 @@ parameters:
15991597
name: submissionPhaseId
16001598
description: The submission phase id filter for submissions.
16011599
required: false
1602-
oneOf:
1603-
- type: string
1604-
- type: integer
1600+
type: integer
16051601

16061602
filterSubmissionReviewScore:
16071603
in: query
@@ -1881,9 +1877,7 @@ definitions:
18811877
description: The legacy upload id.
18821878
example: '5da27562-eaec-4c9f-ad1c-ddfbed6ffdbc'
18831879
submissionPhaseId:
1884-
oneOf:
1885-
- type: string
1886-
- type: integer
1880+
type: integer
18871881
description: The submission phase id.
18881882
example: '5dea6d9e-161a-4c7a-b316-597c73a7b8f4'
18891883

scripts/createIndex.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ co(function * createIndex () {
1717
// fields not specified below will be 'text' by default
1818
properties: {
1919
resource: { type: 'keyword' },
20-
challengeId: { type: 'keyword' },
20+
challengeId: { type: 'long' },
2121
memberId: { type: 'keyword' },
2222
type: { type: 'keyword' },
2323
isFileSubmission: { type: 'boolean' },
@@ -32,7 +32,7 @@ co(function * createIndex () {
3232
aggregateScore: { type: 'float' },
3333
isPassing: { type: 'boolean' },
3434
legacySubmissionId: { type: 'keyword' },
35-
submissionPhaseId: { type: 'keyword' },
35+
submissionPhaseId: { type: 'long' },
3636
fileType: { type: 'keyword' },
3737
filename: { type: 'keyword' },
3838
review: { type: 'nested' },

src/common/helper.js

+25
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,30 @@ function * getM2Mtoken () {
299299
return yield m2m.getMachineToken(config.AUTH0_CLIENT_ID, config.AUTH0_CLIENT_SECRET)
300300
}
301301

302+
/**
303+
* Get legacy challenge id if the challenge id is uuid form
304+
* @param {String} challengeId Challenge ID
305+
* @returns {String} Legacy Challenge ID of the given challengeId
306+
*/
307+
function * getLegacyChallengeId (challengeId) {
308+
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(challengeId)) {
309+
logger.debug(`${challengeId} detected as uuid. Fetching legacy challenge id`)
310+
const token = yield getM2Mtoken()
311+
try {
312+
const response = yield request.get(`${config.CHALLENGEAPI_V5_URL}/${challengeId}`)
313+
.set('Authorization', `Bearer ${token}`)
314+
.set('Content-Type', 'application/json')
315+
const legacyId = parseInt(response.body.legacyId, 10)
316+
logger.debug(`Legacy challenge id is ${legacyId} for v5 challenge id ${challengeId}`)
317+
return legacyId
318+
} catch (err) {
319+
logger.error(`Error while accessing ${config.CHALLENGEAPI_V5_URL}/${challengeId}`)
320+
throw err
321+
}
322+
}
323+
return challengeId
324+
}
325+
302326
/*
303327
* Get submission phase ID of a challenge from Challenge API
304328
* @param challengeId Challenge ID
@@ -604,6 +628,7 @@ module.exports = {
604628
fetchFromES,
605629
camelize,
606630
setPaginationHeaders,
631+
getLegacyChallengeId,
607632
getSubmissionPhaseId,
608633
checkCreateAccess,
609634
checkGetAccess,

src/services/SubmissionService.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ function * downloadSubmission (authUser, submissionId) {
181181
* @return {Object} Data fetched from ES
182182
*/
183183
function * listSubmissions (authUser, query) {
184+
if (query.challengeId) {
185+
// Submission api only works with legacy challenge id
186+
// If it is a v5 challenge id, get the associated legacy challenge id
187+
query.challengeId = yield helper.getLegacyChallengeId(query.challengeId)
188+
}
189+
184190
const data = yield helper.fetchFromES(query, helper.camelize(table))
185191
logger.info(`listSubmissions: returning ${data.length} submissions for query: ${JSON.stringify(query)}`)
186192

@@ -200,7 +206,7 @@ const listSubmissionsQuerySchema = {
200206
challengeId: joi.alternatives().try(joi.id(), joi.string().uuid()),
201207
legacySubmissionId: joi.alternatives().try(joi.id(), joi.string().uuid()),
202208
legacyUploadId: joi.alternatives().try(joi.id(), joi.string().uuid()),
203-
submissionPhaseId: joi.alternatives().try(joi.id(), joi.string().uuid()),
209+
submissionPhaseId: joi.id(),
204210
page: joi.id(),
205211
perPage: joi.pageSize(),
206212
orderBy: joi.sortOrder(),
@@ -262,14 +268,18 @@ function * createSubmission (authUser, files, entity) {
262268
throw new errors.HttpStatusError(400, 'The file should be uploaded under the "submission" attribute')
263269
}
264270

271+
// Submission api only works with legacy challenge id
272+
// If it is a v5 challenge id, get the associated legacy challenge id
273+
const challengeId = yield helper.getLegacyChallengeId(entity.challengeId)
274+
265275
const currDate = (new Date()).toISOString()
266276

267277
const item = {
268278
id: submissionId,
269279
type: entity.type,
270280
url: url,
271281
memberId: entity.memberId,
272-
challengeId: entity.challengeId,
282+
challengeId: challengeId,
273283
created: currDate,
274284
updated: currDate,
275285
createdBy: authUser.handle || authUser.sub,
@@ -287,7 +297,7 @@ function * createSubmission (authUser, files, entity) {
287297
if (entity.submissionPhaseId) {
288298
item.submissionPhaseId = entity.submissionPhaseId
289299
} else {
290-
item.submissionPhaseId = yield helper.getSubmissionPhaseId(entity.challengeId)
300+
item.submissionPhaseId = yield helper.getSubmissionPhaseId(challengeId)
291301
}
292302

293303
if (entity.fileType) {
@@ -353,7 +363,7 @@ createSubmission.schema = {
353363
challengeId: joi.alternatives().try(joi.id(), joi.string().uuid()).required(),
354364
legacySubmissionId: joi.alternatives().try(joi.id(), joi.string().uuid()),
355365
legacyUploadId: joi.alternatives().try(joi.id(), joi.string().uuid()),
356-
submissionPhaseId: joi.alternatives().try(joi.id(), joi.string().uuid())
366+
submissionPhaseId: joi.id()
357367
}).required()
358368
}
359369

@@ -374,6 +384,12 @@ function * _updateSubmission (authUser, submissionId, entity) {
374384
throw new errors.HttpStatusError(404, `Submission with ID = ${submissionId} is not found`)
375385
}
376386

387+
if (entity.challengeId) {
388+
// Submission api only works with legacy challenge id
389+
// If it is a v5 challenge id, get the associated legacy challenge id
390+
entity.challengeId = yield helper.getLegacyChallengeId(entity.challengeId)
391+
}
392+
377393
const currDate = (new Date()).toISOString()
378394
// Record used for updating in Database
379395
const record = {
@@ -466,7 +482,7 @@ updateSubmission.schema = {
466482
challengeId: joi.alternatives().try(joi.id(), joi.string().uuid()).required(),
467483
legacySubmissionId: joi.alternatives().try(joi.id(), joi.string().uuid()),
468484
legacyUploadId: joi.alternatives().try(joi.id(), joi.string().uuid()),
469-
submissionPhaseId: joi.alternatives().try(joi.id(), joi.string().uuid())
485+
submissionPhaseId: joi.id()
470486
}).required()
471487
}
472488

@@ -491,7 +507,7 @@ patchSubmission.schema = {
491507
challengeId: joi.alternatives().try(joi.id(), joi.string().uuid()),
492508
legacySubmissionId: joi.alternatives().try(joi.id(), joi.string().uuid()),
493509
legacyUploadId: joi.alternatives().try(joi.id(), joi.string().uuid()),
494-
submissionPhaseId: joi.alternatives().try(joi.id(), joi.string().uuid())
510+
submissionPhaseId: joi.id()
495511
})
496512
}
497513

test/common/testData.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const testSubmission = {
129129
url: 'https://software.topcoder.com/review/actions/DownloadContestSubmission?uid=123456',
130130
memberId: 'b24d4180-65aa-42ec-a945-5fd21dec0501',
131131
legacySubmissionId: 'b24d4180-65aa-42ec-a945-5fd21dec0501',
132-
submissionPhaseId: 'b24d4180-65aa-42ec-a945-5fd21dec0501',
132+
submissionPhaseId: 764567,
133133
created: '2018-05-20T07:00:30.123Z',
134134
createdBy: 'topcoder user',
135135
updated: '2018-06-01T07:36:28.178Z',
@@ -159,7 +159,7 @@ const testSubmissionPatch = {
159159
url: 'https://software.topcoder.com/review/actions/DownloadContestSubmission?uid=654321',
160160
memberId: 'b24d4180-65aa-42ec-a945-5fd21dec0501',
161161
legacySubmissionId: 'b24d4180-65aa-42ec-a945-5fd21dec0502',
162-
submissionPhaseId: 'b24d4180-65aa-42ec-a945-5fd21dec0502',
162+
submissionPhaseId: 764567,
163163
created: '2018-05-20T07:00:30.123Z',
164164
createdBy: 'topcoder user',
165165
updated: '2018-06-01T07:36:28.178Z',
@@ -184,7 +184,7 @@ const testSubmissionES = {
184184
url: 'https://software.topcoder.com/review/actions/DownloadContestSubmission?uid=123456',
185185
memberId: 'b24d4180-65aa-42ec-a945-5fd21dec0501',
186186
legacySubmissionId: 'b24d4180-65aa-42ec-a945-5fd21dec0501',
187-
submissionPhaseId: 'b24d4180-65aa-42ec-a945-5fd21dec0501',
187+
submissionPhaseId: 764567,
188188
created: '2018-05-20T07:00:30.123Z',
189189
createdBy: 'topcoder user',
190190
updated: '2018-06-01T07:36:28.178Z',

0 commit comments

Comments
 (0)