summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/pom.xml
blob: 595dbd0e09f0e6acb6ced763d1cb0960e1260ab4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!--
  ~ Copyright © 2016-2018 European Support Limited
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://maven.apache.org/POM/4.0.0"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <name>openecomp-sdc-translator-core</name>
  <artifactId>openecomp-sdc-translator-core</artifactId>


  <parent>
    <groupId>org.openecomp.sdc</groupId>
    <artifactId>openecomp-sdc-translator-lib</artifactId>
    <version>1.11.9-SNAPSHOT</version>
  </parent>

  <dependencies>
    <dependency>
      <groupId>org.onap.sdc.common</groupId>
      <artifactId>onap-tosca-datatype</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>${logback.version}</version>
    </dependency>
    <dependency>
      <groupId>org.openecomp.sdc.core</groupId>
      <artifactId>openecomp-utilities-lib</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.openecomp.sdc</groupId>
      <artifactId>openecomp-sdc-translator-api</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.openecomp.sdc</groupId>
      <artifactId>openecomp-sdc-datatypes-lib</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.openecomp.sdc</groupId>
      <artifactId>openecomp-sdc-validation-api</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.openecomp.sdc.core</groupId>
      <artifactId>openecomp-heat-lib</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>${commons.io.version}</version>
    </dependency>
    <dependency>
      <groupId>org.openecomp.sdc</groupId>
      <artifactId>openecomp-sdc-validation-impl</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>

  </dependencies>

  <build>
   <testResources>
     <testResource>
        <directory>src/test/resources</directory>
        <filtering>true</filtering>
      </testResource>
      </testResources>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven-surefire-plugin.version}</version>
        <configuration>
          <parallel>classes</parallel>
          <threadCount>1</threadCount>
          <forkCount>${fork.count}</forkCount>
          <forkMode>${fork.mode}</forkMode>
          <printSummary>false</printSummary>
          <redirectTestOutputToFile>true</redirectTestOutputToFile>
          <rerunFailingTestsCount>1</rerunFailingTestsCount>
          <additionalClasspathElements>
            <additionalClasspathElement>${project.basedir}/src/test/resources
            </additionalClasspathElement>
          </additionalClasspathElements>
          <systemPropertyVariables>
            <logback.configurationFile>src/test/resources/logback-test.xml
            </logback.configurationFile>
          </systemPropertyVariables>
          <useSystemClassLoader>${useSystemClassLoader}</useSystemClassLoader>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <properties>
    <useSystemClassLoader>false</useSystemClassLoader>
  </properties>

