import fj.data.Either;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.onap.sdc.tosca.datatypes.model.PropertyType;
private <T extends PropertyDataDefinition> void validateToscaGetFunction(T property, Component parentComponent) {
final ToscaGetFunctionDataDefinition toscaGetFunction = (ToscaGetFunctionDataDefinition) property.getToscaFunction();
validateGetToscaFunctionAttributes(toscaGetFunction);
- validateGetPropertySource(toscaGetFunction.getFunctionType(), toscaGetFunction.getPropertySource());
- if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_INPUT) {
- validateGetFunction(property, parentComponent.getInputs(), parentComponent.getModel());
- return;
- }
- if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_PROPERTY) {
- if (toscaGetFunction.getPropertySource() == PropertySource.SELF) {
- validateGetFunction(property, parentComponent.getProperties(), parentComponent.getModel());
- } else if (toscaGetFunction.getPropertySource() == PropertySource.INSTANCE) {
- final ComponentInstance componentInstance =
- parentComponent.getComponentInstanceById(toscaGetFunction.getSourceUniqueId())
+ final ToscaGetFunctionType functionType = toscaGetFunction.getFunctionType();
+ validateGetPropertySource(functionType, toscaGetFunction.getPropertySource());
+ final String model = parentComponent.getModel();
+ switch (functionType) {
+ case GET_INPUT:
+ validateGetFunction(property, parentComponent.getInputs(), model);
+ break;
+ case GET_PROPERTY:
+ if (toscaGetFunction.getPropertySource() == PropertySource.SELF) {
+ validateGetFunction(property, parentComponent.getProperties(), model);
+ } else if (toscaGetFunction.getPropertySource() == PropertySource.INSTANCE) {
+ final ComponentInstance componentInstance =
+ parentComponent.getComponentInstanceById(toscaGetFunction.getSourceUniqueId())
+ .orElseThrow(ToscaGetFunctionExceptionSupplier.instanceNotFound(toscaGetFunction.getSourceName()));
+ validateGetFunction(property, componentInstance.getProperties(), model);
+ }
+ break;
+ case GET_ATTRIBUTE:
+ if (toscaGetFunction.getPropertySource() == PropertySource.SELF) {
+ validateGetFunction(property, combine(parentComponent.getProperties(), parentComponent.getAttributes()), model);
+ } else if (toscaGetFunction.getPropertySource() == PropertySource.INSTANCE) {
+ final ComponentInstance componentInstance = parentComponent.getComponentInstanceById(toscaGetFunction.getSourceUniqueId())
.orElseThrow(ToscaGetFunctionExceptionSupplier.instanceNotFound(toscaGetFunction.getSourceName()));
- validateGetFunction(property, componentInstance.getProperties(), parentComponent.getModel());
- }
-
- return;
- }
- if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_ATTRIBUTE) {
- if (toscaGetFunction.getPropertySource() == PropertySource.SELF) {
- validateGetFunction(property, parentComponent.getAttributes(), parentComponent.getModel());
- } else if (toscaGetFunction.getPropertySource() == PropertySource.INSTANCE) {
- final ComponentInstance componentInstance =
- parentComponent.getComponentInstanceById(toscaGetFunction.getSourceUniqueId())
- .orElseThrow(ToscaGetFunctionExceptionSupplier.instanceNotFound(toscaGetFunction.getSourceName()));
- validateGetFunction(property, componentInstance.getAttributes(), parentComponent.getModel());
- }
-
- return;
+ validateGetFunction(property, combine(componentInstance.getProperties(), componentInstance.getAttributes()), model);
+ }
+ break;
+ default:
+ throw ToscaGetFunctionExceptionSupplier.functionNotSupported(functionType).get();
}
+ }
- throw ToscaGetFunctionExceptionSupplier.functionNotSupported(toscaGetFunction.getFunctionType()).get();
+ private List<? extends ToscaPropertyData> combine(final List<? extends ToscaPropertyData> parentProperties,
+ final List<? extends ToscaPropertyData> parentAttributes) {
+ if (CollectionUtils.isNotEmpty(parentProperties) && CollectionUtils.isNotEmpty(parentAttributes)) {
+ return Stream.concat(parentProperties.stream(), parentAttributes.stream()).collect(Collectors.toList());
+ }
+ if (CollectionUtils.isEmpty(parentProperties)) {
+ return parentAttributes;
+ }
+ return parentProperties;
}
private <T extends PropertyDataDefinition> void validateGetFunction(final T property,
- final List<? extends ToscaPropertyData> parentProperties,
- final String model) {
+ final List<? extends ToscaPropertyData> parentProperties,
+ final String model) {
final ToscaGetFunctionDataDefinition toscaGetFunction = (ToscaGetFunctionDataDefinition) property.getToscaFunction();
if (CollectionUtils.isEmpty(parentProperties)) {
throw ToscaGetFunctionExceptionSupplier
* ============LICENSE_END=========================================================
*/
-/**
- * Created by ob0695 on 2/23/2017.
- */
-import from = require("core-js/fn/array/from");
export * from './models/activity';
export * from './models/additional-information';
export * from './models/app-config';
export * from './models/graph/zones/zone';
export * from './models/graph/zones/zone-instance';
export * from './models/csar-component';
-//export * from './models/data-type-properties';
export * from './models/properties-inputs/property-be-model';
export * from './models/properties-inputs/property-fe-model';
export * from './models/properties-inputs/property-fe-map';
export * from './models/properties-inputs/property-input-detail';
export * from './models/properties-inputs/input-fe-model';
export * from './models/properties-inputs/simple-flat-property';
+export * from './models/attributes-outputs/attribute-be-model';
+export * from './models/attributes-outputs/attribute-fe-model';
+export * from './models/attributes-outputs/attribute-fe-map';
+export * from './models/attributes-outputs/attribute-output-detail';
+export * from './models/attributes-outputs/attribute-declare-api-model';
+export * from './models/attributes-outputs/derived-fe-attribute';
+export * from './models/attributes-outputs/output-be-model';
+export * from './models/attributes-outputs/output-fe-model';
+export * from './models/attributes-outputs/simple-flat-attribute';
export * from './models/data-types-map';
export * from './models/data-types';
export * from './models/distribution';
export * from './models/tosca-presentation';
export * from './models/node-types';
export * from './models/capability-types';
-export * from './models/service-csar';
\ No newline at end of file
+export * from './models/service-csar';
*/
import {Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges} from '@angular/core';
-import {AttributeModel, ComponentMetadata, DataTypeModel, PropertyBEModel, PropertyModel} from 'app/models';
+import {AttributeBEModel, ComponentMetadata, DataTypeModel, PropertyBEModel, PropertyModel} from 'app/models';
import {TopologyTemplateService} from "../../../../services/component-services/topology-template.service";
import {WorkspaceService} from "../../../workspace/workspace.service";
import {PropertiesService} from "../../../../services/properties.service";
this.startLoading();
const propertiesObservable: Observable<ComponentGenericResponse> = this.getPropertyObservable();
propertiesObservable.subscribe( (response: ComponentGenericResponse) => {
- const properties: Array<PropertyBEModel | AttributeModel> = this.extractProperties(response);
+ const properties: Array<PropertyBEModel | AttributeBEModel> = this.extractProperties(response);
if (!properties || properties.length === 0) {
const msgCode = this.getNotFoundMsgCode();
this.dropDownErrorMsg = this.translateService.translate(msgCode, {type: this.propertyTypeToString()});
return this.property.type;
}
- private extractProperties(componentGenericResponse: ComponentGenericResponse): Array<PropertyBEModel | AttributeModel> {
+ private extractProperties(componentGenericResponse: ComponentGenericResponse): Array<PropertyBEModel | AttributeBEModel> {
if (this.isGetInput()) {
return componentGenericResponse.inputs;
}
- const propertySource = this.propertySource.value;
+ const instanceId = this.instanceNameAndIdMap.get(this.propertySource.value);
if (this.isGetProperty()) {
if (this.isPropertySourceSelf()) {
return componentGenericResponse.properties;
}
- const componentInstanceProperties: PropertyModel[] = componentGenericResponse.componentInstancesProperties[this.instanceNameAndIdMap.get(propertySource)];
- return this.removeSelectedProperty(componentInstanceProperties);
+ return this.removeSelectedProperty(componentGenericResponse.componentInstancesProperties[instanceId]);
}
if (this.isPropertySourceSelf()) {
- return componentGenericResponse.attributes;
+ return [...(componentGenericResponse.attributes || []), ...(componentGenericResponse.properties || [])];
}
- return componentGenericResponse.componentInstancesAttributes[this.instanceNameAndIdMap.get(propertySource)];
+ return [...(componentGenericResponse.componentInstancesAttributes[instanceId] || []),
+ ...(componentGenericResponse.componentInstancesProperties[instanceId] || [])];
}
private isPropertySourceSelf() {
}
if (this.isGetAttribute()) {
if (this.isPropertySourceSelf()) {
- return this.topologyTemplateService.findAllComponentAttributes(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
+ return this.topologyTemplateService.findAllComponentAttributesAndProperties(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
}
- return this.topologyTemplateService.findAllComponentInstanceAttributes(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
+ return this.topologyTemplateService.getComponentInstanceAttributesAndProperties(this.componentMetadata.uniqueId, this.componentMetadata.componentType);
}
}
this.propertyDropdownList.sort((a, b) => a.propertyLabel.localeCompare(b.propertyLabel));
}
- private addPropertiesToDropdown(properties: Array<PropertyBEModel | AttributeModel>): void {
+ private addPropertiesToDropdown(properties: Array<PropertyBEModel | AttributeBEModel>): void {
for (const property of properties) {
if (this.hasSameType(property)) {
this.addPropertyToDropdown({
}
}
- private fillPropertyDropdownWithMatchingChildProperties(inputProperty: PropertyBEModel | AttributeModel,
- parentPropertyList: Array<PropertyBEModel | AttributeModel> = []): void {
+ private fillPropertyDropdownWithMatchingChildProperties(inputProperty: PropertyBEModel | AttributeBEModel,
+ parentPropertyList: Array<PropertyBEModel | AttributeBEModel> = []): void {
const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, inputProperty.type);
if (!dataTypeFound || !dataTypeFound.properties) {
return;
});
}
- private hasSameType(property: PropertyBEModel | AttributeModel) {
+ private hasSameType(property: PropertyBEModel | AttributeBEModel) {
if (this.typeHasSchema(this.property.type)) {
if (!property.schema || !property.schema.property) {
return false;
export interface ToscaGetFunctionValidationEvent {
isValid: boolean,
toscaGetFunction: ToscaGetFunction,
-}
\ No newline at end of file
+}
return this.getComponentDataByFieldsName(componentType, componentUniqueId, [COMPONENT_FIELDS.COMPONENT_ATTRIBUTES]);
}
+ findAllComponentAttributesAndProperties(componentType: string, componentUniqueId: string): Observable<ComponentGenericResponse> {
+ return this.getComponentDataByFieldsName(componentType, componentUniqueId, [COMPONENT_FIELDS.COMPONENT_ATTRIBUTES, COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
+ }
+
getCapabilitiesAndRequirements(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES]);
}