diff options
16 files changed, 322 insertions, 378 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java index 646a7ecc8b..68adbd5ae3 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java @@ -74,7 +74,9 @@ public class PropertyConvertor { props.stream().filter(p -> p.getOwnerId() == null || p.getOwnerId().equals(component.getUniqueId())).forEach(property -> { ToscaProperty prop = convertProperty(dataTypes, property, false); - properties.put(property.getName(), prop); + if (prop != null) { + properties.put(property.getName(), prop); + } }); if (!properties.isEmpty()) { toscaNodeType.setProperties(properties); @@ -98,13 +100,17 @@ public class PropertyConvertor { } log.trace("try to convert property {} from type {} with default value [{}]", property.getName(), property.getType(), property.getDefaultValue()); prop.setDefaultp(convertToToscaObject(property.getType(), property.getDefaultValue(), innerType, dataTypes)); + + if (prop.getDefaultp() == null) { + return null; + } prop.setType(property.getType()); - prop.setDescription(property.getDescription()); - if (isCapabiltyProperty) { - prop.setStatus(property.getStatus()); - prop.setRequired(property.isRequired()); - } - return prop; + prop.setDescription(property.getDescription()); + if (isCapabiltyProperty) { + prop.setStatus(property.getStatus()); + prop.setRequired(property.isRequired()); + } + return prop; } public Object convertToToscaObject(String propertyType, String value, String innerType, Map<String, DataTypeDefinition> dataTypes) { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java index e6f1ac82fb..a987e0243b 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java @@ -1,71 +1,102 @@ package org.openecomp.sdc.be.tosca; -import java.util.Map; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; -import javax.annotation.Generated; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.Before; import org.junit.Test; -import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; +import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.tosca.ToscaPropertyType; import org.openecomp.sdc.be.tosca.model.ToscaNodeType; import org.openecomp.sdc.be.tosca.model.ToscaProperty; import fj.data.Either; public class PropertyConvertorTest { + private PropertyDefinition property; + Map<String, DataTypeDefinition> dataTypes; - private PropertyConvertor createTestSubject() { - return new PropertyConvertor(); - } - - - @Test - public void testGetInstance() throws Exception { - PropertyConvertor result; - - // default test - result = PropertyConvertor.getInstance(); - } + @Before + public void setUp(){ + property = new PropertyDefinition(); + property.setName("myProperty"); + property.setType(ToscaPropertyType.INTEGER.getType()); + dataTypes = new HashMap<String, DataTypeDefinition>(); + dataTypes.put(property.getName(), new DataTypeDefinition()); + } - - @Test - public void testConvertProperties() throws Exception { - PropertyConvertor testSubject; - Component component = null; - ToscaNodeType toscaNodeType = null; - Map<String, DataTypeDefinition> dataTypes = null; - Either<ToscaNodeType, ToscaError> result; - // default test - testSubject = createTestSubject(); - result = testSubject.convertProperties(component, toscaNodeType, dataTypes); - } + @Test + public void convertPropertyWhenValueAndDefaultNull() { + assertNull(PropertyConvertor.getInstance().convertProperty(dataTypes, property, false)); + } - - @Test - public void testConvertProperty() throws Exception { - PropertyConvertor testSubject; - Map<String, DataTypeDefinition> dataTypes = null; - PropertyDefinition property = null; - boolean isCapabiltyProperty = false; - ToscaProperty result; + @Test + public void convertPropertyWhenValueNullAndDefaultNotEmpty() { + final String def = "1"; + property.setDefaultValue(def); + ToscaProperty result = PropertyConvertor.getInstance().convertProperty(dataTypes, property, false); + assertNotNull(result); + assertEquals(Integer.valueOf(def).intValue(), result.getDefaultp()); + } - // default test - testSubject = createTestSubject(); - } + @Test + public void convertPropertiesWhenValueAndDefaultNullInOne() { + PropertyDefinition property1 = new PropertyDefinition(); + property1.setName("otherProperty"); + property1.setType(ToscaPropertyType.INTEGER.getType()); + property1.setDefaultValue("2"); + dataTypes.put(property1.getName(), new DataTypeDefinition()); + Resource resource = new Resource(); + List<PropertyDefinition> properties = new ArrayList<PropertyDefinition>(); + properties.add(property); + properties.add(property1); + resource.setProperties(properties); + Either<ToscaNodeType, ToscaError> result = PropertyConvertor.getInstance().convertProperties(resource, new ToscaNodeType(), dataTypes); + assertTrue(result.isLeft()); + assertEquals(1, result.left().value().getProperties().size()); + } - - @Test - public void testConvertToToscaObject() throws Exception { - PropertyConvertor testSubject; - String propertyType = ""; - String value = ""; - String innerType = ""; - Map<String, DataTypeDefinition> dataTypes = null; - Object result; + @Test + public void convertPropertiesWhenValueAndDefaultExist() { + PropertyDefinition property1 = new PropertyDefinition(); + property1.setName("otherProperty"); + property1.setType(ToscaPropertyType.INTEGER.getType()); + property1.setDefaultValue("2"); + property.setDefaultValue("1"); + dataTypes.put(property1.getName(), new DataTypeDefinition()); + Resource resource = new Resource(); + List<PropertyDefinition> properties = new ArrayList<PropertyDefinition>(); + properties.add(property); + properties.add(property1); + resource.setProperties(properties); + Either<ToscaNodeType, ToscaError> result = PropertyConvertor.getInstance().convertProperties(resource, new ToscaNodeType(), dataTypes); + assertTrue(result.isLeft()); + assertEquals(2, result.left().value().getProperties().size()); + } - // default test - testSubject = createTestSubject(); - } + @Test + public void convertPropertiesWhenValueAndDefaultNullInAll() { + PropertyDefinition property1 = new PropertyDefinition(); + property1.setName("otherProperty"); + property1.setType(ToscaPropertyType.INTEGER.getType()); + dataTypes.put(property1.getName(), new DataTypeDefinition()); + Resource resource = new Resource(); + List<PropertyDefinition> properties = new ArrayList<PropertyDefinition>(); + properties.add(property); + properties.add(property1); + resource.setProperties(properties); + Either<ToscaNodeType, ToscaError> result = PropertyConvertor.getInstance().convertProperties(resource, new ToscaNodeType(), dataTypes); + assertTrue(result.isLeft()); + assertNull(result.left().value().getProperties()); + } }
\ No newline at end of file diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java index 2d389f5fe5..f3b842e0cf 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java @@ -35,7 +35,7 @@ public class DataTypePropertyConverter { */ public String getDataTypePropertiesDefaultValuesRec(String propertyDataType, Map<String, DataTypeDefinition> dataTypes) { JsonObject defaultValues = getDataTypePropsDefaultValuesRec(propertyDataType, dataTypes); - return !defaultValues.isJsonNull() ? gson.toJson(defaultValues) : null; + return !JsonUtils.isJsonNullOrEmpty(defaultValues) ? gson.toJson(defaultValues) : null; } /** diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java index ebb7566611..e15d784c7a 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java @@ -1,8 +1,5 @@ package org.openecomp.sdc.be.model.tosca.converters; -import static org.junit.Assert.*; - -import com.google.gson.JsonElement; import com.google.gson.JsonObject; import org.junit.Before; import org.junit.Test; @@ -16,226 +13,175 @@ import java.util.HashMap; import java.util.Map; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import java.util.*; -import org.junit.Assert; +import static org.junit.Assert.assertNull; public class DataTypePropertyConverterTest { - private static final String EMPTY_JSON_STR = "{}"; - public static final String PROPERTY2_DEFAULT = "{\"prop1\":\"def1\",\"prop3\":\"def3\"}"; - private DataTypePropertyConverter testInstance = DataTypePropertyConverter.getInstance(); - private Map<String, DataTypeDefinition> dataTypes; - private DataTypeDefinition noDefaultValue, dataType1, dataType2, dataType3; - private PropertyDefinition prop1, prop2, prop3, noDefaultProp; - - @Before - public void setUp() throws Exception { - dataTypes = new HashMap<>(); - - prop1 = new PropertyDefinition(); - prop1.setDefaultValue("def1"); - prop1.setName("prop1"); - - prop2 = new PropertyDefinition(); - prop2.setType("dataType1"); - prop2.setName("prop2"); - - prop3 = new PropertyDefinition(); - prop3.setDefaultValue("def3"); - prop3.setName("prop3"); - - noDefaultProp = new PropertyDefinition(); - noDefaultProp.setName("noDefaultProp"); - - noDefaultValue = new DataTypeDefinition(); - noDefaultValue.setProperties(Collections.singletonList(noDefaultProp)); - - dataType1 = new DataTypeDefinition(); - dataType1.setProperties(Arrays.asList(prop1, prop3)); - - dataType2 = new DataTypeDefinition(); - dataType2.setDerivedFrom(dataType1); - - dataType3 = new DataTypeDefinition(); - dataType3.setProperties(Collections.singletonList(prop2)); - dataType3.setDerivedFrom(noDefaultValue); - - dataTypes.put("noDefault", noDefaultValue); - dataTypes.put("dataType1", dataType1); - dataTypes.put("dataType2", dataType2); - dataTypes.put("dataType3", dataType3); - } - - @Test - public void testGetPropertyDefaultValuesRec_dataTypeNotExist() throws Exception { - String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("someType", dataTypes); - assertEquals(EMPTY_JSON_STR, defaultValue); - } - - @Test - public void testGetPropertyDefaultValuesRec_NoDefaultValue() throws Exception { - String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("noDefault", dataTypes); - assertEquals(EMPTY_JSON_STR, defaultValue); - } - - @Test - public void testGetPropertyDefaultValuesRec() throws Exception { - String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType1", dataTypes); - assertEquals(PROPERTY2_DEFAULT, defaultValue); - } - - @Test - public void testGetPropertyDefaultValuesRec_defaultFromDerivedDataType_derivedDataTypeHasNoDefaults() - throws Exception { - dataType2.setDerivedFrom(noDefaultValue); - String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType2", dataTypes); - assertEquals(EMPTY_JSON_STR, defaultValue); - } - - @Test - public void testGetPropertyDefaultValuesRec_defaultFromDerivedDataType() throws Exception { - String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType2", dataTypes); - assertEquals(PROPERTY2_DEFAULT, defaultValue); - } - - @Test - public void testGetPropertyDefaultValuesRec_defaultFromDataTypesOfProperties_dataTypeOfPropertyHasNoDefault() - throws Exception { - dataType3.getProperties().get(0).setType(noDefaultValue.getName()); - String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType3", dataTypes); - assertEquals(EMPTY_JSON_STR, defaultValue); - } - - @Test - public void testGetPropertyDefaultValuesRec_defaultFromDataTypesOfProperties() throws Exception { - String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType3", dataTypes); - assertEquals("{\"prop2\":" + PROPERTY2_DEFAULT + "}", defaultValue);// data - // type - // 3 - // has - // property - // prop2 - // which - // has - // a - // data - // type - // with - // property - // prop1 - // which - // has - // a - // default - // value - } - - @Test - public void testMergeDefaultValues_allDefaultValuesAreOverridden() throws Exception { - JsonObject value = new JsonObject(); - value.addProperty(noDefaultProp.getName(), "override1"); - - JsonObject prop1Val = new JsonObject(); - prop1Val.addProperty(prop1.getName(), "prop1Override"); - - JsonObject prop3Val = new JsonObject(); - prop3Val.addProperty(prop3.getName(), "prop3Override"); - - JsonObject prop2Value = new JsonObject(); - prop2Value.add(prop3.getName(), prop3Val); - prop2Value.add(prop1.getName(), prop1Val); - - value.add(prop2.getName(), prop2Value); - - String valBeforeMerge = value.toString(); - - testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes); - assertEquals(valBeforeMerge, value.toString()); - } - - @Test - public void testMergeDefaultValues() throws Exception { - JsonObject value = new JsonObject(); - value.addProperty(noDefaultProp.getName(), "override1"); - - JsonObject prop1Val = new JsonObject(); - prop1Val.addProperty(prop1.getName(), "prop1Override"); - - value.add(prop2.getName(), prop1Val); - - testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes); - - assertEquals("{\"noDefaultProp\":\"override1\",\"prop2\":{\"prop1\":\"prop1Override\",\"prop3\":\"def3\"}}", - value.toString());// expect to merge prop 3 default as it was - // not overridden - } - - @Test - public void testMergeDefaultValues_mergeAll() throws Exception { - JsonObject value = new JsonObject(); - testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes); - - assertEquals("{\"prop2\":" + PROPERTY2_DEFAULT + "}", value.toString());// expect - // to - // merge - // prop - // 3 - // default - // as - // it - // was - // not - // overridden - } - - @Test - public void testMergeDefaultValues_doNotAddDefaultsForGetInputValues() throws Exception { - - JsonObject getInputValue = new JsonObject(); - getInputValue.addProperty("get_input", "in1"); - - JsonObject value = new JsonObject(); - value.add(prop2.getName(), getInputValue); - - testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes); - - assertEquals("{\"prop2\":{\"get_input\":\"in1\"}}", value.toString()); - } - - @Test - public void testMergeDefaultValues_doNotAddDefaultsForGetInputInnerValues() throws Exception { - JsonObject getInputValue = new JsonObject(); - getInputValue.addProperty("get_input", "in1"); + private static final String EMPTY_JSON_STR = "{}"; + public static final String PROPERTY2_DEFAULT = "{\"prop1\":\"def1\",\"prop3\":\"def3\"}"; + private DataTypePropertyConverter testInstance = DataTypePropertyConverter.getInstance(); + private Map<String, DataTypeDefinition> dataTypes; + private DataTypeDefinition noDefaultValue, dataType1, dataType2, dataType3; + private PropertyDefinition prop1, prop2, prop3, noDefaultProp; + + @Before + public void setUp() throws Exception { + dataTypes = new HashMap<>(); + + prop1 = new PropertyDefinition(); + prop1.setDefaultValue("def1"); + prop1.setName("prop1"); + + prop2 = new PropertyDefinition(); + prop2.setType("dataType1"); + prop2.setName("prop2"); + + prop3 = new PropertyDefinition(); + prop3.setDefaultValue("def3"); + prop3.setName("prop3"); + + noDefaultProp = new PropertyDefinition(); + noDefaultProp.setName("noDefaultProp"); + + noDefaultValue = new DataTypeDefinition(); + noDefaultValue.setProperties(Collections.singletonList(noDefaultProp)); + + dataType1 = new DataTypeDefinition(); + dataType1.setProperties(Arrays.asList(prop1, prop3)); + + dataType2 = new DataTypeDefinition(); + dataType2.setDerivedFrom(dataType1); + + dataType3 = new DataTypeDefinition(); + dataType3.setProperties(Collections.singletonList(prop2)); + dataType3.setDerivedFrom(noDefaultValue); + + dataTypes.put("noDefault", noDefaultValue); + dataTypes.put("dataType1", dataType1); + dataTypes.put("dataType2", dataType2); + dataTypes.put("dataType3", dataType3); + } + + @Test + public void testGetPropertyDefaultValuesRec_dataTypeNotExist() throws Exception { + String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("someType", dataTypes); + assertNull(defaultValue); + } + + @Test + public void testGetPropertyDefaultValuesRec_NoDefaultValue() throws Exception { + String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("noDefault", dataTypes); + assertNull(defaultValue); + } + + @Test + public void testGetPropertyDefaultValuesRec() throws Exception { + String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType1", dataTypes); + assertEquals(PROPERTY2_DEFAULT, defaultValue); + } + + @Test + public void testGetPropertyDefaultValuesRec_defaultFromDerivedDataType_derivedDataTypeHasNoDefaults() throws Exception { + dataType2.setDerivedFrom(noDefaultValue); + String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType2", dataTypes); + assertNull(defaultValue); + } + + @Test + public void testGetPropertyDefaultValuesRec_defaultFromDerivedDataType() throws Exception { + String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType2", dataTypes); + assertEquals(PROPERTY2_DEFAULT, defaultValue); + } + + @Test + public void testGetPropertyDefaultValuesRec_defaultFromDataTypesOfProperties_dataTypeOfPropertyHasNoDefault() throws Exception { + dataType3.getProperties().get(0).setType(noDefaultValue.getName()); + String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType3", dataTypes); + assertNull(defaultValue); + } + + @Test + public void testGetPropertyDefaultValuesRec_defaultFromDataTypesOfProperties() throws Exception { + String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType3", dataTypes); + assertEquals("{\"prop2\":" + PROPERTY2_DEFAULT + "}", defaultValue);//data type 3 has property prop2 which has a data type with property prop1 which has a default value + } + + @Test + public void testMergeDefaultValues_allDefaultValuesAreOverridden() throws Exception { + JsonObject value = new JsonObject(); + value.addProperty(noDefaultProp.getName(), "override1"); + + JsonObject prop1Val = new JsonObject(); + prop1Val.addProperty(prop1.getName(), "prop1Override"); + + JsonObject prop3Val = new JsonObject(); + prop3Val.addProperty(prop3.getName(), "prop3Override"); + + JsonObject prop2Value = new JsonObject(); + prop2Value.add(prop3.getName(), prop3Val); + prop2Value.add(prop1.getName(), prop1Val); + + value.add(prop2.getName(), prop2Value); + + String valBeforeMerge = value.toString(); + + testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes); + assertEquals(valBeforeMerge, value.toString()); + } + + @Test + public void testMergeDefaultValues() throws Exception { + JsonObject value = new JsonObject(); + value.addProperty(noDefaultProp.getName(), "override1"); + + JsonObject prop1Val = new JsonObject(); + prop1Val.addProperty(prop1.getName(), "prop1Override"); + + value.add(prop2.getName(), prop1Val); + + testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes); + + assertEquals("{\"noDefaultProp\":\"override1\",\"prop2\":{\"prop1\":\"prop1Override\",\"prop3\":\"def3\"}}", + value.toString());//expect to merge prop 3 default as it was not overridden + } + + @Test + public void testMergeDefaultValues_mergeAll() throws Exception { + JsonObject value = new JsonObject(); + testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes); - JsonObject prop1Val = new JsonObject(); - prop1Val.add(prop1.getName(), getInputValue); + assertEquals("{\"prop2\":" + PROPERTY2_DEFAULT + "}", + value.toString());//expect to merge prop 3 default as it was not overridden + } - JsonObject value = new JsonObject(); - value.add(prop2.getName(), prop1Val); + @Test + public void testMergeDefaultValues_doNotAddDefaultsForGetInputValues() throws Exception { - testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes); + JsonObject getInputValue = new JsonObject(); + getInputValue.addProperty("get_input", "in1"); - assertEquals("{\"prop2\":{\"prop1\":{\"get_input\":\"in1\"},\"prop3\":\"def3\"}}", value.toString()); + JsonObject value = new JsonObject(); + value.add(prop2.getName(), getInputValue); - } + testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes); - private DataTypePropertyConverter createTestSubject() { - return DataTypePropertyConverter.getInstance(); - } + assertEquals("{\"prop2\":{\"get_input\":\"in1\"}}", value.toString()); + } - - @Test - public void testGetInstance() throws Exception { - DataTypePropertyConverter result; + @Test + public void testMergeDefaultValues_doNotAddDefaultsForGetInputInnerValues() throws Exception { + JsonObject getInputValue = new JsonObject(); + getInputValue.addProperty("get_input", "in1"); - // default test - result = DataTypePropertyConverter.getInstance(); - } + JsonObject prop1Val = new JsonObject(); + prop1Val.add(prop1.getName(), getInputValue); - + JsonObject value = new JsonObject(); + value.add(prop2.getName(), prop1Val); + testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes); - + assertEquals("{\"prop2\":{\"prop1\":{\"get_input\":\"in1\"},\"prop3\":\"def3\"}}", value.toString()); + } } diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/util/JsonUtils.java b/common-app-api/src/main/java/org/openecomp/sdc/common/util/JsonUtils.java index 367b806104..9022e7246e 100644 --- a/common-app-api/src/main/java/org/openecomp/sdc/common/util/JsonUtils.java +++ b/common-app-api/src/main/java/org/openecomp/sdc/common/util/JsonUtils.java @@ -54,5 +54,8 @@ public class JsonUtils { public static boolean isEmptyJson(JsonElement json) { return json.isJsonPrimitive() ? false : JsonUtils.isEmptyJson(json.getAsJsonObject()); } - + + public static boolean isJsonNullOrEmpty(JsonObject json) { + return json.isJsonNull() || isEmptyJson(json); + } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java index 9e4d3bf51b..0450244355 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java @@ -78,6 +78,7 @@ import java.io.IOException; import java.util.Collection; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; import static org.openecomp.sdc.logging.messages.AuditMessages.SUBMIT_VSP_ERROR; @@ -403,59 +404,30 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName.Re_Submit_ALL_Final_VSPs.toString()); logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.RESUBMIT_ALL_FINAL_VSPS); - List<VersionedVendorSoftwareProductInfo> vspList = Objects.requireNonNull( - vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), user)); - int skippedCounter = 0; - final int vspListSizeBefore = vspList.size(); - - for (VersionedVendorSoftwareProductInfo versionVspInfo : vspList) { - final VspDetails vspDetails = versionVspInfo.getVspDetails(); - final String vspId = vspDetails.getId(); - final Version latestFinalVersion = - getVersionInfo(vspId, VersionableEntityAction.Read, user).getLatestFinalVersion(); - - if (latestFinalVersion.getStatus().equals(VersionStatus.Locked)) { - logger.info("Skipping processing VSP name [{}]/id [{}] due to status LOCKED", vspDetails - .getName(), - vspId); - skippedCounter++; - vspList.remove(versionVspInfo); - } - } + List<VersionedVendorSoftwareProductInfo> latestFinalVsps = Objects + .requireNonNull(vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), user)); - logger.info("Removed {} VSPs out of {} from processing due to status LOCKED", skippedCounter, - vspListSizeBefore); + List<VersionedVendorSoftwareProductInfo> nonLockedLatestFinalVsps = latestFinalVsps.stream() + .filter(vsp -> + !isVspLocked(vsp.getVspDetails().getId(), vsp.getVspDetails().getName(), user)) + .collect(Collectors.toList()); + + logger.info("Removed {} VSPs out of {} from processing due to status LOCKED.\n" + + "Total number of VSPs: {}. Performing healing and resubmit for all non-Manual VSPs " + + "in submitted status.\n No need to pre-set oldVersion field", + latestFinalVsps.size() - nonLockedLatestFinalVsps.size(), latestFinalVsps.size(), + nonLockedLatestFinalVsps.size()); int healingCounter = 0; int failedCounter = 0; - int totalCounter = 0; - - - final int vspListSize = vspList.size(); - logger.info("Total number of VSPs: {}. Performing healing and " + - "resubmit for all non-Manual VSPs in submitted status.\n No need to pre-set oldVersion " + - "field", vspListSize); - - for (VersionedVendorSoftwareProductInfo versionVspInfo : vspList) { + for (int counter = 0; counter < nonLockedLatestFinalVsps.size(); counter++) { + VersionedVendorSoftwareProductInfo versionVspInfo = nonLockedLatestFinalVsps.get(counter); try { - totalCounter++; - final Version activeVersion = versionVspInfo.getVersionInfo().getActiveVersion(); final VspDetails vspDetails = versionVspInfo.getVspDetails(); - final String vspId = vspDetails.getId(); - final Version latestFinalVersion = - getVersionInfo(vspId, VersionableEntityAction.Read, user).getLatestFinalVersion(); - - final String vspName = vspDetails.getName(); - logger.info("VSP Name {}, VSP id [{}], Active Version {} , Active Version Status {}," + - "Latest Final Version {} , " + - "Latest Final Version Status {}", vspName, vspId, activeVersion - .toString(), - activeVersion.getStatus(), latestFinalVersion.toString(), - latestFinalVersion.getStatus()); - - if (Objects.nonNull(latestFinalVersion) && - (!OnboardingMethod.Manual.name().equals(vspDetails.getOnboardingMethod()))) { - reSubmit(vspDetails, user, totalCounter, vspListSize); + if (!OnboardingMethod.Manual.name().equals(vspDetails.getOnboardingMethod())) { + logger.info("Starting on healing and resubmit for VSP [{}], #{} out of total {}", + vspDetails.getName(), counter + 1, nonLockedLatestFinalVsps.size()); + reSubmit(vspDetails, user); healingCounter++; } } catch (Exception e) { @@ -464,42 +436,46 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { } logger.info("Total VSPs processed {}. Completed running healing and resubmit for {} VSPs out" + - " " + - "of total # of {} submitted VSPs. Failures count during resubmitAll: {}", - totalCounter, healingCounter, vspListSize, failedCounter); - + " of total # of {} submitted VSPs. Failures count during resubmitAll: {}", + nonLockedLatestFinalVsps.size(), healingCounter, latestFinalVsps.size(), failedCounter); return Response.ok().build(); } + private boolean isVspLocked(String vspId, String vspName, String user) { + final VersionInfo versionInfo = getVersionInfo(vspId, VersionableEntityAction.Read, user); - private void reSubmit(VspDetails vspDetails, String user, int currentCount, int total) throws - Exception { + if (versionInfo.getStatus().equals(VersionStatus.Locked)) { + logger.info("VSP name [{}]/id [{}] status is LOCKED", vspName, vspId); + return true; + } + logger.info("VSP Name {}, VSP id [{}], Active Version {} , Status {}, Latest Final Version {}", + vspName, vspId, versionInfo.getActiveVersion().toString(), versionInfo.getStatus(), + versionInfo.getLatestFinalVersion().toString()); + return false; + } - final String vspId = vspDetails.getId(); - final String vspName = vspDetails.getName(); - final Version versionBefore = vspDetails.getVersion(); - Version finalVersion; - logger.info("Starting on healing and resubmit for VSP [{}], #{} out of total {}", vspName, - currentCount, total); + private void reSubmit(VspDetails vspDetails, String user) throws Exception { + final Version versionBefore = vspDetails.getVersion(); vspDetails.setOldVersion("true"); + Version finalVersion; try { finalVersion = - vendorSoftwareProductManager.healAndAdvanceFinalVersion(vspId, vspDetails, user); - + vendorSoftwareProductManager + .healAndAdvanceFinalVersion(vspDetails.getId(), vspDetails, user); } catch (Exception e) { - logger.error("Failed during resubmit, VSP [{}] , version before:{}, version after:{}, " + "status after:{}, with exception:{}", - vspName, versionBefore.toString(), vspDetails.getVersion().toString(), vspDetails + vspDetails.getName(), versionBefore.toString(), vspDetails.getVersion().toString(), + vspDetails .getVersion().getStatus().name(), e.getMessage()); throw e; } logger.info("Completed healing and resubmit for VSP [{}], version before:{}, version after:" + - " {}", vspName, versionBefore.toString(), finalVersion); + " {}", vspDetails.getName(), versionBefore.toString(), finalVersion); } private static void printAuditForErrors(List<ErrorMessage> errorList, String vspId, diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java index 3f6ffcc622..07a3fa7f2c 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java @@ -30,6 +30,7 @@ import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.activityLog.ActivityLogManager; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.common.utils.CommonUtil; import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.datatypes.error.ErrorMessage; @@ -258,20 +259,20 @@ public class OrchestrationTemplateCandidateManagerImpl OnboardingTypesEnum type = OnboardingTypesEnum.getOnboardingTypesEnum(vspDetails.getOnboardingOrigin()); - if(vspDetails.getOnboardingOrigin().equals(OnboardingTypesEnum.ZIP.toString())) { + if(CommonUtil.isFileOriginFromZip(vspDetails.getOnboardingOrigin())) { FilesDataStructure structure = JsonUtil .json2Object(candidateDataEntity.get().getFilesDataStructure(), FilesDataStructure.class); String manifest = candidateService.createManifest(vspDetails, structure); mdcDataDebugMessage .debugExitMessage("VSP id", vspId); - return Optional.ofNullable( + return Optional.of( new ImmutablePair<>(OnboardingTypesEnum.ZIP.toString(),candidateService .replaceManifestInZip(candidateDataEntity.get().getContentData(), manifest, vspId, type))); } - return Optional.ofNullable( + return Optional.of( new ImmutablePair<>(vspDetails.getOnboardingOrigin(),candidateDataEntity.get() .getContentData().array())); } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java index dde5d61663..d4879da8d7 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java @@ -832,21 +832,20 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa public Version healAndAdvanceFinalVersion(String vspId, VspDetails vendorSoftwareProductInfo, String user) throws IOException { - Version checkoutFinalVersion = checkout(vspId, user); - autoHeal(vspId, checkoutFinalVersion, vendorSoftwareProductInfo, user); - Version checkinFinalVersion = checkin(vspId, user); + Version checkoutVersion = checkout(vspId, user); + autoHeal(vspId, checkoutVersion, vendorSoftwareProductInfo, user); + Version checkinVersion = checkin(vspId, user); ValidationResponse response = Objects.requireNonNull(submit(vspId, user), "Null response not expected"); if (!response.isValid()) { - return checkout(vspId, user); + return checkinVersion; } - Version finalVersion = checkinFinalVersion.calculateNextFinal(); + Version finalVersion = checkinVersion.calculateNextFinal(); createPackage(vspId, finalVersion, user); return finalVersion; - } @Override @@ -1103,7 +1102,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa (vspDetails.getOnboardingOrigin()), uploadData.getContentData().array()); - if (vspDetails.getOnboardingOrigin().equals(OnboardingTypesEnum.ZIP.name().toLowerCase())) { + if (CommonUtil.isFileOriginFromZip(vspDetails.getOnboardingOrigin())) { ValidationManager validationManager = ValidationManagerUtil.initValidationManager(fileContentMap); validationErrors.putAll(validationManager.validate()); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java index db43e0084e..516d85c2a7 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java @@ -28,11 +28,11 @@ public class OrchestrationProcessFactory { } public static Optional<OrchestrationTemplateProcessHandler> getInstance(String filePrefix) { - filePrefix = filePrefix == null ? null : filePrefix.toLowerCase().trim(); if (filePrefix == null) { return Optional.empty(); } + filePrefix = filePrefix.toLowerCase().trim(); OnboardingTypesEnum onboardingTypesEnum = OnboardingTypesEnum.getOnboardingTypesEnum(filePrefix); if (onboardingTypesEnum == null) { return Optional.empty(); diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java index 1c5293004d..72485d7162 100644 --- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java @@ -42,6 +42,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -67,7 +68,7 @@ public class CommonUtil { throws IOException { Pair<FileContentHandler,List<String> > pair = getFileContentMapFromOrchestrationCandidateZip(uploadFileData); - if(type.equals(OnboardingTypesEnum.ZIP)) { + if(isFileOriginFromZip(type.toString())) { validateNoFolders(pair.getRight()); } @@ -133,7 +134,7 @@ public class CommonUtil { return -1; } - public static boolean validateFilesExtensions(Set<String> allowedExtensions, FileContentHandler + private static boolean validateFilesExtensions(Set<String> allowedExtensions, FileContentHandler files) { for (String fileName : files.getFileList()) { if (!allowedExtensions.contains(FilenameUtils.getExtension(fileName))) { @@ -147,4 +148,9 @@ public class CommonUtil { Set<String> allowedExtensions = new HashSet<>(Arrays.asList("yml", "yaml")); return validateFilesExtensions(allowedExtensions, files); } + + public static boolean isFileOriginFromZip(String fileOrigin){ + return Objects.nonNull(fileOrigin) + && fileOrigin.toLowerCase().equals(OnboardingTypesEnum.ZIP.toString()); + } } diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java index 04e64c33a9..85fe305060 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java @@ -20,13 +20,11 @@ public enum OnboardingTypesEnum { if (inStr == null) { return null; } + Optional<OnboardingTypesEnum> onboardingTypesOptional = asList(OnboardingTypesEnum.values()).stream() - .filter(onboardingTypesEnum -> onboardingTypesEnum.toString().equals(inStr)).findAny(); - if( onboardingTypesOptional.isPresent()){ - return onboardingTypesOptional.get(); - }else { - return null; - } + .filter(onboardingTypesEnum -> onboardingTypesEnum.toString().equals(inStr.toLowerCase())) + .findAny(); + return onboardingTypesOptional.orElse(null); } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/VspDetails.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/VspDetails.java index ccadeced62..3f9768b9d7 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/VspDetails.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/VspDetails.java @@ -26,6 +26,7 @@ import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.dao.types.VersionableEntity; import java.util.List; +import java.util.Objects; public class VspDetails implements VersionableEntity { @@ -34,8 +34,6 @@ <!-- Elastic Search mapper (reference the elastic search version actually). --> <elastic-search.version>2.1.0</elastic-search.version> - <catalog-artifacts.version>1.0.0-SNAPSHOT</catalog-artifacts.version> - <catalog-builders.version>1.0.0-SNAPSHOT</catalog-builders.version> <jetty.version>9.2.10.v20150310</jetty.version> <!-- JSON and YAML Parsing --> @@ -87,7 +85,7 @@ <extentreports.version>3.0.3</extentreports.version> <!-- parser--> - <sdc-tosca-parser.version>1.1.14-SNAPSHOT</sdc-tosca-parser.version> + <sdc-tosca-parser.version>1.1.34</sdc-tosca-parser.version> <!--JaCoCO --> <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin> diff --git a/sdc-os-chef/environments/Template.json b/sdc-os-chef/environments/Template.json index a19f7cf9fd..1022a03285 100644 --- a/sdc-os-chef/environments/Template.json +++ b/sdc-os-chef/environments/Template.json @@ -17,7 +17,7 @@ "private": "eth1" }, "ECompP": { - "ecomp_rest_url": "http://portal.api.simpledemo.openecomp.org:8989/ECOMPPORTAL/auxapi", + "ecomp_rest_url": "http://portal.api.simpledemo.onap.org:8989/ONAPPORTAL/auxapi", "ueb_url_list": "10.0.11.1,10.0.11.1", "app_secret": "XftIATw9Jr3VzAcPqt3NnJOu", "app_key": "x9UfO7JsDn8BESVX", diff --git a/test-apis-ci/pom.xml b/test-apis-ci/pom.xml index 875888facc..d9c080dd7a 100644 --- a/test-apis-ci/pom.xml +++ b/test-apis-ci/pom.xml @@ -281,16 +281,10 @@ <artifactId>json</artifactId> <version>20090211</version> </dependency> - <!-- <dependency> - <groupId>org.openecomp.sdc.sdc-distribution-client</groupId> - <artifactId>sdc-tosca-parser</artifactId> - <version>${sdc-tosca-parser.version}</version> - <scope>compile</scope> - </dependency> --> <dependency> <groupId>org.openecomp.sdc.sdc-tosca</groupId> <artifactId>sdc-tosca</artifactId> - <version>1.1.32-SNAPSHOT</version> + <version>${sdc-tosca-parser.version}</version> <scope>compile</scope> </dependency> </dependencies> diff --git a/ui-ci-dev/pom.xml b/ui-ci-dev/pom.xml index f0ead6de8a..1d6afa9c01 100644 --- a/ui-ci-dev/pom.xml +++ b/ui-ci-dev/pom.xml @@ -252,21 +252,6 @@ </descriptorRefs> </configuration> </execution> - - <!----> - <!--<execution>--> - <!--<id>tarball</id>--> - <!--<phase>package</phase>--> - <!--<goals>--> - <!--<goal>single</goal>--> - <!--</goals>--> - <!--<configuration>--> - <!--<finalName>${project.artifactId}-${full.release.version}${build.type}</finalName>--> - <!--<appendAssemblyId>false</appendAssemblyId>--> - <!--<descriptor>${project.basedir}/tarball.xml</descriptor>--> - <!--<attach>false</attach>--> - <!--</configuration>--> - <!--</execution>--> </executions> </plugin> |