Improve handling 'empty'/null string in Service fields 73/135873/9
authorvasraz <vasyl.razinkov@est.tech>
Tue, 29 Aug 2023 14:29:59 +0000 (15:29 +0100)
committerMichael Morris <michael.morris@est.tech>
Tue, 5 Sep 2023 09:50:12 +0000 (09:50 +0000)
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: Ib301280fe1be2896e2d80e208349ac3c4ff763ec
Issue-ID: SDC-4608

26 files changed:
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentContactIdValidator.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentDescriptionValidator.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentProjectCodeValidator.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceCategoryValidator.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceNamingPolicyValidator.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceRoleValidator.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceTypeValidator.java
catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java
catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java
catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
common-app-api/src/main/java/org/openecomp/sdc/common/util/ValidationUtils.java
common-app-api/src/test/java/org/openecomp/sdc/common/test/CommonUtilsTest.java
common-app-api/src/test/java/org/openecomp/sdc/common/util/ValidationUtilsTest.java

index 837b118..6153309 100644 (file)
@@ -21,6 +21,7 @@ package org.openecomp.sdc.be.components.impl;
 
 import fj.data.Either;
 import java.util.List;
+import org.apache.commons.lang3.StringUtils;
 import org.openecomp.sdc.be.config.BeEcompErrorManager;
 import org.openecomp.sdc.be.config.ConfigurationManager;
 import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -230,8 +231,7 @@ public class AdditionalInformationBusinessLogic extends BaseBusinessLogic {
      * @return
      */
     private Either<String, ResponseFormat> validateValue(String value) {
-        boolean isNonEmptyString = ValidationUtils.validateStringNotEmpty(value);
-        if (!isNonEmptyString) {
+        if (StringUtils.isEmpty(value)) {
             return Either.right(componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED));
         }
         boolean valid = StringValidator.getInstance().isValid(value, null);
@@ -262,8 +262,7 @@ public class AdditionalInformationBusinessLogic extends BaseBusinessLogic {
         AdditionalInfoParameterInfo additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
         additionalInfoParameterInfo.setKey(key);
         String normKey = ValidationUtils.normalizeAdditionalInformation(key);
-        boolean isNonEmptyString = ValidationUtils.validateStringNotEmpty(normKey);
-        if (!isNonEmptyString) {
+        if (StringUtils.isEmpty(normKey)) {
             return Either.right(componentsUtils
                 .getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED, null, null,
                     AdditionalInformationEnum.Label));
index c17af4d..d50ae54 100644 (file)
@@ -2210,7 +2210,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
     }
 
     private Either<Boolean, ResponseFormat> validateAndServiceApiUrl(ArtifactDefinition artifactInfo) {
-        if (!ValidationUtils.validateStringNotEmpty(artifactInfo.getApiUrl())) {
+        if (StringUtils.isEmpty(artifactInfo.getApiUrl())) {
             log.debug("Artifact url cannot be empty.");
             return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, ARTIFACT_URL));
         }
@@ -2879,9 +2879,9 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
             List<HeatParameterDefinition> empltyHeatValues = new ArrayList<>();
             for (HeatParameterDefinition heatParameterDefinition : heatParameters) {
                 String heatValue = heatParameterDefinition.getCurrentValue();
-                if (!ValidationUtils.validateStringNotEmpty(heatValue)) {
+                if (StringUtils.isEmpty(heatValue)) {
                     heatValue = heatParameterDefinition.getDefaultValue();
-                    if (!ValidationUtils.validateStringNotEmpty(heatValue)) {
+                    if (StringUtils.isEmpty(heatValue)) {
                         empltyHeatValues.add(heatParameterDefinition);
                         continue;
                     }
index b3d0bfc..0b60a36 100644 (file)
@@ -304,7 +304,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
         log.debug("validate Icon");
         ComponentTypeEnum type = component.getComponentType();
         String icon = component.getIcon();
-        if (!ValidationUtils.validateStringNotEmpty(icon)) {
+        if (StringUtils.isEmpty(icon)) {
             log.info("icon is missing.");
             ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_ICON, type.getValue());
             componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
index 4db24c1..93fb171 100644 (file)
@@ -21,6 +21,7 @@ package org.openecomp.sdc.be.components.impl;
 
 import fj.data.Either;
 import java.util.Date;
+import org.apache.commons.lang3.StringUtils;
 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
 import org.openecomp.sdc.be.config.BeEcompErrorManager;
 import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -163,7 +164,7 @@ public class ConsumerBusinessLogic extends BaseBusinessLogic {
 
     private Either<ConsumerDefinition, ResponseFormat> validateConsumerName(ConsumerDefinition consumer) {
         String name = consumer.getConsumerName();
-        if (!ValidationUtils.validateStringNotEmpty(name)) {
+        if (StringUtils.isEmpty(name)) {
             log.debug("Consumer name cannot be empty.");
             return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, CONSUMER_NAME));
         }
@@ -185,7 +186,7 @@ public class ConsumerBusinessLogic extends BaseBusinessLogic {
 
     private Either<ConsumerDefinition, ResponseFormat> validateConsumerPassword(ConsumerDefinition consumer) {
         String password = consumer.getConsumerPassword();
-        if (!ValidationUtils.validateStringNotEmpty(password)) {
+        if (StringUtils.isEmpty(password)) {
             log.debug("Consumer password cannot be empty.");
             return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, CONSUMER_PW));
         }
@@ -203,7 +204,7 @@ public class ConsumerBusinessLogic extends BaseBusinessLogic {
 
     private Either<ConsumerDefinition, ResponseFormat> validateConsumerSalt(ConsumerDefinition consumer) {
         String salt = consumer.getConsumerSalt();
-        if (!ValidationUtils.validateStringNotEmpty(salt)) {
+        if (StringUtils.isEmpty(salt)) {
             log.debug("Consumer salt cannot be empty.");
             return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, CONSUMER_SALT));
         }
index aca2536..9344f68 100644 (file)
@@ -29,6 +29,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
+import org.apache.commons.lang3.StringUtils;
 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
 import org.openecomp.sdc.be.components.validation.component.ComponentContactIdValidator;
@@ -300,7 +301,7 @@ public class ProductBusinessLogic extends ComponentBusinessLogic {
         // remove duplicated entries
         for (CategoryDefinition cat : categories) {
             String catName = cat.getName();
-            if (!ValidationUtils.validateStringNotEmpty(catName)) {
+            if (StringUtils.isEmpty(catName)) {
                 // error missing cat name
                 log.debug("Missing category name for product: {}", product.getName());
                 ResponseFormat responseFormat = componentsUtils
@@ -323,7 +324,7 @@ public class ProductBusinessLogic extends ComponentBusinessLogic {
             }
             for (SubCategoryDefinition subcat : subcategories) {
                 String subCatName = subcat.getName();
-                if (!ValidationUtils.validateStringNotEmpty(subCatName)) {
+                if (StringUtils.isEmpty(subCatName)) {
                     // error missing sub cat name for cat
                     log.debug("Missing or empty sub-category for category {} in product {}", catName, product.getName());
                     ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_SUBCATEGORY);
@@ -338,7 +339,7 @@ public class ProductBusinessLogic extends ComponentBusinessLogic {
                 List<GroupingDefinition> groupings = subcat.getGroupings();
                 for (GroupingDefinition group : groupings) {
                     String groupName = group.getName();
-                    if (!ValidationUtils.validateStringNotEmpty(groupName)) {
+                    if (StringUtils.isEmpty(groupName)) {
                         // error missing grouping for sub cat name and cat
                         log.debug("Missing or empty groupng name for sub-category: {} for categor: {} in product: {}", subCatName, catName,
                             product.getName());
@@ -481,7 +482,7 @@ public class ProductBusinessLogic extends ComponentBusinessLogic {
 
     private Either<Boolean, ResponseFormat> validateProductFullNameAndCleanup(User user, Product product, AuditingActionEnum actionEnum) {
         String fullName = product.getFullName();
-        if (!ValidationUtils.validateStringNotEmpty(fullName)) {
+        if (StringUtils.isEmpty(fullName)) {
             ResponseFormat errorResponse = componentsUtils
                 .getResponseFormat(ActionStatus.MISSING_ONE_OF_COMPONENT_NAMES, ComponentTypeEnum.PRODUCT.getValue(), PRODUCT_FULL_NAME);
             componentsUtils.auditComponentAdmin(errorResponse, user, product, actionEnum, ComponentTypeEnum.PRODUCT);
@@ -509,7 +510,7 @@ public class ProductBusinessLogic extends ComponentBusinessLogic {
 
     private Either<Boolean, ResponseFormat> validateProductNameAndCleanup(User user, Product product, AuditingActionEnum actionEnum) {
         String name = product.getName();
-        if (!ValidationUtils.validateStringNotEmpty(name)) {
+        if (StringUtils.isEmpty(name)) {
             ResponseFormat responseFormat = componentsUtils
                 .getResponseFormat(ActionStatus.MISSING_ONE_OF_COMPONENT_NAMES, ComponentTypeEnum.PRODUCT.getValue(), PRODUCT_ABBREVIATED_NAME);
             componentsUtils.auditComponentAdmin(responseFormat, user, product, actionEnum, ComponentTypeEnum.PRODUCT);
index 6e385b2..84e68e6 100644 (file)
@@ -4785,14 +4785,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
             throw new ByActionStatusComponentException(ActionStatus.RESOURCE_TOO_MUCH_SUBCATEGORIES);
         }
         SubCategoryDefinition subcategory = subcategories.get(0);
-        if (!ValidationUtils.validateStringNotEmpty(category.getName())) {
+        if (StringUtils.isEmpty(category.getName())) {
             log.debug(CATEGORY_IS_EMPTY);
             ResponseFormat responseFormat = componentsUtils
                 .getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
             componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
             throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
         }
-        if (!ValidationUtils.validateStringNotEmpty(subcategory.getName())) {
+        if (StringUtils.isEmpty(subcategory.getName())) {
             log.debug(CATEGORY_IS_EMPTY);
             ResponseFormat responseFormat = componentsUtils
                 .getResponseFormat(ActionStatus.COMPONENT_MISSING_SUBCATEGORY, ComponentTypeEnum.RESOURCE.getValue());
@@ -4841,7 +4841,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
     public void validateVendorReleaseName(User user, Resource resource, AuditingActionEnum actionEnum) {
         String vendorRelease = resource.getVendorRelease();
         log.debug("validate vendor relese name");
-        if (!ValidationUtils.validateStringNotEmpty(vendorRelease)) {
+        if (StringUtils.isEmpty(vendorRelease)) {
             log.info("vendor relese name is missing.");
             ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_VENDOR_RELEASE);
             componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
@@ -4870,7 +4870,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
 
     private void validateVendorName(User user, Resource resource, AuditingActionEnum actionEnum) {
         String vendorName = resource.getVendorName();
-        if (!ValidationUtils.validateStringNotEmpty(vendorName)) {
+        if (StringUtils.isEmpty(vendorName)) {
             log.info("vendor name is missing.");
             ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_VENDOR_NAME);
             componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
index 5bde56d..9365fac 100644 (file)
@@ -35,6 +35,7 @@ import lombok.Getter;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.openecomp.sdc.be.components.csar.CsarInfo;
 import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo;
@@ -763,7 +764,7 @@ public class ServiceImportParseLogic {
     public void validateVendorReleaseName(User user, Resource resource, AuditingActionEnum actionEnum) {
         String vendorRelease = resource.getVendorRelease();
         log.debug("validate vendor relese name");
-        if (!ValidationUtils.validateStringNotEmpty(vendorRelease)) {
+        if (StringUtils.isEmpty(vendorRelease)) {
             log.info("vendor relese name is missing.");
             ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_VENDOR_RELEASE);
             componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
@@ -814,14 +815,14 @@ public class ServiceImportParseLogic {
             throw new ComponentException(ActionStatus.RESOURCE_TOO_MUCH_SUBCATEGORIES);
         }
         SubCategoryDefinition subcategory = subcategories.get(0);
-        if (!ValidationUtils.validateStringNotEmpty(category.getName())) {
+        if (StringUtils.isEmpty(category.getName())) {
             log.debug(CATEGORY_IS_EMPTY);
             ResponseFormat responseFormat = componentsUtils
                 .getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
             componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
             throw new ComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
         }
-        if (!ValidationUtils.validateStringNotEmpty(subcategory.getName())) {
+        if (StringUtils.isEmpty(subcategory.getName())) {
             log.debug(CATEGORY_IS_EMPTY);
             ResponseFormat responseFormat = componentsUtils
                 .getResponseFormat(ActionStatus.COMPONENT_MISSING_SUBCATEGORY, ComponentTypeEnum.RESOURCE.getValue());
@@ -875,7 +876,7 @@ public class ServiceImportParseLogic {
 
     protected void validateVendorName(User user, Resource resource, AuditingActionEnum actionEnum) {
         String vendorName = resource.getVendorName();
-        if (!ValidationUtils.validateStringNotEmpty(vendorName)) {
+        if (StringUtils.isEmpty(vendorName)) {
             log.info("vendor name is missing.");
             ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_VENDOR_NAME);
             componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
index 8b01ff1..b569c67 100644 (file)
@@ -26,6 +26,7 @@ import fj.data.Either;
 import java.util.HashMap;
 import java.util.Map;
 import javax.annotation.PostConstruct;
+import org.apache.commons.lang3.StringUtils;
 import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum;
 import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
 import org.openecomp.sdc.be.components.impl.ProductBusinessLogic;
@@ -319,7 +320,7 @@ public class LifecycleBusinessLogic {
         if (LifeCycleTransitionEnum.CERTIFY == transitionEnum || LifeCycleTransitionEnum.CHECKIN == transitionEnum
             // import?
         ) {
-            if (!ValidationUtils.validateStringNotEmpty(comment)) {
+            if (StringUtils.isEmpty(comment)) {
                 log.debug("user comment cannot be empty or null.");
                 ResponseFormat errorResponse = componentUtils.getResponseFormat(ActionStatus.MISSING_DATA, COMMENT);
                 return Either.right(errorResponse);
index 2a177c6..5f27ba1 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.openecomp.sdc.be.components.validation.component;
 
+import org.apache.commons.lang3.StringUtils;
 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
 import org.openecomp.sdc.be.dao.api.ActionStatus;
 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
@@ -45,7 +46,7 @@ public class ComponentContactIdValidator implements ComponentFieldValidator {
         log.debug("validate component contactId");
         ComponentTypeEnum type = component.getComponentType();
         String contactId = component.getContactId();
-        if (!ValidationUtils.validateStringNotEmpty(contactId)) {
+        if (StringUtils.isEmpty(contactId)) {
             log.info("contact is missing.");
             ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue());
             componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
index 8cf985f..f3c94f0 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.openecomp.sdc.be.components.validation.component;
 
+import org.apache.commons.lang3.StringUtils;
 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
 import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -45,7 +46,7 @@ public class ComponentDescriptionValidator implements ComponentFieldValidator {
     public void validateAndCorrectField(User user, Component component, AuditingActionEnum actionEnum) {
         ComponentTypeEnum type = component.getComponentType();
         String description = component.getDescription();
-        if (!ValidationUtils.validateStringNotEmpty(description)) {
+        if (StringUtils.isEmpty(description)) {
             auditErrorAndThrow(user, component, actionEnum, ActionStatus.COMPONENT_MISSING_DESCRIPTION);
         }
         description = ValidationUtils.cleanUpText(description);
index 29b4fda..af08381 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.openecomp.sdc.be.components.validation.component;
 
+import org.apache.commons.lang3.StringUtils;
 import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
 import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -49,7 +50,7 @@ public class ComponentProjectCodeValidator implements ComponentFieldValidator {
         }
         log.debug("validate ProjectCode name ");
         String projectCode = component.getProjectCode();
-        if (!ValidationUtils.validateStringNotEmpty(projectCode)) {
+        if (StringUtils.isEmpty(projectCode)) {
             log.info("projectCode is empty is allowed CR.");
             return;
         }
index f8b3fff..5803259 100644 (file)
@@ -23,6 +23,7 @@ import static org.apache.commons.collections.CollectionUtils.isEmpty;
 
 import fj.data.Either;
 import java.util.List;
+import org.apache.commons.lang3.StringUtils;
 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
 import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
 import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -80,7 +81,7 @@ public class ServiceCategoryValidator implements ServiceFieldValidator {
                 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.SERVICE_CANNOT_CONTAIN_SUBCATEGORY);
                 return Either.right(responseFormat);
             }
-            if (!ValidationUtils.validateStringNotEmpty(category.getName())) {
+            if (StringUtils.isEmpty(category.getName())) {
                 log.debug("Resource category is empty");
                 ResponseFormat responseFormat = componentsUtils
                     .getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
index 73acf20..11974ac 100644 (file)
@@ -49,21 +49,19 @@ public class ServiceNamingPolicyValidator implements ServiceFieldValidator {
             throw new ByActionStatusComponentException(ActionStatus.MISSING_ECOMP_GENERATED_NAMING);
         }
         if (isEcompGeneratedCurr) {
+            if (StringUtils.isEmpty(namingPolicyUpdate)) {
+                return;
+            }
             if (!ValidationUtils.validateServiceNamingPolicyLength(namingPolicyUpdate)) {
                 ResponseFormat responseFormat = componentsUtils
                     .getResponseFormat(ActionStatus.NAMING_POLICY_EXCEEDS_LIMIT, "" + ValidationUtils.SERVICE_NAMING_POLICY_MAX_SIZE);
                 throw new ByResponseFormatComponentException(responseFormat);
             }
-            if (StringUtils.isEmpty(namingPolicyUpdate)) {
-                service.setNamingPolicy("");
-                return;
-            }
             if (!ValidationUtils.validateCommentPattern(namingPolicyUpdate)) {
                 throw new ByActionStatusComponentException(ActionStatus.INVALID_NAMING_POLICY);
             }
-            service.setNamingPolicy(namingPolicyUpdate);
         } else {
-            if (!StringUtils.isEmpty(namingPolicyUpdate)) {
+            if (StringUtils.isNotEmpty(namingPolicyUpdate)) {
                 log.warn("NamingPolicy must be empty for EcompGeneratedNaming=false");
             }
             service.setNamingPolicy("");
index 10c831b..6e10a20 100644 (file)
@@ -45,26 +45,22 @@ public class ServiceRoleValidator implements ServiceFieldValidator {
     @Override
     public void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum) {
         log.debug("validate service role");
-        String serviceRole = service.getServiceRole();
-        if (serviceRole != null) {
-            validateServiceRole(serviceRole);
-        }
+        validateServiceRole(service.getServiceRole());
     }
 
     private void validateServiceRole(String serviceRole) {
         if (StringUtils.isEmpty(serviceRole)) {
             return;
-        } else {
-            if (!ValidationUtils.validateServiceRoleLength(serviceRole)) {
-                log.info("service role exceeds limit.");
-                ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.PROPERTY_EXCEEDS_LIMIT, "" + SERVICE_ROLE);
-                throw new ByResponseFormatComponentException(errorResponse);
-            }
-            if (!ValidationUtils.validateServiceMetadata(serviceRole)) {
-                log.info("service role is not valid.");
-                ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERY, "" + SERVICE_ROLE);
-                throw new ByResponseFormatComponentException(errorResponse);
-            }
+        }
+        if (!ValidationUtils.validateServiceRoleLength(serviceRole)) {
+            log.info("service role exceeds limit.");
+            ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.PROPERTY_EXCEEDS_LIMIT, "" + SERVICE_ROLE);
+            throw new ByResponseFormatComponentException(errorResponse);
+        }
+        if (!ValidationUtils.validateServiceMetadata(serviceRole)) {
+            log.info("service role is not valid.");
+            ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERY, "" + SERVICE_ROLE);
+            throw new ByResponseFormatComponentException(errorResponse);
         }
     }
 }
index 2b592d8..d847a9a 100644 (file)
  */
 package org.openecomp.sdc.be.components.validation.service;
 
+import org.apache.commons.lang3.StringUtils;
 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
 import org.openecomp.sdc.be.dao.api.ActionStatus;
 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
 import org.openecomp.sdc.be.model.Service;
 import org.openecomp.sdc.be.model.User;
 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
@@ -34,25 +34,15 @@ public class ServiceTypeValidator implements ServiceFieldValidator {
 
     private static final Logger log = Logger.getLogger(ServiceTypeValidator.class.getName());
     private static final String SERVICE_TYPE = JsonPresentationFields.SERVICE_TYPE.getPresentation();
-    private ComponentsUtils componentsUtils;
-
-    public ServiceTypeValidator(ComponentsUtils componentsUtils) {
-        this.componentsUtils = componentsUtils;
-    }
 
     @Override
     public void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum) {
         log.debug("validate service type");
-        String serviceType = service.getServiceType();
-        if (serviceType == null) {
-            log.info("service type is not valid.");
-            throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY, "" + SERVICE_TYPE);
-        }
-        validateServiceType(serviceType);
+        validateServiceType(service.getServiceType());
     }
 
     private void validateServiceType(String serviceType) {
-        if (serviceType.isEmpty()) {
+        if (StringUtils.isEmpty(serviceType)) {
             return;
         }
         if (!ValidationUtils.validateServiceTypeLength(serviceType)) {
index 36975f8..df4810d 100644 (file)
@@ -1166,10 +1166,6 @@ public class ComponentsUtils {
         return responseFormat;
     }
 
-    public boolean validateStringNotEmpty(String value) {
-        return value != null && !value.trim().isEmpty();
-    }
-
     public ActionStatus convertFromStorageResponseForAdditionalInformation(StorageOperationStatus storageResponse) {
         ActionStatus responseEnum;
         switch (storageResponse) {
index fa7d2a0..4d99b4d 100644 (file)
@@ -358,7 +358,7 @@ public class ToscaExportHandler {
     }
 
     private List<Map<String, Map<String, String>>> getDefaultToscaImports(final String modelId) {
-        if (modelId == null) {
+        if (StringUtils.isEmpty(modelId)) {
             return getDefaultToscaImportConfig();
         }
 
index 049f8a5..41dc573 100644 (file)
@@ -120,7 +120,7 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
     protected ResourceAdminEvent auditArchive2 = Mockito.mock(ResourceAdminEvent.class);
     protected ResourceAdminEvent auditRestore = Mockito.mock(ResourceAdminEvent.class);
     protected ModelOperation modelOperation = Mockito.mock(ModelOperation.class);
-    protected ServiceTypeValidator serviceTypeValidator = new ServiceTypeValidator(componentsUtils);
+    protected ServiceTypeValidator serviceTypeValidator = new ServiceTypeValidator();
     protected ServiceRoleValidator serviceRoleValidator = new ServiceRoleValidator(componentsUtils);
     protected ServiceFunctionValidator serviceFunctionValidator = new ServiceFunctionValidator(componentsUtils);
     protected ServiceInstantiationTypeValidator serviceInstantiationTypeValidator = new ServiceInstantiationTypeValidator(componentsUtils);
index 4167036..407956d 100644 (file)
@@ -154,7 +154,6 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
         assertTrue(createResponse.isLeft());
     }
 
-
     @Test
     void testCreateServiceWhenGenericTypeHasProperties() {
         final Service service = createServiceObject(false);
@@ -255,8 +254,6 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
             actualService.getProperties(), is(expectedService.getProperties()));
     }
 
-
-
     /* CREATE validations - start ***********************/
     // Service name - start
 
@@ -644,7 +641,6 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
         fail();
     }
 
-
     private void testProjectCodeTooShort() {
 
         Service serviceExist = createServiceObject(false);
@@ -701,7 +697,7 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
         eitherService.left().value().setArchived(false);
         Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
         final ComponentException actualException = assertThrows(ComponentException.class, () -> bl.deleteServiceAllVersions(serviceId, user));
-        assertEquals(actualException.getActionStatus(), ActionStatus.COMPONENT_NOT_ARCHIVED);
+        assertEquals(ActionStatus.COMPONENT_NOT_ARCHIVED, actualException.getActionStatus());
         assertEquals(actualException.getParams()[0], serviceId);
     }
 
@@ -893,16 +889,16 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
         newService.setServiceType("");
         resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService, false, new ArrayList<>());
         assertThat(resultOfUpdate.isLeft()).isTrue();
-        //null is invalid
+        //null is valid
         newService.setServiceType(null);
         resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService, false, new ArrayList<>());
-        assertThat(resultOfUpdate.isRight()).isTrue();
+        assertThat(resultOfUpdate.isLeft()).isTrue();
     }
 
     @Test
     void testCreateDefaultMetadataServiceFunction() {
         Service currentService = createServiceObject(true);
-        assertThat(currentService.getServiceFunction()).isEqualTo("");
+        assertThat(currentService.getServiceFunction()).isEmpty();
     }
 
     @Test
@@ -933,10 +929,9 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
         newService.setServiceFunction(null);
         resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService, false, new ArrayList<>());
         assertThat(resultOfUpdate.isLeft()).isTrue();
-        assertThat(updatedService.getServiceFunction()).isEqualTo("");
+        assertThat(updatedService.getServiceFunction()).isEmpty();
     }
 
-
     @Test
     void testServiceFunctionExceedLength() {
         String serviceName = "Service";
@@ -1096,7 +1091,6 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
         return propertyList;
     }
 
-
     @Test
     void testCreateService_withMultitenancyValidTenant_Success() {
         Assert.assertTrue(MULTITENANCY_ENABLED);
@@ -1113,7 +1107,6 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
         assertEqualsServiceObject(createServiceObject(true), createResponse.left().value());
     }
 
-
     @Test
     void testCreateService_withMultitenancyInvalidTenant_Failure() {
         Service service = createServiceObject(false);
index 45e7f4a..df53faa 100644 (file)
@@ -143,7 +143,7 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
     protected UserValidations userValidations = mock(UserValidations.class);
     protected CatalogOperation catalogOperation = mock(CatalogOperation.class);
     protected ServiceImportParseLogic serviceImportParseLogic = mock(ServiceImportParseLogic.class);
-    protected ServiceTypeValidator serviceTypeValidator = new ServiceTypeValidator(componentsUtils);
+    protected ServiceTypeValidator serviceTypeValidator = new ServiceTypeValidator();
     protected ServiceRoleValidator serviceRoleValidator = new ServiceRoleValidator(componentsUtils);
     protected ServiceFunctionValidator serviceFunctionValidator = new ServiceFunctionValidator(componentsUtils);
     protected ServiceInstantiationTypeValidator serviceInstantiationTypeValidator = new ServiceInstantiationTypeValidator(componentsUtils);
index 0fb88a5..5acc1fd 100644 (file)
@@ -562,18 +562,6 @@ class ComponentsUtilsTest {
         testSubject.auditComponent(responseFormat, modifier, component, actionEnum, type, prevComponent);
     }
 
-    @Test
-    void testValidateStringNotEmpty() {
-        ComponentsUtils testSubject;
-        String value = "";
-        boolean result;
-
-        // default test
-        testSubject = createTestSubject();
-        result = testSubject.validateStringNotEmpty(value);
-        assertThat(result).isFalse();
-    }
-
     @Test
     void testConvertFromStorageResponseForAdditionalInformation() {
         ComponentsUtils testSubject;
index 22548db..f75c7a6 100644 (file)
@@ -1497,7 +1497,7 @@ public class NodeTemplateOperation extends BaseOperation {
                                                                                  String instanceNewName, boolean generateUid,
                                                                                  ToscaElement originToscaElement) {
         String ciOriginComponentUid = resourceInstance.getComponentUid();
-        if (!ValidationUtils.validateStringNotEmpty(resourceInstance.getCustomizationUUID())) {
+        if (StringUtils.isEmpty(resourceInstance.getCustomizationUUID())) {
             resourceInstance.setCustomizationUUID(generateCustomizationUUID());
         }
         ComponentInstanceDataDefinition dataDefinition = new ComponentInstanceDataDefinition(resourceInstance);
index 13729bf..24e1e91 100644 (file)
@@ -39,6 +39,7 @@ import java.util.Set;
 import java.util.stream.Collectors;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.tinkerpop.gremlin.structure.Direction;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -475,10 +476,11 @@ public abstract class ToscaElementOperation extends BaseOperation {
 
     protected StorageOperationStatus associateComponentToModel(final GraphVertex nodeTypeVertex, final ToscaElement nodeType,
                                                                final EdgeLabelEnum edgeLabelEnum) {
-        if (nodeType.getMetadataValue(JsonPresentationFields.MODEL) == null) {
+        Object metadataValue = nodeType.getMetadataValue(JsonPresentationFields.MODEL);
+        if (metadataValue == null || StringUtils.isEmpty((String) metadataValue)) {
             return StorageOperationStatus.OK;
         }
-        final String model = ((String) nodeType.getMetadataValue(JsonPresentationFields.MODEL));
+        final String model = ((String) metadataValue);
         final JanusGraphOperationStatus createEdge = janusGraphDao.createEdge(getModelVertex(model), nodeTypeVertex, edgeLabelEnum, new HashMap<>());
         if (createEdge != JanusGraphOperationStatus.OK) {
             log.trace("Failed to associate resource {} to model {}", nodeType.getUniqueId(), model);
index a0403de..7c5e5fc 100644 (file)
@@ -215,7 +215,7 @@ public class ValidationUtils {
     }
 
     public static boolean validateResourceInstanceNameLength(String resourceInstanceName) {
-        return resourceInstanceName.length() <= RSI_NAME_MAX_LENGTH;
+        return StringUtils.isEmpty(resourceInstanceName) || resourceInstanceName.length() <= RSI_NAME_MAX_LENGTH;
     }
 
     public static boolean validateResourceInstanceName(String resourceInstanceName) {
@@ -223,7 +223,7 @@ public class ValidationUtils {
     }
 
     public static boolean validateUrlLength(String url) {
-        return url.length() <= API_URL_LENGTH;
+        return StringUtils.isEmpty(url) || url.length() <= API_URL_LENGTH;
     }
 
     public static boolean validateArtifactNameLength(String artifactName) {
@@ -235,7 +235,7 @@ public class ValidationUtils {
     }
 
     public static boolean validateComponentNameLength(String componentName) {
-        return componentName.length() <= COMPONENT_NAME_MAX_LENGTH;
+        return StringUtils.isEmpty(componentName) || componentName.length() <= COMPONENT_NAME_MAX_LENGTH;
     }
 
     public static boolean validateIcon(String icon) {
@@ -243,7 +243,7 @@ public class ValidationUtils {
     }
 
     public static boolean validateIconLength(String icon) {
-        return icon.length() <= ICON_MAX_LENGTH;
+        return StringUtils.isEmpty(icon) || icon.length() <= ICON_MAX_LENGTH;
     }
 
     public static boolean validateProjectCode(String projectCode) {
@@ -251,7 +251,7 @@ public class ValidationUtils {
     }
 
     public static boolean validateProjectCodeLegth(String projectCode) {
-        return projectCode.length() <= PROJECT_CODE_MAX_LEGTH;
+        return StringUtils.isEmpty(projectCode) || projectCode.length() <= PROJECT_CODE_MAX_LEGTH;
     }
 
     public static boolean validateContactId(String contactId) {
@@ -340,14 +340,7 @@ public class ValidationUtils {
     }
 
     public static boolean validateDescriptionLength(String description) {
-        return description.length() <= COMPONENT_DESCRIPTION_MAX_LENGTH;
-    }
-
-    public static boolean validateStringNotEmpty(String value) {
-        if ((value == null) || (value.isEmpty())) {
-            return false;
-        }
-        return true;
+        return StringUtils.isEmpty(description) || description.length() <= COMPONENT_DESCRIPTION_MAX_LENGTH;
     }
 
     public static boolean validateListNotEmpty(List<?> list) {
@@ -362,35 +355,35 @@ public class ValidationUtils {
     }
 
     public static boolean validateVendorNameLength(String vendorName) {
-        return vendorName.length() <= VENDOR_NAME_MAX_LENGTH;
+        return StringUtils.isEmpty(vendorName) || vendorName.length() <= VENDOR_NAME_MAX_LENGTH;
     }
 
     public static boolean validateResourceVendorModelNumberLength(String resourceVendorModelNumber) {
-        return resourceVendorModelNumber.length() <= RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH;
+        return StringUtils.isEmpty(resourceVendorModelNumber) || resourceVendorModelNumber.length() <= RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH;
     }
 
     public static boolean validateVendorRelease(String vendorRelease) {
-        return VENDOR_RELEASE_PATTERN.matcher(vendorRelease).matches();
+        return StringUtils.isEmpty(vendorRelease) || VENDOR_RELEASE_PATTERN.matcher(vendorRelease).matches();
     }
 
     public static boolean validateVendorReleaseLength(String vendorRelease) {
-        return vendorRelease.length() <= VENDOR_RELEASE_MAX_LENGTH;
+        return StringUtils.isEmpty(vendorRelease) || vendorRelease.length() <= VENDOR_RELEASE_MAX_LENGTH;
     }
 
     public static boolean validateServiceTypeLength(String serviceType) {
-        return serviceType.length() <= SERVICE_TYPE_MAX_LENGTH;
+        return StringUtils.isEmpty(serviceType) || serviceType.length() <= SERVICE_TYPE_MAX_LENGTH;
     }
 
     public static boolean validateServiceRoleLength(String serviceRole) {
-        return serviceRole.length() <= SERVICE_ROLE_MAX_LENGTH;
+        return StringUtils.isEmpty(serviceRole) || serviceRole.length() <= SERVICE_ROLE_MAX_LENGTH;
     }
 
     public static boolean validateServiceFunctionLength(String serviceFunction) {
-        return serviceFunction.length() <= SERVICE_FUNCTION_MAX_LENGTH;
+        return StringUtils.isEmpty(serviceFunction) || serviceFunction.length() <= SERVICE_FUNCTION_MAX_LENGTH;
     }
 
     public static boolean validateServiceNamingPolicyLength(String namingPolicy) {
-        return namingPolicy.length() <= SERVICE_NAMING_POLICY_MAX_SIZE;
+        return StringUtils.isEmpty(namingPolicy) || namingPolicy.length() <= SERVICE_NAMING_POLICY_MAX_SIZE;
     }
 
     public static boolean hasBeenCertified(String version) {
index 73d8c11..ca9cc0b 100644 (file)
@@ -224,14 +224,6 @@ public class CommonUtilsTest {
 
        }
 
-       @Test
-       public void validateStringNotEmptyTest() {
-               assertTrue(ValidationUtils.validateStringNotEmpty("fsdlfsdlk"));
-               assertFalse(ValidationUtils.validateStringNotEmpty(""));
-               assertFalse(!ValidationUtils.validateStringNotEmpty("  "));
-               assertFalse(!ValidationUtils.validateStringNotEmpty("   "));
-       }
-
        @Test
        public void validateVendorNameTest() {
                assertTrue(ValidationUtils.validateVendorName("fsdlfsdlk"));
index e7aad96..3408c68 100644 (file)
@@ -525,24 +525,6 @@ public class ValidationUtilsTest {
                assertFalse(result);
        }
 
-       @Test
-       public void checkValidateStringNotEmptyReturnsFalseIfStringIsNotEmpty() {
-               final String testString = "test";
-
-               boolean result = ValidationUtils.validateStringNotEmpty(testString);
-
-               assertTrue(result);
-       }
-
-       @Test
-       public void checkValidateStringNotEmptyReturnsFTrueIfStringIsEmpty() {
-               final String testString =  "";
-
-               boolean result = ValidationUtils.validateStringNotEmpty(testString);
-
-               assertFalse(result);
-       }
-
        @Test
        public void checkValidateVendorNameReturnsTrueIfNameFitsPattern() {
                final String testVendorName =  "testVendor";