summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorimamSidero <imam.hussain@est.tech>2023-04-12 16:02:46 +0100
committerMichael Morris <michael.morris@est.tech>2023-05-09 14:33:29 +0000
commita1ba3abf29613ee9e576a7c96a76ceb921086044 (patch)
treef3f9e4d9c98c6b5bc2d8aba1be01b327dd36b31d
parent3bc3a5c724e9a6ea8a112dca72a9a3128eddca19 (diff)
Support for addition of INDEX token to tosca functions
Providing the capability to add the index token to th tosca function of all types Issue-ID: SDC-4472 Signed-off-by: Imam hussain <imam.hussain@est.tech> Change-Id: Ib7ac80f31710101f50de76bdb7c79abdc637cfe3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandler.java28
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/ToscaFunctionValidatorImpl.java4
-rw-r--r--catalog-ui/src/app/models/tosca-get-function.ts12
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.html4
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts62
-rw-r--r--catalog-ui/src/assets/languages/en_US.json1
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java17
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java25
-rw-r--r--common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java4
10 files changed, 133 insertions, 28 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandler.java
index 2a7af62a0c..0b9432b3a1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ToscaFunctionYamlParsingHandler.java
@@ -23,8 +23,11 @@ package org.openecomp.sdc.be.components.csar;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.datatypes.elements.CustomYamlFunction;
import org.openecomp.sdc.be.datatypes.elements.ToscaConcatFunction;
import org.openecomp.sdc.be.datatypes.elements.ToscaCustomFunction;
@@ -51,7 +54,9 @@ public class ToscaFunctionYamlParsingHandler {
}
final List<String> functionParameters;
try {
- functionParameters = (List<String>) functionValueObj;
+ functionParameters = ((List<Object>) functionValueObj).stream()
+ .map(object -> Objects.toString(object, null))
+ .collect(Collectors.toList());
} catch (final ClassCastException ignored) {
return Optional.empty();
}
@@ -66,7 +71,14 @@ public class ToscaFunctionYamlParsingHandler {
toscaGetFunction.setPropertySource(PropertySource.INSTANCE);
toscaGetFunction.setSourceName(propertySourceType);
}
- toscaGetFunction.setPropertyPathFromSource(functionParameters.subList(1, functionParameters.size()));
+ List<String> propertySourceIndex = functionParameters.subList(1, functionParameters.size());
+ String toscaIndexValue = propertySourceIndex.get((propertySourceIndex.size() - 1));
+ if (propertySourceIndex.size() > 1 && (toscaIndexValue.equalsIgnoreCase("INDEX") || StringUtils.isNumeric(toscaIndexValue))) {
+ toscaGetFunction.setPropertyPathFromSource(propertySourceIndex.subList(0,(propertySourceIndex.size() - 1)));
+ toscaGetFunction.setToscaIndex(toscaIndexValue);
+ } else {
+ toscaGetFunction.setPropertyPathFromSource(propertySourceIndex);
+ }
final String propertyName = toscaGetFunction.getPropertyPathFromSource().get(toscaGetFunction.getPropertyPathFromSource().size() - 1);
toscaGetFunction.setPropertyName(propertyName);
return Optional.of(toscaGetFunction);
@@ -85,11 +97,19 @@ public class ToscaFunctionYamlParsingHandler {
} else {
final List<String> functionParameters;
try {
- functionParameters = (List<String>) functionValueObj;
+ functionParameters = ((List<Object>) functionValueObj).stream()
+ .map(object -> Objects.toString(object, null))
+ .collect(Collectors.toList());
} catch (final ClassCastException ignored) {
return Optional.empty();
}
- toscaGetFunction.setPropertyPathFromSource(functionParameters);
+ String toscaIndexValue = functionParameters.get((functionParameters.size() - 1));
+ if (functionParameters.size() > 1 && (toscaIndexValue.equalsIgnoreCase("INDEX") || StringUtils.isNumeric(toscaIndexValue))) {
+ toscaGetFunction.setPropertyPathFromSource(functionParameters.subList(0,(functionParameters.size() - 1)));
+ toscaGetFunction.setToscaIndex(toscaIndexValue);
+ } else {
+ toscaGetFunction.setPropertyPathFromSource(functionParameters);
+ }
}
final String propertyName = toscaGetFunction.getPropertyPathFromSource().get(toscaGetFunction.getPropertyPathFromSource().size() - 1);
toscaGetFunction.setPropertyName(propertyName);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
index f43f7de860..16ec9ade96 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
@@ -2543,11 +2543,11 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
referredProperty = findSubProperty(referredProperty, toscaGetFunction, model);
}
- if (!property.getType().equals(referredProperty.getType())) {
+ if (!property.getType().equals(referredProperty.getType()) && !"list".equalsIgnoreCase(referredProperty.getType())) {
throw ToscaGetFunctionExceptionSupplier
.propertyTypeDiverge(toscaGetFunction.getType(), referredProperty.getType(), property.getType()).get();
}
- if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getSchemaType())) {
+ if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getType()) && !referredProperty.getSchemaType().equals(property.getSchemaType())) {
throw ToscaGetFunctionExceptionSupplier
.propertySchemaDiverge(toscaGetFunction.getType(), referredProperty.getSchemaType(), property.getSchemaType()).get();
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/ToscaFunctionValidatorImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/ToscaFunctionValidatorImpl.java
index 083a03fb42..1e485d9b27 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/ToscaFunctionValidatorImpl.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/validation/ToscaFunctionValidatorImpl.java
@@ -129,11 +129,11 @@ public class ToscaFunctionValidatorImpl implements ToscaFunctionValidator {
referredProperty = findSubProperty(referredProperty, toscaGetFunction, model);
}
- if (!property.getType().equals(referredProperty.getType())) {
+ if (!property.getType().equals(referredProperty.getType()) && !"list".equalsIgnoreCase(referredProperty.getType())) {
throw ToscaGetFunctionExceptionSupplier
.propertyTypeDiverge(toscaGetFunction.getType(), referredProperty.getType(), property.getType()).get();
}
- if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getSchemaType())) {
+ if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getType()) && !referredProperty.getSchemaType().equals(property.getSchemaType())) {
throw ToscaGetFunctionExceptionSupplier
.propertySchemaDiverge(toscaGetFunction.getType(), referredProperty.getSchemaType(), property.getSchemaType()).get();
}
diff --git a/catalog-ui/src/app/models/tosca-get-function.ts b/catalog-ui/src/app/models/tosca-get-function.ts
index 7e6c5ad739..3bb207700b 100644
--- a/catalog-ui/src/app/models/tosca-get-function.ts
+++ b/catalog-ui/src/app/models/tosca-get-function.ts
@@ -34,7 +34,8 @@ export class ToscaGetFunction implements ToscaFunction, ToscaFunctionParameter {
sourceName: string;
functionType: ToscaGetFunctionType;
propertyPathFromSource: Array<string>;
- value: any
+ value: any;
+ toscaIndex: string;
constructor(toscaGetFunction?: ToscaGetFunction) {
if (!toscaGetFunction) {
@@ -48,6 +49,7 @@ export class ToscaGetFunction implements ToscaFunction, ToscaFunctionParameter {
this.sourceUniqueId = toscaGetFunction.sourceUniqueId;
this.sourceName = toscaGetFunction.sourceName;
this.functionType = toscaGetFunction.functionType;
+ this.toscaIndex = toscaGetFunction.toscaIndex;
if (toscaGetFunction.propertyPathFromSource) {
this.propertyPathFromSource = [...toscaGetFunction.propertyPathFromSource];
}
@@ -69,20 +71,20 @@ export class ToscaGetFunction implements ToscaFunction, ToscaFunctionParameter {
private buildGetInputFunctionValue(): Object {
if (this.propertyPathFromSource.length === 1) {
- return {[this.functionType.toLowerCase()]: this.propertyPathFromSource[0]};
+ return {[this.functionType.toLowerCase()]: [this.propertyPathFromSource[0], this.toscaIndex]};
}
- return {[this.functionType.toLowerCase()]: this.propertyPathFromSource};
+ return {[this.functionType.toLowerCase()]: [this.propertyPathFromSource, this.toscaIndex]};
}
private buildFunctionValueWithPropertySource(): Object {
if (this.propertySource == PropertySource.SELF) {
return {
- [this.functionType.toLowerCase()]: [PropertySource.SELF, ...this.propertyPathFromSource]
+ [this.functionType.toLowerCase()]: [PropertySource.SELF, ...this.propertyPathFromSource, this.toscaIndex]
};
}
if (this.propertySource == PropertySource.INSTANCE) {
return {
- [this.functionType.toLowerCase()]: [this.sourceName, ...this.propertyPathFromSource]
+ [this.functionType.toLowerCase()]: [this.sourceName, ...this.propertyPathFromSource,this.toscaIndex]
};
}
}
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.html b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.html
index 62cd697f8c..387bb5cbcb 100644
--- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.html
+++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.html
@@ -28,9 +28,11 @@
</div>
<div *ngIf="showPropertyDropdown()" class="i-sdc-form-item">
<label class="i-sdc-form-label required">{{dropdownValuesLabel}}</label>
- <select formControlName="selectedProperty">
+ <select formControlName="selectedProperty" (change)="onPropertyValueChange()">
<option *ngFor="let value of propertyDropdownList" [ngValue]="value">{{value.propertyLabel}}</option>
</select>
+ <label class="i-sdc-form-label required" *ngIf="toscaIndexFlag">Index</label>
+ <input type="text" *ngIf="toscaIndexFlag" formControlName="toscaIndex" (change)="indexTokenChange()"/>
</div>
<div *ngIf="dropDownErrorMsg" class="tosca-error">{{dropDownErrorMsg}}</div>
</form>
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 36ead13117..fe6f2f143c 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
@@ -52,7 +52,8 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
formGroup: FormGroup = new FormGroup({
'selectedProperty': new FormControl(undefined, Validators.required),
- 'propertySource': new FormControl(undefined, Validators.required)
+ 'propertySource': new FormControl(undefined, Validators.required),
+ 'toscaIndex' : new FormControl(undefined)
});
isLoading: boolean = false;
@@ -61,6 +62,7 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
instanceNameAndIdMap: Map<string, string> = new Map<string, string>();
dropdownValuesLabel: string;
dropDownErrorMsg: string;
+ toscaIndexFlag: boolean = false;
private isInitialized: boolean = false;
private componentMetadata: ComponentMetadata;
@@ -78,8 +80,14 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
if (!this.isInitialized) {
return;
}
+ let formGroupStatus : boolean = this.formGroup.valid;
+ const selectedProperty: PropertyDropdownValue = this.formGroup.value.selectedProperty;
+ if (selectedProperty != null && selectedProperty.isList && formGroupStatus
+ && (this.toscaIndex.value == null || this.toscaIndex.value == '')) {
+ formGroupStatus = false;
+ }
this.onValidityChange.emit({
- isValid: this.formGroup.valid,
+ isValid: formGroupStatus,
toscaGetFunction: this.formGroup.valid ? this.buildGetFunctionFromForm() : undefined
});
if (this.formGroup.valid) {
@@ -132,6 +140,10 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
} else {
subscriber.next();
}
+ if (this.toscaGetFunction.toscaIndex != null) {
+ this.toscaIndexFlag = true;
+ this.toscaIndex.setValue(this.toscaGetFunction.toscaIndex);
+ }
});
}
@@ -154,6 +166,7 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
toscaGetFunction.propertyUniqueId = selectedProperty.propertyId;
toscaGetFunction.propertyName = selectedProperty.propertyName;
toscaGetFunction.propertyPathFromSource = selectedProperty.propertyPath;
+ toscaGetFunction.toscaIndex = this.toscaIndex.value;
return toscaGetFunction;
}
@@ -219,6 +232,7 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
private resetPropertyDropdown(): void {
this.dropDownErrorMsg = undefined;
this.selectedProperty.reset();
+ this.toscaIndex.reset();
this.propertyDropdownList = [];
}
@@ -357,7 +371,8 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
propertyName: property.name,
propertyId: property.uniqueId,
propertyLabel: property.name,
- propertyPath: [property.name]
+ propertyPath: [property.name],
+ isList: property.type === PROPERTY_TYPES.LIST
});
} else if (this.isComplexType(property.type)) {
this.fillPropertyDropdownWithMatchingChildProperties(property);
@@ -378,7 +393,8 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
propertyName: dataTypeProperty.name,
propertyId: parentPropertyList[0].uniqueId,
propertyLabel: parentPropertyList.map(property => property.name).join('->') + '->' + dataTypeProperty.name,
- propertyPath: [...parentPropertyList.map(property => property.name), dataTypeProperty.name]
+ propertyPath: [...parentPropertyList.map(property => property.name), dataTypeProperty.name],
+ isList : dataTypeProperty.type === PROPERTY_TYPES.LIST
});
} else if (this.isComplexType(dataTypeProperty.type)) {
this.fillPropertyDropdownWithMatchingChildProperties(dataTypeProperty, [...parentPropertyList])
@@ -390,23 +406,24 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
if (this.property.type === PROPERTY_TYPES.ANY) {
return true;
}
+ let validPropertyType = property.type === PROPERTY_TYPES.LIST ? property.schemaType : property.type;
if (this.typeHasSchema(this.property.type)) {
if ((this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty) || this.compositionMap) {
let childObject : DerivedFEProperty = (<DerivedFEProperty>(<PropertyDeclareAPIModel> this.property).input);
let childSchemaType = this.property.schemaType != null ? this.property.schemaType : childObject.type;
if(this.isComplexType(childSchemaType) && !this.compositionMap){
if (childObject.type == PROPERTY_TYPES.MAP && childObject.isChildOfListOrMap) {
- return property.type === PROPERTY_TYPES.STRING;
+ return validPropertyType === PROPERTY_TYPES.STRING;
}
- return property.type === childObject.type;
+ return validPropertyType === childObject.type;
}else{
- return property.type === this.property.schema.property.type;
+ return validPropertyType === this.property.schema.property.type;
}
}
if (!property.schema || !property.schema.property) {
return false;
}
- return property.type === this.property.type && this.property.schema.property.type === property.schema.property.type;
+ return validPropertyType === this.property.type && this.property.schema.property.type === property.schema.property.type;
}
if (this.property.schema.property.isDataType && this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel>this.property).propertiesName){
let typeToMatch = (<PropertyDeclareAPIModel> this.property).input.type;
@@ -414,10 +431,10 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
if (childObject.type == PROPERTY_TYPES.MAP && childObject.isChildOfListOrMap) {
typeToMatch = PROPERTY_TYPES.STRING;
}
- return property.type === typeToMatch;
+ return validPropertyType === typeToMatch;
}
- return property.type === this.property.type;
+ return validPropertyType === this.property.type;
}
private getType(propertyPath:string[], type: string): string {
@@ -467,12 +484,32 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
onPropertySourceChange(): void {
this.selectedProperty.reset();
+ this.toscaIndex.reset();
if (!this.functionType || !this.propertySource.valid) {
return;
}
this.loadPropertyDropdown();
}
+ onPropertyValueChange(): void {
+ this.toscaIndexFlag = false;
+ this.toscaIndex.reset();
+ const selectedProperty: PropertyDropdownValue = this.selectedProperty.value;
+ if (selectedProperty.isList) {
+ this.toscaIndexFlag = true;
+ }
+ }
+
+ indexTokenChange(): void {
+ if ((this.toscaIndex.value).toLowerCase() === 'index') {
+ return;
+ }
+ let indexTokenValue = Number(this.toscaIndex.value);
+ if (isNaN(indexTokenValue)) {
+ this.toscaIndex.reset();
+ }
+ }
+
showPropertySourceDropdown(): boolean {
return this.isGetProperty() || this.isGetAttribute();
}
@@ -489,6 +526,10 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
return this.formGroup.get('selectedProperty') as FormControl;
}
+ private get toscaIndex(): FormControl {
+ return this.formGroup.get('toscaIndex') as FormControl;
+ }
+
}
export interface PropertyDropdownValue {
@@ -496,6 +537,7 @@ export interface PropertyDropdownValue {
propertyId: string;
propertyLabel: string;
propertyPath: Array<string>;
+ isList: boolean;
}
export interface ToscaGetFunctionValidationEvent {
diff --git a/catalog-ui/src/assets/languages/en_US.json b/catalog-ui/src/assets/languages/en_US.json
index 18813280d6..ff90fb854e 100644
--- a/catalog-ui/src/assets/languages/en_US.json
+++ b/catalog-ui/src/assets/languages/en_US.json
@@ -523,6 +523,7 @@
"=========== PROPERTIES ASSIGNMENT TOSCA FUNCTION BUTTON ===========": "",
"TOSCA_FUNCTION_LABEL": "TOSCA function",
"TOSCA_FUNCTION_PROPERTY_SOURCE_LABEL": "Property Source",
+ "TOSCA_FUNCTION_PROPERTY_INDEX": "Index",
"TOSCA_FUNCTION_CLEAR_VALUE_BUTTON": "Clear Value",
"TOSCA_FUNCTION_MODAL_TITLE": "Set value using TOSCA functions",
"INPUT_DROPDOWN_LABEL": "Input",
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java
index ec3459989e..2e57a4158a 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java
@@ -113,6 +113,7 @@ public class ToscaFunctionJsonDeserializer extends StdDeserializer<ToscaFunction
toscaGetFunction.setSourceUniqueId(getAsTextOrElseNull(node, "sourceUniqueId"));
toscaGetFunction.setPropertyName(getAsTextOrElseNull(node, "propertyName"));
toscaGetFunction.setPropertyUniqueId(getAsTextOrElseNull(node, "propertyUniqueId"));
+ toscaGetFunction.setToscaIndex(getNumberAsTextOrElseNull(node, "toscaIndex"));
final String propertySource = getAsTextOrElseNull(node, "propertySource");
if (StringUtils.isNotEmpty(propertySource)) {
final PropertySource propertySource1 = PropertySource.findType(propertySource).orElseThrow(() ->
@@ -145,6 +146,22 @@ public class ToscaFunctionJsonDeserializer extends StdDeserializer<ToscaFunction
return jsonNode.asText();
}
+ private Object getNumberAsTextOrElseNull(final JsonNode node, final String fieldName) {
+ final JsonNode jsonNode = node.get(fieldName);
+ if (jsonNode == null) {
+ return null;
+ }
+ if (jsonNode.asText().equalsIgnoreCase("INDEX")) {
+ return jsonNode.asText();
+ }
+ try {
+ Integer.parseInt(jsonNode.asText());
+ } catch(Exception e) {
+ return null;
+ }
+ return Integer.parseInt(jsonNode.asText());
+ }
+
private ToscaConcatFunction deserializeConcatFunction(final JsonNode concatFunctionJsonNode,
final DeserializationContext context) throws IOException {
final var toscaConcatFunction = new ToscaConcatFunction();
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java
index 4fe3f3ae13..0ef417f8e2 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java
@@ -30,6 +30,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.datatypes.enums.PropertySource;
import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
@@ -43,6 +44,7 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct
private String sourceName;
private ToscaGetFunctionType functionType;
private List<String> propertyPathFromSource = new ArrayList<>();
+ private Object toscaIndex;
public ToscaGetFunctionDataDefinition() {
//necessary for JSON conversions
@@ -87,6 +89,12 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct
);
}
if (propertySource == PropertySource.SELF) {
+ if (toscaIndex != null) {
+ Object toscaIndexValue = StringUtils.isNumeric(toscaIndex.toString()) ? Integer.parseInt(toscaIndex.toString()) : toscaIndex;
+ return Map.of(functionType.getFunctionName(),
+ Stream.concat(Stream.of(PropertySource.SELF.getName()), Stream.concat(propertyPathFromSource.stream(),Stream.of(toscaIndexValue))).collect(Collectors.toList())
+ );
+ }
return Map.of(functionType.getFunctionName(),
Stream.concat(Stream.of(PropertySource.SELF.getName()), propertyPathFromSource.stream()).collect(Collectors.toList())
);
@@ -97,6 +105,12 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct
String.format("sourceName is required in order to generate the %s from INSTANCE value", functionType.getFunctionName())
);
}
+ if (toscaIndex != null) {
+ Object toscaIndexValue = StringUtils.isNumeric(toscaIndex.toString()) ? Integer.parseInt(toscaIndex.toString()) : toscaIndex;
+ return Map.of(functionType.getFunctionName(),
+ Stream.concat(Stream.of(sourceName), Stream.concat(propertyPathFromSource.stream(),Stream.of(toscaIndexValue))).collect(Collectors.toList())
+ );
+ }
return Map.of(functionType.getFunctionName(),
Stream.concat(Stream.of(sourceName), propertyPathFromSource.stream()).collect(Collectors.toList())
);
@@ -106,10 +120,17 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct
}
private Map<String, Object> buildGetInputFunctionValue() {
+ List<Object> propertySourceCopy = new ArrayList<Object>(this.propertyPathFromSource);
+ List<Object> propertySourceOneCopy = new ArrayList<>();
+ propertySourceOneCopy.add(this.propertyPathFromSource.get(0));
+ if (toscaIndex != null) {
+ propertySourceCopy.add(toscaIndex);
+ propertySourceOneCopy.add(toscaIndex);
+ }
if (this.propertyPathFromSource.size() == 1) {
- return Map.of(this.functionType.getFunctionName(), this.propertyPathFromSource.get(0));
+ return Map.of(this.functionType.getFunctionName(), propertySourceOneCopy);
}
- return Map.of(this.functionType.getFunctionName(), this.propertyPathFromSource);
+ return Map.of(this.functionType.getFunctionName(), propertySourceCopy);
}
@Override
diff --git a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java
index 5daeaa5aad..581f62a91f 100644
--- a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java
+++ b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java
@@ -61,8 +61,8 @@ class ToscaGetFunctionDataDefinitionTest {
final Map<?, ?> getInputJsonAsMap = convertJsonStringToMap(actualValue);
assertTrue(getInputJsonAsMap.containsKey(ToscaGetFunctionType.GET_INPUT.getFunctionName()));
final Object value = getInputJsonAsMap.get(ToscaGetFunctionType.GET_INPUT.getFunctionName());
- assertTrue(value instanceof String);
- assertEquals(value, propertyName);
+ assertTrue(value instanceof List);
+ assertEquals(((List<String>)value).get(0), propertyName);
}
@Test