summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src')
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java48
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java49
2 files changed, 22 insertions, 75 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
index f8b9f75b8f..e9a8f58426 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
@@ -436,36 +436,24 @@ public class ToscaConverterImpl implements ToscaConverter {
return CsarFileTypes.externalFile;
}
- private Optional<Manifest> getCsarManifest(Map<String, byte[]> csarFiles) throws IOException {
- Optional<byte[]> manifestContent = getManifestContent(csarFiles);
-
- if (manifestContent.isPresent()) {
- ByteArrayInputStream byteInputStream = new ByteArrayInputStream(manifestContent.get());
-
- return Optional.of(new Manifest(byteInputStream));
- }
-
- return Optional.empty();
- }
-
- private NodeTemplate convertNodeTemplate(Object candidateNodeTemplate) {
- NodeTemplate nodeTemplate = new NodeTemplate();
-
- Map<String, Object> nodeTemplateAsMap = (Map<String, Object>) candidateNodeTemplate;
- nodeTemplate.setArtifacts((Map<String, ArtifactDefinition>) nodeTemplateAsMap.get("artifacts"));
- nodeTemplate.setAttributes((Map<String, Object>) nodeTemplateAsMap.get("attributes"));
- nodeTemplate.setCopy((String) nodeTemplateAsMap.get("copy"));
- nodeTemplate.setDescription((String) nodeTemplateAsMap.get("description"));
- nodeTemplate.setDirectives((List<String>) nodeTemplateAsMap.get("directives"));
- nodeTemplate.setInterfaces(
- (Map<String, InterfaceDefinition>) nodeTemplateAsMap.get("interfaces"));
- nodeTemplate.setNode_filter((NodeFilter) nodeTemplateAsMap.get("node_filter"));
- nodeTemplate.setProperties((Map<String, Object>) nodeTemplateAsMap.get("properties"));
- nodeTemplate.setRequirements(
- (List<Map<String, RequirementAssignment>>) nodeTemplateAsMap.get("requirements"));
- nodeTemplate.setType((String) nodeTemplateAsMap.get("type"));
- nodeTemplate.setCapabilities(
- convertCapabilities((Map<String, Object>) nodeTemplateAsMap.get("capabilities")));
+ private NodeTemplate convertNodeTemplate(Object candidateNodeTemplate) {
+ NodeTemplate nodeTemplate = new NodeTemplate();
+
+ Map<String, Object> nodeTemplateAsMap = (Map<String, Object>) candidateNodeTemplate;
+ nodeTemplate.setArtifacts((Map<String, ArtifactDefinition>) nodeTemplateAsMap.get("artifacts"));
+ nodeTemplate.setAttributes((Map<String, Object>) nodeTemplateAsMap.get("attributes"));
+ nodeTemplate.setCopy((String) nodeTemplateAsMap.get("copy"));
+ nodeTemplate.setDescription((String) nodeTemplateAsMap.get("description"));
+ nodeTemplate.setDirectives((List<String>) nodeTemplateAsMap.get("directives"));
+ nodeTemplate.setInterfaces(
+ (Map<String, Object>) nodeTemplateAsMap.get("interfaces"));
+ nodeTemplate.setNode_filter((NodeFilter) nodeTemplateAsMap.get("node_filter"));
+ nodeTemplate.setProperties((Map<String, Object>) nodeTemplateAsMap.get("properties"));
+ nodeTemplate.setRequirements(
+ (List<Map<String, RequirementAssignment>>) nodeTemplateAsMap.get("requirements"));
+ nodeTemplate.setType((String) nodeTemplateAsMap.get("type"));
+ nodeTemplate.setCapabilities(
+ convertCapabilities((Map<String, Object>) nodeTemplateAsMap.get("capabilities")));
return nodeTemplate;
}
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 802827e343..2236622222 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
@@ -17,13 +17,12 @@
package org.openecomp.core.impl;
import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang.StringUtils;
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.lang.reflect.Field;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
@@ -34,13 +33,10 @@ import java.util.stream.Stream;
public class ToscaConverterUtil {
- private static final String SET = "set";
private static final String DEFAULT = "default";
private static final String DEFAULT_CAPITAL = "Default";
private static final Set<String> DEFAULT_VALUE_KEYS;
- private static final Logger LOGGER = LoggerFactory.getLogger(ToscaConverterUtil.class);
-
static {
DEFAULT_VALUE_KEYS =
Stream.of(DEFAULT, DEFAULT_CAPITAL).collect(Collectors.toSet());
@@ -50,11 +46,11 @@ public class ToscaConverterUtil {
// static utility methods only, prevent instantiation
}
- public static <T> Optional<T> createObjectFromClass(String objectId,
+ static <T> Optional<T> createObjectFromClass(String objectId,
Object objectCandidate,
Class<T> classToCreate) {
try {
- return createObjectUsingSetters(objectCandidate, classToCreate);
+ return CommonUtil.createObjectUsingSetters(objectCandidate, classToCreate);
} catch (Exception ex) {
throw new CoreException(
new CreateToscaObjectErrorBuilder(classToCreate.getSimpleName(), objectId)
@@ -62,45 +58,8 @@ public class ToscaConverterUtil {
}
}
- private static <T> Optional<T> createObjectUsingSetters(Object objectCandidate,
- Class<T> classToCreate)
- throws ReflectiveOperationException {
- if (Objects.isNull(objectCandidate)
- || !(objectCandidate instanceof Map)) {
- return Optional.empty();
- }
-
- Map<String, Object> objectAsMap = (Map<String, Object>) objectCandidate;
- Field[] classFields = classToCreate.getDeclaredFields();
- T result = classToCreate.newInstance();
-
- for (Field field : classFields) {
- Object fieldValueToAssign = objectAsMap.get(field.getName());
- String methodName = SET + StringUtils.capitalize(field.getName());
-
- if(shouldSetterMethodNeedsToGetInvoked(classToCreate, field, fieldValueToAssign, methodName)) {
- classToCreate.getMethod(methodName, field.getType()).invoke(result, fieldValueToAssign);
- }
- }
-
- return Optional.of(result);
- }
- private static <T> boolean shouldSetterMethodNeedsToGetInvoked(Class<T> classToCreate,
- Field field,
- Object fieldValueToAssign,
- String methodName) {
-
- try {
- return Objects.nonNull(fieldValueToAssign)
- && Objects.nonNull(classToCreate.getMethod(methodName, field.getType()));
- } catch (NoSuchMethodException e) {
- LOGGER.debug(String.format("Could not extract method '%s' from class '%s'. returning false " +
- "with filedType '%s'.", methodName, classToCreate, field.getType()), e);
- return false;
- }
- }
- public static Optional<Object> getDefaultValue(Object entryValue,
+ static Optional<Object> getDefaultValue(Object entryValue,
Object objectToAssignDefaultValue) {
if (!(entryValue instanceof Map)
|| Objects.isNull(objectToAssignDefaultValue)) {