Skip to content

Commit

Permalink
fix: potential xml type matching
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon committed Jun 11, 2021
1 parent 47f4366 commit bd494d3
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/service/inFileHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ const JSON_PARSER_OPTION = {
}

class InFileHandler extends StandardHandler {
static xmlObjectToPackageType

constructor(line, type, work, metadata) {
super(line, type, work, metadata)
this.parentMetadata = this.metadata[this.type]
this.xmlObjectToPackageType = Object.keys(this.metadata)
.filter(meta => !!this.metadata[meta].xmlTag)
.reduce((acc, meta) => {
acc[this.metadata[meta].xmlTag] = this.metadata[meta]
this.xmlObjectToPackageType =
this.xmlObjectToPackageType ??
Object.keys(this.metadata)
.filter(meta => !!this.metadata[meta].xmlTag)
.reduce((acc, meta) => {
acc[this.metadata[meta].xmlTag] = this.metadata[meta]

return acc
}, {})
return acc
}, {})
}

handleAddition() {
Expand Down Expand Up @@ -82,7 +86,7 @@ class InFileHandler extends StandardHandler {
subType = `${this.parentMetadata.directoryName}.${potentialType}`
}
const xmlTagMatchResult = line.match(XML_TAG)
if (!!xmlTagMatchResult && !!xmlTagMatchResult[1]) {
if (this._matchAllowedXmlTag(xmlTagMatchResult)) {
potentialType = xmlTagMatchResult[1]
fullName = null
}
Expand All @@ -98,6 +102,17 @@ class InFileHandler extends StandardHandler {
return toAdd
}

_matchAllowedXmlTag(matchResult) {
return (
!!matchResult &&
!!matchResult[1] &&
Object.prototype.hasOwnProperty.call(
this.xmlObjectToPackageType,
matchResult[1]
)
)
}

_treatInFileResult(toRemove, toAdd) {
Object.keys(toRemove).forEach(type =>
[...toRemove[type]]
Expand Down

0 comments on commit bd494d3

Please sign in to comment.