diff --git a/apps/client/src/flogo/home/core/import-error-formatter.service.ts b/apps/client/src/flogo/home/core/import-error-formatter.service.ts index 54bd053cf..4317ed457 100644 --- a/apps/client/src/flogo/home/core/import-error-formatter.service.ts +++ b/apps/client/src/flogo/home/core/import-error-formatter.service.ts @@ -47,6 +47,9 @@ export class ImportErrorFormatterService { case 'improper-import': messageHeader = this._translate.instant('IMPORT-ERROR:IMPROPER_IMPORT'); break; + case 'contrib-not-installed': + messageHeader = this._translate.instant('IMPORT-ERROR:CONTRIB_NOT_INSTALLED'); + break; default: messageHeader = this._translate.instant('APP-LIST:BROKEN_RULE_UNKNOWN'); break; @@ -124,6 +127,11 @@ export class ImportErrorFormatterService { ref: detail.params.ref, }); break; + case 'contrib-not-installed': + errorMessage = this._translate.instant('IMPORT-ERROR:CONTRIB_NOT_INSTALLED_CONTENT', { + ref: detail.params.ref, + }); + break; default: errorMessage = this._translate.instant('APP-LIST:BROKEN_RULE_UNKNOWN'); break; diff --git a/apps/client/src/i18n/en.json b/apps/client/src/i18n/en.json index f0318ee30..78bb1bb80 100644 --- a/apps/client/src/i18n/en.json +++ b/apps/client/src/i18n/en.json @@ -41,6 +41,7 @@ "IMPORT-ERROR:PROPERTY_REQUIRED": "Property required", "IMPORT-ERROR:ACTIVITY_MISSING": "Activity missing", "IMPORT-ERROR:TRIGGER_MISSING": "Trigger missing", + "IMPORT-ERROR:CONTRIB_NOT_INSTALLED": "Contribution missing", "IMPORT-ERROR:ACTIVITY_MISSING_IN_IMPORT": "Activity missing in imports", "IMPORT-ERROR:TRIGGER_MISSING_IN_IMPORT": "Trigger missing in imports", "IMPORT-ERROR:UNKNOWN_APP_TYPE": "Unknown app type/model", @@ -50,6 +51,7 @@ "IMPORT-ERROR:ONE_AMONG_CONTENT": "should equal one of the allowed values: {{allowedValues}}", "IMPORT-ERROR:ACTIVITY_MISSING_CONTENT": "{{ref}} - You will need to install this activity before you can use it in an app.", "IMPORT-ERROR:TRIGGER_MISSING_CONTENT": "{{ref}} - You will need to install this trigger before you can use it in an app.", + "IMPORT-ERROR:CONTRIB_NOT_INSTALLED_CONTENT": "{{ref}} - You will need to install this contribution before you can use it in an app", "IMPORT-ERROR:ACTIVITY_MISSING_IN_IMPORT_CONTENT": "{{dataPath}} - {{ref}} activity is missing in the imports", "IMPORT-ERROR:TRIGGER_MISSING_IN_IMPORT_CONTENT": "{{dataPath}} - {{ref}} trigger is missing in the imports", "IMPORT-ERROR:UNSUPPORTED_RESOURCE_TYPE": "Unsupported resource type", diff --git a/apps/server/src/modules/transfer/import/import-app.ts b/apps/server/src/modules/transfer/import/import-app.ts index 4dd24ba31..a439c25b5 100644 --- a/apps/server/src/modules/transfer/import/import-app.ts +++ b/apps/server/src/modules/transfer/import/import-app.ts @@ -44,7 +44,7 @@ export function importApp( ): App { const now = new Date().toISOString(); if (rawApp.imports) { - validateImports(rawApp.imports); + validateImports(rawApp.imports, contributions); } const importsRefAgent = createFromImports(rawApp.imports, contributions); const newApp = cleanAndValidateApp( @@ -94,10 +94,11 @@ export function importApp( return newApp; } -function validateImports(imports) { +function validateImports(imports, contributions) { const improperImports = imports.filter( eachImport => !IMPORT_SYNTAX.exec(eachImport.trim()) ); + const importsErrors = improperImports.map(importsError => ({ keyword: 'improper-import', dataPath: '.imports', @@ -106,8 +107,28 @@ function validateImports(imports) { ref: importsError, }, })); - if (importsErrors.length) { - throw new ValidationError('Validation error in imports', importsErrors); + + const contribsNotInstalled = imports.filter( + eachImport => { + const validateImport = IMPORT_SYNTAX.exec(eachImport.trim()); + if(validateImport) { + return !contributions.has(validateImport[2]); + } + }); + + const contribsNotInstalledErrors = contribsNotInstalled.map( + contribRef => ({ + keyword: "contrib-not-installed", + message: `contribution "${contribRef}" is not installed`, + params: { + ref: contribRef, + }, + })); + + const allErrors = [...importsErrors, ...contribsNotInstalledErrors]; + + if (allErrors.length) { + throw new ValidationError('Validation error in imports', allErrors); } }