summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-lib/src/main/java
diff options
context:
space:
mode:
authorshiria <shiri.amichai@amdocs.com>2018-07-02 11:10:56 +0300
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-07-02 09:10:51 +0000
commit6d7284b5bcbbf6f57b843c5f30a50e9387b5ece8 (patch)
treea3e1b2e8af332d1472e81392f421e59f4d0ef37d /openecomp-be/lib/openecomp-tosca-lib/src/main/java
parent82fa3004cc68ef367e4f210900619743eb9abc95 (diff)
Fix getFlat for datatype
Fix getFlat when we driven from primitive type like string Adding support for service filter as tosca extension Issue-ID: SDC-1455 Change-Id: I57f05af13b394239ca55b71a946d69f56675bf19 Signed-off-by: shiria <shiri.amichai@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.java83
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java56
2 files changed, 40 insertions, 99 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 fc411bf009..ac2f5da44a 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
@@ -18,49 +18,9 @@ package org.openecomp.sdc.tosca.services;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.NotSerializableException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
-import org.onap.sdc.tosca.datatypes.model.AttributeDefinition;
-import org.onap.sdc.tosca.datatypes.model.CapabilityAssignment;
-import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
-import org.onap.sdc.tosca.datatypes.model.Constraint;
-import org.onap.sdc.tosca.datatypes.model.EntrySchema;
-import org.onap.sdc.tosca.datatypes.model.GroupDefinition;
-import org.onap.sdc.tosca.datatypes.model.Import;
-import org.onap.sdc.tosca.datatypes.model.InterfaceDefinition;
-import org.onap.sdc.tosca.datatypes.model.InterfaceDefinitionType;
-import org.onap.sdc.tosca.datatypes.model.InterfaceType;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.NodeType;
-import org.onap.sdc.tosca.datatypes.model.OperationDefinition;
-import org.onap.sdc.tosca.datatypes.model.OperationDefinitionTemplate;
-import org.onap.sdc.tosca.datatypes.model.OperationDefinitionType;
-import org.onap.sdc.tosca.datatypes.model.ParameterDefinition;
-import org.onap.sdc.tosca.datatypes.model.PolicyDefinition;
-import org.onap.sdc.tosca.datatypes.model.PropertyDefinition;
-import org.onap.sdc.tosca.datatypes.model.RelationshipTemplate;
-import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
-import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping;
-import org.onap.sdc.tosca.datatypes.model.TopologyTemplate;
+import org.onap.sdc.tosca.datatypes.model.*;
import org.onap.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt;
import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
import org.onap.sdc.tosca.services.YamlUtil;
@@ -72,13 +32,12 @@ import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
-import org.openecomp.sdc.tosca.errors.CreateInterfaceObjectErrorBuilder;
-import org.openecomp.sdc.tosca.errors.CreateInterfaceOperationObjectErrorBuilder;
-import org.openecomp.sdc.tosca.errors.InvalidAddActionNullEntityErrorBuilder;
-import org.openecomp.sdc.tosca.errors.InvalidRequirementAssignmentErrorBuilder;
-import org.openecomp.sdc.tosca.errors.ToscaInvalidInterfaceValueErrorBuilder;
+import org.openecomp.sdc.tosca.errors.*;
import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
+import java.io.*;
+import java.util.*;
+
/**
* The type Data model util.
*/
@@ -723,11 +682,11 @@ public class DataModelUtil {
if (CollectionUtils.isEmpty(templateRequirements)) {
return nodeTemplateRequirementsAssignment;
}
- YamlUtil yamlUtil = new YamlUtil();
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
for (Map<String, RequirementAssignment> requirementAssignmentMap : templateRequirements) {
for (Map.Entry<String, RequirementAssignment> requirementEntry : requirementAssignmentMap.entrySet()) {
RequirementAssignment requirementAssignment =
- (yamlUtil.yamlToObject(yamlUtil.objectToYaml(requirementEntry.getValue()),
+ (toscaExtensionYamlUtil.yamlToObject(toscaExtensionYamlUtil.objectToYaml(requirementEntry.getValue()),
RequirementAssignment.class));
nodeTemplateRequirementsAssignment.put(requirementEntry.getKey(), requirementAssignment);
}
@@ -782,10 +741,10 @@ public class DataModelUtil {
List<RequirementAssignment> matchRequirementAssignmentList = new ArrayList<>();
for (Map<String, RequirementAssignment> requirementMap : requirementsAssignmentList) {
if (requirementMap.containsKey(requirementKey)) {
- YamlUtil yamlUtil = new YamlUtil();
- RequirementAssignment requirementAssignment =
- (yamlUtil.yamlToObject(yamlUtil.objectToYaml(requirementMap.get(requirementKey)),
- RequirementAssignment.class));
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ RequirementAssignment requirementAssignment = (toscaExtensionYamlUtil.yamlToObject(
+ toscaExtensionYamlUtil.objectToYaml(requirementMap.get(requirementKey)),
+ RequirementAssignment.class));
matchRequirementAssignmentList.add(requirementAssignment);
}
}
@@ -1311,17 +1270,17 @@ public class DataModelUtil {
private static <T extends OperationDefinition> void updateInterfaceDefinitionOperations(Map<String, Object> interfaceAsMap,
InterfaceDefinition interfaceDefinition) {
- {
- Set<String> fieldNames = CommonUtil.getClassFieldNames(InterfaceDefinitionType.class);
- 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));
- }
+
+ Set<String> fieldNames = CommonUtil.getClassFieldNames(InterfaceDefinitionType.class);
+ 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));
}
+
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
index 46e58bdc81..5e0f2f2e41 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
@@ -19,50 +19,22 @@ package org.openecomp.sdc.tosca.services.impl;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
+import org.onap.sdc.tosca.datatypes.model.*;
+import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
import org.openecomp.core.utilities.CommonMethods;
import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.errors.SdcRuntimeException;
import org.openecomp.sdc.tosca.datatypes.ToscaElementTypes;
import org.openecomp.sdc.tosca.datatypes.ToscaFlatData;
-import org.onap.sdc.tosca.datatypes.model.AttributeDefinition;
-import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
-import org.onap.sdc.tosca.datatypes.model.CapabilityType;
-import org.onap.sdc.tosca.datatypes.model.DefinitionOfDataType;
-import org.onap.sdc.tosca.datatypes.model.DataType;
-import org.onap.sdc.tosca.datatypes.model.Import;
-import org.onap.sdc.tosca.datatypes.model.InterfaceDefinitionType;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.NodeType;
-import org.onap.sdc.tosca.datatypes.model.ParameterDefinition;
-import org.onap.sdc.tosca.datatypes.model.PropertyDefinition;
-import org.onap.sdc.tosca.datatypes.model.PropertyType;
-import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
-import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-import org.openecomp.sdc.tosca.errors.CreateInterfaceObjectErrorBuilder;
-import org.openecomp.sdc.tosca.errors.ToscaElementTypeNotFoundErrorBuilder;
-import org.openecomp.sdc.tosca.errors.ToscaFileNotFoundErrorBuilder;
-import org.openecomp.sdc.tosca.errors.ToscaInvalidEntryNotFoundErrorBuilder;
-import org.openecomp.sdc.tosca.errors.ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder;
-import org.openecomp.sdc.tosca.errors.ToscaInvalidSubstitutionServiceTemplateErrorBuilder;
+import org.openecomp.sdc.tosca.errors.*;
import org.openecomp.sdc.tosca.services.DataModelUtil;
-import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
import org.openecomp.sdc.tosca.services.ToscaAnalyzerService;
import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.tosca.services.ToscaUtil;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
import java.lang.reflect.InvocationTargetException;
-
-import org.openecomp.sdc.tosca.services.ToscaUtil;
+import java.util.*;
public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
@@ -272,7 +244,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
!= null) {
Object serviceTemplateFilter =
substitutableNodeTemplate.getProperties().get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME);
- if (serviceTemplateFilter != null && serviceTemplateFilter instanceof Map) {
+ if (serviceTemplateFilter instanceof Map) {
Object substituteServiceTemplate =
((Map) serviceTemplateFilter).get(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME);
handleNoSubstituteServiceTemplate(substituteNodeTemplateId, substituteServiceTemplate);
@@ -660,7 +632,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
DataType targetDataType = (DataType) flatData.getFlatEntity();
DataType sourceDataType = serviceTemplate.getData_types().get(typeId);
derivedFrom = sourceDataType.getDerived_from();
- if (derivedFrom != null) {
+ if (derivedFrom != null && !isPrimitiveType(derivedFrom)) {
boolean isEntityFound =
scanAnFlatEntity(elementType, derivedFrom, flatData, serviceTemplate, toscaModel, filesScanned,
rootScanStartInx);
@@ -675,6 +647,12 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
return false;
}
+ private static boolean isPrimitiveType(String toscaType) {
+ return (toscaType.equals(PropertyType.STRING.getDisplayName()) || toscaType.equals(PropertyType.INTEGER
+ .getDisplayName())
+ || toscaType.equals(PropertyType.FLOAT.getDisplayName()));
+ }
+
private boolean enrichCapabilityType(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData,
ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel,
List<String> filesScanned, int rootScanStartInx) {
@@ -789,7 +767,11 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
combineInterface.setOperations(
CommonMethods.mergeMaps(targetInterface.getOperations(), sourceInterface.getOperations()));
- return DataModelUtil.convertInterfaceDefinitionTypeToObj(combineInterface).get();
+ Optional<Object> interfaceDefObject = DataModelUtil.convertInterfaceDefinitionTypeToObj(combineInterface);
+ if( !interfaceDefObject.isPresent()){
+ throw new SdcRuntimeException("Illegal Statement");
+ }
+ return interfaceDefObject.get();
}
private void combineDataTypeInfo(DataType sourceDataType, DataType targetDataType) {