From 298c383225d728eb6a04e4b8cb03472f4990de7e Mon Sep 17 00:00:00 2001 From: shiria Date: Wed, 21 Mar 2018 09:11:30 +0200 Subject: Handle OperationDefinition in Tosca Data Model Change-Id: Ib1a7f0c5548fc9c7a98cff1182ff02300353443d Issue-ID: SDC-1154 Signed-off-by: shiria --- .../sdc/tosca/services/DataModelUtil.java | 33 ++++++++++++++-------- 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/main/java') 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 6b1046bb45..97932289b9 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 @@ -40,11 +40,14 @@ import org.openecomp.sdc.tosca.datatypes.model.EntrySchema; import org.openecomp.sdc.tosca.datatypes.model.GroupDefinition; import org.openecomp.sdc.tosca.datatypes.model.Import; import org.openecomp.sdc.tosca.datatypes.model.InterfaceDefinition; +import org.openecomp.sdc.tosca.datatypes.model.InterfaceDefinitionTemplate; import org.openecomp.sdc.tosca.datatypes.model.InterfaceDefinitionType; import org.openecomp.sdc.tosca.datatypes.model.InterfaceType; import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; import org.openecomp.sdc.tosca.datatypes.model.NodeType; import org.openecomp.sdc.tosca.datatypes.model.OperationDefinition; +import org.openecomp.sdc.tosca.datatypes.model.OperationDefinitionTemplate; +import org.openecomp.sdc.tosca.datatypes.model.OperationDefinitionType; import org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition; import org.openecomp.sdc.tosca.datatypes.model.PolicyDefinition; import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition; @@ -1226,8 +1229,8 @@ public class DataModelUtil { return interfaceDefinition; } catch (Exception ex) { throw new CoreException( - new CreateInterfaceObjectErrorBuilder(InterfaceDefinitionType.class.getName(), interfaceId, - ex.getMessage()).build()); + new CreateInterfaceObjectErrorBuilder(InterfaceDefinitionType.class.getName(), + interfaceId, ex.getMessage()).build()); } } @@ -1280,19 +1283,21 @@ public class DataModelUtil { Set fieldNames = CommonUtil.getClassFieldNames(InterfaceType.class); for (Map.Entry entry : interfaceAsMap.entrySet()) { - Optional operationDefinition = - createOperation(entry.getKey(), entry.getValue(), fieldNames); + Optional operationDefinition = + createOperation(entry.getKey(), entry.getValue(), fieldNames, + OperationDefinitionType.class); operationDefinition .ifPresent(operation -> interfaceType.addOperation(entry.getKey(), operation)); } } - private static Optional createOperation(String propertyName, - Object operationCandidate, - Set fieldNames) { + private static Optional createOperation(String propertyName, + Object operationCandidate, + Set fieldNames, + Class operationClass) { if (!fieldNames.contains(propertyName)) { try { - return CommonUtil.createObjectUsingSetters(operationCandidate, OperationDefinition.class); + return CommonUtil.createObjectUsingSetters(operationCandidate, operationClass); } catch (Exception ex) { throw new CoreException( new CreateInterfaceOperationObjectErrorBuilder(propertyName, ex.getMessage()).build()); @@ -1302,14 +1307,18 @@ public class DataModelUtil { return Optional.empty(); } - private static void updateInterfaceDefinitionOperations(Map interfaceAsMap, - InterfaceDefinition interfaceDefinition) { + private static void updateInterfaceDefinitionOperations( + Map interfaceAsMap, + InterfaceDefinition interfaceDefinition) { Set fieldNames = CommonUtil.getClassFieldNames(InterfaceDefinitionType.class); + Optional operationDefinition = Optional.empty(); for (Map.Entry entry : interfaceAsMap.entrySet()) { - Optional operationDefinition = - createOperation(entry.getKey(), entry.getValue(), fieldNames); + operationDefinition = createOperation(entry.getKey(), entry.getValue(), fieldNames, + interfaceDefinition instanceof InterfaceDefinitionType ? OperationDefinitionType.class : + OperationDefinitionTemplate.class); + operationDefinition .ifPresent(operation -> interfaceDefinition.addOperation(entry.getKey(), operation)); -- cgit 1.2.3-korg