Improve handling 'empty'/null string in Service fields
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / validation / service / ServiceNamingPolicyValidator.java
index 5a76542..11974ac 100644 (file)
@@ -17,7 +17,6 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
-
 package org.openecomp.sdc.be.components.validation.service;
 
 import org.apache.commons.lang3.StringUtils;
@@ -41,6 +40,7 @@ public class ServiceNamingPolicyValidator implements ServiceFieldValidator {
     public ServiceNamingPolicyValidator(ComponentsUtils componentsUtils) {
         this.componentsUtils = componentsUtils;
     }
+
     @Override
     public void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum) {
         Boolean isEcompGeneratedCurr = service.isEcompGeneratedNaming();
@@ -49,20 +49,19 @@ public class ServiceNamingPolicyValidator implements ServiceFieldValidator {
             throw new ByActionStatusComponentException(ActionStatus.MISSING_ECOMP_GENERATED_NAMING);
         }
         if (isEcompGeneratedCurr) {
-            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.validateServiceNamingPolicyLength(namingPolicyUpdate)) {
+                ResponseFormat responseFormat = componentsUtils
+                    .getResponseFormat(ActionStatus.NAMING_POLICY_EXCEEDS_LIMIT, "" + ValidationUtils.SERVICE_NAMING_POLICY_MAX_SIZE);
+                throw new ByResponseFormatComponentException(responseFormat);
+            }
             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("");