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

Commit a4e8e45

Browse files
implement metadata extractor
1 parent 46b29e5 commit a4e8e45

File tree

3 files changed

+301
-40
lines changed

3 files changed

+301
-40
lines changed

src/constants.js

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/**
22
* constants
33
*/
4+
const metadataExtractor = require('./utils/metadataExtractor')
45

56
const prizeSetTypes = {
67
ChallengePrizes: 'placement',
78
CopilotPayment: 'copilot',
89
ReviewerPayment: 'reviewer',
9-
CheckPoint: 'checkpoint'
10+
CheckPoint: 'checkpoint',
11+
SpecReview: 'specReviewer'
1012
}
1113

1214
const EVENT_ORIGINATOR = 'legacy-challenge-processor'
@@ -57,12 +59,81 @@ const prizeTypesIds = {
5759
}
5860

5961
const supportedMetadata = {
60-
allowStockArt: 52,
61-
drPoints: 30,
62-
submissionViewable: 53,
63-
submissionLimit: 51,
64-
codeRepo: 85,
65-
environment: 84
62+
32: {
63+
method: metadataExtractor.extractBillingProject,
64+
defaultValue: null,
65+
description: 'Billing Project'
66+
},
67+
30: {
68+
method: metadataExtractor.extractDrPoints,
69+
defaultValue: 0,
70+
description: 'DR points'
71+
},
72+
35: {
73+
method: metadataExtractor.extractSpecReviewCost,
74+
defaultValue: null,
75+
description: 'Spec review cost'
76+
},
77+
41: {
78+
method: metadataExtractor.extractApprovalRequired,
79+
defaultValue: true,
80+
description: 'Approval Required'
81+
},
82+
44: {
83+
method: metadataExtractor.extractPostMortemRequired,
84+
defaultValue: true,
85+
description: 'Post-Mortem Required'
86+
},
87+
48: {
88+
method: metadataExtractor.extractTrackLateDeliverablesRequired,
89+
defaultValue: true,
90+
description: 'Track Late Deliverables'
91+
},
92+
51: {
93+
method: metadataExtractor.extractSubmissionLimit,
94+
defaultValue: null,
95+
description: 'Maximum submissions'
96+
},
97+
52: {
98+
method: metadataExtractor.extractAllowStockArtRequired,
99+
defaultValue: false,
100+
description: 'Allow Stock Art'
101+
},
102+
53: {
103+
method: metadataExtractor.extractSubmissionViewable,
104+
defaultValue: false,
105+
description: 'Viewable Submissions Flag'
106+
},
107+
59: {
108+
method: metadataExtractor.extractReviewFeedback,
109+
defaultValue: true,
110+
description: 'Review Feedback Flag'
111+
},
112+
84: {
113+
method: metadataExtractor.extractEnvironment,
114+
defaultValue: null,
115+
description: 'Environment'
116+
},
117+
85: {
118+
method: metadataExtractor.extractCodeRepo,
119+
defaultValue: null,
120+
description: 'Code repo'
121+
},
122+
88: {
123+
method: metadataExtractor.extractEstimateEffortHours,
124+
defaultValue: 0,
125+
description: 'Effort Hours Estimate'
126+
},
127+
89: {
128+
method: metadataExtractor.extractEstimateEffortOffshore,
129+
defaultValue: 0,
130+
description: 'Estimate Effort Days offshore'
131+
},
132+
90: {
133+
method: metadataExtractor.extractEstimateEffortOnsite,
134+
defaultValue: 0,
135+
description: 'Estimate Effort Days Onsite'
136+
}
66137
}
67138

