aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
authortalio <tali.orenbach@amdocs.com>2018-03-25 13:25:43 +0300
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-04-09 12:14:23 +0000
commitad8669b1b40e199a4b39832d81203d16f720941c (patch)
treed5466f2d5b5628446b962f5dd44ebd06fbd3b3d6 /openecomp-be
parentd9d360318e1a4ae67958356d0fe3fb207f90fbf8 (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')
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java2
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java51
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);
}
}