diff options
author | shiria <shiri.amichai@amdocs.com> | 2018-03-21 09:11:30 +0200 |
---|---|---|
committer | Oren Kleks <orenkle@amdocs.com> | 2018-03-21 12:24:17 +0000 |
commit | 298c383225d728eb6a04e4b8cb03472f4990de7e (patch) | |
tree | 5b975c4620ad350ff46060f1427a6accfc12ec2c /openecomp-be/lib/openecomp-tosca-lib/src/main/java/org | |
parent | f59a22539d5b372e2425c39963547985379d6990 (diff) |
Handle OperationDefinition in Tosca Data Model
Change-Id: Ib1a7f0c5548fc9c7a98cff1182ff02300353443d
Issue-ID: SDC-1154
Signed-off-by: shiria <shiri.amichai@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/main/java/org')
-rw-r--r-- | openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java | 33 |
1 files changed, 21 insertions, 12 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 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<String> fieldNames = CommonUtil.getClassFieldNames(InterfaceType.class); for (Map.Entry<String, Object> entry : interfaceAsMap.entrySet()) { - Optional<OperationDefinition> operationDefinition = - createOperation(entry.getKey(), entry.getValue(), fieldNames); + Optional<? extends OperationDefinition> operationDefinition = + createOperation(entry.getKey(), entry.getValue(), fieldNames, + OperationDefinitionType.class); operationDefinition .ifPresent(operation -> interfaceType.addOperation(entry.getKey(), operation)); } } - private static Optional<OperationDefinition> createOperation(String propertyName, - Object operationCandidate, - Set<String> fieldNames) { + private static Optional<? extends OperationDefinition> createOperation(String propertyName, + Object operationCandidate, + Set<String> fieldNames, + Class<? extends OperationDefinition> 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<String, Object> interfaceAsMap, - InterfaceDefinition interfaceDefinition) { + private static <T extends OperationDefinition> void updateInterfaceDefinitionOperations( + Map<String, Object> interfaceAsMap, + InterfaceDefinition interfaceDefinition) { Set<String> fieldNames = CommonUtil.getClassFieldNames(InterfaceDefinitionType.class); + Optional<? extends OperationDefinition> operationDefinition = Optional.empty(); for (Map.Entry<String, Object> entry : interfaceAsMap.entrySet()) { - Optional<OperationDefinition> 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)); |