summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorimamSidero <imam.hussain@est.tech>2023-02-08 14:40:35 +0000
committerMichael Morris <michael.morris@est.tech>2023-02-16 09:30:47 +0000
commit2c30bf8b461108e687d874acad3b444fc732ef4c (patch)
treec829bbff40a176edb9b5afac82e256738bc8ba9a
parent59148be1a5a9beea5a157ace746eea3c969f5ed4 (diff)
Provide tosca function to list of map values
Providing the capability to add tosca function for list of map values Issue-ID: SDC-4379 Signed-off-by: Imam hussain <imam.hussain@est.tech> Change-Id: Iec404ec27431eb2b5e085d3f9474e61fadab8d45
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java26
-rw-r--r--catalog-ui/src/app/directives/property-types/type-list/type-list-directive.less2
-rw-r--r--catalog-ui/src/app/directives/property-types/type-map/type-map-directive.less2
-rw-r--r--catalog-ui/src/app/models/properties-inputs/derived-fe-property.ts39
-rw-r--r--catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.html2
-rw-r--r--catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.ts52
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts10
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts5
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts7
9 files changed, 100 insertions, 45 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
index 46bd763ec0..a25a332b9e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
@@ -41,6 +41,7 @@ import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.constraints.ConstraintUtil;
import org.openecomp.sdc.be.model.tosca.constraints.LengthConstraint;
@@ -57,7 +58,9 @@ public class PropertyValueConstraintValidationUtil {
private static final String UNDERSCORE = "_";
private static final String VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY = "%nValue provided in invalid format for %s property";
private static final Logger logger = LoggerFactory.getLogger(PropertyValueConstraintValidationUtil.class);
- private static final String IGNORE_PROPERTY_VALUE_START_WITH = "{\"get_input\":";
+ private static final String IGNORE_PROPERTY_VALUE_START_WITH_INPUT = "{\"get_input\":";
+ private static final String IGNORE_PROPERTY_VALUE_START_WITH_PROPERTY = "{\"get_property\":";
+ private static final String IGNORE_PROPERTY_VALUE_START_WITH_ATTRIBUTE = "{\"get_attribute\":";
private Map<String, DataTypeDefinition> dataTypeDefinitionCache;
private final ObjectMapper objectMapper = new ObjectMapper();
private final List<String> errorMessages = new ArrayList<>();
@@ -153,7 +156,8 @@ public class PropertyValueConstraintValidationUtil {
}
private boolean isPropertyNotMappedAsInput(PropertyDefinition propertyDefinition) {
- return !propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH);
+ return !propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_INPUT) && !propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_PROPERTY)
+ && !propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_ATTRIBUTE);
}
private void checkAndEvaluatePrimitiveProperty(PropertyDefinition propertyDefinition, DataTypeDefinition dataTypeDefinition) {
@@ -203,21 +207,21 @@ public class PropertyValueConstraintValidationUtil {
}
}
if (ToscaType.isPrimitiveType(prop.getType())) {
- newPropertyWithValue = copyPropertyWithNewValue(prop, String.valueOf(valueMap.get(prop.getName())));
+ newPropertyWithValue = copyPropertyWithNewValue(prop, String.valueOf(valueMap.get(prop.getName())), prop.getName());
if (isPropertyToEvaluate(newPropertyWithValue)) {
evaluateConstraintsOnProperty(newPropertyWithValue);
}
} else if (ToscaType.isCollectionType(prop.getType())) {
newPropertyWithValue =
copyPropertyWithNewValue(prop,
- objectMapper.writeValueAsString(valueMap.get(prop.getName())));
+ objectMapper.writeValueAsString(valueMap.get(prop.getName())), prop.getName());
if (isPropertyToEvaluate(newPropertyWithValue)) {
evaluateCollectionTypeProperties(newPropertyWithValue);
}
} else {
newPropertyWithValue =
copyPropertyWithNewValue(prop,
- objectMapper.writeValueAsString(valueMap.get(prop.getName())));
+ objectMapper.writeValueAsString(valueMap.get(prop.getName())), prop.getName());
if (isPropertyToEvaluate(newPropertyWithValue)) {
evaluateComplexTypeProperties(newPropertyWithValue);
}
@@ -365,7 +369,7 @@ public class PropertyValueConstraintValidationUtil {
final Object value = valueMap.get(mapKey);
try {
final PropertyDefinition propertyCopyWithNewValue = copyPropertyWithNewValue(propertyDefinition,
- objectMapper.writeValueAsString(value));
+ objectMapper.writeValueAsString(value),mapKey);
propertyCopyWithNewValue.setToscaSubPath(mapKey);
if (ToscaType.isPrimitiveType(schemaType)) {
evaluateCollectionPrimitiveSchemaType(propertyCopyWithNewValue, schemaType);
@@ -399,8 +403,16 @@ public class PropertyValueConstraintValidationUtil {
return propertyName;
}
- private PropertyDefinition copyPropertyWithNewValue(final PropertyDefinition propertyToCopy, final String value) {
+ private PropertyDefinition copyPropertyWithNewValue(final PropertyDefinition propertyToCopy, final String value, final String key) {
final var propertyDefinition = new PropertyDefinition(propertyToCopy);
+ if (key != null && propertyToCopy.getSubPropertyToscaFunctions() != null) {
+ propertyToCopy.getSubPropertyToscaFunctions().forEach(subPropertyToscaFunction -> {
+ final List<String> subPropertyPath = subPropertyToscaFunction.getSubPropertyPath();
+ if (subPropertyPath.get((subPropertyPath.size() - 1)).equals(key)) {
+ propertyDefinition.setToscaFunction(subPropertyToscaFunction.getToscaFunction());
+ }
+ });
+ }
propertyDefinition.setValue(value);
return propertyDefinition;
}
diff --git a/catalog-ui/src/app/directives/property-types/type-list/type-list-directive.less b/catalog-ui/src/app/directives/property-types/type-list/type-list-directive.less
index 971ef3b007..181d48f75d 100644
--- a/catalog-ui/src/app/directives/property-types/type-list/type-list-directive.less
+++ b/catalog-ui/src/app/directives/property-types/type-list/type-list-directive.less
@@ -96,7 +96,7 @@
}
}
-.tosca-function {
+.div-tosca-function {
max-width: 165px;
}
diff --git a/catalog-ui/src/app/directives/property-types/type-map/type-map-directive.less b/catalog-ui/src/app/directives/property-types/type-map/type-map-directive.less
index 1714178c9f..060ca487b3 100644
--- a/catalog-ui/src/app/directives/property-types/type-map/type-map-directive.less
+++ b/catalog-ui/src/app/directives/property-types/type-map/type-map-directive.less
@@ -91,7 +91,7 @@
display: inline-block;
}
-.tosca-function {
+.div-tosca-function {
max-width: 165px;
}
diff --git a/catalog-ui/src/app/models/properties-inputs/derived-fe-property.ts b/catalog-ui/src/app/models/properties-inputs/derived-fe-property.ts
index 3985b98c93..02b2d0b30d 100644
--- a/catalog-ui/src/app/models/properties-inputs/derived-fe-property.ts
+++ b/catalog-ui/src/app/models/properties-inputs/derived-fe-property.ts
@@ -45,7 +45,8 @@ export class DerivedFEProperty extends PropertyBEModel {
canBeDeclared: boolean;
mapKey: string;
mapKeyError: string;
- mapInlist: boolean
+ mapInlist: boolean;
+ parentMapKey: string;
constructor(property: PropertyBEModel, parentName?: string, createChildOfListOrMap?: boolean, key?:string, value?:any) {
if (!createChildOfListOrMap) { //creating a standard derived prop
@@ -68,26 +69,28 @@ export class DerivedFEProperty extends PropertyBEModel {
this.parentName = parentName;
this.propertiesName = parentName + '#' + this.name;
- if (property.type == PROPERTY_TYPES.LIST) {
- if (property.schemaType != PROPERTY_TYPES.MAP) {
- if(property.value != null) {
- const valueJson = JSON.parse(property.value);
- if (key != '') {
- this.mapKey = key;
- }else{
- let indexNumber = Number(Object.keys(valueJson).sort().reverse()[0]) + 1;
- this.mapKey = indexNumber.toString();
- }
- }else {
- this.mapKey = "0";
+ if (property.type == PROPERTY_TYPES.LIST) {
+ let parentKey : string = null;
+ if(property.value != null) {
+ const valueJson = JSON.parse(property.value);
+ if (key != '') {
+ parentKey = key;
+ }else{
+ let indexNumber = Number(Object.keys(valueJson).sort().reverse()[0]) + 1;
+ parentKey = indexNumber.toString();
}
+ }else {
+ parentKey = "0";
+ }
+ if (property.schemaType != PROPERTY_TYPES.MAP) {
+ this.mapKey = parentKey;
}
this.mapKeyError = null;
this.type = property.schema.property.type;
if (this.type == PROPERTY_TYPES.MAP){
this.mapInlist = true;
+ this.parentMapKey = parentKey;
}
-
this.schema = new SchemaPropertyGroupModel(new SchemaProperty(property.schema.property));
} else { //map
if (key) {
@@ -105,12 +108,18 @@ export class DerivedFEProperty extends PropertyBEModel {
schProp.simpleType = PROPERTY_TYPES.STRING;
this.schema = new SchemaPropertyGroupModel(schProp);
this.schemaType = PROPERTY_TYPES.STRING;
+ if (property instanceof DerivedFEProperty) {
+ this.parentMapKey = property.parentMapKey;
+ if (value != null && typeof value == 'object') {
+ this.toscaFunction = property.toscaFunction;
+ }
+ }
} else {
this.schema = new SchemaPropertyGroupModel(new SchemaProperty(property.schema.property));
}
}
- this.valueObj = (this.type == PROPERTY_TYPES.JSON && typeof value == 'object') ? JSON.stringify(value) : value;
+ this.valueObj = ((this.type == PROPERTY_TYPES.JSON || this.type == PROPERTY_TYPES.MAP) && typeof value == 'object') ? JSON.stringify(value) : value;
if (value != null) {
this.value = typeof value == 'object' ? JSON.stringify(value) : value;
}
diff --git a/catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.html b/catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.html
index a5c2b60ee3..e19986416f 100644
--- a/catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.html
+++ b/catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.html
@@ -44,7 +44,7 @@
<!-- RIGHT CELL OR FULL WIDTH CELL-->
<ng-container *ngIf="propType == derivedPropertyTypes.SIMPLE || property.isDeclared || (property.isToscaFunction() && !property.isChildOfListOrMap) || (property.isChildOfListOrMap && propType == derivedPropertyTypes.MAP && property.schema.property.isSimpleType)">
<div class="table-cell">
- <checkbox class="{{propType == derivedPropertyTypes.MAP ? 'inline-checkBox' : 'inline-checkBox-List'}}" *ngIf="(nestedLevel == 1 && property.isChildOfListOrMap && property.schema.property.isSimpleType)" [(checked)]="property.isSelected" [disabled]="property.isDisabled || readonly || property.mapKey == ''" (checkedChange)="toggleTosca.emit(property)" ></checkbox>
+ <checkbox class="{{propType == derivedPropertyTypes.MAP ? 'inline-checkBox' : 'inline-checkBox-List'}}" *ngIf="((nestedLevel == 1 || nestedLevel == 2) && property.isChildOfListOrMap && property.schema.property.isSimpleType)" [(checked)]="property.isSelected" [disabled]="property.isDisabled || readonly || property.mapKey == ''" (checkedChange)="toggleTosca.emit(property)" ></checkbox>
<dynamic-element class="value-input"
pattern="validationUtils.getValidationPattern(property.type)"
[value]="(property.isDeclared || property.isToscaFunction()) ? property.value : property.valueObj"
diff --git a/catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.ts b/catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.ts
index 548c676285..c5e9c43176 100644
--- a/catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.ts
+++ b/catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.ts
@@ -154,21 +154,24 @@ export class DynamicPropertyComponent {
createNewChildProperty = (): void => {
let mapKeyValue = this.property instanceof DerivedFEProperty ? this.property.mapKey : "";
+ let parentToscaFunction = null;
if (this.property.type == PROPERTY_TYPES.LIST && mapKeyValue === "") {
- if (this.property.schemaType != PROPERTY_TYPES.MAP) {
- 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";
+ 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";
}
}
+ if (this.property.type == PROPERTY_TYPES.MAP && this.property instanceof DerivedFEProperty && this.property.mapInlist) {
+ parentToscaFunction = this.property.toscaFunction;
+ this.property.toscaFunction = null;
+ }
let newProps: Array<DerivedFEProperty> = this.propertiesUtils.createListOrMapChildren(this.property, mapKeyValue, null);
this.propertiesUtils.assignFlattenedChildrenValues(this.property.valueObj, [newProps[0]], this.property.propertiesName);
@@ -177,6 +180,7 @@ export class DynamicPropertyComponent {
} else {
this.addChildPropsToParent.emit(newProps);
}
+ this.property.toscaFunction = parentToscaFunction;
}
addChildProps = (newProps: Array<DerivedFEProperty>, childPropName: string) => {
@@ -221,9 +225,20 @@ export class DynamicPropertyComponent {
deleteListOrMapItem = (item: DerivedFEProperty) => {
if (this.property instanceof PropertyFEModel) {
+ const childMapKey = item.mapKey;
this.removeValueFromParent(item);
this.property.flattenedChildren.splice(this.property.getIndexOfChild(item.propertiesName), this.property.getCountOfChildren(item.propertiesName));
this.expandChildById(item.propertiesName);
+ if (this.property.type == PROPERTY_TYPES.LIST && this.property.schemaType == PROPERTY_TYPES.MAP && childMapKey != null) {
+ let valueObject = JSON.parse(this.property.value);
+ let innerObject = valueObject[item.parentMapKey];
+ delete innerObject[childMapKey];
+ this.property.valueObj = valueObject;
+ this.property.value = JSON.stringify(valueObject);
+ this.property.flattenedChildren[0].valueObj = valueObject;
+ this.property.flattenedChildren[0].value = JSON.stringify(valueObject);
+ this.property.flattenedChildren[0].valueObjIsChanged = true;
+ }
}
}
@@ -234,12 +249,19 @@ export class DynamicPropertyComponent {
if (!itemParent) {
return;
}
- const oldKey = item.getActualMapKey();
+ let oldKey = item.getActualMapKey();
+ let keyIndex : number = 0;
+ if(item.parentMapKey != null && oldKey != null) {
+ keyIndex = 1;
+ }
+ if(item.parentMapKey != null && oldKey == null) {
+ oldKey = item.parentMapKey;
+ }
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.forEach((subToscaItem : SubPropertyToscaFunction) => {
+ if(subToscaItem.subPropertyPath[keyIndex] != oldKey){
+ tempSubToscaFunction.push(subToscaItem);
}
});
this.property.subPropertyToscaFunctions = tempSubToscaFunction;
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts
index e66de41f09..7fef3532a3 100644
--- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts
+++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts
@@ -592,8 +592,11 @@ export class PropertiesAssignmentComponent {
const parts = propertiesNameArray.split("#");
let currentKey = [];
if (this.isListOrMap(checkedInstanceProperty.type)) {
+ if (checkedInstanceProperty.schemaType == PROPERTY_TYPES.MAP) {
+ currentKey.push((<DerivedFEProperty>checkedInstanceProperty.input).parentMapKey);
+ }
currentKey.push((<DerivedFEProperty>checkedInstanceProperty.input).mapKey);
- if (this.isComplexSchemaType(checkedInstanceProperty.schemaType)) {
+ if (checkedInstanceProperty.schemaType != PROPERTY_TYPES.MAP && this.isComplexSchemaType(checkedInstanceProperty.schemaType)) {
currentKey.push(parts.reverse()[0]);
}
}
@@ -636,8 +639,11 @@ export class PropertiesAssignmentComponent {
const parts = propertiesName.split("#");
let currentKey = [];
if (this.isListOrMap(checkedProperty.type)) {
+ if (checkedProperty.schemaType == PROPERTY_TYPES.MAP) {
+ currentKey.push((<DerivedFEProperty>checkedProperty.input).parentMapKey);
+ }
currentKey.push((<DerivedFEProperty>checkedProperty.input).mapKey);
- if (this.isComplexSchemaType(checkedProperty.schemaType)) {
+ if (checkedProperty.schemaType != PROPERTY_TYPES.MAP && this.isComplexSchemaType(checkedProperty.schemaType)) {
currentKey.push(parts.reverse()[0]);
}
}
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts
index f697eed027..9ea0c8f214 100644
--- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts
+++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts
@@ -116,8 +116,11 @@ export class ToscaFunctionComponent implements OnInit, OnChanges {
if (propertiesPath.length > 1){
let keyToFind = [];
if (this.property.type == PROPERTY_TYPES.MAP || this.property.type == PROPERTY_TYPES.LIST) {
+ if (this.property.type == PROPERTY_TYPES.LIST && this.property.schemaType == PROPERTY_TYPES.MAP) {
+ keyToFind.push((<DerivedFEProperty>this.property.input).parentMapKey);
+ }
keyToFind.push((<DerivedFEProperty>this.property.input).mapKey);
- if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.property.schemaType) === -1) {
+ if (this.property.schemaType != PROPERTY_TYPES.MAP && PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.property.schemaType) === -1) {
keyToFind.push(propertiesPath.reverse()[0]);
}
}
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts
index 9fdc8c19aa..b0146cc1cf 100644
--- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts
+++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts
@@ -267,7 +267,8 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
if ((this.typeHasSchema(this.property.type) && this.property instanceof PropertyDeclareAPIModel &&
(<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty) || this.compositionMap) {
if(this.isComplexType(this.property.schemaType) && !this.compositionMap){
- return (<PropertyDeclareAPIModel> this.property).input.type;
+ let propertySchemaType = (<PropertyDeclareAPIModel> this.property).input.type;
+ return propertySchemaType == PROPERTY_TYPES.MAP ? PROPERTY_TYPES.STRING : propertySchemaType;
}else{
return this.property.schema.property.type;
}
@@ -379,7 +380,9 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
if (this.typeHasSchema(this.property.type)) {
if ((this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty) || this.compositionMap) {
if(this.isComplexType(this.property.schemaType) && !this.compositionMap){
- return property.type === (<PropertyDeclareAPIModel> this.property).input.type;
+ let propertySchemaType = (<PropertyDeclareAPIModel> this.property).input.type;
+ propertySchemaType = propertySchemaType == PROPERTY_TYPES.MAP ? PROPERTY_TYPES.STRING : propertySchemaType;
+ return property.type === propertySchemaType;
}else{
return property.type === this.property.schema.property.type;
}