68139
module.exports = {

src/services/ProcessorService.js

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -689,42 +689,25 @@ async function processUpdate (message) {
689689
logger.debug(JSON.stringify(saveDraftContestDTO))
690690
// logger.debug('Parsed Payload', saveDraftContestDTO)
691691
try {
692-
// Thomas - get rid of this and add required info directly via IFX
693-
try {
694-
if (challenge) {
695-
await helper.putRequest(`${config.V4_CHALLENGE_API_URL}/${legacyId}`, { param: _.omit(saveDraftContestDTO, ['groupsToBeAdded', 'groupsToBeDeleted']) }, m2mToken)
692+
// extract metadata from challenge and insert into IFX
693+
for (const metadataKey of _.keys(constants.supportedMetadata)) {
694+
const metaValue = constants.supportedMetadata[metadataKey].method(message.payload, constants.supportedMetadata[metadataKey].defaultValue)
695+
try {
696+
await metadataService.createOrUpdateMetadata(legacyId, metadataKey, metaValue, _.get(message, 'payload.updatedBy') || _.get(message, 'payload.createdBy'))
697+
} catch (e) {
698+
logger.warn(`Failed to set ${constants.supportedMetadata[metadataKey].description} to ${metaValue}`)
696699
}
697-
} catch (e) {
698-
logger.warn('Failed to update the challenge via the V4 API')
699-
logger.error(e)
700700
}
701+
// Thomas - get rid of this and add required info directly via IFX
702+
// try {
703+
// if (challenge) {
704+
// await helper.putRequest(`${config.V4_CHALLENGE_API_URL}/${legacyId}`, { param: _.omit(saveDraftContestDTO, ['groupsToBeAdded', 'groupsToBeDeleted']) }, m2mToken)
705+
// }
706+
// } catch (e) {
707+
// logger.warn('Failed to update the challenge via the V4 API')
708+
// logger.error(e)
709+
// }
701710

702-
// Update metadata in IFX
703-
if (message.payload.metadata && message.payload.metadata.length > 0) {
704-
for (const metadataKey of _.keys(constants.supportedMetadata)) {
705-
const entry = _.find(message.payload.metadata, meta => meta.name === metadataKey)
706-
if (entry) {
707-
if (metadataKey === 'submissionLimit') {
708-
// data here is JSON stringified
709-
try {
710-
const parsedEntryValue = JSON.parse(entry.value)
711-
if (parsedEntryValue.limit) {
712-
entry.value = parsedEntryValue.count
713-
} else {
714-
entry.value = null
715-
}
716-
} catch (e) {
717-
entry.value = null
718-
}
719-
}
720-
try {
721-
await metadataService.createOrUpdateMetadata(legacyId, constants.supportedMetadata[metadataKey], entry.value, _.get(message, 'payload.updatedBy') || _.get(message, 'payload.createdBy'))
722-
} catch (e) {
723-
logger.warn(`Failed to set ${metadataKey} (${constants.supportedMetadata[metadataKey]})`)
724-
}
725-
}
726-
}
727-
}
728711
if (message.payload.status && challenge) {
729712
// logger.info(`The status has changed from ${challenge.currentStatus} to ${message.payload.status}`)
730713
if (message.payload.status === constants.challengeStatuses.Active && challenge.currentStatus !== constants.challengeStatuses.Active) {

src/utils/metadataExtractor.js

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
/**
2+
* Metadata extractor
3+
*/
4+
const _ = require('lodash')
5+
const { prizeSetTypes } = require('../constants')
6+
7+
/**
8+
* Get metadata entry by key
9+
* @param {Array} metadata the metadata array
10+
* @param {String} key the metadata key
11+
*/
12+
const getMeta = (metadata = [], key) => _.find(metadata, meta => meta.name === key)
13+
14+
/**
15+
* Convert string to bool
16+
* @param {String} v the value
17+
*/
18+
const toBool = v => _.toString(v).toLowerCase() === 'true'
19+
20+
/**
21+
* Extract billing project
22+
* @param {Object} challenge the challenge object
23+
* @param {Any} defaultValue the default value
24+
*/
25+
function extractBillingProject (challenge, defaultValue) {
26+
return _.get(challenge, 'billingAccountId', _.get(challenge, 'billing.billingAccountId', defaultValue))
27+
}
28+
29+
/**
30+
* Extract submission limit
31+
* @param {Object} challenge the challenge object
32+
* @param {Any} defaultValue the default value
33+
*/
34+
function extractSubmissionLimit (challenge, defaultValue) {
35+
const entry = getMeta(challenge.metadata, 'submissionLimit')
36+
if (!entry) return defaultValue
37+
try {
38+
const parsedEntryValue = JSON.parse(entry.value)
39+
if (parsedEntryValue.limit) {
40+
entry.value = parsedEntryValue.count
41+
} else {
42+
entry.value = null
43+
}
44+
} catch (e) {
45+
entry.value = null
46+
}
47+
return entry.value || defaultValue
48+
}
49+
50+
/**
51+
* Extract spec review cost
52+
* @param {Object} challenge the challenge object
53+
* @param {Any} defaultValue the default value
54+
*/
55+
function extractSpecReviewCost (challenge, defaultValue) {
56+
return _.get(_.find(_.get(challenge, 'prizeSets', []), p => p.type === prizeSetTypes.SpecReview) || {}, 'prizes[0].value', defaultValue)
57+
}
58+
59+
/**
60+
* Extract DR points
61+
* @param {Object} challenge the challenge object
62+
* @param {Any} defaultValue the default value
63+
*/
64+
function extractDrPoints (challenge, defaultValue) {
65+
const entry = getMeta(challenge.metadata, 'drPoints')
66+
if (!entry) return defaultValue
67+
return entry.value || defaultValue
68+
}
69+
70+
/**
71+
* Extract Approval required
72+
* @param {Object} challenge the challenge object
73+
* @param {Any} defaultValue the default value
74+
*/
75+
function extractApprovalRequired (challenge, defaultValue) {
76+
const entry = getMeta(challenge.metadata, 'approvalRequired')
77+
if (!entry) return defaultValue
78+
return toBool(entry.value)
79+
}
80+
81+
/**
82+
* Extract Post-mortem required
83+
* @param {Object} challenge the challenge object
84+
* @param {Any} defaultValue the default value
85+
*/
86+
function extractPostMortemRequired (challenge, defaultValue) {
87+
const entry = getMeta(challenge.metadata, 'postMortemRequired')
88+
if (!entry) return defaultValue
89+
return toBool(entry.value)
90+
}
91+
92+
/**
93+
* Extract track late deliverables required
94+
* @param {Object} challenge the challenge object
95+
* @param {Any} defaultValue the default value
96+
*/
97+
function extractTrackLateDeliverablesRequired (challenge, defaultValue) {
98+
const entry = getMeta(challenge.metadata, 'trackLateDeliverables')
99+
if (!entry) return defaultValue
100+
return toBool(entry.value)
101+
}
102+
103+
/**
104+
* Extract allow stock art required
105+
* @param {Object} challenge the challenge object
106+
* @param {Any} defaultValue the default value
107+
*/
108+
function extractAllowStockArtRequired (challenge, defaultValue) {
109+
const entry = getMeta(challenge.metadata, 'allowStockArt')
110+
if (!entry) return defaultValue
111+
return toBool(entry.value)
112+
}
113+
114+
/**
115+
* Extract submission viewable
116+
* @param {Object} challenge the challenge object
117+
* @param {Any} defaultValue the default value
118+
*/
119+
function extractSubmissionViewable (challenge, defaultValue) {
120+
const entry = getMeta(challenge.metadata, 'submissionViewable')
121+
if (!entry) return defaultValue
122+
return toBool(entry.value)
123+
}
124+
125+
/**
126+
* Extract review feedback
127+
* @param {Object} challenge the challenge object
128+
* @param {Any} defaultValue the default value
129+
*/
130+
function extractReviewFeedback (challenge, defaultValue) {
131+
const entry = getMeta(challenge.metadata, 'reviewFeedback')
132+
if (!entry) return defaultValue
133+
return toBool(entry.value)
134+
}
135+
136+
/**
137+
* Extract environment
138+
* @param {Object} challenge the challenge object
139+
* @param {Any} defaultValue the default value
140+
*/
141+
function extractEnvironment (challenge, defaultValue) {
142+
const entry = getMeta(challenge.metadata, 'environment')
143+
if (!entry) return defaultValue
144+
return entry.value
145+
}
146+
147+
/**
148+
* Extract code repo
149+
* @param {Object} challenge the challenge object
150+
* @param {Any} defaultValue the default value
151+
*/
152+
function extractCodeRepo (challenge, defaultValue) {
153+
const entry = getMeta(challenge.metadata, 'codeRepo')
154+
if (!entry) return defaultValue
155+
return entry.value
156+
}
157+
158+
/**
159+
* Extract estimate effort hours
160+
* @param {Object} challenge the challenge object
161+
* @param {Any} defaultValue the default value
162+
*/
163+
function extractEstimateEffortHours (challenge, defaultValue) {
164+
const entry = getMeta(challenge.metadata, 'effortHoursEstimate')
165+
if (!entry) return defaultValue
166+
return _.toNumber(entry.value)
167+
}
168+
169+
/**
170+
* Extract estimate effort days offshore
171+
* @param {Object} challenge the challenge object
172+
* @param {Any} defaultValue the default value
173+
*/
174+
function extractEstimateEffortOffshore (challenge, defaultValue) {
175+
const entry = getMeta(challenge.metadata, 'effortHoursOffshore')
176+
if (!entry) return defaultValue
177+
return _.toNumber(entry.value)
178+
}
179+
180+
/**
181+
* Extract estimate effort days Onsite
182+
* @param {Object} challenge the challenge object
183+
* @param {Any} defaultValue the default value
184+
*/
185+
function extractEstimateEffortOnsite (challenge, defaultValue) {
186+
const entry = getMeta(challenge.metadata, 'effortHoursOnshore')
187+
if (!entry) return defaultValue
188+
return _.toNumber(entry.value)
189+
}
190+
191+
module.exports = {
192+
extractBillingProject,
193+
extractSubmissionLimit,
194+
extractSpecReviewCost,
195+
extractDrPoints,
196+
extractApprovalRequired,
197+
extractPostMortemRequired,
198+
extractTrackLateDeliverablesRequired,
199+
extractAllowStockArtRequired,
200+
extractSubmissionViewable,
201+
extractReviewFeedback,
202+
extractEnvironment,
203+
extractCodeRepo,
204+
extractEstimateEffortHours,
205+
extractEstimateEffortOffshore,
206+
extractEstimateEffortOnsite
207+
}

0 commit comments

Comments
 (0)