Skip to content

Commit

Permalink
feat: updates to taxonomy logic [] (#2857)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayakarabula authored Nov 26, 2024
1 parent 3f9366d commit e828da8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
12 changes: 10 additions & 2 deletions docs/organization/taxonomy-transform/examples/example-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,30 @@ module.exports = async function ({ csv, taxonomy, fs }) {
//Cocneptscheme
if (row[1] != '') {
conceptScheme = taxonomy.addConceptScheme(row[0], {
prefLabel: row[1]
prefLabel: { 'en-US': row[1] }
})

if (!conceptScheme) {
conceptScheme = taxonomy.getConceptScheme(row[0])
}
} else {
const notEmptyIndex = row.findIndex((c, index) => c != '' && index > 0)
let concept = taxonomy.getConcept(row[0])

if (!concept) {
concept = taxonomy.addConcept(row[0], {
prefLabel: row[notEmptyIndex]
prefLabel: { 'en-US': row[notEmptyIndex] }
})
}

conceptScheme.addConcept(row[0])

parent = findParent(data, i)

if (parent) {
concept.addBroader(parent)
} else {
conceptScheme.addTopConcept(row[0])
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions lib/cmds/organization_cmds/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,13 @@ async function importCommand(params: OrgImportParams) {
accessToken: managementToken,
feature: 'org-import',
headers: getHeadersFromOption(header),
throttle: 8,
logHandler: noop
})

const importContext: OrgImportContext = {
data: {},
requestQueue: new PQueue({
concurrency: 1,
concurrency: 7,
interval: ONE_SECOND,
intervalCap: 1,
carryoverConcurrencyCount: true
Expand Down
6 changes: 6 additions & 0 deletions lib/cmds/organization_cmds/taxonomy/concept-scheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export class ConceptScheme {
if (!this.model.topConcepts) {
this.model.topConcepts = []
}
if (this.model.topConcepts.find(concept => concept.sys.id === conceptId)) {
return this
}
this.model.topConcepts.push({
sys: {
id: conceptId,
Expand Down Expand Up @@ -82,6 +85,9 @@ export class ConceptScheme {
if (!this.model.concepts) {
this.model.concepts = []
}
if (this.model.concepts.find(concept => concept.sys.id === conceptId)) {
return this
}
this.model.concepts.push({
sys: {
id: conceptId,
Expand Down
6 changes: 6 additions & 0 deletions lib/cmds/organization_cmds/taxonomy/concept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export class Concept {
if (!this.model.broader) {
this.model.broader = []
}
if (this.model.broader.some(concept => concept.sys.id === conceptId)) {
return this
}
this.model.broader.push({
sys: {
id: conceptId,
Expand All @@ -158,6 +161,9 @@ export class Concept {
if (!this.model.related) {
this.model.related = []
}
if (this.model.related.some(concept => concept.sys.id === conceptId)) {
return this
}
this.model.related.push({
sys: {
id: conceptId,
Expand Down
6 changes: 4 additions & 2 deletions lib/cmds/organization_cmds/taxonomy/taxonomy-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ const taxonomyImport = async (
}

if (!operations.length) {
return
continue
}

const version = entityHasVersion(concept) ? concept.sys.version : 1
const version = entityHasVersion(concept)
? concept.sys.version + 1
: 1

await ctx.cmaClient.concept.patch(
{
Expand Down

0 comments on commit e828da8

Please sign in to comment.