This repository has been archived by the owner on Oct 23, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve handling of certain FileProperties
* refactor fetching and parsing describe information from remotes * determine active Flow version by running a SOQL query (fixes #21) * identify PersonAccount RecordTypes listed as Account RecordTypes by running a SOQL query * retrieve api versions from remote
- Loading branch information
Showing
14 changed files
with
776 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
"use strict"; | ||
|
||
var _ = require('underscore'); | ||
var config = new(require('./config'))(); | ||
var MetadataComponent = require('./metadata-component'); | ||
|
||
var folderBasedMetadataMap = config.get('folderBasedMetadataMap'); | ||
|
||
var getFolderTypes = function() { | ||
var folderTypes = []; | ||
Object.keys(folderBasedMetadataMap).forEach(function(key) { | ||
folderTypes.push(key); | ||
folderTypes.push(folderBasedMetadataMap[key]); | ||
}); | ||
return folderTypes; | ||
} | ||
|
||
var FetchResultParser = module.exports = function(resultJSON) { | ||
var self = this; | ||
resultJSON = JSON.parse(JSON.stringify(resultJSON)); | ||
self.apiVersions = resultJSON.apiVersions || []; | ||
self.describeMetadataResult = resultJSON.describeMetadataResult || {}; | ||
self.fileProperties = resultJSON.fileProperties || []; | ||
self.personAccountRecordTypes = resultJSON.personAccountRecordTypes || []; | ||
self.flowDefinitions = resultJSON.flowDefinitions || []; | ||
self.warnings = resultJSON.warnings || []; | ||
}; | ||
|
||
FetchResultParser.prototype.getApiVersion = function() { | ||
var self = this; | ||
var versions = self.apiVersions; | ||
if (Array.isArray(versions) && versions.length) { | ||
return versions[versions.length - 1]; | ||
} | ||
return null; | ||
}; | ||
|
||
FetchResultParser.prototype.getComponents = function(opts) { | ||
var self = this; | ||
opts = opts ? opts : {}; | ||
opts.filterManaged = opts.filterManaged !== undefined ? opts.filterManaged : true; | ||
var components = []; | ||
if (opts.filterManaged) { | ||
self.filterManaged(); | ||
} | ||
self.transform(); | ||
self.filterInvalid(); | ||
self.fileProperties.forEach(function(fileProperty) { | ||
components.push( | ||
new MetadataComponent({ | ||
type: fileProperty.type, | ||
fullName: fileProperty.fullName, | ||
fileName: fileProperty.fileName | ||
}) | ||
); | ||
}); | ||
return components; | ||
}; | ||
|
||
FetchResultParser.prototype.getWarnings = function() { | ||
return this.warnings; | ||
} | ||
|
||
FetchResultParser.prototype.filterManaged = function() { | ||
var self = this; | ||
// filter installed metadata components | ||
self.fileProperties = _.filter(self.fileProperties, function(fileProperty) { | ||
return fileProperty.manageableState !== 'installed' && fileProperty.type !== 'InstalledPackage'; | ||
}); | ||
return self; | ||
} | ||
|
||
FetchResultParser.prototype.transform = function() { | ||
var self = this; | ||
self.fileProperties = self.fileProperties.map(function(fileProperty) { | ||
if (Object.keys(folderBasedMetadataMap).indexOf(fileProperty.type) > -1) { | ||
// DocumentFolder has to be listed as Document | ||
fileProperty.type = folderBasedMetadataMap[fileProperty.type]; | ||
} else if (fileProperty.type === 'Flow' && !new RegExp('^.*-[0-9]+$').test(fileProperty.fullName) && self.flowDefinitions) { | ||
// determine the active version number using the FlowDefinition Metadata | ||
var flowDefinitionMatch = _.findWhere(self.flowDefinitions, { | ||
DeveloperName: fileProperty.fullName | ||
}); | ||
if (flowDefinitionMatch && flowDefinitionMatch.ActiveVersion && flowDefinitionMatch.ActiveVersion.VersionNumber) { | ||
fileProperty.fullName = fileProperty.fullName + '-' + flowDefinitionMatch.ActiveVersion.VersionNumber; | ||
} | ||
} else if (fileProperty.type === 'RecordType' && self.personAccountRecordTypes) { | ||
// PersonAccount RecordTypes are being listed incorrectly as Account RecordTypes | ||
var fullNameParts = fileProperty.fullName.split('.'); | ||
var itemType = fullNameParts[0]; | ||
var itemName = fullNameParts[1]; | ||
var personAccountRecordTypeMatch = _.findWhere(self.personAccountRecordTypes, { | ||
Name: itemName, | ||
SobjectType: itemType, | ||
IsPersonType: true | ||
}); | ||
if (personAccountRecordTypeMatch) { | ||
fileProperty.fullName = 'PersonAccount.' + itemName; | ||
} | ||
} | ||
return fileProperty; | ||
}); | ||
return self; | ||
}; | ||
|
||
FetchResultParser.prototype.filterInvalid = function() { | ||
var self = this; | ||
var folderTypes = getFolderTypes(); | ||
self.fileProperties = _.filter(self.fileProperties, function(fileProperty) { | ||
if (folderTypes.indexOf(fileProperty.type) > -1 && fileProperty.fullName === 'unfiled$public') { | ||
// we don't consider this as a warning | ||
// self.warnings.push('Warning: Skipped standard ' + fileProperty.type + ': ' + fileProperty.fullName); | ||
return false; | ||
} else if (fileProperty.type === 'QuickAction' && new RegExp('^09D26.*').test(fileProperty.id)) { | ||
self.warnings.push('Warning: Skipped non-global QuickAction: ' + fileProperty.fullName); | ||
return false; | ||
} else if (fileProperty.type === 'Flow' && !new RegExp('^.*-[0-9]+$').test(fileProperty.fullName)) { | ||
self.warnings.push('Warning: Skipped non-versioned Flow: ' + fileProperty.fullName); | ||
return false; | ||
} else if (fileProperty.type === 'CustomObject' && fileProperty.fullName === 'PersonAccount') { | ||
// self.warnings.push('Warning: Skipped CustomObject: ' + fileProperty.fullName + ', though children of this custom object will remain.'); | ||
return false; | ||
} | ||
return true; | ||
}); | ||
return self; | ||
}; |
Oops, something went wrong.