aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2023-08-29 15:29:59 +0100
committerMichael Morris <michael.morris@est.tech>2023-09-05 09:50:12 +0000
commit438650c3a958c9176db3720204ec1ff9af94fc3a (patch)
treef0dc5b6b5bd837a6f689245e8a41d36d0a488f9b /catalog-be
parent0c47a1b7118b45eecbbb0064b635efb026173ec4 (diff)
Improve handling 'empty'/null string in Service fields
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: Ib301280fe1be2896e2d80e208349ac3c4ff763ec Issue-ID: SDC-4608
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogic.java7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java9
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentContactIdValidator.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentDescriptionValidator.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentProjectCodeValidator.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceCategoryValidator.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceNamingPolicyValidator.java10
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceRoleValidator.java26
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceTypeValidator.java16
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java17
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java12
21 files changed, 62 insertions, 94 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java
index 837b1185f3..6153309bb6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java
@@ -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));
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
index c17af4d4de..d50ae540a5 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
@@ -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;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
index b3d0bfc573..0b60a3671d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
@@ -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);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogic.java
index 4db24c1a25..93fb171539 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogic.java
@@ -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));
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java
index aca253682c..9344f68275 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java
@@ -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);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
index 6e385b200a..84e68e6868 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
@@ -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);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
index 5bde56de80..9365fac4fc 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
@@ -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);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java
index 8b01ff1853..b569c67852 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java
@@ -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);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentContactIdValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentContactIdValidator.java
index 2a177c632e..5f27ba1659 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentContactIdValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentContactIdValidator.java
@@ -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);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentDescriptionValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentDescriptionValidator.java
index 8cf985feb6..f3c94f0eff 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentDescriptionValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentDescriptionValidator.java
@@ -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);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentProjectCodeValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentProjectCodeValidator.java
index 29b4fdab75..af0838144a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentProjectCodeValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentProjectCodeValidator.java
@@ -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;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceCategoryValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceCategoryValidator.java
index f8b3fff6c2..5803259be8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceCategoryValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceCategoryValidator.java
@@ -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());
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceNamingPolicyValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceNamingPolicyValidator.java
index 73acf20c53..11974acc34 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceNamingPolicyValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceNamingPolicyValidator.java
@@ -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("");
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceRoleValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceRoleValidator.java
index 10c831b909..6e10a20887 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceRoleValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceRoleValidator.java
@@ -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);
}
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceTypeValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceTypeValidator.java
index 2b592d8f9c..d847a9ac38 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceTypeValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceTypeValidator.java
@@ -19,10 +19,10 @@
*/
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)) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
index 36975f81d8..df4810d334 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
@@ -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) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
index fa7d2a0d83..4d99b4de98 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -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();
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java
index 049f8a5541..41dc5736c3 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java
@@ -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);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java
index 416703637f..407956db0e 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java
@@ -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);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java
index 45e7f4a7ad..df53faa3b7 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java
@@ -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);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java
index 0fb88a531b..5acc1fd116 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java
@@ -563,18 +563,6 @@ class ComponentsUtilsTest {
}
@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;
StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND;