Skip to content

Commit

Permalink
Merge pull request #476 from vlocityinc/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
Adam Rutland authored Jun 14, 2022
2 parents 38c616e + c89edb4 commit e278623
Show file tree
Hide file tree
Showing 11 changed files with 627 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"%vlocity_namespace%__BatchSize__c": 200,
"%vlocity_namespace%__CheckFieldLevelSecurity__c": false,
"%vlocity_namespace%__CustomInputClass__c": "",
"%vlocity_namespace%__CustomOutputClass__c": "",
"%vlocity_namespace%__DRMapItem__c": "DataRaptor-Migration_Mappings.json",
"%vlocity_namespace%__DRMapName__c": "DataRaptor Migration",
"%vlocity_namespace%__DeleteOnSuccess__c": false,
"%vlocity_namespace%__Description__c": "",
"%vlocity_namespace%__GlobalKey__c": "DataRaptor Migration",
"%vlocity_namespace%__IgnoreErrors__c": false,
"%vlocity_namespace%__InputCustom__c": "",
"%vlocity_namespace%__InputJson__c": "",
"%vlocity_namespace%__InputType__c": "",
"%vlocity_namespace%__InputXml__c": "",
"%vlocity_namespace%__InterfaceObject__c": "JSON",
"%vlocity_namespace%__IsDefaultForInterface__c": false,
"%vlocity_namespace%__IsProcessSuperBulk__c": false,
"%vlocity_namespace%__OMplusSyncEnabled__c": true,
"%vlocity_namespace%__OuboundStagingObjectDataField__c": "",
"%vlocity_namespace%__OutboundConfigurationField__c": "",
"%vlocity_namespace%__OutboundConfigurationName__c": "",
"%vlocity_namespace%__OutboundStagingObjectName__c": "",
"%vlocity_namespace%__OutputType__c": "",
"%vlocity_namespace%__OverwriteAllNullValues__c": false,
"%vlocity_namespace%__PreprocessorClassName__c": "",
"%vlocity_namespace%__ProcessNowThreshold__c": -1,
"%vlocity_namespace%__RequiredPermission__c": "",
"%vlocity_namespace%__RollbackOnError__c": false,
"%vlocity_namespace%__SalesforcePlatformCacheType__c": "",
"%vlocity_namespace%__SampleInputCustom__c": "",
"%vlocity_namespace%__SampleInputJSON__c": "",
"%vlocity_namespace%__SampleInputRows__c": "",
"%vlocity_namespace%__SampleInputXML__c": "",
"%vlocity_namespace%__TargetOutCustom__c": "",
"%vlocity_namespace%__TargetOutDocuSignTemplateId__c": "",
"%vlocity_namespace%__TargetOutJson__c": "",
"%vlocity_namespace%__TargetOutPdfDocName__c": "",
"%vlocity_namespace%__TargetOutXml__c": "",
"%vlocity_namespace%__TimeToLiveMinutes__c": "",
"%vlocity_namespace%__Type__c": "Migration",
"%vlocity_namespace%__UseAssignmentRules__c": false,
"%vlocity_namespace%__XmlOutputSequence__c": "",
"%vlocity_namespace%__XmlRemoveDeclaration__c": false,
"Name": "DataRaptor Migration",
"VlocityDataPackType": "SObject",
"VlocityRecordSObjectType": "%vlocity_namespace%__DRBundle__c",
"VlocityRecordSourceKey": "%vlocity_namespace%__DRBundle__c/DataRaptor Migration"
}

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,10 @@ This will provide a list of files that are different locally than in the org. In
`packGetAllAvailableExports`: Get list of all DataPacks that can be exported
`refreshVlocityBase`: Deploy and Activate the Base Vlocity DataPacks included in the Managed Package
`installVlocityInitial`: Deploy and Activate the Base Vlocity DataPacks and Configuration DataPacks included in the Managed Package
`installDPsfromStaticResource`: Install DataPacks from Static Resource based on a Query. Add query to job file: StaticResourceQuery:<SOQL>
`installDPsfromStaticResource`: Install DataPacks from Static Resource based on a Query. Please add the query to job file:
```yaml
StaticResourceQuery: Select Name, Body from StaticResource where Name = 'DP_TEMPLATES_AsyncQuoteToContractSample'
```
## Example Commands
Expand Down
1 change: 1 addition & 0 deletions apex/AddDocument.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
insert new Document(Name='OmniScript URL Document Do Not Delete', Body=Blob.valueOf('txt'),FolderId=UserInfo.getUserId());
92 changes: 92 additions & 0 deletions javascript/fixSandboxMetadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

module.exports = async function(vlocity, currentContextData, jobInfo, callback) {

let metadataToDataBindings = [{
metadataQuery: "Select Id, DeveloperName from OmniUiCardConfig",
dataQuery: "Select Id, Name, AuthorName, VersionNumber from OmniUiCard",
keyFields: [ "Name", "AuthorName", "VersionNumber" ],
type: "OmniUiCardConfig"
},{
metadataQuery: "Select Id, DeveloperName from OmniScriptConfig",
dataQuery: "Select Id, Type, SubType, Language, VersionNumber from OmniProcess",
keyFields: [ "Type", "SubType", "Language", "VersionNumber" ],
type: "OmniScriptConfig"
},{
metadataQuery: "Select Id, DeveloperName from OmniIntegrationProcConfig",
dataQuery: "Select Id, Type, SubType, Language, VersionNumber from OmniProcess",
keyFields: [ "Type", "SubType", "Language", "VersionNumber" ],
type: "OmniIntegrationProcConfig"
},
{
metadataQuery: "Select Id, DeveloperName from OmniDataTransformConfig",
dataQuery: "Select Id, Name, VersionNumber from OmniDataTransform",
keyFields: [ "Name", "VersionNumber" ],
type: "OmniDataTransformConfig"
}];

try {
let allMetadataToDelete = [];
for (let binding of metadataToDataBindings) {
vlocity.jsForceConnection.version = "54.0";
let foundMetadataComponents = await vlocity.jsForceConnection.tooling.query(binding.metadataQuery);

if (foundMetadataComponents.records == 0) {
continue;
}

foundMetadataComponents = foundMetadataComponents.records;

let foundDataComponents = await vlocity.jsForceConnection.query(binding.dataQuery);

foundDataComponents = foundDataComponents.records;
let dataComponentKeys = [];

for (let dataRecord of foundDataComponents) {
let metadataKey = "";

for (let key of binding.keyFields) {
if (metadataKey) {
metadataKey += "_";
}

metadataKey += dataRecord[key];
}

dataComponentKeys.push(metadataKey);
}

for (let metadataRecord of foundMetadataComponents) {
if (!dataComponentKeys.includes(metadataRecord.DeveloperName)) {
allMetadataToDelete.push(metadataRecord);
}
}
}

let iterations = 0;

while (allMetadataToDelete.length > 0 && iterations < 10) {
iterations++;

let failedMetadata = [];

for (let metadataRecord of allMetadataToDelete) {
try {
await vlocity.jsForceConnection.tooling.delete(metadataRecord.attributes.type, metadataRecord.Id);
VlocityUtils.log("Delete Success", metadataRecord.DeveloperName);
} catch (e) {
failedMetadata.push(metadataRecord);
VlocityUtils.log("Delete Failed", metadataRecord.DeveloperName);
}
}

allMetadataToDelete = failedMetadata;
}



} catch (e) {
VlocityUtils.error(e);
}


}
13 changes: 11 additions & 2 deletions lib/datapacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,18 @@ DataPacks.prototype.makeApexPostRequest = async function(endpoint, payload) {
DataPacks.prototype.ignoreActivationErrors = async function(dataPackId) {
var dataPackObj = { Id: dataPackId };

dataPackObj[this.vlocity.namespacePrefix + 'ActivationStatus__c'] = "";
let sobjectType;

// This is the prefix for this new object
if (dataPackId.indexOf('0nc') == 0) {
sobjectType = 'OmniDataPack';
dataPackObj.ActivationStatus = "";
} else {
dataPackObj[this.vlocity.namespacePrefix + 'ActivationStatus__c'] = "";
sobjectType = this.vlocity.namespacePrefix + 'VlocityDataPack__c'
}

await this.vlocity.jsForceConnection.sobject(this.vlocity.namespacePrefix + 'VlocityDataPack__c').update(dataPackObj);
await this.vlocity.jsForceConnection.sobject(sobjectType).update(dataPackObj);
};

DataPacks.prototype.getDataPackData = async function(dataPackId, retry) {
Expand Down
126 changes: 81 additions & 45 deletions lib/datapacksjob.js
Original file line number Diff line number Diff line change
Expand Up @@ -1814,13 +1814,26 @@ DataPacksJob.prototype.deployDataPackMetadataConfigurations = async function(pat
}
};

DataPacksJob.prototype.ensureDocumentExists = async function() {

var query = `Select Id from Document LIMIT 1`;
let result = await this.vlocity.jsForceConnection.query(query);

if (!result.records || result.records.length == 0) {
VlocityUtils.verbose('Adding Default Document to Org as it affects LWC Compilation and OmniScript Runtime');
await this.vlocity.datapacksutils.runApex('.', 'AddDocument.cls');
}
}

DataPacksJob.prototype.updateSettings = async function(jobInfo) {
var projectPathsToDeploy = [ 'latest' ];

if (!this.vlocity.organizationId) {
return;
}

await this.ensureDocumentExists();

if (this.vlocity.isOmniStudioInstalled && !this.vlocity.isOmniStudioIndustryInstalled) {
return;
}
Expand Down Expand Up @@ -2061,52 +2074,57 @@ DataPacksJob.prototype.activateAll = async function(dataPack, jobInfo, attempts)

var shouldRetry = false;

for (var dataPack of dataPackData.dataPacks) {
if (dataPack.ActivationStatus == 'Activated' || allActivated.includes(dataPack.VlocityDataPackKey)) {
await this.vlocity.datapacksutils.handleDataPackEvent('afterActivationSuccess', dataPack.VlocityDataPackType, {dataPack: dataPack, jobInfo: jobInfo});
} else if (dataPack.ActivationStatus == 'Ready' && dataPack.VlocityDataPackStatus == 'Success') {

// If it is the only one in the deploy and it fails to activate it must be set to error. Otherwise retry the deploy and activation separate from others.
if (dataPackData.dataPacks.length == 1) {
var onActivateErrorResult = await this.vlocity.datapacksutils.handleDataPackEvent('onActivateError', dataPack.VlocityDataPackType, dataPackData);

var errorMessage = ' --- Not Activated';

if (onActivateErrorResult) {
if (onActivateErrorResult.ActivationStatus === 'Success') {
continue;
if (!dataPackData.dataPacks) {
shouldRetry = attempts < 3;
attempts++;
} else {
for (var dataPack of dataPackData.dataPacks) {
if (dataPack.ActivationStatus == 'Activated' || allActivated.includes(dataPack.VlocityDataPackKey)) {
await this.vlocity.datapacksutils.handleDataPackEvent('afterActivationSuccess', dataPack.VlocityDataPackType, {dataPack: dataPack, jobInfo: jobInfo});
} else if (dataPack.ActivationStatus == 'Ready' && dataPack.VlocityDataPackStatus == 'Success') {

// If it is the only one in the deploy and it fails to activate it must be set to error. Otherwise retry the deploy and activation separate from others.
if (dataPackData.dataPacks.length == 1) {
var onActivateErrorResult = await this.vlocity.datapacksutils.handleDataPackEvent('onActivateError', dataPack.VlocityDataPackType, dataPackData);

var errorMessage = ' --- Not Activated';

if (onActivateErrorResult) {
if (onActivateErrorResult.ActivationStatus === 'Success') {
continue;
}

errorMessage = ' --- ' + onActivateErrorResult.message;
} else if (allActivationErrors[dataPack.VlocityDataPackKey]) {
errorMessage = ' --- ' + allActivationErrors[dataPack.VlocityDataPackKey];
}

errorMessage = ' --- ' + onActivateErrorResult.message;
} else if (allActivationErrors[dataPack.VlocityDataPackKey]) {
errorMessage = ' --- ' + allActivationErrors[dataPack.VlocityDataPackKey];

jobInfo.hasError = true;
jobInfo.currentStatus[dataPack.VlocityDataPackKey] = 'Error';
jobInfo.currentErrors[dataPack.VlocityDataPackKey] = 'Activation Error >> ' + dataPack.VlocityDataPackKey + errorMessage;
jobInfo.errors.push('Activation Error >> ' + dataPack.VlocityDataPackKey + errorMessage);
VlocityUtils.error('Activation Error', dataPack.VlocityDataPackKey + errorMessage);

} else if (attempts < 3) {
shouldRetry = true;
} else {
jobInfo.currentStatus[dataPack.VlocityDataPackKey] = 'ReadySeparate';
}

} else if (dataPack.ActivationStatus == 'Error') {

var message = 'Activation Error >> ' + dataPack.VlocityDataPackKey + ' --- ' + (dataPack.VlocityDataPackMessage ? dataPack.VlocityDataPackMessage : (activateResult.error != 'OK' ? activateResult.error : ''));

jobInfo.hasError = true;
jobInfo.currentStatus[dataPack.VlocityDataPackKey] = 'Error';
jobInfo.currentErrors[dataPack.VlocityDataPackKey] = 'Activation Error >> ' + dataPack.VlocityDataPackKey + errorMessage;
jobInfo.errors.push('Activation Error >> ' + dataPack.VlocityDataPackKey + errorMessage);
VlocityUtils.error('Activation Error', dataPack.VlocityDataPackKey + errorMessage);

} else if (attempts < 3) {
shouldRetry = true;
} else {
jobInfo.currentStatus[dataPack.VlocityDataPackKey] = 'ReadySeparate';
}
} else if (dataPack.ActivationStatus == 'Error') {

var message = 'Activation Error >> ' + dataPack.VlocityDataPackKey + ' --- ' + (dataPack.VlocityDataPackMessage ? dataPack.VlocityDataPackMessage : (activateResult.error != 'OK' ? activateResult.error : ''));

jobInfo.hasError = true;
jobInfo.currentStatus[dataPack.VlocityDataPackKey] = 'Error';

jobInfo.currentErrors[dataPack.VlocityDataPackKey] = message;

if (jobInfo.errors.indexOf(message) == -1) {
jobInfo.errors.push(message);

jobInfo.currentErrors[dataPack.VlocityDataPackKey] = message;

if (jobInfo.errors.indexOf(message) == -1) {
jobInfo.errors.push(message);
}

VlocityUtils.error('Activation Error', dataPack.VlocityDataPackKey, dataPack.VlocityDataPackMessage ? dataPack.VlocityDataPackMessage : (activateResult.error != 'OK' ? activateResult.error : ''));
}

VlocityUtils.error('Activation Error', dataPack.VlocityDataPackKey, dataPack.VlocityDataPackMessage ? dataPack.VlocityDataPackMessage : (activateResult.error != 'OK' ? activateResult.error : ''));
}
}

Expand Down Expand Up @@ -2364,6 +2382,18 @@ DataPacksJob.prototype.deployPack = async function(inputMap) {
var stepPostDeployResults = [];
let dataPackData = await this.vlocity.datapacks.getDataPackData(dataPackId);

if (!dataPackData.dataPacks) {
VlocityUtils.error("Error Fetching DataPack Data", result.VlocityDataPackId, allDeploymentKeys);
allDeploymentKeys.forEach(key => {
jobInfo.hasError = true;
jobInfo.currentStatus[key] = 'Error';
jobInfo.currentErrors[dataPack.VlocityDataPackKey] = `${key} - Error Fetching DataPack Data`;
jobInfo.errors.push(`${key} - ${result.message}`);
});

return;
}

for (var dataPack of dataPackData.dataPacks) {
var objectName = self.vlocity.datapacksutils.getBulkJobObjectName(dataPack.VlocityDataPackType);
var objectKey = self.vlocity.datapacksutils.getBulkJobObjectKey(dataPack.VlocityDataPackType);
Expand Down Expand Up @@ -2707,10 +2737,16 @@ DataPacksJob.prototype.deployJob = async function(jobInfo) {

// Ensure there is a sfdx-project.json file
this.vlocity.datapacksutils.getSFDXProject({...jobInfo, sfdxForcePath: tempSfdxLwcFolder});

// Deploy using sfdx
const deployGeneratedLwcFolder = await this.vlocity.utilityservice.sfdx('source:deploy', tempDeployOptions);
jobInfo.currentStatus = Object.assign(jobInfo.currentStatus, this.vlocity.datapacksutils.formatSalesforceDeployResponse(deployGeneratedLwcFolder));
try {
// Deploy using sfdx
const deployGeneratedLwcFolder = await this.vlocity.utilityservice.sfdx('source:deploy', tempDeployOptions);
jobInfo.currentStatus = Object.assign(jobInfo.currentStatus, this.vlocity.datapacksutils.formatSalesforceDeployResponse(deployGeneratedLwcFolder));
} catch (err) {
VlocityUtils.log(err);
jobInfo.errors.push( "OmniScript or FlexCard Compilation Failed:\n" + JSON.stringify(err, null, 2));
jobInfo.hasError = true;
}

} else {
VlocityUtils.error('Can\'t find compiled LWC components path. Skipping...');
}
Expand Down
Loading

0 comments on commit e278623

Please sign in to comment.