Skip to content

Commit

Permalink
Merge pull request #347 from vlocityinc/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
Adam Rutland authored Feb 7, 2021
2 parents a6f5d1b + ce34ddf commit 9b6c6b7
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"fullName": "%vlocity_namespace%__DRMatchingKey__mdt.OrchestrationScenario",
"label": "OrchestrationScenarioFix",
"values": [
{
"field": "%vlocity_namespace%__MatchingKeyFields__c",
"value": "%vlocity_namespace%__GlobalKey__c"
},
{
"field": "%vlocity_namespace%__MatchingKeyObject__c",
"value": "%vlocity_namespace%__OrchestrationScenario__c"
},
{
"field": "%vlocity_namespace%__ObjectAPIName__c",
"value": "%vlocity_namespace%__OrchestrationScenario__c"
},
{
"field": "%vlocity_namespace%__ReturnKeyField__c",
"value": "Id"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,20 @@
"VlocityDataPackType": "SObject",
"VlocityRecordSObjectType": "%vlocity_namespace%__DRMapItem__c"
},
{
"%vlocity_namespace%__DomainObjectAPIName__c": "JSON",
"%vlocity_namespace%__DomainObjectCreationOrder__c": 0,
"%vlocity_namespace%__DomainObjectFieldAPIName__c": "Product2:%vlocity_namespace%__AttributeAssignment__c",
"%vlocity_namespace%__FilterOperator__c": "LIMIT",
"%vlocity_namespace%__FilterValue__c": "500",
"%vlocity_namespace%__InterfaceFieldAPIName__c": "",
"%vlocity_namespace%__InterfaceObjectLookupOrder__c": 5,
"%vlocity_namespace%__InterfaceObjectName__c": "%vlocity_namespace%__AttributeAssignment__c",
"%vlocity_namespace%__MapId__c": "Product2 Migration12323231",
"Name": "Product2 Migration",
"VlocityDataPackType": "SObject",
"VlocityRecordSObjectType": "%vlocity_namespace%__DRMapItem__c"
},
{
"%vlocity_namespace%__ConfigurationAttribute__c": "%vlocity_namespace%__CompiledAttributeOverride__c",
"%vlocity_namespace%__ConfigurationCategory__c": "PUT",
Expand Down
8 changes: 5 additions & 3 deletions lib/datapacksexpanddefinition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ DataPacks:
HeadersOnly: All
PaginationSize: 500
Product2:
HeadersExclusions:
- ProductChildItem__c
- AttributeAssignment__c
HeadersOnly: true
IgnoreExpand:
- StandardPricebookEntry
Expand All @@ -127,6 +124,10 @@ DataPacks:
PaginationActions:
ObjectFieldAttribute__c:
- Remove
AttributeAssignment__c:
- RemoveFromInitial
OverrideDefinition__c:
- RemoveFromInitial
ProductChildItem:
ProductChildItem__c:
FolderName:
Expand Down Expand Up @@ -1137,6 +1138,7 @@ SObjects:
OrchestrationScenario__c:
SourceKeyDefinition:
- Name
- GlobalKey__c
- Product2Id__c
OrchestrationQueueAssignmentRule:
FolderName:
Expand Down
57 changes: 56 additions & 1 deletion lib/datapacksjob.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ DataPacksJob.prototype.doRunJob = async function(jobInfo, action) {
await this.getOrgProjects(jobInfo);
} else if (action == 'runTestProcedure') {
return await this.vlocity.testframework.runJob(jobInfo, 'Start');
} else if (action == 'runAllTestProcedures') {
return await this.vlocity.testframework.runJob(jobInfo, 'StartAll');
} else if (action == 'getTestProcedures') {
return await this.vlocity.testframework.runJob(jobInfo, 'GetTestProcedures');
} else if (action === 'datapackOpen') {
Expand Down Expand Up @@ -511,10 +513,12 @@ DataPacksJob.prototype.formatResponse = async function(jobInfo, error) {
response.records = jobInfo.data;
response.message = jobInfo.errors;
response.status = jobInfo.hasError ? 'error' : 'success';
} else if (jobInfo.jobAction === 'getTestProcedures') {
} else if (jobInfo.jobAction === 'getTestProcedures') {
response.records = jobInfo.data;
response.message = jobInfo.errors;
response.status = jobInfo.hasError ? 'error' : 'success';
} else if (jobInfo.jobAction === 'runAllTestProcedures') {
this.formatTestResults(jobInfo, response);
} else {

for (var key in jobInfo.currentStatus) {
Expand Down Expand Up @@ -650,6 +654,57 @@ DataPacksJob.prototype.formatResponse = async function(jobInfo, error) {
}
};

DataPacksJob.prototype.formatTestResults = function(jobInfo, response) {
response.data = jobInfo.data;
response.records = [];
response.message = '';
response.status = jobInfo.hasError ? 'error' : 'success';
let numberPassed = 0;

if (jobInfo.data.testResults) {
for (var test of jobInfo.data.testResults) {
var resultingTest = {
VlocityDataPackKey: test['%vlocity_namespace%__TestName__c'],
VlocityDataPackStatus: test['%vlocity_namespace%__Status__c']
};

if (resultingTest.VlocityDataPackStatus == 'Failed') {
let errors = [];
response.status = 'error';

for (let j = 0; j < test.trackingEntry.length; j++) {
let entry = test.trackingEntry[j];

if (
entry.StepResult &&
entry.ElementName &&
entry.StepResult.success === false &&
entry.StepResult.result &&
entry.StepResult.result.assertConditionalFormula
) {
errors.push(`${entry.ElementName} - ${entry.StepResult.result.assertFailureMessage}`);
}
}

if (errors.length > 0) {
resultingTest.message = errors.join("\n\t");
response.message += `${resultingTest.VlocityDataPackKey}:\n\t${resultingTest.message}\n`;
} else {
response.message += `${resultingTest.VlocityDataPackKey}: Pass`;
}
} else {
numberPassed++;
}

response.records.push(resultingTest);
}

if (response.status == 'success') {
response.message = `All tests passed`;
}
}
}

DataPacksJob.prototype.formatManifest = async function(jobInfo) {

VlocityUtils.verbose('Formatting Manifest');
Expand Down
6 changes: 5 additions & 1 deletion lib/datapacksutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const namespaceFieldPrefix = '%' + namespacePrefix + '%__';

var CURRENT_INFO_FILE;

VLOCITY_BUILD_SALESFORCE_API_VERSION = '48.0';
VLOCITY_BUILD_SALESFORCE_API_VERSION = '50.0';

var DataPacksUtils = module.exports = function(vlocity) {
this.vlocity = vlocity || {};
Expand Down Expand Up @@ -3973,6 +3973,7 @@ DataPacksUtils.prototype.retrieveLwcDependencies = async function (retrievedMeta
}
}

let USE_SFDX_TYPES = [ 'ApprovalProcess' ];
DataPacksUtils.prototype.retrieveByType = async function(deploymentOptions, metaDesc, jobInfo) {
var tries = 0;

Expand All @@ -3999,6 +4000,7 @@ DataPacksUtils.prototype.retrieveByType = async function(deploymentOptions, meta

for (var folderName of folderList) {
if (folderName.manageableState == 'unmanaged') {

var inFolderFiles = await this.vlocity.jsForceConnection.metadata.list([{ type: metaDesc.xmlName, folder: folderName.fullName }], VLOCITY_BUILD_SALESFORCE_API_VERSION);

if (!Array.isArray(inFolderFiles)) {
Expand All @@ -4010,6 +4012,8 @@ DataPacksUtils.prototype.retrieveByType = async function(deploymentOptions, meta
}
}
}
} else if (USE_SFDX_TYPES.includes(metaDesc.xmlName)) {
metaList = await this.vlocity.utilityservice.sfdx('mdapi:listmetadata', { metadatatype: metaDesc.xmlName, targetusername: this.vlocity.username });
} else {
metaList = await this.vlocity.jsForceConnection.metadata.list([{ type: metaDesc.xmlName, folder: null }], VLOCITY_BUILD_SALESFORCE_API_VERSION);
}
Expand Down
46 changes: 46 additions & 0 deletions lib/datapacktypes/product2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var Product2 = module.exports = function(vlocity) {
this.vlocity = vlocity;
};

Product2.prototype.childrenExport = async function(inputMap) {
try {
var jobInfo = inputMap.jobInfo;
var childrenDataPacks = inputMap.childrenDataPacks;

var dataPackType = childrenDataPacks[0].VlocityDataPackType;

let queryString = `Select Id from Product2 WHERE `;
let whereClause = '';

for (var dataPack of childrenDataPacks) {

if (whereClause) {
whereClause += ' OR ';
}

whereClause += `(${this.vlocity.namespacePrefix}GlobalGroupKey__c = '${dataPack.VlocityDataPackData.Id}')`;
}

let result = await this.vlocity.queryservice.query(queryString + whereClause);
VlocityUtils.verbose('Children Query', queryString + whereClause, 'Results', result.records.length);
for (var record of result.records) {
let recordAdded = this.vlocity.datapacksjob.addRecordToExport(jobInfo, { VlocityDataPackType: dataPackType, manifestOnly: true }, record);

if (recordAdded) {
VlocityUtils.verbose('Added from Children Query', dataPackType, record.Id);
}
}

for (var dataPack of childrenDataPacks) {
jobInfo.currentStatus[dataPack.VlocityDataPackKey] = 'Ignored';
if (jobInfo.alreadyExportedKeys.indexOf(dataPack.VlocityDataPackKey) == -1) {
jobInfo.alreadyExportedKeys.push(dataPack.VlocityDataPackKey);
}
}

return true;
} catch (e) {
VlocityUtils.error('Children Export Error', e);
return null;
}
}
9 changes: 5 additions & 4 deletions lib/testframework.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TestFramework.prototype.start = async function(input) {
};

TestFramework.prototype.startAll = async function() {
let result = await this.vlocity.jsForceConnection.apex.post('/' + this.vlocity.namespace + '/v1/testprocedure/startAll');
let result = await this.vlocity.jsForceConnection.apex.post('/' + this.vlocity.namespace + '/v1/testprocedure/startAll', {});
return this.toJson(result);
};

Expand Down Expand Up @@ -216,12 +216,13 @@ TestFramework.prototype.createResponse = function(response, testSuiteUniqueKey)
let uniqueKey = testResult.Name;
let statusField = testResult[VLOCITY_NAMESPACE_PREFIX + 'Status__c'];
let testName = testResult[VLOCITY_NAMESPACE_PREFIX + 'TestName__c'];

if (statusField === 'Success') {
this.jobInfo.currentStatus[uniqueKey] = 'Success';
}
else {
VlocityUtils.success('Passed', testName);
} else {
this.jobInfo.currentStatus[uniqueKey] = 'Error';
VlocityUtils.error('Failed', testName);

if (statusField === 'Invalid Test Name') {
this.jobInfo.errors.push(`Invalid Test Name >> ${testName} - TestUniqueKey__c >> ${uniqueKey} - TestSuiteUniqueKey__c >> ${testSuiteUniqueKey}`);
Expand Down
50 changes: 36 additions & 14 deletions lib/utilityservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,14 @@ UtilityService.prototype.sfdx = async function(command, options) {
flags.quiet = VlocityUtils.quiet;
flags.json = VlocityUtils.quiet || !VlocityUtils.showLoggingStatements;

let allCacheKeys = Object.keys(require.cache);

for (let key of allCacheKeys) {
if (key.includes('salesforce-alm')) {
delete require.cache[key];
}
}

try {
if (command == 'org:display') {
var OrgDisplayCommand = require("salesforce-alm/dist/commands/force/org/display");
Expand All @@ -760,6 +768,9 @@ UtilityService.prototype.sfdx = async function(command, options) {
var SourceDeleteCommand = require("salesforce-alm/dist/commands/force/source/delete");
sfdxCommand = new SourceDeleteCommand.SourceDeleteCommand();
sfdxCommand.ux = await require("@salesforce/command").UX.create();
} else if (command == 'mdapi:listmetadata') {
var MdapiListmetadataCommand = require("salesforce-alm/dist/commands/force/mdapi/listmetadata");
sfdxCommand = new MdapiListmetadataCommand.MdapiListmetadataCommand();
}

sfdxCommand.flags = flags;
Expand All @@ -776,7 +787,6 @@ UtilityService.prototype.sfdx = async function(command, options) {
}
}


UtilityService.prototype.updateCustomObject = async function(metadata) {
return await this.updateMetadata('CustomObject', metadata);
};
Expand Down Expand Up @@ -1023,27 +1033,43 @@ UtilityService.prototype.runGitCommit = async function (jobInfo) {
} else if (sfdxFolder && replacedFileOrFolderName && fs.existsSync(path.join(sfdxProject.sfdxPath, sfdxFolder, 'main', 'default', replacedFileOrFolderName))) {
await simpleGit(jobInfo.localRepoPath).add(path.join(sfdxProject.sfdxPath, sfdxFolder, 'main', 'default', replacedFileOrFolderName));
} else {
if(jobInfo.expansionPath !== '.vlocity'){
var sanitizedFileorFoldername = unidecode(fileOrFolderName)
var fileOrFolderPath = path.join(commitPath, fileOrFolderName);
var sanitizedFileOrFolderName;
var sanitizedFileOrFolderPath;

if (jobInfo.expansionPath !== '.vlocity') {
sanitizedFileOrFolderName = unidecode(fileOrFolderName)
.replace("\\", "-")
.replace(/[^A-Za-z0-9/_\-]+/g, "-")
.replace(/[-]+/g, "-")
.replace(/[-_]+_/g, "_")
.replace(/[-]+\/[-]+/g, "/")
.replace(/^[-_\\/]+/, "")
.replace(/[-_\\/]+$/, "");
}

var fileOrFloderPath = path.join(commitPath, fileOrFolderName);
sanitizedFileOrFolderPath = path.join(commitPath, sanitizedFileOrFolderName);
}

try {
if (fs.existsSync(fileOrFloderPath)) {
if (fs.lstatSync(fileOrFloderPath).isDirectory()) {
VlocityUtils.verbose('Committing', path.join(fileOrFloderPath, '*'));
if (fs.existsSync(fileOrFolderPath)) {
if (fs.lstatSync(fileOrFolderPath).isDirectory()) {
VlocityUtils.log('Committing', path.join(fileOrFolderPath, '*'));
await simpleGit(jobInfo.localRepoPath).add(path.join(fileOrFolderPath, '*'));
} else {
VlocityUtils.verbose('Committing', fileOrFolderPath);
await simpleGit(jobInfo.localRepoPath).add(path.join(fileOrFolderPath, ''));
}

results.push(jobInfo.manifest[fileOrFolderName]);
} else if (sanitizedFileOrFolderPath && fs.existsSync(sanitizedFileOrFolderPath)) {
if (fs.lstatSync(sanitizedFileOrFolderPath).isDirectory()) {
VlocityUtils.log('Committing', path.join(sanitizedFileOrFolderPath, '*'));
await simpleGit(jobInfo.localRepoPath).add(path.join(sanitizedFileOrFolderPath, '*'));
} else {
VlocityUtils.verbose('Committing', fileOrFloderPath);
VlocityUtils.verbose('Committing', sanitizedFileOrFolderPath);
await simpleGit(jobInfo.localRepoPath).add(sanitizedFileOrFolderPath);
}
await simpleGit(jobInfo.localRepoPath).add(path.join(fileOrFloderPath, ''));

results.push(jobInfo.manifest[fileOrFolderName]);
}
} catch (err) {
Expand All @@ -1052,9 +1078,6 @@ UtilityService.prototype.runGitCommit = async function (jobInfo) {
}
}
}
} else {
await simpleGit(jobInfo.localRepoPath).add(path.join(commitPath, sanitizedFileorFoldername));
results.push([jobInfo.manifest]);
}

try {
Expand All @@ -1071,7 +1094,6 @@ UtilityService.prototype.runGitCommit = async function (jobInfo) {
jobInfo.message = 'Committed';
}
} catch (err) {
await gitP(jobInfo.localRepoPath).reset(['HEAD']);
jobInfo.hasError = true;
jobInfo.errors.push(err);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/vlocity.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ var Vlocity = module.exports = function(options) {
}

VlocityUtils.verbose('Vlocity Build v' + VLOCITY_BUILD_VERSION);

if (VLOCITY_BUILD_VERSION == "0.0.1") {
VlocityUtils.log('Folder: ' + __dirname);
}

this.jsForceConnection = new jsforce.Connection({
loginUrl: options.loginUrl ? options.loginUrl : 'https://login.salesforce.com',
Expand Down
7 changes: 6 additions & 1 deletion lib/vlocitycli.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ var VLOCITY_COMMANDLINE_OPTIONS = {
"multiDeployPaths": Array,
"name": String,
"outputDir": String,
"upgradeDataPackFields": Boolean
"upgradeDataPackFields": Boolean,
"testKeys": Array
};

var VLOCITY_COMMANDLINE_OPTIONS_SHORTHAND = {
Expand Down Expand Up @@ -304,6 +305,10 @@ VLOCITY_COMMANDLINE_COMMANDS = {
name: 'runTestProcedure',
description: 'Run Test Procedure'
},
runAllTestProcedures: {
name: 'runAllTestProcedures',
description: 'Run All Test Procedures'
},
getTestProcedures: {
name: 'getTestProcedures',
description: 'Get Test Procedures'
Expand Down
Loading

0 comments on commit 9b6c6b7

Please sign in to comment.