aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/components
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2020-01-29 17:25:21 +0000
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-04-19 16:35:32 +0000
commitcd6f933375c412c2f79a12e909821322d58a8499 (patch)
tree758ff2e742b514169bbc84a8433d68fe221ef5c9 /catalog-ui/src/app/ng2/components
parentdc56692a4a307f378c827f017d2efbf754c223e0 (diff)
Configure a new Artifact Type
Centralizes artifact configuration in one yaml entry. Allow the configuration of a new artifact type without the need of code changes. The configuration file now is used as a source of artifacts types instead the artifact type enum. The enum will be used as a source of base artifact types and also in hard coded business rules. Change-Id: Id0383d9fca9bce0519a4d52a4ecb3a68c8713f0f Issue-ID: SDC-2754 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-ui/src/app/ng2/components')
-rw-r--r--catalog-ui/src/app/ng2/components/forms/artifacts-form/__snapshots__/artifact-form.component.spec.ts.snap1
-rw-r--r--catalog-ui/src/app/ng2/components/forms/artifacts-form/artifact-form.component.spec.ts100
-rw-r--r--catalog-ui/src/app/ng2/components/forms/artifacts-form/artifact-form.component.ts41
-rw-r--r--catalog-ui/src/app/ng2/components/forms/artifacts-form/artifacts.service.ts10
4 files changed, 68 insertions, 84 deletions
diff --git a/catalog-ui/src/app/ng2/components/forms/artifacts-form/__snapshots__/artifact-form.component.spec.ts.snap b/catalog-ui/src/app/ng2/components/forms/artifacts-form/__snapshots__/artifact-form.component.spec.ts.snap
index 8cd085e248..440dc74d72 100644
--- a/catalog-ui/src/app/ng2/components/forms/artifacts-form/__snapshots__/artifact-form.component.spec.ts.snap
+++ b/catalog-ui/src/app/ng2/components/forms/artifacts-form/__snapshots__/artifact-form.component.spec.ts.snap
@@ -2,6 +2,7 @@
exports[`artifact form component should match current snapshot of artifact form component 1`] = `
<artifact-form
+ artifactConfigService={[Function Object]}
artifactTypesOptions={[Function Array]}
cacheService={[Function Object]}
initArtifactTypes={[Function Function]}
diff --git a/catalog-ui/src/app/ng2/components/forms/artifacts-form/artifact-form.component.spec.ts b/catalog-ui/src/app/ng2/components/forms/artifacts-form/artifact-form.component.spec.ts
index fc69509ee9..49a06b27e0 100644
--- a/catalog-ui/src/app/ng2/components/forms/artifacts-form/artifact-form.component.spec.ts
+++ b/catalog-ui/src/app/ng2/components/forms/artifacts-form/artifact-form.component.spec.ts
@@ -7,32 +7,37 @@ import {CacheService} from "../../../services/cache.service";
import {TranslateService} from "../../../shared/translator/translate.service";
import {ArtifactModel} from "../../../../models/artifacts";
import {IDropDownOption} from "onap-ui-angular/dist/form-elements/dropdown/dropdown-models";
-import {Observable, Subject} from "rxjs";
-import {getValue} from "@ngxs/store";
+import {Subject} from "rxjs";
+import {ArtifactConfigService} from "../../../services/artifact-config.service";
+import {ArtifactType, ComponentType} from "../../../../utils/constants";
describe('artifact form component', () => {
let fixture: ComponentFixture<ArtifactFormComponent>;
let cacheServiceMock: Partial<CacheService>;
+ let artifactConfigService: Partial<ArtifactConfigService>;
let onValidationChangeMock: Partial<Subject<boolean>>;
let artifactModel = new ArtifactModel();
+ artifactConfigService = {
+ findAllTypeBy: jest.fn()
+ };
beforeEach(
async(() => {
onValidationChangeMock = {
next: jest.fn()
- }
+ };
cacheServiceMock = {
contains: jest.fn(),
remove: jest.fn(),
set: jest.fn(),
get: jest.fn()
- }
+ };
const configure: ConfigureFn = testBed => {
testBed.configureTestingModule({
@@ -41,6 +46,7 @@ describe('artifact form component', () => {
schemas: [NO_ERRORS_SCHEMA],
providers: [
{provide: CacheService, useValue: cacheServiceMock},
+ {provide: ArtifactConfigService, useValue: artifactConfigService},
{provide: TranslateService, useValue: {}}
],
});
@@ -55,91 +61,73 @@ describe('artifact form component', () => {
it('should verify initArtifactTypes for DEPLOYMENT and ArtifactType = HEAT_ENV', () =>{
- cacheServiceMock.get.mockImplementation(() =>{
- return {
- artifacts: {
- deployment:{
- resourceInstanceDeploymentArtifacts: [{name: "Dummy Value Returned from ui api"}],
- }
- }
+ artifactConfigService.findAllTypeBy.mockImplementation((artifactType, componentType, resourceType) => {
+ if (artifactType == 'DEPLOYMENT' && componentType == ComponentType.RESOURCE_INSTANCE && resourceType == 'VF') {
+ return ['Val1', 'Val2', 'Val3', ArtifactType.HEAT_ENV];
}
});
fixture.componentInstance.artifactType = 'DEPLOYMENT';
+ fixture.componentInstance.resourceType = 'VF';
fixture.componentInstance.artifact = artifactModel;
- fixture.componentInstance.artifact.artifactType = 'HEAT_ENV';
+ fixture.componentInstance.artifact.artifactType = ArtifactType.HEAT_ENV;
fixture.componentInstance.initArtifactTypes();
- expect(fixture.componentInstance.selectedFileType).toEqual(undefined);
+ expect(fixture.componentInstance.selectedFileType).toEqual({"label": ArtifactType.HEAT_ENV, "value": ArtifactType.HEAT_ENV});
});
- it('should verify initArtifactTypes for DEPLOYMENT and ComponentType = RESOURCE', () =>{
+ it('should verify initArtifactTypes for DEPLOYMENT and ComponentType = RESOURCE', () => {
- cacheServiceMock.get.mockImplementation(() =>{
- return {
- artifacts: {
- deployment:{
- resourceDeploymentArtifacts: [{name: "Dummy Value Returned from ui api"}],
- }
- }
+ const expectedSelectedValue = 'Val3';
+ const artifactType = 'DEPLOYMENT';
+ const resourceType = 'VF';
+ artifactConfigService.findAllTypeBy.mockImplementation((artifactType1, componentType1, resourceType1) => {
+ if (artifactType1 == artifactType && componentType1 == ComponentType.RESOURCE && resourceType1 == resourceType) {
+ return ['Val1', 'Val2', expectedSelectedValue, 'Val4'];
}
- });
-
- fixture.componentInstance.artifactType = 'DEPLOYMENT';
- fixture.componentInstance.artifact = artifactModel;
- fixture.componentInstance.componentType = 'RESOURCE';
-
- fixture.componentInstance.initArtifactTypes();
-
- expect(fixture.componentInstance.selectedFileType).toEqual(undefined);
-
- });
-
- it('should verify initArtifactTypes for DEPLOYMENT and NOT ComponentType = RESOURCE OR NOT ArtifactType = HEAT_ENV', () =>{
- cacheServiceMock.get.mockImplementation(() =>{
- return {
- artifacts: {
- deployment:{
- serviceDeploymentArtifacts: [{name: "Dummy Value Returned from ui api"}],
- }
- }
- }
+ return [];
});
- fixture.componentInstance.artifactType = 'DEPLOYMENT';
+ fixture.componentInstance.artifactType = artifactType;
fixture.componentInstance.artifact = artifactModel;
- // fixture.componentInstance.componentType = 'RESOURCE';
+ fixture.componentInstance.resourceType = resourceType;
+ fixture.componentInstance.componentType = ComponentType.RESOURCE;
+ fixture.componentInstance.artifact.artifactType = expectedSelectedValue;
fixture.componentInstance.initArtifactTypes();
- expect(fixture.componentInstance.selectedFileType).toEqual(undefined);
+ expect(fixture.componentInstance.selectedFileType).toEqual({'label': expectedSelectedValue, 'value': expectedSelectedValue});
});
- it('should verify initArtifactTypes for INFORMATION', () =>{
+ it('should verify initArtifactTypes for INFORMATIONAL', () => {
- cacheServiceMock.get.mockImplementation(() =>{
- return {
- artifacts: {
- other: [{name: "Val1"}, {name: "ExpectedValToBeSelected"}, {name: "Val3"}]
- }
+ const expectedSelectedValue = 'Val3';
+ const artifactType = 'INFORMATIONAL';
+ const resourceType = null;
+ artifactConfigService.findAllTypeBy.mockImplementation((artifactType1, componentType1, resourceType1) => {
+ if (artifactType1 == artifactType && componentType1 == ComponentType.SERVICE && resourceType1 == resourceType) {
+ return ['Val1', 'Val2', expectedSelectedValue, 'Val4'];
}
+
+ return [];
});
- fixture.componentInstance.artifactType = 'INFORMATIONAL';
+ fixture.componentInstance.artifactType = artifactType;
fixture.componentInstance.artifact = artifactModel;
- fixture.componentInstance.artifact.artifactType = 'ExpectedValToBeSelected';
+ fixture.componentInstance.resourceType = resourceType;
+ fixture.componentInstance.componentType = ComponentType.SERVICE;
+ fixture.componentInstance.artifact.artifactType = expectedSelectedValue;
fixture.componentInstance.initArtifactTypes();
- expect(fixture.componentInstance.selectedFileType).toEqual({"label": "ExpectedValToBeSelected", "value": "ExpectedValToBeSelected"});
+ expect(fixture.componentInstance.selectedFileType).toEqual({'label': expectedSelectedValue, 'value': expectedSelectedValue});
});
-
it('should match current snapshot of artifact form component', () => {
expect(fixture).toMatchSnapshot();
});
@@ -147,7 +135,7 @@ describe('artifact form component', () => {
it('should verify onUploadFile -> file gets file name', () => {
let file = {
filename:'dummyFileName'
- }
+ };
fixture.componentInstance.verifyTypeAndFileWereFilled = jest.fn();
fixture.componentInstance.artifact = artifactModel;
diff --git a/catalog-ui/src/app/ng2/components/forms/artifacts-form/artifact-form.component.ts b/catalog-ui/src/app/ng2/components/forms/artifacts-form/artifact-form.component.ts
index 905d1a25ad..f7dbf09e3f 100644
--- a/catalog-ui/src/app/ng2/components/forms/artifacts-form/artifact-form.component.ts
+++ b/catalog-ui/src/app/ng2/components/forms/artifacts-form/artifact-form.component.ts
@@ -9,6 +9,7 @@ import { ArtifactModel } from '../../../../models';
import { ArtifactType, ComponentType } from '../../../../utils';
import { Dictionary } from '../../../../utils/dictionary/dictionary';
import { CacheService } from '../../../services/cache.service';
+import { ArtifactConfigService } from '../../../services/artifact-config.service';
@Component({
selector: 'artifact-form',
@@ -20,6 +21,7 @@ export class ArtifactFormComponent {
@Input() artifact: ArtifactModel;
@Input() artifactType: ArtifactType;
@Input() componentType: string;
+ @Input() resourceType: string;
@Input() instanceId: string;
@Input() isViewOnly: boolean;
@@ -31,7 +33,8 @@ export class ArtifactFormComponent {
private descriptionIsValid: boolean;
private labelIsValid: boolean;
- constructor(private cacheService: CacheService) {
+ constructor(private cacheService: CacheService,
+ private artifactConfigService: ArtifactConfigService) {
}
ngOnInit(): void {
@@ -44,7 +47,7 @@ export class ArtifactFormComponent {
public onTypeChange = (selectedFileType: IDropDownOption) => {
this.artifact.artifactType = selectedFileType.value;
this.verifyTypeAndFileWereFilled();
- }
+ };
public onUploadFile = (file) => {
if (file) {
@@ -55,34 +58,24 @@ export class ArtifactFormComponent {
this.artifact.artifactName = null;
}
this.verifyTypeAndFileWereFilled();
- }
+ };
private initArtifactTypes = (): void => {
- const artifactTypes: any = this.cacheService.get('UIConfiguration');
- let validExtensions: string[];
let artifactTypesList: string[];
-
switch (this.artifactType) {
case ArtifactType.DEPLOYMENT:
if (this.artifact.artifactType === ArtifactType.HEAT_ENV || this.instanceId) {
- validExtensions = artifactTypes.artifacts.deployment.resourceInstanceDeploymentArtifacts;
- } else if (this.componentType === ComponentType.RESOURCE) {
- validExtensions = artifactTypes.artifacts.deployment.resourceDeploymentArtifacts;
+ artifactTypesList = this.artifactConfigService.findAllTypeBy(this.artifactType, ComponentType.RESOURCE_INSTANCE, this.resourceType);
} else {
- validExtensions = artifactTypes.artifacts.deployment.serviceDeploymentArtifacts;
- }
- if (validExtensions) {
- artifactTypesList = Object.keys(validExtensions);
+ artifactTypesList = this.artifactConfigService.findAllTypeBy(this.artifactType, this.componentType, this.resourceType);
}
break;
case ArtifactType.INFORMATION:
- artifactTypesList = artifactTypes.artifacts.other.map((element: any) => {
- return element.name;
- });
- _.remove(artifactTypesList, (item: string) => {
- return _.has(ArtifactType.THIRD_PARTY_RESERVED_TYPES, item) ||
- _.has(ArtifactType.TOSCA, item);
- });
+ if (this.instanceId) {
+ artifactTypesList = this.artifactConfigService.findAllTypeBy(this.artifactType, ComponentType.RESOURCE_INSTANCE, this.resourceType);
+ } else {
+ artifactTypesList = this.artifactConfigService.findAllTypeBy(this.artifactType, this.componentType, this.resourceType);
+ }
break;
}
@@ -94,7 +87,7 @@ export class ArtifactFormComponent {
return artifactType.value === this.artifact.artifactType;
});
- }
+ };
// Verify that the Type and the Name (file) are filled in the Modal
// For Description and Label - I used this.descriptionIsValid:boolean & this.labelIsValid:boolean as part of the sdc-validation Element
@@ -116,17 +109,17 @@ export class ArtifactFormComponent {
this.onValidationChange.next(false);
}
}
- }
+ };
// sdc-validation for Description
private onDescriptionChange = (isValid: boolean): void => {
this.descriptionIsValid = isValid;
this.onValidationChange.next(isValid) && this.verifyTypeAndFileWereFilled();
- }
+ };
// sdc-validation for Label
private onLabelChange = (isValid: boolean): void => {
this.labelIsValid = isValid;
this.onValidationChange.next(isValid) && this.verifyTypeAndFileWereFilled();
- }
+ };
}
diff --git a/catalog-ui/src/app/ng2/components/forms/artifacts-form/artifacts.service.ts b/catalog-ui/src/app/ng2/components/forms/artifacts-form/artifacts.service.ts
index f9400e9d18..ead85a6afa 100644
--- a/catalog-ui/src/app/ng2/components/forms/artifacts-form/artifacts.service.ts
+++ b/catalog-ui/src/app/ng2/components/forms/artifacts-form/artifacts.service.ts
@@ -25,12 +25,13 @@ export class ArtifactsService {
private store: Store) {
}
- public dispatchArtifactAction = (componentId: string, componentType: string, artifact: ArtifactModel, artifactType: ArtifactGroupType, instanceId: string) => {
+ public dispatchArtifactAction = (componentId: string, componentType: string, artifact: ArtifactModel, artifactType: ArtifactGroupType, instanceId: string, resourceType?: string) => {
const artifactObj = {
componentType,
componentId,
instanceId,
- artifact
+ artifact,
+ resourceType
};
// Create or update instance artifact
@@ -48,14 +49,14 @@ export class ArtifactsService {
}
}
- public openArtifactModal = (componentId: string, componentType: string, artifact: ArtifactModel, artifactType: ArtifactGroupType, isViewOnly?: boolean, instanceId?: string) => {
+ public openArtifactModal = (componentId: string, componentType: string, artifact: ArtifactModel, artifactType: ArtifactGroupType, isViewOnly?: boolean, instanceId?: string, resourceType?: string) => {
let modalInstance;
const onOkPressed = () => {
const updatedArtifact = modalInstance.innerModalContent.instance.artifact;
this.serviceLoader.activate();
- this.dispatchArtifactAction(componentId, componentType, updatedArtifact, artifactType, instanceId)
+ this.dispatchArtifactAction(componentId, componentType, updatedArtifact, artifactType, instanceId, resourceType)
.subscribe().add(() => this.serviceLoader.deactivate());
};
@@ -82,6 +83,7 @@ export class ArtifactsService {
artifactType,
instanceId,
componentType,
+ resourceType: resourceType,
isViewOnly
});