diff options
author | talio <tali.orenbach@amdocs.com> | 2018-03-25 13:25:43 +0300 |
---|---|---|
committer | Avi Gaffa <avi.gaffa@amdocs.com> | 2018-04-09 12:14:23 +0000 |
commit | ad8669b1b40e199a4b39832d81203d16f720941c (patch) | |
tree | d5466f2d5b5628446b962f5dd44ebd06fbd3b3d6 /openecomp-be/lib/openecomp-tosca-lib/src/main/java | |
parent | d9d360318e1a4ae67958356d0fe3fb207f90fbf8 (diff) |
Interface definition
Add handling in reading and writing operation definition
Change-Id: I0fd5770b19a8cf5d5a8d2b93a549fd66a3b1e728
Issue-ID: SDC-1161
Signed-off-by: talio <tali.orenbach@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/main/java')
-rw-r--r-- | openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java | 51 |
1 files changed, 37 insertions, 14 deletions
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); } } |