diff options
Diffstat (limited to 'openecomp-be/lib')
2 files changed, 37 insertions, 16 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java index 2236622222..32cfb89418 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java @@ -20,8 +20,6 @@ import org.apache.commons.collections4.CollectionUtils; import org.openecomp.core.converter.errors.CreateToscaObjectErrorBuilder; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.utils.CommonUtil; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; import java.util.HashSet; import java.util.Map; diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java index c66a5ba13b..ecd182f384 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java @@ -1269,16 +1269,25 @@ public class DataModelUtil { CommonUtil.createObjectUsingSetters(interfaceObj, interfaceClass); interfaceDefinition.ifPresent(interfaceDefinitionType1 -> updateInterfaceDefinitionOperations( CommonUtil.getObjectAsMap(interfaceObj), - interfaceDefinitionType1)); + interfaceDefinitionType1, getOperationClass(interfaceClass))); return interfaceDefinition; } catch (Exception ex) { throw new CoreException( new CreateInterfaceObjectErrorBuilder(InterfaceDefinitionType.class.getName(), - interfaceId, ex.getMessage()).build()); + interfaceId, + ex.getMessage()).build()); } } + private static <T extends OperationDefinition, V extends InterfaceDefinition> Class<T> getOperationClass( + Class<V> interfaceClass) { + return interfaceClass.equals(InterfaceDefinitionType.class) + ? (Class<T>) OperationDefinitionType.class + : + (Class<T>) OperationDefinitionTemplate.class; + } + public static Optional<Object> convertInterfaceDefinitionToObj( InterfaceDefinitionType interfaceDefinitionType) { return converInetrfaceToToscaInterfaceObj(interfaceDefinitionType); @@ -1351,21 +1360,35 @@ public class DataModelUtil { return Optional.empty(); } - private static <T extends OperationDefinition> void updateInterfaceDefinitionOperations( - Map<String, Object> interfaceAsMap, - InterfaceDefinition interfaceDefinition) { + private static <T extends OperationDefinition> void updateInterfaceDefinitionOperations + (Map<String, Object> interfaceAsMap, InterfaceDefinition interfaceDefinition, + Class<T> operationClass) { - Set<String> fieldNames = CommonUtil.getClassFieldNames(InterfaceDefinitionType.class); - Optional<? extends OperationDefinition> operationDefinition = Optional.empty(); + Set<String> fieldNames = CommonUtil.getClassFieldNames(interfaceDefinition.getClass()); + Optional<? extends OperationDefinition> operationDefinition; for (Map.Entry<String, Object> entry : interfaceAsMap.entrySet()) { - operationDefinition = createOperation(entry.getKey(), entry.getValue(), fieldNames, - interfaceDefinition instanceof InterfaceDefinitionType ? OperationDefinitionType.class : - OperationDefinitionTemplate.class); - - operationDefinition - .ifPresent(operation -> interfaceDefinition.addOperation(entry.getKey(), operation)); - + operationDefinition = + createOperation(entry.getKey(), entry.getValue(), fieldNames, operationClass); + operationDefinition.ifPresent(operation -> addOperationToInterface(interfaceDefinition, + entry.getKey(), operation)); + } + } + + private static void addOperationToInterface(InterfaceDefinition interfaceDefinition, + String operationName, + OperationDefinition operationDefinition) { + if (interfaceDefinition instanceof InterfaceDefinitionType) { + InterfaceDefinitionType interfaceDefinitionType = + (InterfaceDefinitionType) interfaceDefinition; + interfaceDefinitionType.addOperation(operationName, (OperationDefinitionType) + operationDefinition); + } + if (interfaceDefinition instanceof InterfaceDefinitionTemplate) { + InterfaceDefinitionTemplate interfaceDefinitionTemplate = + (InterfaceDefinitionTemplate) interfaceDefinition; + interfaceDefinitionTemplate.addOperation(operationName, (OperationDefinitionTemplate) + operationDefinition); } } |