From ad8669b1b40e199a4b39832d81203d16f720941c Mon Sep 17 00:00:00 2001 From: talio Date: Sun, 25 Mar 2018 13:25:43 +0300 Subject: Interface definition Add handling in reading and writing operation definition Change-Id: I0fd5770b19a8cf5d5a8d2b93a549fd66a3b1e728 Issue-ID: SDC-1161 Signed-off-by: talio --- .../sdc/tosca/services/DataModelUtil.java | 51 ++++++++++++++++------ 1 file changed, 37 insertions(+), 14 deletions(-) (limited to 'openecomp-be/lib/openecomp-tosca-lib/src') 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 Class getOperationClass( + Class interfaceClass) { + return interfaceClass.equals(InterfaceDefinitionType.class) + ? (Class) OperationDefinitionType.class + : + (Class) OperationDefinitionTemplate.class; + } + public static Optional convertInterfaceDefinitionToObj( InterfaceDefinitionType interfaceDefinitionType) { return converInetrfaceToToscaInterfaceObj(interfaceDefinitionType); @@ -1351,21 +1360,35 @@ public class DataModelUtil { return Optional.empty(); } - private static void updateInterfaceDefinitionOperations( - Map interfaceAsMap, - InterfaceDefinition interfaceDefinition) { + private static void updateInterfaceDefinitionOperations + (Map interfaceAsMap, InterfaceDefinition interfaceDefinition, + Class operationClass) { - Set fieldNames = CommonUtil.getClassFieldNames(InterfaceDefinitionType.class); - Optional operationDefinition = Optional.empty(); + Set fieldNames = CommonUtil.getClassFieldNames(interfaceDefinition.getClass()); + Optional operationDefinition; for (Map.Entry 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); } } -- cgit 1.2.3-korg