</project>
">: ['./dynamic-property.component.less'], animations: [trigger('fadeIn', [transition(':enter', [style({ opacity: '0' }), animate('.7s ease-out', style({ opacity: '1' }))])])] }) export class DynamicPropertyComponent { derivedPropertyTypes = DerivedPropertyType; //http://stackoverflow.com/questions/35835984/how-to-use-a-typescript-enum-value-in-an-angular2-ngswitch-statement propType: DerivedPropertyType; propPath: string; isPropertyFEModel: boolean; nestedLevel: number; propertyTestsId: string; constraints:string[]; @Input() canBeDeclared: boolean; @Input() property: PropertyFEModel | DerivedFEProperty; @Input() expandedChildId: string; @Input() selectedPropertyId: string; @Input() propertyNameSearchText: string; @Input() readonly: boolean; @Input() hasChildren: boolean; @Input() hasDeclareOption:boolean; @Input() rootProperty: PropertyFEModel; @Output('propertyChanged') emitter: EventEmitter<void> = new EventEmitter<void>(); @Output() expandChild: EventEmitter<string> = new EventEmitter<string>(); @Output() checkProperty: EventEmitter<string> = new EventEmitter<string>(); @Output() toggleTosca: EventEmitter<DerivedFEProperty> = new EventEmitter<DerivedFEProperty>(); @Output() deleteItem: EventEmitter<string> = new EventEmitter<string>(); @Output() clickOnPropertyRow: EventEmitter<PropertyFEModel | DerivedFEProperty> = new EventEmitter<PropertyFEModel | DerivedFEProperty>(); @Output() mapKeyChanged: EventEmitter<string> = new EventEmitter<string>(); @Output() addChildPropsToParent: EventEmitter<Array<DerivedFEProperty>> = new EventEmitter<Array<DerivedFEProperty>>(); @ViewChild('mapKeyInput') public mapKeyInput: DynamicElementComponent; constructor(private propertiesUtils: PropertiesUtils, private dataTypeService: DataTypeService) { } ngOnInit() { this.isPropertyFEModel = this.property instanceof PropertyFEModel; this.propType = this.property.derivedDataType; this.propPath = (this.property instanceof PropertyFEModel) ? this.property.name : this.property.propertiesName; this.nestedLevel = (this.property.propertiesName.match(/#/g) || []).length; this.rootProperty = (this.rootProperty) ? this.rootProperty : <PropertyFEModel>this.property; this.propertyTestsId = this.getPropertyTestsId(); this.initConsraintsValues(); } initConsraintsValues(){ let primitiveProperties = ['string', 'integer', 'float', 'boolean', PROPERTY_TYPES.TIMESTAMP]; //Property has constraints if(this.property.constraints && this.property.constraints[0]){ this.constraints = this.property.constraints[0].validValues } //Complex Type else if (primitiveProperties.indexOf(this.rootProperty.type) == -1 && primitiveProperties.indexOf(this.property.type) >= 0 ){ this.constraints = this.dataTypeService.getConstraintsByParentTypeAndUniqueID(this.rootProperty.type, this.property.name); } else{ this.constraints = null; } } ngDoCheck() { // set custom error for mapKeyInput if (this.mapKeyInput) { const mapKeyInputControl = this.mapKeyInput.cmpRef.instance.control; const mapKeyError = (<DerivedFEProperty>this.property).mapKeyError; if (mapKeyInputControl.getError('mapKeyError') !== mapKeyError) { mapKeyInputControl.setErrors({mapKeyError}); } } } ngOnChanges() { this.propType = this.property.derivedDataType; this.propPath = (this.property instanceof PropertyFEModel) ? this.property.name : this.property.propertiesName; this.rootProperty = (this.rootProperty) ? this.rootProperty : <PropertyFEModel>this.property; this.propertyTestsId = this.getPropertyTestsId(); } onClickPropertyRow = (property, event) => { // Because DynamicPropertyComponent is recrusive second time the event is fire event.stopPropagation = undefined event && event.stopPropagation && event.stopPropagation(); this.clickOnPropertyRow.emit(property); } expandChildById = (id: string) => { this.expandedChildId = id; this.expandChild.emit(id); } checkedChange = (propName: string) => { this.checkProperty.emit(propName); } toggleToscaFunction = (prop: DerivedFEProperty) => { this.toggleTosca.emit(prop); } getHasChildren = (property:DerivedFEProperty): boolean => {// enter to this function only from base property (PropertyFEModel) and check for child property if it has children return _.filter((<PropertyFEModel>this.property).flattenedChildren,(prop:DerivedFEProperty)=>{ return _.startsWith(prop.propertiesName + '#', property.propertiesName); }).length > 1; } getPropertyTestsId = () => { return [this.rootProperty.name].concat(this.rootProperty.getParentNamesArray(this.property.propertiesName, [], true)).join('.'); }; onElementChanged = (event: IUiElementChangeEvent) => { this.property.updateValueObj(event.value, event.isValid); this.emitter.emit(); }; createNewChildProperty = (): void => { let mapKeyValue = this.property instanceof DerivedFEProperty ? this.property.mapKey : ""; if (this.property.type == PROPERTY_TYPES.LIST && mapKeyValue === "") { if(this.property.value != null) { const valueJson = JSON.parse(this.property.value); if(this.property instanceof PropertyFEModel && this.property.expandedChildPropertyId != null){ let indexNumber = Number(Object.keys(valueJson).sort().reverse()[0]) + 1; mapKeyValue = indexNumber.toString(); }else{ mapKeyValue = Object.keys(valueJson).sort().reverse()[0]; } }else { mapKeyValue = "0"; } } let newProps: Array<DerivedFEProperty> = this.propertiesUtils.createListOrMapChildren(this.property, mapKeyValue, null); this.propertiesUtils.assignFlattenedChildrenValues(this.property.valueObj, [newProps[0]], this.property.propertiesName); if (this.property instanceof PropertyFEModel) { this.addChildProps(newProps, this.property.name); } else { this.addChildPropsToParent.emit(newProps); } } addChildProps = (newProps: Array<DerivedFEProperty>, childPropName: string) => { if (this.property instanceof PropertyFEModel) { let insertIndex: number = this.property.getIndexOfChild(childPropName) + this.property.getCountOfChildren(childPropName); //insert after parent prop and existing children this.property.flattenedChildren.splice(insertIndex, 0, ...newProps); //using ES6 spread operator this.expandChildById(newProps[0].propertiesName); this.updateMapKeyValueOnMainParent(newProps); } } updateMapKeyValueOnMainParent(childrenProps: Array<DerivedFEProperty>){ if (this.property instanceof PropertyFEModel) { const property: PropertyFEModel = <PropertyFEModel>this.property; //Update only if all this property parents has key name if (property.getParentNamesArray(childrenProps[0].propertiesName, []).indexOf('') === -1){ angular.forEach(childrenProps, (prop:DerivedFEProperty):void => { //Update parent PropertyFEModel with value for each child, including nested props property.childPropUpdated(prop); if (prop.isChildOfListOrMap && prop.mapKey !== undefined) { property.childPropMapKeyUpdated(prop, prop.mapKey, true); } },this); //grab the cumulative value for the new item from parent PropertyFEModel and assign that value to DerivedFEProp[0] (which is the list or map parent with UUID of the set we just added) let parentNames = (<PropertyFEModel>property).getParentNamesArray(childrenProps[0].propertiesName, []); childrenProps[0].valueObj = _.get(property.valueObj, parentNames.join('.'), null); } } } childValueChanged = (property: DerivedFEProperty) => { //value of child property changed if (this.property instanceof PropertyFEModel) { // will always be the case if (this.property.getParentNamesArray(property.propertiesName, []).indexOf('') === -1) {//If one of the parents is empty key -don't save this.property.childPropUpdated(property); this.dataTypeService.checkForCustomBehavior(this.property); this.emitter.emit(); } } } deleteListOrMapItem = (item: DerivedFEProperty) => { if (this.property instanceof PropertyFEModel) { this.removeValueFromParent(item); this.property.flattenedChildren.splice(this.property.getIndexOfChild(item.propertiesName), this.property.getCountOfChildren(item.propertiesName)); this.expandChildById(item.propertiesName); } } removeValueFromParent = (item: DerivedFEProperty) => { if (this.property instanceof PropertyFEModel) { let itemParent = (item.parentName == this.property.name) ? this.property : this.property.flattenedChildren.find(prop => prop.propertiesName == item.parentName); if (!itemParent) { return; } const oldKey = item.getActualMapKey(); if (this.property.subPropertyToscaFunctions !== null) { let tempSubToscaFunction: SubPropertyToscaFunction[] = []; this.property.subPropertyToscaFunctions.forEach((item : SubPropertyToscaFunction, index) => { if(item.subPropertyPath[0] != oldKey){ tempSubToscaFunction.push(item); } }); this.property.subPropertyToscaFunctions = tempSubToscaFunction; } if (item.derivedDataType == DerivedPropertyType.MAP && !item.mapInlist) { delete itemParent.valueObj[oldKey]; if (itemParent instanceof PropertyFEModel) { delete itemParent.valueObjValidation[oldKey]; itemParent.valueObjIsValid = itemParent.calculateValueObjIsValid(); } this.property.childPropMapKeyUpdated(item, null); // remove map key } else { const itemIndex: number = this.property.flattenedChildren.filter(prop => prop.parentName == item.parentName).map(prop => prop.propertiesName).indexOf(item.propertiesName); itemParent.valueObj.splice(itemIndex, 1); if (itemParent instanceof PropertyFEModel) { itemParent.valueObjValidation.splice(itemIndex, 1); itemParent.valueObjIsValid = itemParent.calculateValueObjIsValid(); } } if (itemParent instanceof PropertyFEModel) { //direct child this.emitter.emit(); } else { //nested child - need to update parent prop by getting flattened name (recurse through parents and replace map/list keys, etc) this.childValueChanged(itemParent); } } } updateChildKeyInParent(childProp: DerivedFEProperty, newMapKey: string) { if (this.property instanceof PropertyFEModel) { let oldKey = childProp.getActualMapKey(); this.property.childPropMapKeyUpdated(childProp, newMapKey); this.property.flattenedChildren.forEach(tempDervObj => { if (childProp.propertiesName === tempDervObj.parentName) { tempDervObj.mapKey = newMapKey; } }); if (this.property.subPropertyToscaFunctions != null) { this.property.subPropertyToscaFunctions.forEach((item : SubPropertyToscaFunction) => { if(item.subPropertyPath[0] === oldKey){ item.subPropertyPath = [newMapKey]; } }); } this.emitter.emit(); } } preventInsertItem = (property:DerivedFEProperty):boolean => { if(property.type == PROPERTY_TYPES.MAP && Object.keys(property.valueObj).indexOf('') > -1 ){ return true; } return false; } }