Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit f3b5bdc

Browse files
resole conflicts
2 parents 7214181 + 719a4de commit f3b5bdc

File tree

9 files changed

+418
-158
lines changed

9 files changed

+418
-158
lines changed

config/default.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,18 @@ module.exports = {
6868
SUBMISSION_PHASE_ID: process.env.SUBMISSION_PHASE_ID || '6950164f-3c5e-4bdc-abc8-22aaf5a1bd49',
6969
CHECKPOINT_SUBMISSION_PHASE_ID: process.env.CHECKPOINT_SUBMISSION_PHASE_ID || 'd8a2cdbe-84d1-4687-ab75-78a6a7efdcc8',
7070

71-
V5_TERMS_NDA_ID: process.env.V5_TERMS_NDA_ID || '77f558c1-56fb-427c-b974-61ea0a060ca7',
72-
LEGACY_TERMS_NDA_ID: process.env.LEGACY_TERMS_NDA_ID || 21343,
71+
V5_TERMS_NDA_ID: process.env.V5_TERMS_NDA_ID || 'e5811a7b-43d1-407a-a064-69e5015b4900',
72+
LEGACY_TERMS_NDA_ID: process.env.LEGACY_TERMS_NDA_ID || 21233,
73+
74+
V5_TERMS_STANDARD_ID: process.env.V5_TERMS_STANDARD_ID || '317cd8f9-d66c-4f2a-8774-63c612d99cd4',
75+
LEGACY_TERMS_STANDARD_ID: process.env.LEGACY_TERMS_STANDARD_ID || 21305,
76+
7377
LEGACY_SUBMITTER_ROLE_ID: process.env.LEGACY_SUBMITTER_ROLE_ID || 1,
7478

7579
COPILOT_PAYMENT_TYPE: process.env.COPILOT_PAYMENT_TYPE || 'copilot',
7680

81+
COPILOT_ROLE_ID: process.env.COPILOT_ROLE_ID || 'cfe12b3f-2a24-4639-9d8b-ec86726f76bd',
82+
7783
// V5 Term UUID
7884
SYNC_V5_TERM_UUID: process.env.SYNC_V5_TERM_UUID || '317cd8f9-d66c-4f2a-8774-63c612d99cd4',
7985
SYNC_V5_WRITE_ENABLED: process.env.SYNC_V5_WRITE_ENABLED === 'true' || false

src/app.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ const dataHandler = (messageSet, topic, partition) => Promise.each(messageSet, a
6464

6565
try {
6666
if (topic === config.CREATE_CHALLENGE_TOPIC) {
67-
// create shut off. Only works with challenges of status draft, which happens on update
68-
// await ProcessorService.processCreate(messageJSON)
67+
await ProcessorService.processCreate(messageJSON)
6968
} else {
7069
await ProcessorService.processUpdate(messageJSON)
7170
}

src/constants.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,22 @@ const prizeTypesIds = {
5555
Checkpoint: 14
5656
}
5757

58+
const supportedMetadata = {
59+
allowStockArt: 52,
60+
drPoints: 30,
61+
submissionViewable: 53,
62+
submissionLimit: 51,
63+
codeRepo: 85,
64+
environment: 84
65+
}
66+
5867
module.exports = {
5968
prizeSetTypes,
6069
EVENT_ORIGINATOR,
6170
EVENT_MIME_TYPE,
6271
createChallengeStatusesMap,
6372
challengeStatuses,
6473
PhaseStatusTypes,
65-
prizeTypesIds
74+
prizeTypesIds,
75+
supportedMetadata
6676
}

src/services/ProcessorService.js

Lines changed: 126 additions & 37 deletions
Large diffs are not rendered by default.

src/services/copilotPaymentService.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const helper = require('../common/helper')
55

66
const COPILOT_PAYMENT_PROJECT_INFO_ID = 49
77
const COPILOT_PAYMENT_RESOURCE_INFO_ID = 7
8+
const COPILOT_PAYMENT_TYPE_ID = 15
89
const COPILOT_RESOURCE_ROLE_ID = 14
910

1011
const QUERY_GET_COPILOT_RESOURCE_FOR_CHALLENGE = `SELECT limit 1 resource_id as resourceid FROM resource WHERE project_id = %d AND resource_role_id = ${COPILOT_RESOURCE_ROLE_ID}`
@@ -32,6 +33,10 @@ const QUERY_DELETE_COPILOT_PAYMENT = `DELETE FROM project_info WHERE project_inf
3233
const QUERY_UPDATE_COPILOT_RESOURCE_PAYMENT = `UPDATE resource_info SET value = ?, modify_user = ?, modify_date = CURRENT WHERE resource_id = ? AND resource_info_type_id = ${COPILOT_PAYMENT_RESOURCE_INFO_ID}`
3334
// const QUERY_DELETE_COPILOT_RESOURCE_PAYMENT = `DELETE FROM resource_info WHERE resource_id = ? AND resource_info_type_id = ${COPILOT_PAYMENT_RESOURCE_INFO_ID}`
3435

36+
const QUERY_SELECT_PAYMENT_TYPE = `SELECT value FROM resource_info WHERE resource_info_type_id = ${COPILOT_PAYMENT_TYPE_ID} AND resource_id = %d`
37+
const QUERY_INSERT_PAYMENT_TYPE = `INSERT INTO resource_info (resource_id, resource_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (?, "${COPILOT_PAYMENT_TYPE_ID}", ?, ?, CURRENT, ?, CURRENT)`
38+
const QUERY_UPDATE_PAYMENT_TYPE = `UPDATE resource_info SET value = ?, modify_user = ?, modify_date = CURRENT WHERE resource_id = ? AND resource_info_type_id = ${COPILOT_PAYMENT_TYPE_ID}`
39+
3540
/**
3641
* Prepare Informix statement
3742
* @param {Object} connection the Informix connection
@@ -58,6 +63,14 @@ async function setCopilotPayment (challengeLegacyId, amount, createdBy, updatedB
5863
const copilotResourceId = await getCopilotResourceId(connection, challengeLegacyId)
5964
const copilotPayment = await getCopilotPayment(connection, challengeLegacyId)
6065
if (amount != null && amount >= 0) {
66+
// Make sure the payment type is set to manual
67+
// TODO: Figure out why data is not saved in IFX even when there are no errors
68+
// const paymentType = await getCopilotPaymentType(connection, copilotResourceId)
69+
// if (!paymentType) {
70+
// await createCopilotPaymentType(connection, copilotResourceId, 'TRUE', updatedBy || createdBy)
71+
// } else if (_.toLower(_.toString(paymentType.value)) !== 'true') {
72+
// await updateCopilotPaymentType(connection, copilotResourceId, 'TRUE', updatedBy || createdBy)
73+
// }
6174
if (copilotPayment) {
6275
logger.debug(`Copilot payment exists, updating: ${challengeLegacyId}`)
6376
return updateCopilotPayment(connection, copilotResourceId, challengeLegacyId, amount, updatedBy)
@@ -78,6 +91,43 @@ async function setCopilotPayment (challengeLegacyId, amount, createdBy, updatedB
7891
}
7992
}
8093

94+
/**
95+
* Gets the copilot payment type for a legacyId
96+
* @param {Object} connection the connection
97+
* @param {Number} resourceId the resource ID
98+
*/
99+
async function getCopilotPaymentType (connection, resourceId) {
100+
const result = await connection.queryAsync(util.format(QUERY_SELECT_PAYMENT_TYPE, resourceId))
101+
logger.debug(`Result: ${JSON.stringify(result, null, 2)}`)
102+
return _.get(result, '[0]', null)
103+
}
104+
105+
/**
106+
* Create the copilot payment type record
107+
* @param {Object} connection the connection
108+
* @param {Number} resourceId the resource ID
109+
* @param {Boolean} value the value
110+
* @param {String} createdBy the create user handle
111+
*/
112+
async function createCopilotPaymentType (connection, resourceId, value, createdBy) {
113+
const query = await prepare(connection, QUERY_INSERT_PAYMENT_TYPE)
114+
logger.debug(`Create Copilot Payment Type Values: ${[resourceId, value, createdBy, createdBy]}`)
115+
await query.executeAsync([resourceId, value, createdBy, createdBy])
116+
}
117+
118+
/**
119+
* Update the copilot payment type record
120+
* @param {Object} connection the connection
121+
* @param {Number} resourceId the resource ID
122+
* @param {Boolean} value the value
123+
* @param {String} createdBy the create user handle
124+
*/
125+
async function updateCopilotPaymentType (connection, resourceId, value, createdBy) {
126+
const query = await prepare(connection, QUERY_UPDATE_PAYMENT_TYPE)
127+
logger.debug(`Update Copilot Payment Type Values: ${[value, createdBy, resourceId]}`)
128+
await query.executeAsync([value, createdBy, resourceId])
129+
}
130+
81131
/**
82132
* Gets the copilot payment for a legacyId
83133
* @param {Object} connection

src/services/groupsService.js

Lines changed: 84 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ const _ = require('lodash')
33
const util = require('util')
44
const helper = require('../common/helper')
55

6-
const QUERY_GET_ELIGIBILITY_ID = 'SELECT limit 1 * FROM contest_eligibility WHERE contest_id = %d'
7-
const QUERY_GET_GROUP_ELIGIBILITY_ID = 'SELECT limit 1 * FROM group_contest_eligibility WHERE contest_eligibility_id = %d AND group_id = %d'
8-
const QUERY_GET_GROUPS = 'SELECT group_id FROM group_contest_eligibility WHERE contest_eligibility_id = %d'
9-
const QUERY_GET_GROUPS_COUNT = 'SELECT count(*) as cnt FROM group_contest_eligibility WHERE contest_eligibility_id = %d'
10-
6+
const QUERY_GET_CONTEST_ELIGIBILITIES_IDS = 'SELECT contest_eligibility_id FROM contest_eligibility WHERE contest_id = %d'
117
const QUERY_INSERT_CONTEST_ELIGIBILITY = 'INSERT INTO contest_eligibility (contest_eligibility_id, contest_id, is_studio) VALUES(contest_eligibility_seq.NEXTVAL, ?, 0)'
8+
9+
const QUERY_GET_GROUPS = 'SELECT contest_eligibility_id, group_id FROM group_contest_eligibility WHERE contest_eligibility_id in'
1210
const QUERY_INSERT_GROUP_CONTEST_ELIGIBILITY = 'INSERT INTO group_contest_eligibility (contest_eligibility_id, group_id) VALUES(?, ?)'
11+
1312
const QUERY_DELETE_GROUP_CONTEST_ELIGIBILITY = 'DELETE FROM group_contest_eligibility WHERE contest_eligibility_id = ? AND group_id = ?'
1413
const QUERY_DELETE_CONTEST_ELIGIBILITY = 'DELETE FROM contest_eligibility WHERE contest_eligibility_id = ?'
1514

@@ -25,15 +24,20 @@ async function prepare (connection, sql) {
2524
return Promise.promisifyAll(stmt)
2625
}
2726

27+
/**
28+
* Get groups for a challenge
29+
* @param {Number} challengeLegacyId the legacy challenge ID
30+
*/
2831
async function getGroupsForChallenge (challengeLegacyId) {
2932
// logger.debug(`Getting Groups for Challenge ${challengeLegacyId}`)
3033
const connection = await helper.getInformixConnection()
3134
let groupIds = []
3235
try {
3336
// await connection.beginTransactionAsync()
34-
const eligibilityId = await getChallengeEligibilityId(connection, challengeLegacyId)
35-
if (eligibilityId) {
36-
groupIds = await getGroupIdsForEligibilityId(connection, eligibilityId)
37+
const eligibilityIds = await getChallengeEligibilityIds(connection, challengeLegacyId)
38+
if (eligibilityIds && eligibilityIds.length > 0) {
39+
const groups = await getGroupsForEligibilityIds(connection, eligibilityIds)
40+
groupIds = _.map(groups, g => g.group_id)
3741
// logger.debug(`Groups Found for ${challengeLegacyId} - ${JSON.stringify(groupIds)}`)
3842
}
3943
// logger.debug(`No groups Found for ${challengeLegacyId}`)
@@ -48,23 +52,25 @@ async function getGroupsForChallenge (challengeLegacyId) {
4852
return groupIds
4953
}
5054

55+
/**
56+
* Add a group to a challenge
57+
* @param {Number} challengeLegacyId the legacy challenge ID
58+
* @param {Number} groupLegacyId the legacy group ID
59+
*/
5160
async function addGroupToChallenge (challengeLegacyId, groupLegacyId) {
61+
const existingGroups = await getGroupsForChallenge(challengeLegacyId)
62+
if (existingGroups.indexOf(groupLegacyId) > -1) {
63+
logger.info(`Group ${groupLegacyId} is already assigned to challenge ${challengeLegacyId}. Skipping...`)
64+
return
65+
}
5266
const connection = await helper.getInformixConnection()
5367

5468
try {
5569
await connection.beginTransactionAsync()
56-
let eligibilityId = await getChallengeEligibilityId(connection, challengeLegacyId)
57-
if (!eligibilityId) {
58-
eligibilityId = await createChallengeEligibilityRecord(connection, challengeLegacyId)
59-
}
60-
61-
const groupMappingExists = await groupEligbilityExists(connection, eligibilityId, groupLegacyId)
62-
if (groupMappingExists) {
63-
logger.warn(`Group Relation Already Exists for ${groupMappingExists} - ${eligibilityId} ${groupLegacyId}`)
64-
} else {
65-
await createGroupEligibilityRecord(connection, eligibilityId, groupLegacyId)
66-
}
67-
70+
// create eligibility entry
71+
const eligibilityId = await createContestEligibility(connection, challengeLegacyId)
72+
// create group association
73+
await createGroupContestEligibility(connection, eligibilityId, groupLegacyId)
6874
await connection.commitTransactionAsync()
6975
} catch (e) {
7076
logger.error(`Error in 'addGroupToChallenge' ${e}, rolling back transaction`)
@@ -76,114 +82,96 @@ async function addGroupToChallenge (challengeLegacyId, groupLegacyId) {
7682
}
7783
}
7884

85+
/**
86+
* Remove group from a challenge
87+
* @param {Number} challengeLegacyId the legacy challenge ID
88+
* @param {Number} groupLegacyId the group ID
89+
*/
7990
async function removeGroupFromChallenge (challengeLegacyId, groupLegacyId) {
8091
const connection = await helper.getInformixConnection()
8192

8293
try {
8394
await connection.beginTransactionAsync()
84-
const eligibilityId = await getChallengeEligibilityId(connection, challengeLegacyId)
85-
if (!eligibilityId) {
86-
throw new Error(`Eligibility not found for legacyId ${challengeLegacyId}`)
87-
}
88-
const groupEligibilityRecord = await groupEligbilityExists(connection, eligibilityId, groupLegacyId)
89-
90-
if (groupEligibilityRecord) {
91-
await deleteGroupEligibilityRecord(connection, eligibilityId, groupLegacyId)
92-
// logger.debug('Getting Groups Count')
93-
const { groupsCount } = await getCountOfGroupsInEligibilityRecord(connection, eligibilityId)
94-
// logger.debug(`${groupsCount} groups exist`)
95-
if (groupsCount <= 0) {
96-
logger.debug('No groups exist, deleting eligibility group')
97-
await deleteEligibilityRecord(connection, eligibilityId)
95+
const eligibilityIds = await getChallengeEligibilityIds(connection, challengeLegacyId)
96+
if (eligibilityIds && eligibilityIds.length > 0) {
97+
const groups = await getGroupsForEligibilityIds(connection, eligibilityIds)
98+
const groupToRemove = _.find(groups, g => g.group_id === groupLegacyId)
99+
if (groupToRemove) {
100+
await clearData(connection, groupToRemove.contest_eligibility_id, groupToRemove.group_id)
98101
}
99102
}
100-
101103
await connection.commitTransactionAsync()
102104
} catch (e) {
103105
logger.error(`Error in 'removeGroupFromChallenge' ${e}, rolling back transaction`)
104106
await connection.rollbackTransactionAsync()
105107
throw e
106108
} finally {
107-
logger.info(`Group ${groupLegacyId} removed to challenge ${challengeLegacyId}`)
109+
logger.info(`Group ${groupLegacyId} removed from challenge ${challengeLegacyId}`)
108110
await connection.closeAsync()
109111
}
110112
}
111113

112114
/**
113-
* Gets the eligibility ID of a legacyId
114-
* @param {Object} connection
115-
* @param {Number} challengeLegacyId
116-
* @returns {Object} { eligibilityId }
115+
* Get group IDs
116+
* @param {Object} connection the connection
117+
* @param {Array} eligibilityIds the eligibility IDs
117118
*/
118-
async function getChallengeEligibilityId (connection, challengeLegacyId) {
119-
// get the challenge eligibility record, if one doesn't exist, create it and return the id
120-
// logger.info(`getChallengeEligibilityId Query: ${util.format(QUERY_GET_ELIGIBILITY_ID, challengeLegacyId)}`)
121-
const result = await connection.queryAsync(util.format(QUERY_GET_ELIGIBILITY_ID, challengeLegacyId))
122-
// logger.info(`getChallengeEligibilityId Result: ${JSON.stringify(result)}`)
123-
return (result && result[0]) ? result[0].contest_eligibility_id : false
119+
async function getGroupsForEligibilityIds (connection, eligibilityIds) {
120+
const query = `${QUERY_GET_GROUPS} (${eligibilityIds.join(', ')})`
121+
// logger.debug(`getGroupIdsForEligibilityId ${query}`)
122+
const result = await connection.queryAsync(query)
123+
return result
124124
}
125125

126126
/**
127-
* @param {Object} connection
128-
* @param {Number} eligibilityId
129-
* @param {Number} groupLegacyId
130-
* @returns {Object} DB Result
127+
* Gets the eligibility IDs
128+
* @param {Object} connection the connection
129+
* @param {Number} challengeLegacyId the legacy challenge ID
131130
*/
132-
async function groupEligbilityExists (connection, eligibilityId, groupLegacyId) {
133-
// logger.debug(`groupEligibiltyExists query ${util.format(QUERY_GET_GROUP_ELIGIBILITY_ID, eligibilityId, groupLegacyId)}`)
134-
const result = await connection.queryAsync(util.format(QUERY_GET_GROUP_ELIGIBILITY_ID, eligibilityId, groupLegacyId))
135-
// logger.debug(`groupEligibiltyExists result ${JSON.stringify(result)} ${JSON.stringify(result[0])}`)
136-
return (result && result[0]) || false
131+
async function getChallengeEligibilityIds (connection, challengeLegacyId) {
132+
const query = util.format(QUERY_GET_CONTEST_ELIGIBILITIES_IDS, challengeLegacyId)
133+
// logger.debug(`getGroupIdsForEligibilityId ${query}`)
134+
const result = await connection.queryAsync(query)
135+
return _.map(result, r => r.contest_eligibility_id)
137136
}
138137

139-
async function createChallengeEligibilityRecord (connection, challengeLegacyId) {
138+
/**
139+
* Create a contest eligibility
140+
* @param {Object} connection the connection
141+
* @param {Number} legacyChallengeId the legacy challenge ID
142+
*/
143+
async function createContestEligibility (connection, legacyChallengeId) {
140144
const query = await prepare(connection, QUERY_INSERT_CONTEST_ELIGIBILITY)
141-
const result = await query.executeAsync([challengeLegacyId])
142-
if (result) {
143-
const idResult = await connection.queryAsync(util.format(QUERY_GET_ELIGIBILITY_ID, challengeLegacyId))
144-
return idResult[0].contest_eligibility_id
145-
}
146-
return false
145+
await query.executeAsync([legacyChallengeId])
146+
const ids = await getChallengeEligibilityIds(connection, legacyChallengeId)
147+
const groups = await getGroupsForEligibilityIds(connection, ids)
148+
return _.get(_.filter(ids, id => !_.find(groups, g => g.contest_eligibility_id === id)), '[0]')
147149
}
148150

149-
async function createGroupEligibilityRecord (connection, eligibilityId, groupLegacyId) {
151+
/**
152+
* Create group contest eligibility
153+
* @param {Object} connection the connection
154+
* @param {Number} eligibilityId the eligibility ID
155+
* @param {Number} groupId the group ID
156+
*/
157+
async function createGroupContestEligibility (connection, eligibilityId, groupId) {
150158
const query = await prepare(connection, QUERY_INSERT_GROUP_CONTEST_ELIGIBILITY)
151-
const result = await query.executeAsync([eligibilityId, groupLegacyId])
152-
if (result) {
153-
const idResult = await connection.queryAsync(util.format(QUERY_GET_GROUP_ELIGIBILITY_ID, eligibilityId, groupLegacyId))
154-
return idResult[0]
155-
}
156-
return result
157-
}
158-
159-
async function deleteGroupEligibilityRecord (connection, eligibilityId, groupLegacyId) {
160-
const query = await prepare(connection, QUERY_DELETE_GROUP_CONTEST_ELIGIBILITY)
161-
const result = await query.executeAsync([eligibilityId, groupLegacyId])
162-
// logger.debug(`deleteGroupEligibilityRecord ${JSON.stringify(result)}`)
163-
return result
159+
return await query.executeAsync([eligibilityId, groupId])
164160
}
165161

166-
async function deleteEligibilityRecord (connection, eligibilityId) {
167-
const query = await prepare(connection, QUERY_DELETE_CONTEST_ELIGIBILITY)
168-
// logger.debug(`deleteEligibilityRecord Query ${JSON.stringify(query)}`)
169-
const result = await query.executeAsync([eligibilityId])
170-
// logger.debug(`deleteEligibilityRecord ${JSON.stringify(result)}`)
171-
return result
172-
}
173-
174-
async function getCountOfGroupsInEligibilityRecord (connection, eligibilityId) {
175-
const query = util.format(QUERY_GET_GROUPS_COUNT, eligibilityId)
176-
// logger.debug(`Query! ${query}`)
177-
const result = await connection.queryAsync(query)
178-
// logger.debug(`getCountOfGroupsInEligibilityRecord ${JSON.stringify(result)}`)
179-
return { groupsCount: result[0].cnt || 0 }
180-
}
162+
/**
163+
* Removes entries from group_contest_eligibility and contest_eligibility
164+
* @param {Object} connection the connection
165+
* @param {Number} eligibilityId the eligibility ID
166+
* @param {Number} groupId the group ID
167+
*/
168+
async function clearData (connection, eligibilityId, groupId) {
169+
let query
170+
query = await prepare(connection, QUERY_DELETE_GROUP_CONTEST_ELIGIBILITY)
171+
await query.executeAsync([eligibilityId, groupId])
181172

182-
async function getGroupIdsForEligibilityId (connection, eligibilityId) {
183-
const query = util.format(QUERY_GET_GROUPS, eligibilityId)
184-
// logger.debug(`getGroupIdsForEligibilityId ${query}`)
185-
const result = await connection.queryAsync(query)
186-
return _.map(result, r => r.group_id)
173+
query = await prepare(connection, QUERY_DELETE_CONTEST_ELIGIBILITY)
174+
await query.executeAsync([eligibilityId])
187175
}
188176

189177
module.exports = {

0 commit comments

Comments
 (0)