summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/validation')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AccessValidations.java18
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AnnotationValidator.java36
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ApiResourceEnum.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/CapabilitiesValidation.java147
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ComponentValidations.java57
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java430
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java247
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PolicyUtils.java96
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PropertyValidator.java91
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/RequirementValidation.java186
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidation.java40
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java67
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ValidationException.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ValidationUtils.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentContactIdValidator.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentDescriptionValidator.java15
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentFieldValidator.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentIconValidator.java20
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentNameValidator.java25
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentProjectCodeValidator.java9
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentTagsValidator.java22
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentValidator.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceCategoryValidator.java21
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceEnvironmentContextValidator.java16
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFieldValidator.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFunctionValidator.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceInstantiationTypeValidator.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceNamingPolicyValidator.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceRoleValidator.java14
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceTypeValidator.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceValidator.java10
31 files changed, 641 insertions, 987 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AccessValidations.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AccessValidations.java
index 5674c2b4cb..e1f902dee6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AccessValidations.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AccessValidations.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,17 +17,15 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation;
+import java.util.ArrayList;
+import java.util.List;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.user.Role;
-import java.util.ArrayList;
-import java.util.List;
-
@org.springframework.stereotype.Component
public class AccessValidations {
@@ -39,10 +37,10 @@ public class AccessValidations {
this.componentValidations = componentValidations;
}
- public Component validateUserCanRetrieveComponentData(String componentId, String componentType, String userId, String actionContext) {
+ public Component validateUserCanRetrieveComponentData(String componentId, String componentType, String userId, String actionContext) {
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
retrieveUser(userId, actionContext);
- return componentValidations.getComponent(componentId, componentTypeEnum);
+ return componentValidations.getComponent(componentId, componentTypeEnum);
}
public Component validateUserCanWorkOnComponent(String componentId, ComponentTypeEnum componentType, String userId, String actionContext) {
@@ -61,12 +59,11 @@ public class AccessValidations {
retrieveUser(userId, context);
}
-
public void validateUserExist(String userId, String actionContext) {
userValidations.validateUserExists(userId);
}
- public User userIsAdminOrDesigner(String userId, String actionContext){
+ public User userIsAdminOrDesigner(String userId, String actionContext) {
User user = retrieveUser(userId, actionContext);
validateUserIsAdminOrDesigner(user);
return user;
@@ -82,5 +79,4 @@ public class AccessValidations {
roles.add(Role.DESIGNER);
userValidations.validateUserRole(user, roles);
}
-
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AnnotationValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AnnotationValidator.java
index 428d6d9d19..b4f6bbe7db 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AnnotationValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AnnotationValidator.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,9 +17,11 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
import org.openecomp.sdc.be.components.impl.utils.ExceptionUtils;
import org.openecomp.sdc.be.datatypes.elements.Annotation;
@@ -32,25 +34,17 @@ import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.stereotype.Component;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
@Component
public class AnnotationValidator {
-
+ private static final Logger log = Logger.getLogger(ResourceImportManager.class);
private final PropertyValidator propertyValidator;
private final ExceptionUtils exceptionUtils;
private final ApplicationDataTypeCache dataTypeCache;
private final ComponentsUtils componentsUtils;
- private static final Logger log = Logger.getLogger(ResourceImportManager.class);
-
-
- public AnnotationValidator(PropertyValidator propertyValidator
- , ExceptionUtils exceptionUtils, ApplicationDataTypeCache dataTypeCache
- ,ComponentsUtils componentsUtils) {
+ public AnnotationValidator(PropertyValidator propertyValidator, ExceptionUtils exceptionUtils, ApplicationDataTypeCache dataTypeCache,
+ ComponentsUtils componentsUtils) {
this.propertyValidator = propertyValidator;
this.exceptionUtils = exceptionUtils;
this.dataTypeCache = dataTypeCache;
@@ -59,9 +53,8 @@ public class AnnotationValidator {
public List<Annotation> validateAnnotationsProperties(Annotation annotation, AnnotationTypeDefinition dbAnnotationTypeDefinition) {
List<Annotation> validAnnotations = new ArrayList<>();
- if (annotation != null && propertiesValidator(
- annotation.getProperties(), dbAnnotationTypeDefinition.getProperties())) {
- validAnnotations.add(annotation);
+ if (annotation != null && propertiesValidator(annotation.getProperties(), dbAnnotationTypeDefinition.getProperties())) {
+ validAnnotations.add(annotation);
}
return validAnnotations;
}
@@ -71,14 +64,9 @@ public class AnnotationValidator {
if (properties == null || dbAnnotationTypeDefinitionProperties == null) {
return false;
}
- properties.stream()
- .forEach(property -> propertyDefinitionsList.add(new PropertyDefinition(property)));
- Map<String, DataTypeDefinition> allDataTypes = dataTypeCache.getAll()
- .left()
- .on( error -> exceptionUtils
- .rollBackAndThrow(error));
+ properties.stream().forEach(property -> propertyDefinitionsList.add(new PropertyDefinition(property)));
+ Map<String, DataTypeDefinition> allDataTypes = dataTypeCache.getAll().left().on(error -> exceptionUtils.rollBackAndThrow(error));
propertyValidator.thinPropertiesValidator(propertyDefinitionsList, dbAnnotationTypeDefinitionProperties, allDataTypes);
return true;
}
-
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ApiResourceEnum.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ApiResourceEnum.java
index 7f217b95b1..da8e8bbf4d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ApiResourceEnum.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ApiResourceEnum.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation;
import lombok.Getter;
@@ -27,11 +26,7 @@ import lombok.Getter;
*/
@Getter
public enum ApiResourceEnum {
-
- ENVIRONMENT_ID("Environment ID"),
- RESOURCE_ID("Resource ID"),
- SERVICE_ID("Service ID");
-
+ ENVIRONMENT_ID("Environment ID"), RESOURCE_ID("Resource ID"), SERVICE_ID("Service ID");
private String value;
ApiResourceEnum(String value) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/CapabilitiesValidation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/CapabilitiesValidation.java
index 2c69ee5b38..3f53f6b993 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/CapabilitiesValidation.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/CapabilitiesValidation.java
@@ -13,10 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.be.components.validation;
import fj.data.Either;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
@@ -28,26 +33,17 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
@Component("capabilitiesValidation")
public class CapabilitiesValidation {
+
private static final Logger LOGGER = LoggerFactory.getLogger(CapabilitiesValidation.class);
private static final String CAPABILITY_NOT_FOUND_IN_COMPONENT = "Capability not found in component {} ";
private static final Pattern NAME_VALIDATION_REGEX_PATTERN = Pattern.compile("^[a-zA-Z0-9_.]*$");
- public Either<Boolean, ResponseFormat> validateCapabilities(
- Collection<CapabilityDefinition> capabilities,
- org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
-
- for(CapabilityDefinition capabilityDefinition : capabilities) {
- Either<Boolean, ResponseFormat> validateCapabilityResponse = validateCapability(capabilityDefinition,
- component, isUpdate);
+ public Either<Boolean, ResponseFormat> validateCapabilities(Collection<CapabilityDefinition> capabilities,
+ org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
+ for (CapabilityDefinition capabilityDefinition : capabilities) {
+ Either<Boolean, ResponseFormat> validateCapabilityResponse = validateCapability(capabilityDefinition, component, isUpdate);
if (validateCapabilityResponse.isRight()) {
return validateCapabilityResponse;
}
@@ -56,29 +52,25 @@ public class CapabilitiesValidation {
}
private Either<Boolean, ResponseFormat> validateCapability(CapabilityDefinition capabilityDefinition,
- org.openecomp.sdc.be.model.Component component,
- boolean isUpdate) {
+ org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
ResponseFormatManager responseFormatManager = getResponseFormatManager();
-
- if(isUpdate) {
- Either<Boolean, ResponseFormat> capabilityExistValidationEither
- = isCapabilityExist(capabilityDefinition, responseFormatManager, component);
+ if (isUpdate) {
+ Either<Boolean, ResponseFormat> capabilityExistValidationEither = isCapabilityExist(capabilityDefinition, responseFormatManager,
+ component);
if (capabilityExistValidationEither.isRight()) {
return Either.right(capabilityExistValidationEither.right().value());
}
}
- Either<Boolean, ResponseFormat> capabilityNameValidationResponse
- = validateCapabilityName(capabilityDefinition, responseFormatManager, component, isUpdate);
+ Either<Boolean, ResponseFormat> capabilityNameValidationResponse = validateCapabilityName(capabilityDefinition, responseFormatManager,
+ component, isUpdate);
if (capabilityNameValidationResponse.isRight()) {
return Either.right(capabilityNameValidationResponse.right().value());
}
- Either<Boolean, ResponseFormat> capabilityTypeEmptyEither =
- isCapabilityTypeEmpty(responseFormatManager, capabilityDefinition.getType());
+ Either<Boolean, ResponseFormat> capabilityTypeEmptyEither = isCapabilityTypeEmpty(responseFormatManager, capabilityDefinition.getType());
if (capabilityTypeEmptyEither.isRight()) {
return Either.right(capabilityTypeEmptyEither.right().value());
}
- Either<Boolean, ResponseFormat> capabilityOccurrencesValidationEither =
- validateOccurrences(capabilityDefinition, responseFormatManager);
+ Either<Boolean, ResponseFormat> capabilityOccurrencesValidationEither = validateOccurrences(capabilityDefinition, responseFormatManager);
if (capabilityOccurrencesValidationEither.isRight()) {
return Either.right(capabilityOccurrencesValidationEither.right().value());
}
@@ -89,9 +81,9 @@ public class CapabilitiesValidation {
ResponseFormatManager responseFormatManager) {
String maxOccurrences = capabilityDefinition.getMaxOccurrences();
String minOccurrences = capabilityDefinition.getMinOccurrences();
- if(maxOccurrences != null && minOccurrences != null) {
- Either<Boolean, ResponseFormat> capabilityOccurrencesValidationEither =
- validateOccurrences(responseFormatManager, minOccurrences, maxOccurrences);
+ if (maxOccurrences != null && minOccurrences != null) {
+ Either<Boolean, ResponseFormat> capabilityOccurrencesValidationEither = validateOccurrences(responseFormatManager, minOccurrences,
+ maxOccurrences);
if (capabilityOccurrencesValidationEither.isRight()) {
return Either.right(capabilityOccurrencesValidationEither.right().value());
}
@@ -99,32 +91,26 @@ public class CapabilitiesValidation {
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> isCapabilityExist(CapabilityDefinition definition,
- ResponseFormatManager responseFormatManager,
+ private Either<Boolean, ResponseFormat> isCapabilityExist(CapabilityDefinition definition, ResponseFormatManager responseFormatManager,
org.openecomp.sdc.be.model.Component component) {
Map<String, List<CapabilityDefinition>> componentCapabilities = component.getCapabilities();
- if(MapUtils.isEmpty(componentCapabilities)){
+ if (MapUtils.isEmpty(componentCapabilities)) {
LOGGER.error(CAPABILITY_NOT_FOUND_IN_COMPONENT, component.getUniqueId());
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .CAPABILITY_NOT_FOUND, component.getUniqueId());
+ ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus.CAPABILITY_NOT_FOUND, component.getUniqueId());
return Either.right(errorResponse);
}
-
- List<CapabilityDefinition> capabilityDefinitionList = componentCapabilities.values()
- .stream().flatMap(Collection::stream).collect(Collectors.toList());
- if(CollectionUtils.isEmpty(capabilityDefinitionList)){
+ List<CapabilityDefinition> capabilityDefinitionList = componentCapabilities.values().stream().flatMap(Collection::stream)
+ .collect(Collectors.toList());
+ if (CollectionUtils.isEmpty(capabilityDefinitionList)) {
LOGGER.error(CAPABILITY_NOT_FOUND_IN_COMPONENT, component.getUniqueId());
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .CAPABILITY_NOT_FOUND, component.getUniqueId());
+ ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus.CAPABILITY_NOT_FOUND, component.getUniqueId());
return Either.right(errorResponse);
}
- boolean isCapabilityExist = capabilityDefinitionList.stream().anyMatch(capabilityDefinition ->
- capabilityDefinition.getUniqueId().equalsIgnoreCase(definition.getUniqueId()));
-
- if(!isCapabilityExist) {
+ boolean isCapabilityExist = capabilityDefinitionList.stream()
+ .anyMatch(capabilityDefinition -> capabilityDefinition.getUniqueId().equalsIgnoreCase(definition.getUniqueId()));
+ if (!isCapabilityExist) {
LOGGER.error(CAPABILITY_NOT_FOUND_IN_COMPONENT, component.getUniqueId());
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .CAPABILITY_NOT_FOUND, component.getUniqueId());
+ ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus.CAPABILITY_NOT_FOUND, component.getUniqueId());
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
@@ -132,36 +118,30 @@ public class CapabilitiesValidation {
private Either<Boolean, ResponseFormat> validateCapabilityName(CapabilityDefinition capabilityDefinition,
ResponseFormatManager responseFormatManager,
- org.openecomp.sdc.be.model.Component component,
- boolean isUpdate) {
- Either<Boolean, ResponseFormat> capabilityNameEmptyEither =
- isCapabilityNameEmpty(responseFormatManager, capabilityDefinition.getName());
+ org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
+ Either<Boolean, ResponseFormat> capabilityNameEmptyEither = isCapabilityNameEmpty(responseFormatManager, capabilityDefinition.getName());
if (capabilityNameEmptyEither.isRight()) {
return Either.right(capabilityNameEmptyEither.right().value());
}
-
- Either<Boolean, ResponseFormat> capabilityNameRegexValidationResponse =
- isCapabilityNameRegexValid(responseFormatManager, capabilityDefinition.getName());
+ Either<Boolean, ResponseFormat> capabilityNameRegexValidationResponse = isCapabilityNameRegexValid(responseFormatManager,
+ capabilityDefinition.getName());
if (capabilityNameRegexValidationResponse.isRight()) {
return Either.right(capabilityNameRegexValidationResponse.right().value());
}
-
- Either<Boolean, ResponseFormat> operationTypeUniqueResponse
- = validateCapabilityNameUnique(capabilityDefinition, component, isUpdate );
- if(operationTypeUniqueResponse.isRight()) {
+ Either<Boolean, ResponseFormat> operationTypeUniqueResponse = validateCapabilityNameUnique(capabilityDefinition, component, isUpdate);
+ if (operationTypeUniqueResponse.isRight()) {
return Either.right(operationTypeUniqueResponse.right().value());
}
if (!operationTypeUniqueResponse.left().value()) {
LOGGER.error("Capability name {} already in use ", capabilityDefinition.getName());
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .CAPABILITY_NAME_ALREADY_IN_USE, capabilityDefinition.getName());
+ ResponseFormat errorResponse = responseFormatManager
+ .getResponseFormat(ActionStatus.CAPABILITY_NAME_ALREADY_IN_USE, capabilityDefinition.getName());
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> isCapabilityNameEmpty(ResponseFormatManager responseFormatManager,
- String capabilityName) {
+ private Either<Boolean, ResponseFormat> isCapabilityNameEmpty(ResponseFormatManager responseFormatManager, String capabilityName) {
if (StringUtils.isEmpty(capabilityName)) {
LOGGER.error("Capability Name is mandatory");
ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus.CAPABILITY_NAME_MANDATORY);
@@ -170,8 +150,7 @@ public class CapabilitiesValidation {
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> isCapabilityTypeEmpty(ResponseFormatManager responseFormatManager,
- String capabilityType) {
+ private Either<Boolean, ResponseFormat> isCapabilityTypeEmpty(ResponseFormatManager responseFormatManager, String capabilityType) {
if (StringUtils.isEmpty(capabilityType)) {
LOGGER.error("Capability type is mandatory");
ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus.CAPABILITY_TYPE_MANDATORY);
@@ -180,11 +159,10 @@ public class CapabilitiesValidation {
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> validateOccurrences (ResponseFormatManager responseFormatManager,
- String minOccurrences, String maxOccurrences ) {
+ private Either<Boolean, ResponseFormat> validateOccurrences(ResponseFormatManager responseFormatManager, String minOccurrences,
+ String maxOccurrences) {
try {
- if (StringUtils.isNotEmpty(maxOccurrences) && "UNBOUNDED".equalsIgnoreCase(maxOccurrences)
- && Integer.parseInt(minOccurrences) >= 0) {
+ if (StringUtils.isNotEmpty(maxOccurrences) && "UNBOUNDED".equalsIgnoreCase(maxOccurrences) && Integer.parseInt(minOccurrences) >= 0) {
return Either.left(Boolean.TRUE);
} else if (Integer.parseInt(minOccurrences) < 0) {
LOGGER.debug("Invalid occurrences format.low_bound occurrence negative {}", minOccurrences);
@@ -192,8 +170,8 @@ public class CapabilitiesValidation {
return Either.right(responseFormat);
} else if (Integer.parseInt(maxOccurrences) < Integer.parseInt(minOccurrences)) {
LOGGER.error("Capability maxOccurrences should be greater than minOccurrences");
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .MAX_OCCURRENCES_SHOULD_BE_GREATER_THAN_MIN_OCCURRENCES);
+ ResponseFormat errorResponse = responseFormatManager
+ .getResponseFormat(ActionStatus.MAX_OCCURRENCES_SHOULD_BE_GREATER_THAN_MIN_OCCURRENCES);
return Either.right(errorResponse);
}
} catch (NumberFormatException ex) {
@@ -205,40 +183,36 @@ public class CapabilitiesValidation {
}
private Either<Boolean, ResponseFormat> validateCapabilityNameUnique(CapabilityDefinition capabilityDefinition,
- org.openecomp.sdc.be.model.Component component,
- boolean isUpdate) {
+ org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
boolean isCapabilityNameUnique = false;
Map<String, List<CapabilityDefinition>> componentCapabilities = component.getCapabilities();
- if(MapUtils.isEmpty(componentCapabilities)){
+ if (MapUtils.isEmpty(componentCapabilities)) {
return Either.left(true);
}
- List<CapabilityDefinition> capabilityDefinitionList = componentCapabilities.values()
- .stream().flatMap(Collection::stream).collect(Collectors.toList());
- if(CollectionUtils.isEmpty(capabilityDefinitionList)){
+ List<CapabilityDefinition> capabilityDefinitionList = componentCapabilities.values().stream().flatMap(Collection::stream)
+ .collect(Collectors.toList());
+ if (CollectionUtils.isEmpty(capabilityDefinitionList)) {
return Either.left(true);
}
Map<String, String> capabilityNameMap = new HashMap<>();
capabilityDefinitionList.forEach(capability -> capabilityNameMap.put(capability.getUniqueId(), capability.getName()));
-
- if (!capabilityNameMap.values().contains(capabilityDefinition.getName())){
+ if (!capabilityNameMap.values().contains(capabilityDefinition.getName())) {
isCapabilityNameUnique = true;
}
- if (!isCapabilityNameUnique && isUpdate){
- List<Map.Entry<String, String>> capNamesEntries = capabilityNameMap.entrySet().stream().filter(entry ->
- entry.getValue().equalsIgnoreCase(capabilityDefinition.getName())).collect(Collectors.toList());
- if(capNamesEntries.size() == 1 && capNamesEntries.get(0).getKey().equals(capabilityDefinition.getUniqueId())) {
+ if (!isCapabilityNameUnique && isUpdate) {
+ List<Map.Entry<String, String>> capNamesEntries = capabilityNameMap.entrySet().stream()
+ .filter(entry -> entry.getValue().equalsIgnoreCase(capabilityDefinition.getName())).collect(Collectors.toList());
+ if (capNamesEntries.size() == 1 && capNamesEntries.get(0).getKey().equals(capabilityDefinition.getUniqueId())) {
isCapabilityNameUnique = true;
}
}
return Either.left(isCapabilityNameUnique);
}
- private Either<Boolean, ResponseFormat> isCapabilityNameRegexValid(ResponseFormatManager responseFormatManager,
- String capabilityName) {
+ private Either<Boolean, ResponseFormat> isCapabilityNameRegexValid(ResponseFormatManager responseFormatManager, String capabilityName) {
if (!isValidCapabilityName(capabilityName)) {
LOGGER.error("Capability name {} is invalid, Only alphanumeric chars, underscore and dot allowed", capabilityName);
- ResponseFormat errorResponse = responseFormatManager
- .getResponseFormat(ActionStatus.INVALID_CAPABILITY_NAME, capabilityName);
+ ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CAPABILITY_NAME, capabilityName);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
@@ -251,5 +225,4 @@ public class CapabilitiesValidation {
protected ResponseFormatManager getResponseFormatManager() {
return ResponseFormatManager.getInstance();
}
-
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ComponentValidations.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ComponentValidations.java
index bdd7f656b3..10bb1d0ea6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ComponentValidations.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ComponentValidations.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,9 +19,14 @@
* Modifications copyright (c) 2019 Nokia
* ================================================================================
*/
-
package org.openecomp.sdc.be.components.validation;
+import static java.util.stream.Collectors.toList;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
import org.apache.commons.collections.CollectionUtils;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -38,13 +43,6 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
import org.openecomp.sdc.common.util.ValidationUtils;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-
-import static java.util.stream.Collectors.toList;
-
@org.springframework.stereotype.Component
public class ComponentValidations {
@@ -55,17 +53,13 @@ public class ComponentValidations {
}
public Optional<ComponentInstance> getComponentInstance(Component component, String instanceId) {
- return component.getComponentInstances()
- .stream()
- .filter(ci -> ci.getUniqueId().equals(instanceId))
- .findFirst();
+ return component.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(instanceId)).findFirst();
}
public static boolean validateComponentInstanceExist(Component component, String instanceId) {
return Optional.ofNullable(component.getComponentInstances())
- .map(componentInstances -> componentInstances.stream().map(ComponentInstance::getUniqueId).collect(toList()))
- .filter(instancesIds -> instancesIds.contains(instanceId))
- .isPresent();
+ .map(componentInstances -> componentInstances.stream().map(ComponentInstance::getUniqueId).collect(toList()))
+ .filter(instancesIds -> instancesIds.contains(instanceId)).isPresent();
}
public static String getNormalizedName(ToscaDataDefinition toscaDataDefinition) {
@@ -74,8 +68,8 @@ public class ComponentValidations {
}
/**
- * The following logic is applied:
- * For each name new or existing name we look at the normalized name which is used in Tosca representation
+ * The following logic is applied: For each name new or existing name we look at the normalized name which is used in Tosca representation
+ *
* @param currentName
* @param newName
* @param component
@@ -84,7 +78,6 @@ public class ComponentValidations {
public static boolean validateNameIsUniqueInComponent(String currentName, String newName, Component component) {
String normalizedCurrentName = ValidationUtils.normalizeComponentInstanceName(currentName);
String normalizedNewName = ValidationUtils.normalizeComponentInstanceName(newName);
-
if (normalizedCurrentName.equals(normalizedNewName)) {
return true; //As it's same entity, still considered unique
}
@@ -92,17 +85,11 @@ public class ComponentValidations {
List<ComponentInstance> componentInstances = component.getComponentInstances();
Set<String> existingNames = new HashSet<>();
if (CollectionUtils.isNotEmpty(groups)) {
- List<String> existingGroupNames = groups
- .stream()
- .map(ComponentValidations::getNormalizedName)
- .collect(toList());
+ List<String> existingGroupNames = groups.stream().map(ComponentValidations::getNormalizedName).collect(toList());
existingNames.addAll(existingGroupNames);
}
if (CollectionUtils.isNotEmpty(componentInstances)) {
- List<String> existingInstanceNames = componentInstances
- .stream()
- .map(ComponentValidations::getNormalizedName)
- .collect(toList());
+ List<String> existingInstanceNames = componentInstances.stream().map(ComponentValidations::getNormalizedName).collect(toList());
existingNames.addAll(existingInstanceNames);
}
return !existingNames.contains(normalizedNewName);
@@ -110,9 +97,11 @@ public class ComponentValidations {
void validateComponentIsCheckedOutByUser(Component component, String userId) {
if (!ComponentValidationUtils.canWorkOnComponent(component, userId)) {
- throw new ByActionStatusComponentException(ActionStatus.ILLEGAL_COMPONENT_STATE, component.getComponentType().name(), component.getName(), component.getLifecycleState().name());
+ throw new ByActionStatusComponentException(ActionStatus.ILLEGAL_COMPONENT_STATE, component.getComponentType().name(), component.getName(),
+ component.getLifecycleState().name());
}
}
+
Component validateComponentIsCheckedOutByUser(String componentId, ComponentTypeEnum componentTypeEnum, String userId) {
Component component = getComponent(componentId, componentTypeEnum);
validateComponentIsCheckedOutByUser(component, userId);
@@ -120,17 +109,14 @@ public class ComponentValidations {
}
Component getComponent(String componentId, ComponentTypeEnum componentType) {
- Component component = toscaOperationFacade.getToscaElement(componentId, new ComponentParametersView())
- .left()
- .on(storageOperationStatus -> onToscaOperationError(storageOperationStatus, componentId));
-
+ Component component = toscaOperationFacade.getToscaElement(componentId, new ComponentParametersView()).left()
+ .on(storageOperationStatus -> onToscaOperationError(storageOperationStatus, componentId));
validateComponentType(component, componentType);
-
return component;
}
private void validateComponentType(Component component, ComponentTypeEnum componentType) {
- if (componentType!=component.getComponentType()) {
+ if (componentType != component.getComponentType()) {
throw new ByActionStatusComponentException(ActionStatus.INVALID_RESOURCE_TYPE);
}
}
@@ -138,5 +124,4 @@ public class ComponentValidations {
private Component onToscaOperationError(StorageOperationStatus storageOperationStatus, String componentId) {
throw new StorageException(storageOperationStatus, componentId);
}
-
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java
index b876782ce4..419430beaa 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java
@@ -13,11 +13,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.be.components.validation;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOperationOutputName;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOtherOperationOutputsOfComponent;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.isOperationInputMappedToComponentInput;
+import static org.openecomp.sdc.be.components.utils.PropertiesUtils.isCapabilityProperty;
+
import com.google.common.collect.Sets;
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
@@ -35,262 +51,194 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOperationOutputName;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOtherOperationOutputsOfComponent;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.isOperationInputMappedToComponentInput;
-import static org.openecomp.sdc.be.components.utils.PropertiesUtils.isCapabilityProperty;
-
@Component("interfaceOperationValidation")
public class InterfaceOperationValidation {
private static final String TYPE_VALIDATION_REGEX = "^[a-zA-Z0-9_]{1,200}$";
-
private static final Logger LOGGER = LoggerFactory.getLogger(InterfaceOperationValidation.class);
- public Either<Boolean, ResponseFormat> validateInterfaceOperations(
- InterfaceDefinition inputInterfaceDefinition, org.openecomp.sdc.be.model.Component component,
- InterfaceDefinition storedInterfaceDefinition, Map<String, InterfaceDefinition> globalInterfaceTypes,
- boolean isUpdate) {
-
- Either<Boolean, ResponseFormat> validateAllowedOperationsOnGlobalInterfaceType =
- validateAllowedOperationsOnGlobalInterfaceType(inputInterfaceDefinition, globalInterfaceTypes);
+ public Either<Boolean, ResponseFormat> validateInterfaceOperations(InterfaceDefinition inputInterfaceDefinition,
+ org.openecomp.sdc.be.model.Component component,
+ InterfaceDefinition storedInterfaceDefinition,
+ Map<String, InterfaceDefinition> globalInterfaceTypes, boolean isUpdate) {
+ Either<Boolean, ResponseFormat> validateAllowedOperationsOnGlobalInterfaceType = validateAllowedOperationsOnGlobalInterfaceType(
+ inputInterfaceDefinition, globalInterfaceTypes);
if (validateAllowedOperationsOnGlobalInterfaceType.isRight()) {
return validateAllowedOperationsOnGlobalInterfaceType;
}
-
- Either<Boolean, ResponseFormat> validateOperationNameUniqueness =
- validateOperationNameUniquenessInCollection(inputInterfaceDefinition.getOperationsMap().values());
+ Either<Boolean, ResponseFormat> validateOperationNameUniqueness = validateOperationNameUniquenessInCollection(
+ inputInterfaceDefinition.getOperationsMap().values());
if (validateOperationNameUniqueness.isRight()) {
return validateOperationNameUniqueness;
}
-
for (Operation interfaceOperation : inputInterfaceDefinition.getOperationsMap().values()) {
- Either<Boolean, ResponseFormat> interfaceOperationValidatorResponse = validateInterfaceOperation(
- interfaceOperation, storedInterfaceDefinition, inputInterfaceDefinition, component, isUpdate);
+ Either<Boolean, ResponseFormat> interfaceOperationValidatorResponse = validateInterfaceOperation(interfaceOperation,
+ storedInterfaceDefinition, inputInterfaceDefinition, component, isUpdate);
if (interfaceOperationValidatorResponse.isRight()) {
return interfaceOperationValidatorResponse;
}
}
-
return Either.left(Boolean.TRUE);
}
- public Either<Boolean, ResponseFormat> validateDeleteOperationContainsNoMappedOutput(
- Operation interfaceOperationToDelete, org.openecomp.sdc.be.model.Component component,
- InterfaceDefinition storedInterfaceDefinition) {
+ public Either<Boolean, ResponseFormat> validateDeleteOperationContainsNoMappedOutput(Operation interfaceOperationToDelete,
+ org.openecomp.sdc.be.model.Component component,
+ InterfaceDefinition storedInterfaceDefinition) {
ResponseFormatManager responseFormatManager = getResponseFormatManager();
- List<OperationOutputDefinition> existingOperationOutputs =
- getInterfaceOperationOutputs(interfaceOperationToDelete.getUniqueId(), component.getInterfaces());
+ List<OperationOutputDefinition> existingOperationOutputs = getInterfaceOperationOutputs(interfaceOperationToDelete.getUniqueId(),
+ component.getInterfaces());
if (existingOperationOutputs.isEmpty()) {
return Either.left(Boolean.TRUE);
}
String mappedOutputPrefix = storedInterfaceDefinition.getType() + "." + interfaceOperationToDelete.getName();
- List<OperationInputDefinition> interfaceOperationInputs =
- getOtherOperationInputsOfComponent(mappedOutputPrefix, component.getInterfaces());
+ List<OperationInputDefinition> interfaceOperationInputs = getOtherOperationInputsOfComponent(mappedOutputPrefix, component.getInterfaces());
Set<String> mappedOutputsInDeletedOperation = new HashSet<>();
- Set<String> existingOperationOutputNames = existingOperationOutputs.stream()
- .map(OperationOutputDefinition::getName)
- .collect(Collectors.toSet());
+ Set<String> existingOperationOutputNames = existingOperationOutputs.stream().map(OperationOutputDefinition::getName)
+ .collect(Collectors.toSet());
for (String existingOperationOutputName : existingOperationOutputNames) {
- Set<String> matchedOutputsMappedToInputs = interfaceOperationInputs.stream()
- .filter(operationInputDefinition -> operationInputDefinition.getInputId()
- .equals(mappedOutputPrefix + "." + existingOperationOutputName))
- .map(operationInputDefinition -> getOperationOutputName(operationInputDefinition.getInputId()))
- .collect(Collectors.toSet());
+ Set<String> matchedOutputsMappedToInputs = interfaceOperationInputs.stream().filter(
+ operationInputDefinition -> operationInputDefinition.getInputId().equals(mappedOutputPrefix + "." + existingOperationOutputName))
+ .map(operationInputDefinition -> getOperationOutputName(operationInputDefinition.getInputId())).collect(Collectors.toSet());
mappedOutputsInDeletedOperation.addAll(matchedOutputsMappedToInputs);
}
-
if (CollectionUtils.isNotEmpty(mappedOutputsInDeletedOperation)) {
return getMappedOutputErrorResponse(responseFormatManager, mappedOutputsInDeletedOperation,
- "Cannot delete interface operation with output(s) '{}' mapped to another operation input",
- ActionStatus.INTERFACE_OPERATION_DELETE_WITH_MAPPED_OUTPUT);
+ "Cannot delete interface operation with output(s) '{}' mapped to another operation input",
+ ActionStatus.INTERFACE_OPERATION_DELETE_WITH_MAPPED_OUTPUT);
}
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> validateAllowedOperationsOnGlobalInterfaceType(
- InterfaceDefinition interfaceDefinition, Map<String, InterfaceDefinition> globalInterfaceTypes) {
-
+ private Either<Boolean, ResponseFormat> validateAllowedOperationsOnGlobalInterfaceType(InterfaceDefinition interfaceDefinition,
+ Map<String, InterfaceDefinition> globalInterfaceTypes) {
if (globalInterfaceTypes == null) {
return Either.left(Boolean.TRUE);
}
- boolean isOperationValidOnGlobalInterfaceType = Stream.of(interfaceDefinition)
- .filter(interfaceDef -> globalInterfaceTypes.values().stream().anyMatch(interfaceDef1 ->
- interfaceDef1.getType().equalsIgnoreCase(interfaceDef.getType())))
- .flatMap(interfaceDef -> interfaceDef.getOperationsMap().values().stream().map(Operation::getName))
- .allMatch(operationName -> globalInterfaceTypes.values().stream()
- .flatMap(interfaceDef -> interfaceDef.getOperationsMap().keySet().stream())
- .anyMatch(opName -> opName.equalsIgnoreCase(operationName)));
+ boolean isOperationValidOnGlobalInterfaceType = Stream.of(interfaceDefinition).filter(interfaceDef -> globalInterfaceTypes.values().stream()
+ .anyMatch(interfaceDef1 -> interfaceDef1.getType().equalsIgnoreCase(interfaceDef.getType())))
+ .flatMap(interfaceDef -> interfaceDef.getOperationsMap().values().stream().map(Operation::getName)).allMatch(
+ operationName -> globalInterfaceTypes.values().stream().flatMap(interfaceDef -> interfaceDef.getOperationsMap().keySet().stream())
+ .anyMatch(opName -> opName.equalsIgnoreCase(operationName)));
if (!isOperationValidOnGlobalInterfaceType) {
return Either.right(getResponseFormatManager()
- .getResponseFormat(ActionStatus.INTERFACE_OPERATION_INVALID_FOR_GLOBAL_TYPE,
- interfaceDefinition.getType()));
+ .getResponseFormat(ActionStatus.INTERFACE_OPERATION_INVALID_FOR_GLOBAL_TYPE, interfaceDefinition.getType()));
}
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> validateOperationNameUniquenessInCollection(
- Collection<Operation> operationList) {
+ private Either<Boolean, ResponseFormat> validateOperationNameUniquenessInCollection(Collection<Operation> operationList) {
HashSet<String> operationNames = new HashSet<>();
for (Operation operation : operationList) {
if (!operationNames.add(operation.getName())) {
- return Either.right(getResponseFormatManager()
- .getResponseFormat(ActionStatus.INTERFACE_OPERATION_NAME_ALREADY_IN_USE,
- operation.getName()));
+ return Either
+ .right(getResponseFormatManager().getResponseFormat(ActionStatus.INTERFACE_OPERATION_NAME_ALREADY_IN_USE, operation.getName()));
}
}
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> validateInterfaceOperation(Operation interfaceOperation,
- InterfaceDefinition storedInterfaceDefinition, InterfaceDefinition inputInterfaceDefinition,
- org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
-
+ private Either<Boolean, ResponseFormat> validateInterfaceOperation(Operation interfaceOperation, InterfaceDefinition storedInterfaceDefinition,
+ InterfaceDefinition inputInterfaceDefinition,
+ org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
ResponseFormatManager responseFormatManager = getResponseFormatManager();
- Either<Boolean, ResponseFormat> interfaceOperationTypeResponse =
- isInterfaceOperationTypeValid(interfaceOperation, responseFormatManager, storedInterfaceDefinition,
- isUpdate);
+ Either<Boolean, ResponseFormat> interfaceOperationTypeResponse = isInterfaceOperationTypeValid(interfaceOperation, responseFormatManager,
+ storedInterfaceDefinition, isUpdate);
if (interfaceOperationTypeResponse.isRight()) {
return Either.right(interfaceOperationTypeResponse.right().value());
}
-
- if (null != interfaceOperation.getInputs()
- && CollectionUtils.isNotEmpty(interfaceOperation.getInputs().getListToscaDataDefinition())) {
- Either<Boolean, ResponseFormat> inputParametersResponse =
- validateInputParameters(interfaceOperation, responseFormatManager);
+ if (null != interfaceOperation.getInputs() && CollectionUtils.isNotEmpty(interfaceOperation.getInputs().getListToscaDataDefinition())) {
+ Either<Boolean, ResponseFormat> inputParametersResponse = validateInputParameters(interfaceOperation, responseFormatManager);
if (inputParametersResponse.isRight()) {
return Either.right(inputParametersResponse.right().value());
}
-
- Either<Boolean, ResponseFormat> inputPropertyExistInComponent =
- validateInputPropertyExistInComponent(interfaceOperation,
- inputInterfaceDefinition, component, responseFormatManager);
+ Either<Boolean, ResponseFormat> inputPropertyExistInComponent = validateInputPropertyExistInComponent(interfaceOperation,
+ inputInterfaceDefinition, component, responseFormatManager);
if (inputPropertyExistInComponent.isRight()) {
return Either.right(inputPropertyExistInComponent.right().value());
}
}
-
- if (null != interfaceOperation.getOutputs()
- && CollectionUtils.isNotEmpty(interfaceOperation.getOutputs().getListToscaDataDefinition())) {
- Either<Boolean, ResponseFormat> outputParametersResponse =
- validateOutputParameters(interfaceOperation, responseFormatManager);
+ if (null != interfaceOperation.getOutputs() && CollectionUtils.isNotEmpty(interfaceOperation.getOutputs().getListToscaDataDefinition())) {
+ Either<Boolean, ResponseFormat> outputParametersResponse = validateOutputParameters(interfaceOperation, responseFormatManager);
if (outputParametersResponse.isRight()) {
return Either.right(outputParametersResponse.right().value());
}
}
-
if (MapUtils.isNotEmpty(component.getInterfaces()) && isUpdate) {
- Either<Boolean, ResponseFormat> mappedOutputModifiedResponse =
- validateMappedOutputNotModified(interfaceOperation, component, inputInterfaceDefinition,
- responseFormatManager);
+ Either<Boolean, ResponseFormat> mappedOutputModifiedResponse = validateMappedOutputNotModified(interfaceOperation, component,
+ inputInterfaceDefinition, responseFormatManager);
if (mappedOutputModifiedResponse.isRight()) {
return Either.right(mappedOutputModifiedResponse.right().value());
}
}
-
return Either.left(Boolean.TRUE);
}
-
private Either<Boolean, ResponseFormat> validateMappedOutputNotModified(Operation interfaceOperation,
- org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDefinition,
- ResponseFormatManager responseFormatManager) {
-
- List<OperationOutputDefinition> existingOperationOutputs =
- getInterfaceOperationOutputs(interfaceOperation.getUniqueId(), component.getInterfaces());
+ org.openecomp.sdc.be.model.Component component,
+ InterfaceDefinition interfaceDefinition,
+ ResponseFormatManager responseFormatManager) {
+ List<OperationOutputDefinition> existingOperationOutputs = getInterfaceOperationOutputs(interfaceOperation.getUniqueId(),
+ component.getInterfaces());
if (existingOperationOutputs.isEmpty()) {
return Either.left(Boolean.TRUE);
}
- Set<String> existingOperationOutputNames = existingOperationOutputs.stream()
- .map(OperationOutputDefinition::getName)
- .collect(Collectors.toSet());
-
+ Set<String> existingOperationOutputNames = existingOperationOutputs.stream().map(OperationOutputDefinition::getName)
+ .collect(Collectors.toSet());
ListDataDefinition<OperationOutputDefinition> currentOutputs = interfaceOperation.getOutputs();
Set<String> currentOperationOutputNames = new HashSet<>();
if (currentOutputs != null && !currentOutputs.isEmpty()) {
- currentOperationOutputNames = currentOutputs.getListToscaDataDefinition().stream()
- .map(OperationOutputDefinition::getName)
- .collect(Collectors.toSet());
+ currentOperationOutputNames = currentOutputs.getListToscaDataDefinition().stream().map(OperationOutputDefinition::getName)
+ .collect(Collectors.toSet());
}
String mappedOutputPrefix = interfaceDefinition.getType() + "." + interfaceOperation.getName();
//Get the deleted outputs (name changed also equivalent to deleted)
Set<String> deletedOutputs = Sets.difference(existingOperationOutputNames, currentOperationOutputNames);
- Set<String> deletedMappedOutputs = getModifiedMappedOutputs(deletedOutputs, mappedOutputPrefix,
- component.getInterfaces());
-
+ Set<String> deletedMappedOutputs = getModifiedMappedOutputs(deletedOutputs, mappedOutputPrefix, component.getInterfaces());
if (CollectionUtils.isNotEmpty(deletedMappedOutputs)) {
return getMappedOutputErrorResponse(responseFormatManager, deletedMappedOutputs,
- "Cannot update or delete interface operation output(s) '{}' mapped to an operation input",
- ActionStatus.INTERFACE_OPERATION_MAPPED_OUTPUT_MODIFIED);
+ "Cannot update or delete interface operation output(s) '{}' mapped to an operation input",
+ ActionStatus.INTERFACE_OPERATION_MAPPED_OUTPUT_MODIFIED);
}
-
if (currentOutputs != null && !currentOutputs.isEmpty()) {
//Get the unchanged outputs based on name to see if other attributes (type/mandatory) have not been changed
- Set<String> unchangedOutputNames = Sets.intersection(existingOperationOutputNames,
- currentOperationOutputNames);
- Set<String> modifiedOutputNames =
- getModifiedOutputNames(currentOutputs.getListToscaDataDefinition(),
- existingOperationOutputs, unchangedOutputNames);
- Set<String> modifiedMappedOutputNames = getModifiedMappedOutputs(modifiedOutputNames, mappedOutputPrefix,
- component.getInterfaces());
+ Set<String> unchangedOutputNames = Sets.intersection(existingOperationOutputNames, currentOperationOutputNames);
+ Set<String> modifiedOutputNames = getModifiedOutputNames(currentOutputs.getListToscaDataDefinition(), existingOperationOutputs,
+ unchangedOutputNames);
+ Set<String> modifiedMappedOutputNames = getModifiedMappedOutputs(modifiedOutputNames, mappedOutputPrefix, component.getInterfaces());
if (CollectionUtils.isNotEmpty(modifiedMappedOutputNames)) {
return getMappedOutputErrorResponse(responseFormatManager, modifiedMappedOutputNames,
- "Cannot update or delete interface operation output(s) '{}' mapped to an operation input",
- ActionStatus.INTERFACE_OPERATION_MAPPED_OUTPUT_MODIFIED);
+ "Cannot update or delete interface operation output(s) '{}' mapped to an operation input",
+ ActionStatus.INTERFACE_OPERATION_MAPPED_OUTPUT_MODIFIED);
}
}
-
return Either.left(Boolean.TRUE);
}
private Set<String> getModifiedMappedOutputs(Set<String> modifiedOutputNames, String mappedOutputPrefix,
Map<String, InterfaceDefinition> componentInterfaces) {
return modifiedOutputNames.stream()
- .filter(modifiedOutputName -> isMappedOutputModified(mappedOutputPrefix, modifiedOutputName,
- componentInterfaces))
- .map(InterfaceOperationUtils::getOperationOutputName)
- .collect(Collectors.toSet());
+ .filter(modifiedOutputName -> isMappedOutputModified(mappedOutputPrefix, modifiedOutputName, componentInterfaces))
+ .map(InterfaceOperationUtils::getOperationOutputName).collect(Collectors.toSet());
}
- private boolean isMappedOutputModified(String mappedOutputPrefix, String outputName,
- Map<String, InterfaceDefinition> componentInterfaces) {
- List<OperationInputDefinition> interfaceOperationInputs =
- getOtherOperationInputsOfComponent(mappedOutputPrefix, componentInterfaces);
+ private boolean isMappedOutputModified(String mappedOutputPrefix, String outputName, Map<String, InterfaceDefinition> componentInterfaces) {
+ List<OperationInputDefinition> interfaceOperationInputs = getOtherOperationInputsOfComponent(mappedOutputPrefix, componentInterfaces);
return interfaceOperationInputs.stream()
- .anyMatch(operationInputDefinition -> operationInputDefinition.getInputId()
- .equals(mappedOutputPrefix + "." + outputName));
+ .anyMatch(operationInputDefinition -> operationInputDefinition.getInputId().equals(mappedOutputPrefix + "." + outputName));
}
private static Set<String> getModifiedOutputNames(List<OperationOutputDefinition> currentOperationOutputs,
- List<OperationOutputDefinition> existingOperationOutputs,
- Set<String> unchangedOutputNames) {
+ List<OperationOutputDefinition> existingOperationOutputs, Set<String> unchangedOutputNames) {
Set<String> modifiedOutputDefinitionNames = new HashSet<>();
- Map<String, OperationOutputDefinition> newOutputMap = currentOperationOutputs.stream()
- .collect(Collectors.toMap(OperationOutputDefinition::getName,
- (OperationOutputDefinition operationOutputDefinition) -> operationOutputDefinition));
-
- Map<String, OperationOutputDefinition> existingOutputMap = existingOperationOutputs.stream()
- .collect(Collectors.toMap(OperationOutputDefinition::getName,
- (OperationOutputDefinition operationOutputDefinition) -> operationOutputDefinition));
-
+ Map<String, OperationOutputDefinition> newOutputMap = currentOperationOutputs.stream().collect(
+ Collectors.toMap(OperationOutputDefinition::getName, (OperationOutputDefinition operationOutputDefinition) -> operationOutputDefinition));
+ Map<String, OperationOutputDefinition> existingOutputMap = existingOperationOutputs.stream().collect(
+ Collectors.toMap(OperationOutputDefinition::getName, (OperationOutputDefinition operationOutputDefinition) -> operationOutputDefinition));
for (String outputName : unchangedOutputNames) {
OperationOutputDefinition existingOutputDefinition = existingOutputMap.get(outputName);
OperationOutputDefinition newOutputDefinition = newOutputMap.get(outputName);
- if (!existingOutputDefinition.getType().equals(newOutputDefinition.getType())
- || !existingOutputDefinition.isRequired().equals(newOutputDefinition.isRequired())) {
+ if (!existingOutputDefinition.getType().equals(newOutputDefinition.getType()) || !existingOutputDefinition.isRequired()
+ .equals(newOutputDefinition.isRequired())) {
modifiedOutputDefinitionNames.add(outputName);
}
}
@@ -298,8 +246,7 @@ public class InterfaceOperationValidation {
}
private Either<Boolean, ResponseFormat> getMappedOutputErrorResponse(ResponseFormatManager responseFormatManager,
- Set<String> modifiedMappedOutputs,
- String message,
+ Set<String> modifiedMappedOutputs, String message,
ActionStatus errorStatus) {
String modifiedOutputNameList = String.join(",", modifiedMappedOutputs);
LOGGER.error(message, modifiedOutputNameList);
@@ -307,152 +254,120 @@ public class InterfaceOperationValidation {
return Either.right(errorResponse);
}
-
protected ResponseFormatManager getResponseFormatManager() {
return ResponseFormatManager.getInstance();
}
- private Either<Boolean, ResponseFormat> isInterfaceOperationTypeValid(Operation interfaceOperation,
- ResponseFormatManager responseFormatManager,
- InterfaceDefinition interfaceDefinition,
- boolean isUpdate) {
-
- Either<Boolean, ResponseFormat> operationTypeEmptyEither =
- isOperationTypeEmpty(responseFormatManager, interfaceOperation.getName());
+ private Either<Boolean, ResponseFormat> isInterfaceOperationTypeValid(Operation interfaceOperation, ResponseFormatManager responseFormatManager,
+ InterfaceDefinition interfaceDefinition, boolean isUpdate) {
+ Either<Boolean, ResponseFormat> operationTypeEmptyEither = isOperationTypeEmpty(responseFormatManager, interfaceOperation.getName());
if (operationTypeEmptyEither.isRight()) {
return Either.right(operationTypeEmptyEither.right().value());
}
-
- Either<Boolean, ResponseFormat> operationTypeRegexValidationResponse =
- isOperationTypeRegexValid(responseFormatManager, interfaceOperation.getName());
+ Either<Boolean, ResponseFormat> operationTypeRegexValidationResponse = isOperationTypeRegexValid(responseFormatManager,
+ interfaceOperation.getName());
if (operationTypeRegexValidationResponse.isRight()) {
return Either.right(operationTypeRegexValidationResponse.right().value());
}
-
- Either<Boolean, ResponseFormat> operationTypeUniqueResponse = validateOperationTypeUnique(interfaceOperation,
- interfaceDefinition, isUpdate);
+ Either<Boolean, ResponseFormat> operationTypeUniqueResponse = validateOperationTypeUnique(interfaceOperation, interfaceDefinition, isUpdate);
if (operationTypeUniqueResponse.isRight()) {
return Either.right(operationTypeUniqueResponse.right().value());
}
if (!operationTypeUniqueResponse.left().value()) {
LOGGER.error("Interface Operation type {} already in use ", interfaceOperation.getName());
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(
- ActionStatus.INTERFACE_OPERATION_NAME_ALREADY_IN_USE, interfaceOperation.getName());
+ ResponseFormat errorResponse = responseFormatManager
+ .getResponseFormat(ActionStatus.INTERFACE_OPERATION_NAME_ALREADY_IN_USE, interfaceOperation.getName());
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> validateInputParameters(Operation interfaceOperation,
- ResponseFormatManager responseFormatManager) {
+ private Either<Boolean, ResponseFormat> validateInputParameters(Operation interfaceOperation, ResponseFormatManager responseFormatManager) {
if (isInputParameterNameEmpty(interfaceOperation)) {
LOGGER.error("Interface operation input parameter name can't be empty");
- ResponseFormat inputResponse =
- responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_INPUT_NAME_MANDATORY);
+ ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_INPUT_NAME_MANDATORY);
return Either.right(inputResponse);
}
-
- Either<Boolean, Set<String>> validateInputParametersUniqueResponse =
- isInputParametersUnique(interfaceOperation);
+ Either<Boolean, Set<String>> validateInputParametersUniqueResponse = isInputParametersUnique(interfaceOperation);
if (validateInputParametersUniqueResponse.isRight()) {
- LOGGER.error("Interface operation input parameter names {} already in use",
- validateInputParametersUniqueResponse.right().value());
- ResponseFormat inputResponse =
- responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_INPUT_NAME_ALREADY_IN_USE,
- validateInputParametersUniqueResponse.right().value().toString());
+ LOGGER.error("Interface operation input parameter names {} already in use", validateInputParametersUniqueResponse.right().value());
+ ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_INPUT_NAME_ALREADY_IN_USE,
+ validateInputParametersUniqueResponse.right().value().toString());
return Either.right(inputResponse);
}
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> validateOutputParameters(Operation interfaceOperation,
- ResponseFormatManager responseFormatManager) {
+ private Either<Boolean, ResponseFormat> validateOutputParameters(Operation interfaceOperation, ResponseFormatManager responseFormatManager) {
if (isOutputParameterNameEmpty(interfaceOperation)) {
LOGGER.error("Interface operation output parameter name can't be empty");
- ResponseFormat inputResponse =
- responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY);
+ ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY);
return Either.right(inputResponse);
}
-
- Either<Boolean, Set<String>> validateOutputParametersUniqueResponse =
- isOutputParametersUnique(interfaceOperation);
+ Either<Boolean, Set<String>> validateOutputParametersUniqueResponse = isOutputParametersUnique(interfaceOperation);
if (validateOutputParametersUniqueResponse.isRight()) {
- LOGGER.error("Interface operation output parameter names {} already in use",
- validateOutputParametersUniqueResponse.right().value());
- ResponseFormat inputResponse =
- responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE,
- validateOutputParametersUniqueResponse.right().value().toString());
+ LOGGER.error("Interface operation output parameter names {} already in use", validateOutputParametersUniqueResponse.right().value());
+ ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE,
+ validateOutputParametersUniqueResponse.right().value().toString());
return Either.right(inputResponse);
}
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> isOperationTypeEmpty(ResponseFormatManager responseFormatManager,
- String operationType) {
+ private Either<Boolean, ResponseFormat> isOperationTypeEmpty(ResponseFormatManager responseFormatManager, String operationType) {
if (StringUtils.isEmpty(operationType)) {
LOGGER.error("Interface Operation type is mandatory");
- ResponseFormat errorResponse =
- responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NAME_MANDATORY);
+ ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NAME_MANDATORY);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> isOperationTypeRegexValid(ResponseFormatManager responseFormatManager,
- String operationType) {
+ private Either<Boolean, ResponseFormat> isOperationTypeRegexValid(ResponseFormatManager responseFormatManager, String operationType) {
if (!isValidOperationType(operationType)) {
LOGGER.error("Interface Operation type {} is invalid, Operation type should not contain"
- + "Special character, space, numbers and should not be greater than 200 characters",
- operationType);
- ResponseFormat errorResponse = responseFormatManager
- .getResponseFormat(ActionStatus.INTERFACE_OPERATION_NAME_INVALID,
- operationType);
+ + "Special character, space, numbers and should not be greater than 200 characters", operationType);
+ ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NAME_INVALID, operationType);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> validateOperationTypeUnique(Operation interfaceOperation,
- InterfaceDefinition interfaceDefinition, boolean isUpdate) {
+ private Either<Boolean, ResponseFormat> validateOperationTypeUnique(Operation interfaceOperation, InterfaceDefinition interfaceDefinition,
+ boolean isUpdate) {
boolean isOperationTypeUnique = false;
-
if (interfaceDefinition == null || CollectionUtils.isEmpty(interfaceDefinition.getOperationsMap().values())) {
return Either.left(true);
}
-
Map<String, String> operationTypes = new HashMap<>();
interfaceDefinition.getOperationsMap().values()
- .forEach(operationType -> operationTypes.put(operationType.getUniqueId(), operationType.getName()));
-
+ .forEach(operationType -> operationTypes.put(operationType.getUniqueId(), operationType.getName()));
if (!operationTypes.values().contains(interfaceOperation.getName())) {
isOperationTypeUnique = true;
}
if (!isOperationTypeUnique && isUpdate) {
- Optional<String> id = operationTypes.entrySet().stream().filter(entry -> Objects.equals(entry.getValue(),
- interfaceOperation.getName())).map(Map.Entry::getKey).findAny();
+ Optional<String> id = operationTypes.entrySet().stream().filter(entry -> Objects.equals(entry.getValue(), interfaceOperation.getName()))
+ .map(Map.Entry::getKey).findAny();
if (id.isPresent() && id.get().equalsIgnoreCase(interfaceOperation.getUniqueId())) {
isOperationTypeUnique = true;
}
}
-
return Either.left(isOperationTypeUnique);
}
private Boolean isInputParameterNameEmpty(Operation operationDataDefinition) {
- return operationDataDefinition.getInputs().getListToscaDataDefinition().stream().anyMatch(
- inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY));
+ return operationDataDefinition.getInputs().getListToscaDataDefinition().stream()
+ .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY));
}
-
private Either<Boolean, Set<String>> isInputParametersUnique(Operation operationDataDefinition) {
Set<String> inputParamNamesSet = new HashSet<>();
Set<String> duplicateParamNamesToReturn = new HashSet<>();
- operationDataDefinition.getInputs().getListToscaDataDefinition()
- .forEach(inputParam -> {
- if (!inputParamNamesSet.add(inputParam.getName().trim())) {
- duplicateParamNamesToReturn.add(inputParam.getName().trim());
- }
- });
+ operationDataDefinition.getInputs().getListToscaDataDefinition().forEach(inputParam -> {
+ if (!inputParamNamesSet.add(inputParam.getName().trim())) {
+ duplicateParamNamesToReturn.add(inputParam.getName().trim());
+ }
+ });
if (!duplicateParamNamesToReturn.isEmpty()) {
return Either.right(duplicateParamNamesToReturn);
}
@@ -460,89 +375,80 @@ public class InterfaceOperationValidation {
}
private Boolean isOutputParameterNameEmpty(Operation operationDataDefinition) {
- return operationDataDefinition.getOutputs().getListToscaDataDefinition().stream().anyMatch(
- outputParam -> outputParam.getName() == null || outputParam.getName().trim().equals(StringUtils.EMPTY));
+ return operationDataDefinition.getOutputs().getListToscaDataDefinition().stream()
+ .anyMatch(outputParam -> outputParam.getName() == null || outputParam.getName().trim().equals(StringUtils.EMPTY));
}
private Either<Boolean, Set<String>> isOutputParametersUnique(Operation operationDataDefinition) {
Set<String> outputParamNamesSet = new HashSet<>();
Set<String> duplicateParamNamesToReturn = new HashSet<>();
- operationDataDefinition.getOutputs().getListToscaDataDefinition()
- .forEach(outputParam -> {
- if (!outputParamNamesSet.add(outputParam.getName().trim())) {
- duplicateParamNamesToReturn.add(outputParam.getName().trim());
- }
- });
+ operationDataDefinition.getOutputs().getListToscaDataDefinition().forEach(outputParam -> {
+ if (!outputParamNamesSet.add(outputParam.getName().trim())) {
+ duplicateParamNamesToReturn.add(outputParam.getName().trim());
+ }
+ });
if (!duplicateParamNamesToReturn.isEmpty()) {
return Either.right(duplicateParamNamesToReturn);
}
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> validateInputPropertyExistInComponent(Operation operation,
- InterfaceDefinition inputInterfaceDefinition, org.openecomp.sdc.be.model.Component component,
- ResponseFormatManager responseFormatManager) {
-
+ private Either<Boolean, ResponseFormat> validateInputPropertyExistInComponent(Operation operation, InterfaceDefinition inputInterfaceDefinition,
+ org.openecomp.sdc.be.model.Component component,
+ ResponseFormatManager responseFormatManager) {
boolean isOperationInputToInputPropertyMappingValid = false;
boolean isOperationInputToOtherOperationOutputMappingValid = false;
String mappingName = "";
- List<OperationInputDefinition> inputListToscaDataDefinition =
- operation.getInputs().getListToscaDataDefinition();
+ List<OperationInputDefinition> inputListToscaDataDefinition = operation.getInputs().getListToscaDataDefinition();
for (OperationInputDefinition inputDefinition : inputListToscaDataDefinition) {
- if (isOperationInputMappedToComponentInput(inputDefinition, component.getInputs())
- || isCapabilityProperty(inputDefinition.getInputId(), component).isPresent()) {
+ if (isOperationInputMappedToComponentInput(inputDefinition, component.getInputs()) || isCapabilityProperty(inputDefinition.getInputId(),
+ component).isPresent()) {
isOperationInputToInputPropertyMappingValid = true;
} else {
- mappingName = inputDefinition.getInputId().contains(".")
- ? inputDefinition.getInputId().substring(inputDefinition.getInputId().lastIndexOf('.') + 1)
- : inputDefinition.getInputId();
+ mappingName = inputDefinition.getInputId().contains(".") ? inputDefinition.getInputId()
+ .substring(inputDefinition.getInputId().lastIndexOf('.') + 1) : inputDefinition.getInputId();
break;
}
}
if (isOperationInputToInputPropertyMappingValid) {
return Either.left(Boolean.TRUE);
}
-
//Mapped property not found in the component properties.. Check in other operation output parameters of
+
// component (other operation => not having the same full name)
String actualOperationIdentifier = inputInterfaceDefinition.getType() + "." + operation.getName();
- ListDataDefinition<OperationOutputDefinition> outputListDataDefinition =
- getOtherOperationOutputsOfComponent(actualOperationIdentifier, component.getInterfaces());
-
- List<OperationOutputDefinition> componentOutputsFromOtherOperations =
- outputListDataDefinition.getListToscaDataDefinition();
+ ListDataDefinition<OperationOutputDefinition> outputListDataDefinition = getOtherOperationOutputsOfComponent(actualOperationIdentifier,
+ component.getInterfaces());
+ List<OperationOutputDefinition> componentOutputsFromOtherOperations = outputListDataDefinition.getListToscaDataDefinition();
if (validateOutputExistsInComponent(mappingName, componentOutputsFromOtherOperations)) {
isOperationInputToOtherOperationOutputMappingValid = true;
} else {
//Get the output parameter display name from the full name
mappingName = getOperationOutputName(mappingName);
}
-
if (!isOperationInputToOtherOperationOutputMappingValid) {
LOGGER.error("Interface operation input parameter property {} not found in component input properties or"
- + "capability properties or outputs of other operations.", mappingName);
+ + "capability properties or outputs of other operations.", mappingName);
ResponseFormat inputResponse = responseFormatManager
- .getResponseFormat(ActionStatus.INTERFACE_OPERATION_INPUT_PROPERTY_NOT_FOUND_IN_COMPONENT,
- mappingName, component.getComponentType().getValue());
+ .getResponseFormat(ActionStatus.INTERFACE_OPERATION_INPUT_PROPERTY_NOT_FOUND_IN_COMPONENT, mappingName,
+ component.getComponentType().getValue());
return Either.right(inputResponse);
}
return Either.left(Boolean.TRUE);
}
- private boolean validateOutputExistsInComponent(String mappedOutputName,
- List<OperationOutputDefinition> outputs) {
- return outputs.stream()
- .anyMatch(output -> output.getName().equals(mappedOutputName));
+ private boolean validateOutputExistsInComponent(String mappedOutputName, List<OperationOutputDefinition> outputs) {
+ return outputs.stream().anyMatch(output -> output.getName().equals(mappedOutputName));
}
/**
* Get the input definitions of other operations of the component from current as well as other interfaces.
+ *
* @param currentOperationIdentifier Identifier for the request operation (interface_name.operation_name)
- * @param componentInterfaces Interfaces of the component
+ * @param componentInterfaces Interfaces of the component
*/
private List<OperationInputDefinition> getOtherOperationInputsOfComponent(String currentOperationIdentifier,
- Map<String, InterfaceDefinition>
- componentInterfaces) {
+ Map<String, InterfaceDefinition> componentInterfaces) {
List<OperationInputDefinition> otherOperationInputs = new ArrayList<>();
if (MapUtils.isEmpty(componentInterfaces)) {
return otherOperationInputs;
@@ -554,8 +460,7 @@ public class InterfaceOperationValidation {
}
for (Map.Entry<String, OperationDataDefinition> operationEntry : operations.entrySet()) {
ListDataDefinition<OperationInputDefinition> inputs = operationEntry.getValue().getInputs();
- String expectedOperationIdentifier =
- interfaceDefinitionEntry.getValue().getType() + "." + operationEntry.getValue().getName();
+ String expectedOperationIdentifier = interfaceDefinitionEntry.getValue().getType() + "." + operationEntry.getValue().getName();
if (!currentOperationIdentifier.equals(expectedOperationIdentifier) && Objects.nonNull(inputs) && !inputs.isEmpty()) {
otherOperationInputs.addAll(inputs.getListToscaDataDefinition());
}
@@ -566,12 +471,12 @@ public class InterfaceOperationValidation {
/**
* Get the output of an operation in an interface.
- * @param inputOperationId Unique identifier for the request operation
+ *
+ * @param inputOperationId Unique identifier for the request operation
* @param componentInterfaces Interfaces of the component
*/
private List<OperationOutputDefinition> getInterfaceOperationOutputs(String inputOperationId,
- Map<String, InterfaceDefinition>
- componentInterfaces) {
+ Map<String, InterfaceDefinition> componentInterfaces) {
List<OperationOutputDefinition> operationOutputDefinitions = new ArrayList<>();
if (MapUtils.isEmpty(componentInterfaces)) {
return operationOutputDefinitions;
@@ -584,11 +489,9 @@ public class InterfaceOperationValidation {
for (Map.Entry<String, OperationDataDefinition> operationEntry : operations.entrySet()) {
String expectedOperationId = operationEntry.getValue().getUniqueId();
if (expectedOperationId.equals(inputOperationId)) {
- ListDataDefinition<OperationOutputDefinition> operationOutputs =
- operationEntry.getValue().getOutputs();
- return (Objects.isNull(operationOutputs) || operationOutputs.isEmpty())
- ? operationOutputDefinitions
- : operationOutputs.getListToscaDataDefinition();
+ ListDataDefinition<OperationOutputDefinition> operationOutputs = operationEntry.getValue().getOutputs();
+ return (Objects.isNull(operationOutputs) || operationOutputs.isEmpty()) ? operationOutputDefinitions
+ : operationOutputs.getListToscaDataDefinition();
}
}
}
@@ -598,5 +501,4 @@ public class InterfaceOperationValidation {
private boolean isValidOperationType(String operationType) {
return Pattern.matches(TYPE_VALIDATION_REGEX, operationType);
}
-
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
index 8c27396e3b..6bfe26aab0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation;
import com.google.common.collect.ImmutableSet;
@@ -55,34 +54,28 @@ import org.springframework.util.CollectionUtils;
public class NodeFilterValidator {
private static final String SOURCE = "Source";
- public static final Set<String> comparableTypes = ImmutableSet.of(ToscaPropertyType.STRING.getType(),
- ToscaPropertyType.INTEGER.getType(), ToscaPropertyType.FLOAT.getType());
- public static final Set<String> schemableTypes =
- ImmutableSet.of(ToscaPropertyType.MAP.getType(), ToscaPropertyType.LIST.getType());
- public static final Set<String> comparableConstraintsOperators =
- ImmutableSet.of(ConstraintConvertor.GREATER_THAN_OPERATOR, ConstraintConvertor.LESS_THAN_OPERATOR);
-
+ public static final Set<String> comparableTypes = ImmutableSet
+ .of(ToscaPropertyType.STRING.getType(), ToscaPropertyType.INTEGER.getType(), ToscaPropertyType.FLOAT.getType());
+ public static final Set<String> schemableTypes = ImmutableSet.of(ToscaPropertyType.MAP.getType(), ToscaPropertyType.LIST.getType());
+ public static final Set<String> comparableConstraintsOperators = ImmutableSet
+ .of(ConstraintConvertor.GREATER_THAN_OPERATOR, ConstraintConvertor.LESS_THAN_OPERATOR);
protected final ToscaOperationFacade toscaOperationFacade;
protected final ComponentsUtils componentsUtils;
-
private static final Logger LOGGER = LoggerFactory.getLogger(NodeFilterValidator.class);
@Autowired
- public NodeFilterValidator(final ToscaOperationFacade toscaOperationFacade,
- final ComponentsUtils componentsUtils) {
+ public NodeFilterValidator(final ToscaOperationFacade toscaOperationFacade, final ComponentsUtils componentsUtils) {
this.toscaOperationFacade = toscaOperationFacade;
this.componentsUtils = componentsUtils;
}
- public Either<Boolean, ResponseFormat> validateComponentInstanceExist(final Component component,
- final String componentInstanceId) {
+ public Either<Boolean, ResponseFormat> validateComponentInstanceExist(final Component component, final String componentInstanceId) {
if (component == null || StringUtils.isEmpty(componentInstanceId)) {
LOGGER.error("Input data cannot be empty");
return getErrorResponse(ActionStatus.FILTER_NOT_FOUND);
}
- if (CollectionUtils.isEmpty(component.getComponentInstances()) ||
- component.getComponentInstances().stream()
- .noneMatch(ci -> ci.getUniqueId().equals(componentInstanceId))) {
+ if (CollectionUtils.isEmpty(component.getComponentInstances()) || component.getComponentInstances().stream()
+ .noneMatch(ci -> ci.getUniqueId().equals(componentInstanceId))) {
LOGGER.error("Component Instance list is empty");
return getErrorResponse(ActionStatus.FILTER_NOT_FOUND);
}
@@ -94,31 +87,26 @@ public class NodeFilterValidator {
return Either.right(errorResponse);
}
- public Either<Boolean, ResponseFormat> validateFilter(final Component parentComponent,
- final String componentInstanceId,
- final List<String> uiConstraints,
- final NodeFilterConstraintAction action,
+ public Either<Boolean, ResponseFormat> validateFilter(final Component parentComponent, final String componentInstanceId,
+ final List<String> uiConstraints, final NodeFilterConstraintAction action,
final NodeFilterConstraintType nodeFilterConstraintType) {
try {
if (NodeFilterConstraintAction.ADD == action || NodeFilterConstraintAction.UPDATE == action) {
for (final String uiConstraint : uiConstraints) {
final UIConstraint constraint = new ConstraintConvertor().convert(uiConstraint);
if (ConstraintConvertor.PROPERTY_CONSTRAINT.equals(constraint.getSourceType())) {
- final Either<Boolean, ResponseFormat> booleanResponseFormatEither =
- validatePropertyConstraint(parentComponent, componentInstanceId, constraint);
+ final Either<Boolean, ResponseFormat> booleanResponseFormatEither = validatePropertyConstraint(parentComponent,
+ componentInstanceId, constraint);
if (booleanResponseFormatEither.isRight()) {
return booleanResponseFormatEither;
}
} else if (ConstraintConvertor.STATIC_CONSTRAINT.equals(constraint.getSourceType())) {
Either<Boolean, ResponseFormat> booleanResponseFormatEither;
if (NodeFilterConstraintType.PROPERTIES.equals(nodeFilterConstraintType)) {
- booleanResponseFormatEither = isComponentPropertyFilterValid(
- parentComponent, componentInstanceId, constraint);
+ booleanResponseFormatEither = isComponentPropertyFilterValid(parentComponent, componentInstanceId, constraint);
} else {
- booleanResponseFormatEither = isComponentCapabilityPropertyFilterValid(
- parentComponent, componentInstanceId, constraint);
+ booleanResponseFormatEither = isComponentCapabilityPropertyFilterValid(parentComponent, componentInstanceId, constraint);
}
-
if (booleanResponseFormatEither.isRight()) {
return booleanResponseFormatEither;
}
@@ -129,75 +117,49 @@ public class NodeFilterValidator {
LOGGER.debug("Provided constraint" + uiConstraints, e);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.CONSTRAINT_FORMAT_INCORRECT));
}
-
return Either.left(true);
}
private Either<Boolean, ResponseFormat> isComponentCapabilityPropertyFilterValid(final Component parentComponent,
final String componentInstanceId,
final UIConstraint uiConstraint) {
-
return validateStaticValueAndOperatorOfCapabilityProperties(parentComponent, componentInstanceId, uiConstraint);
-
}
- private Either<Boolean, ResponseFormat> isComponentPropertyFilterValid(Component parentComponent,
- String componentInstanceId,
+ private Either<Boolean, ResponseFormat> isComponentPropertyFilterValid(Component parentComponent, String componentInstanceId,
UIConstraint constraint) {
-
return validateStaticValueAndOperator(parentComponent, componentInstanceId, constraint);
}
- private Either<Boolean, ResponseFormat> validatePropertyConstraint(final Component parentComponent,
- final String componentInstanceId,
+ private Either<Boolean, ResponseFormat> validatePropertyConstraint(final Component parentComponent, final String componentInstanceId,
final UIConstraint uiConstraint) {
String source = SOURCE;
final Optional<ComponentInstance> optionalComponentInstance;
-
final List<PropertyDefinition> propertyDefinitions = parentComponent.getProperties();
List<? extends PropertyDefinition> sourcePropertyDefinition =
- parentComponent.getName().equals(uiConstraint.getSourceName()) &&
- propertyDefinitions != null ? propertyDefinitions : Collections.emptyList();
-
+ parentComponent.getName().equals(uiConstraint.getSourceName()) && propertyDefinitions != null ? propertyDefinitions
+ : Collections.emptyList();
if (sourcePropertyDefinition.isEmpty() && !parentComponent.getName().equals(uiConstraint.getSourceName())) {
optionalComponentInstance = parentComponent.getComponentInstances().stream()
- .filter(componentInstance -> uiConstraint.getSourceName()
- .equals(componentInstance
- .getName()))
- .findFirst();
-
+ .filter(componentInstance -> uiConstraint.getSourceName().equals(componentInstance.getName())).findFirst();
if (optionalComponentInstance.isPresent()) {
- final List<ComponentInstanceProperty> componentInstanceProperties =
- parentComponent.getComponentInstancesProperties()
- .get(optionalComponentInstance.get().getUniqueId());
- sourcePropertyDefinition =
- componentInstanceProperties == null ? new ArrayList<>() : componentInstanceProperties;
+ final List<ComponentInstanceProperty> componentInstanceProperties = parentComponent.getComponentInstancesProperties()
+ .get(optionalComponentInstance.get().getUniqueId());
+ sourcePropertyDefinition = componentInstanceProperties == null ? new ArrayList<>() : componentInstanceProperties;
}
}
-
if (!CollectionUtils.isEmpty(sourcePropertyDefinition)) {
final Optional<? extends PropertyDefinition> sourceSelectedProperty = sourcePropertyDefinition.stream()
- .filter(property -> uiConstraint
- .getValue()
- .equals(property.getName()))
- .findFirst();
-
- final Optional<? extends PropertyDefinition> targetComponentInstanceProperty =
- parentComponent.getComponentInstancesProperties().get(componentInstanceId).stream()
- .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName()))
- .findFirst();
-
+ .filter(property -> uiConstraint.getValue().equals(property.getName())).findFirst();
+ final Optional<? extends PropertyDefinition> targetComponentInstanceProperty = parentComponent.getComponentInstancesProperties()
+ .get(componentInstanceId).stream().filter(property -> uiConstraint.getServicePropertyName().equals(property.getName())).findFirst();
source = !targetComponentInstanceProperty.isPresent() ? "Target" : SOURCE;
if (sourceSelectedProperty.isPresent() && targetComponentInstanceProperty.isPresent()) {
return validatePropertyData(uiConstraint, sourceSelectedProperty, targetComponentInstanceProperty);
}
}
-
- final String missingProperty =
- source.equals(SOURCE) ? uiConstraint.getValue().toString() : uiConstraint.getServicePropertyName();
-
- return Either.right(
- componentsUtils.getResponseFormat(ActionStatus.MAPPED_PROPERTY_NOT_FOUND, source, missingProperty));
+ final String missingProperty = source.equals(SOURCE) ? uiConstraint.getValue().toString() : uiConstraint.getServicePropertyName();
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.MAPPED_PROPERTY_NOT_FOUND, source, missingProperty));
}
private Either<Boolean, ResponseFormat> validatePropertyData(UIConstraint uiConstraint,
@@ -213,122 +175,105 @@ public class NodeFilterValidator {
final SchemaDefinition sourceSchemaDefinition = sourcePropDefinition.getSchema();
final SchemaDefinition targetSchemaDefinition = targetPropDefinition.getSchema();
if (!sourceSchemaDefinition.equals(targetSchemaDefinition)) {
- return Either
- .right(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_SCHEMA_MISMATCH,
- uiConstraint.getServicePropertyName(), uiConstraint.getValue().toString()));
+ return Either.right(componentsUtils
+ .getResponseFormat(ActionStatus.SOURCE_TARGET_SCHEMA_MISMATCH, uiConstraint.getServicePropertyName(),
+ uiConstraint.getValue().toString()));
}
}
return Either.left(Boolean.TRUE);
} else {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_PROPERTY_TYPE_MISMATCH,
- uiConstraint.getServicePropertyName(), uiConstraint.getValue().toString()));
+ return Either.right(componentsUtils
+ .getResponseFormat(ActionStatus.SOURCE_TARGET_PROPERTY_TYPE_MISMATCH, uiConstraint.getServicePropertyName(),
+ uiConstraint.getValue().toString()));
}
} else {
- LOGGER.debug(
- "Null value passed to `validatePropertyData` - sourceSelectedProperty: '{}' - targetComponentInstanceProperty: '{}'",
+ LOGGER.debug("Null value passed to `validatePropertyData` - sourceSelectedProperty: '{}' - targetComponentInstanceProperty: '{}'",
sourceSelectedProperty, targetComponentInstanceProperty);
return Either.right(componentsUtils
- .getResponseFormat(ActionStatus.GENERAL_ERROR, uiConstraint.getServicePropertyName(),
- uiConstraint.getValue().toString()));
+ .getResponseFormat(ActionStatus.GENERAL_ERROR, uiConstraint.getServicePropertyName(), uiConstraint.getValue().toString()));
}
}
- private Either<Boolean, ResponseFormat> validateStaticValueAndOperator(
- final Component parentComponent,
- final String componentInstanceId, final UIConstraint uiConstraint) {
+ private Either<Boolean, ResponseFormat> validateStaticValueAndOperator(final Component parentComponent, final String componentInstanceId,
+ final UIConstraint uiConstraint) {
if (!(Objects.nonNull(uiConstraint) && uiConstraint.getValue() instanceof String)) {
return Either.left(false);
}
//TODO: get capabilities properties when constraint type is capabilities
- final Optional<ComponentInstanceProperty> componentInstanceProperty =
- parentComponent.getComponentInstancesProperties().get(componentInstanceId).stream()
- .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName()))
- .findFirst();
-
+ final Optional<ComponentInstanceProperty> componentInstanceProperty = parentComponent.getComponentInstancesProperties()
+ .get(componentInstanceId).stream().filter(property -> uiConstraint.getServicePropertyName().equals(property.getName())).findFirst();
if (!componentInstanceProperty.isPresent()) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT,
- uiConstraint.getServicePropertyName()));
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT, uiConstraint.getServicePropertyName()));
}
- if (comparableConstraintsOperators.contains(uiConstraint.getConstraintOperator()) && !comparableTypes.contains(
- componentInstanceProperty.get().getType())) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED,
- uiConstraint.getServicePropertyName(), uiConstraint.getConstraintOperator()));
+ if (comparableConstraintsOperators.contains(uiConstraint.getConstraintOperator()) && !comparableTypes
+ .contains(componentInstanceProperty.get().getType())) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, uiConstraint.getServicePropertyName(),
+ uiConstraint.getConstraintOperator()));
}
-
return isValidValueCheck(componentInstanceProperty.get().getType(), String.valueOf(uiConstraint.getValue()),
uiConstraint.getServicePropertyName());
}
- private Either<Boolean, ResponseFormat> validateStaticValueAndOperatorOfCapabilityProperties(
- final Component parentComponent, final String componentInstanceId, final UIConstraint uiConstraint) {
+ private Either<Boolean, ResponseFormat> validateStaticValueAndOperatorOfCapabilityProperties(final Component parentComponent,
+ final String componentInstanceId,
+ final UIConstraint uiConstraint) {
if (!(Objects.nonNull(uiConstraint) && uiConstraint.getValue() instanceof String)) {
return Either.left(false);
}
Optional<ComponentInstanceProperty> optionalComponentInstanceProperty = Optional.empty();
final Optional<ComponentInstance> optionalComponentInstances = parentComponent.getComponentInstances().stream()
- .filter(componentInstance -> componentInstanceId.equalsIgnoreCase(componentInstance.getUniqueId()))
- .findFirst();
+ .filter(componentInstance -> componentInstanceId.equalsIgnoreCase(componentInstance.getUniqueId())).findFirst();
if (optionalComponentInstances.isPresent()) {
- final Optional<List<CapabilityDefinition>> optionalCapabilityDefinitionList = optionalComponentInstances.get()
- .getCapabilities().values().stream()
- .filter(capabilityDefinitions -> capabilityDefinitions
- .stream().allMatch(capabilityDefinition -> capabilityDefinition.getProperties() != null))
- .collect(Collectors.toList())
- .stream().filter(capabilityDefinitions -> capabilityDefinitions.stream().allMatch(
- capabilityDefinition -> capabilityDefinition.getProperties().stream().anyMatch(
- componentInstanceProperty -> uiConstraint.getServicePropertyName()
- .equalsIgnoreCase(componentInstanceProperty.getName())))).findFirst();
-
+ final Optional<List<CapabilityDefinition>> optionalCapabilityDefinitionList = optionalComponentInstances.get().getCapabilities().values()
+ .stream().filter(capabilityDefinitions -> capabilityDefinitions.stream()
+ .allMatch(capabilityDefinition -> capabilityDefinition.getProperties() != null)).collect(Collectors.toList()).stream().filter(
+ capabilityDefinitions -> capabilityDefinitions.stream().allMatch(
+ capabilityDefinition -> capabilityDefinition.getProperties().stream().anyMatch(
+ componentInstanceProperty -> uiConstraint.getServicePropertyName()
+ .equalsIgnoreCase(componentInstanceProperty.getName())))).findFirst();
if (optionalCapabilityDefinitionList.isPresent()) {
optionalComponentInstanceProperty = optionalCapabilityDefinitionList.get().stream().findAny()
.map(capabilityDefinition -> capabilityDefinition.getProperties().get(0));
}
}
-
if (optionalComponentInstanceProperty.isEmpty()) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT,
- uiConstraint.getServicePropertyName()));
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT, uiConstraint.getServicePropertyName()));
}
- if (comparableConstraintsOperators.contains(uiConstraint.getConstraintOperator()) && !comparableTypes.contains(
- optionalComponentInstanceProperty.get().getType())) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED,
- uiConstraint.getServicePropertyName(), uiConstraint.getConstraintOperator()));
+ if (comparableConstraintsOperators.contains(uiConstraint.getConstraintOperator()) && !comparableTypes
+ .contains(optionalComponentInstanceProperty.get().getType())) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, uiConstraint.getServicePropertyName(),
+ uiConstraint.getConstraintOperator()));
}
-
return isValidValueCheck(optionalComponentInstanceProperty.get().getType(), String.valueOf(uiConstraint.getValue()),
uiConstraint.getServicePropertyName());
}
private Either<Boolean, ResponseFormat> isValidValueCheck(String type, String value, String propertyName) {
-
ToscaPropertyType toscaPropertyType = ToscaPropertyType.isValidType(type);
if (Objects.isNull(toscaPropertyType)) {
- return Either.right(
- componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_PROPERTY_TYPE, type, propertyName));
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_PROPERTY_TYPE, type, propertyName));
}
if (toscaPropertyType.getValidator().isValid(value, null)) {
return Either.left(Boolean.TRUE);
}
- return Either.right(
- componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, type, propertyName, value));
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, type, propertyName, value));
}
- public Either<Boolean, ResponseFormat> validateComponentFilter(final Component component,
- final List<String> uiConstraints,
+ public Either<Boolean, ResponseFormat> validateComponentFilter(final Component component, final List<String> uiConstraints,
final NodeFilterConstraintAction action) {
try {
if (NodeFilterConstraintAction.ADD == action || NodeFilterConstraintAction.UPDATE == action) {
for (final String uiConstraint : uiConstraints) {
final UIConstraint constraint = new ConstraintConvertor().convert(uiConstraint);
if (ConstraintConvertor.PROPERTY_CONSTRAINT.equals(constraint.getSourceType())) {
- final Either<Boolean, ResponseFormat> booleanResponseFormatEither =
- validateComponentPropertyConstraint(component, constraint);
+ final Either<Boolean, ResponseFormat> booleanResponseFormatEither = validateComponentPropertyConstraint(component,
+ constraint);
if (booleanResponseFormatEither.isRight()) {
return booleanResponseFormatEither;
}
} else if (ConstraintConvertor.STATIC_CONSTRAINT.equals(constraint.getSourceType())) {
- final Either<Boolean, ResponseFormat> booleanResponseFormatEither =
- validateComponentStaticValueAndOperator(component, constraint);
+ final Either<Boolean, ResponseFormat> booleanResponseFormatEither = validateComponentStaticValueAndOperator(component,
+ constraint);
if (booleanResponseFormatEither.isRight()) {
return booleanResponseFormatEither;
}
@@ -339,66 +284,42 @@ public class NodeFilterValidator {
LOGGER.debug("Provided constraint" + uiConstraints, e);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.CONSTRAINT_FORMAT_INCORRECT));
}
-
return Either.left(true);
}
- private Either<Boolean, ResponseFormat> validateComponentPropertyConstraint(final Component component,
- final UIConstraint uiConstraint) {
+ private Either<Boolean, ResponseFormat> validateComponentPropertyConstraint(final Component component, final UIConstraint uiConstraint) {
String source = SOURCE;
-
final List<PropertyDefinition> propertyDefinitions = component.getProperties();
List<? extends PropertyDefinition> sourcePropertyDefinition =
- component.getName().equals(uiConstraint.getSourceName()) &&
- propertyDefinitions != null ? propertyDefinitions : Collections.emptyList();
-
+ component.getName().equals(uiConstraint.getSourceName()) && propertyDefinitions != null ? propertyDefinitions : Collections.emptyList();
if (!CollectionUtils.isEmpty(sourcePropertyDefinition)) {
final Optional<? extends PropertyDefinition> sourceSelectedProperty = sourcePropertyDefinition.stream()
- .filter(property -> uiConstraint
- .getValue()
- .equals(property.getName()))
- .findFirst();
-
- final Optional<? extends PropertyDefinition> targetComponentProperty =
- component.getProperties().stream()
- .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName()))
- .findFirst();
-
+ .filter(property -> uiConstraint.getValue().equals(property.getName())).findFirst();
+ final Optional<? extends PropertyDefinition> targetComponentProperty = component.getProperties().stream()
+ .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName())).findFirst();
source = !targetComponentProperty.isPresent() ? "Target" : SOURCE;
if (sourceSelectedProperty.isPresent() && targetComponentProperty.isPresent()) {
return validatePropertyData(uiConstraint, sourceSelectedProperty, targetComponentProperty);
}
}
-
- final String missingProperty =
- source.equals(SOURCE) ? uiConstraint.getValue().toString() : uiConstraint.getServicePropertyName();
-
- return Either.right(
- componentsUtils.getResponseFormat(ActionStatus.MAPPED_PROPERTY_NOT_FOUND, source, missingProperty));
+ final String missingProperty = source.equals(SOURCE) ? uiConstraint.getValue().toString() : uiConstraint.getServicePropertyName();
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.MAPPED_PROPERTY_NOT_FOUND, source, missingProperty));
}
- private Either<Boolean, ResponseFormat> validateComponentStaticValueAndOperator(
- final Component component, final UIConstraint uiConstraint) {
+ private Either<Boolean, ResponseFormat> validateComponentStaticValueAndOperator(final Component component, final UIConstraint uiConstraint) {
if (!(Objects.nonNull(uiConstraint) && uiConstraint.getValue() instanceof String)) {
return Either.left(false);
}
- final Optional<PropertyDefinition> componentProperty =
- component.getProperties().stream()
- .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName()))
- .findFirst();
-
+ final Optional<PropertyDefinition> componentProperty = component.getProperties().stream()
+ .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName())).findFirst();
if (componentProperty.isEmpty()) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT,
- uiConstraint.getServicePropertyName()));
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT, uiConstraint.getServicePropertyName()));
}
- if (comparableConstraintsOperators.contains(uiConstraint.getConstraintOperator()) && !comparableTypes.contains(
- componentProperty.get().getType())) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED,
- uiConstraint.getServicePropertyName(), uiConstraint.getConstraintOperator()));
+ if (comparableConstraintsOperators.contains(uiConstraint.getConstraintOperator()) && !comparableTypes
+ .contains(componentProperty.get().getType())) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, uiConstraint.getServicePropertyName(),
+ uiConstraint.getConstraintOperator()));
}
-
- return isValidValueCheck(componentProperty.get().getType(), String.valueOf(uiConstraint.getValue()),
- uiConstraint.getServicePropertyName());
+ return isValidValueCheck(componentProperty.get().getType(), String.valueOf(uiConstraint.getValue()), uiConstraint.getServicePropertyName());
}
-
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PolicyUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PolicyUtils.java
index 7947cbc292..b1bc10b10a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PolicyUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PolicyUtils.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,10 +17,19 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation;
+import static org.apache.commons.collections.MapUtils.isEmpty;
+import static org.apache.commons.collections.MapUtils.isNotEmpty;
+import static org.apache.commons.lang3.StringUtils.isEmpty;
+import static org.apache.commons.lang3.StringUtils.isNotEmpty;
+import static org.openecomp.sdc.common.api.Constants.GROUP_POLICY_NAME_DELIMETER;
+
import fj.data.Either;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
@@ -34,17 +43,6 @@ import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.ValidationUtils;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-
-import static org.apache.commons.collections.MapUtils.isEmpty;
-import static org.apache.commons.collections.MapUtils.isNotEmpty;
-import static org.apache.commons.lang3.StringUtils.isEmpty;
-import static org.apache.commons.lang3.StringUtils.isNotEmpty;
-import static org.openecomp.sdc.common.api.Constants.GROUP_POLICY_NAME_DELIMETER;
-
/**
* Provides specific functionality for policy
*/
@@ -65,16 +63,10 @@ public class PolicyUtils {
public static int getNextPolicyCounter(Map<String, PolicyDefinition> policies) {
int nextCounter = 0;
if (isNotEmpty(policies)) {
- int nextCounterFromIds = policies.values()
- .stream()
- .map(p -> extractNextPolicyCounterFromUniqueId(p.getUniqueId()))
- .max(Integer::compareTo)
- .orElse(0);
- int nextCounterFromNames = policies.values()
- .stream()
- .map(p -> extractNextPolicyCounterFromName(p.getName()))
- .max(Integer::compareTo)
- .orElse(0);
+ int nextCounterFromIds = policies.values().stream().map(p -> extractNextPolicyCounterFromUniqueId(p.getUniqueId()))
+ .max(Integer::compareTo).orElse(0);
+ int nextCounterFromNames = policies.values().stream().map(p -> extractNextPolicyCounterFromName(p.getName())).max(Integer::compareTo)
+ .orElse(0);
nextCounter = nextCounterFromIds > nextCounterFromNames ? nextCounterFromIds : nextCounterFromNames;
}
return nextCounter;
@@ -88,7 +80,8 @@ public class PolicyUtils {
* @param policies all the polices related to the component
* @return validated and updated policy or an error as action status
*/
- public static Either<PolicyDefinition, ActionStatus> validatePolicyFields(PolicyDefinition recievedPolicy, PolicyDefinition validPolicy, Map<String, PolicyDefinition> policies) {
+ public static Either<PolicyDefinition, ActionStatus> validatePolicyFields(PolicyDefinition recievedPolicy, PolicyDefinition validPolicy,
+ Map<String, PolicyDefinition> policies) {
validateImmutablePolicyFields(recievedPolicy, validPolicy);
return validateUpdateMutablePolicyFields(recievedPolicy, validPolicy, policies);
}
@@ -99,28 +92,21 @@ public class PolicyUtils {
* @return the set of the policies
*/
public static Set<String> getExcludedPolicyTypesByComponent(Component component) {
- if (isEmpty(ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getExcludedPolicyTypesMapping())) {
+ if (isEmpty(ConfigurationManager.getConfigurationManager().getConfiguration().getExcludedPolicyTypesMapping())) {
return Collections.emptySet();
}
if (component.getComponentType() == ComponentTypeEnum.SERVICE) {
- return ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getExcludedPolicyTypesMapping()
- .get(component.getComponentType().name());
+ return ConfigurationManager.getConfigurationManager().getConfiguration().getExcludedPolicyTypesMapping()
+ .get(component.getComponentType().name());
}
- return ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getExcludedPolicyTypesMapping()
- .get(((Resource) component).getResourceType().getValue());
+ return ConfigurationManager.getConfigurationManager().getConfiguration().getExcludedPolicyTypesMapping()
+ .get(((Resource) component).getResourceType().getValue());
}
public static PolicyDefinition getDeclaredPolicyDefinition(String componentInstanceId, ComponentInstanceProperty property) {
PolicyDefinition policyDefinition = new PolicyDefinition(property);
policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentInstanceId, property.getName()));
policyDefinition.setInstanceUniqueId(componentInstanceId);
-
return policyDefinition;
}
@@ -146,14 +132,15 @@ public class PolicyUtils {
int beginIndex = policyName.lastIndexOf(GROUP_POLICY_NAME_DELIMETER) + GROUP_POLICY_NAME_DELIMETER.length();
String counterStr = policyName.substring(beginIndex, endIndex);
counter = Integer.valueOf(counterStr) + 1;
- }
- catch (NumberFormatException | IndexOutOfBoundsException e) {
+ } catch (NumberFormatException | IndexOutOfBoundsException e) {
log.error("#extractNextPolicyCounter - An error occurred when attempting to extract counter from policy name [{}]. ", policyName, e);
}
return counter;
}
- private static Either<PolicyDefinition, ActionStatus> validateUpdateMutablePolicyFields(PolicyDefinition recievedPolicy, PolicyDefinition validPolicy, Map<String, PolicyDefinition> policies) {
+ private static Either<PolicyDefinition, ActionStatus> validateUpdateMutablePolicyFields(PolicyDefinition recievedPolicy,
+ PolicyDefinition validPolicy,
+ Map<String, PolicyDefinition> policies) {
return validateUpdatePolicyName(recievedPolicy, validPolicy, policies);
}
@@ -168,15 +155,15 @@ public class PolicyUtils {
logImmutableFieldUpdateWarning(receivedPolicy.getPolicyTypeUid(), validPolicy.getPolicyTypeUid(), JsonPresentationFields.TYPE_UNIQUE_ID);
logImmutableFieldUpdateWarning(receivedPolicy.getPolicyUUID(), validPolicy.getPolicyUUID(), JsonPresentationFields.UUID);
logImmutableFieldUpdateWarning(receivedPolicy.getVersion(), validPolicy.getVersion(), JsonPresentationFields.VERSION);
- logImmutableFieldUpdateWarning(receivedPolicy.getIsFromCsar().toString(), validPolicy.getIsFromCsar().toString(), JsonPresentationFields.IS_FROM_CSAR);
+ logImmutableFieldUpdateWarning(receivedPolicy.getIsFromCsar().toString(), validPolicy.getIsFromCsar().toString(),
+ JsonPresentationFields.IS_FROM_CSAR);
}
private static boolean isUpdatedField(String oldField, String newField) {
boolean isUpdatedField = false;
if (isEmpty(oldField) && isNotEmpty(newField)) {
isUpdatedField = true;
- }
- else if (isNotEmpty(oldField) && isNotEmpty(newField) && !oldField.equals(newField)) {
+ } else if (isNotEmpty(oldField) && isNotEmpty(newField) && !oldField.equals(newField)) {
isUpdatedField = true;
}
return isUpdatedField;
@@ -184,27 +171,28 @@ public class PolicyUtils {
private static void logImmutableFieldUpdateWarning(String oldValue, String newValue, JsonPresentationFields field) {
if (isUpdatedField(oldValue, newValue)) {
- log.warn("#logImmutableFieldUpdateWarning - Update of the field {} of a policy not allowed. The change will be ignored. The old value is {} , the new value is {}. ", field, oldValue, newValue);
+ log.warn(
+ "#logImmutableFieldUpdateWarning - Update of the field {} of a policy not allowed. The change will be ignored. The old value is {} , the new value is {}. ",
+ field, oldValue, newValue);
}
}
- private static Either<PolicyDefinition, ActionStatus> validateUpdatePolicyName(PolicyDefinition receivedPolicy, PolicyDefinition validPolicy, Map<String, PolicyDefinition> policies) {
+ private static Either<PolicyDefinition, ActionStatus> validateUpdatePolicyName(PolicyDefinition receivedPolicy, PolicyDefinition validPolicy,
+ Map<String, PolicyDefinition> policies) {
Either<PolicyDefinition, ActionStatus> result = null;
Optional<PolicyDefinition> sameNamePolicy = Optional.empty();
- if (isEmpty(receivedPolicy.getName()) || !ValidationUtils.POLICY_NAME_PATTERN.matcher(receivedPolicy
- .getName()).matches()) {
- log.error("#validateUpdatePolicyName - Failed to validate the name {} of the policy {}. ", receivedPolicy.getName(), receivedPolicy.getUniqueId());
+ if (isEmpty(receivedPolicy.getName()) || !ValidationUtils.POLICY_NAME_PATTERN.matcher(receivedPolicy.getName()).matches()) {
+ log.error("#validateUpdatePolicyName - Failed to validate the name {} of the policy {}. ", receivedPolicy.getName(),
+ receivedPolicy.getUniqueId());
result = Either.right(ActionStatus.INVALID_POLICY_NAME);
}
if (result == null && isNotEmpty(policies)) {
- sameNamePolicy = policies.values()
- .stream()
- .filter(p -> p.getName().equals(receivedPolicy.getName()))
- .findFirst();
+ sameNamePolicy = policies.values().stream().filter(p -> p.getName().equals(receivedPolicy.getName())).findFirst();
}
if (sameNamePolicy.isPresent()) {
- log.error("#validateUpdatePolicyName - Failed to validate the name {} of the policy {}. The policy {} with the same name already exists. ", receivedPolicy
- .getName(), receivedPolicy.getUniqueId(), sameNamePolicy.get().getUniqueId());
+ log.error(
+ "#validateUpdatePolicyName - Failed to validate the name {} of the policy {}. The policy {} with the same name already exists. ",
+ receivedPolicy.getName(), receivedPolicy.getUniqueId(), sameNamePolicy.get().getUniqueId());
result = Either.right(ActionStatus.POLICY_NAME_ALREADY_EXIST);
}
if (result == null) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PropertyValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PropertyValidator.java
index ecbb039fa3..bdb6799cb6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PropertyValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PropertyValidator.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,10 +17,12 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation;
import fj.data.Either;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
import org.openecomp.sdc.be.components.impl.utils.ExceptionUtils;
@@ -39,10 +41,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
@Component
public class PropertyValidator {
@@ -52,94 +50,84 @@ public class PropertyValidator {
private final ExceptionUtils exceptionUtils;
private static final Logger log = LoggerFactory.getLogger(ResourceBusinessLogic.class);
- public PropertyValidator(PropertyOperation propertyOperation, ComponentsUtils componentsUtils,
- ApplicationDataTypeCache applicationDataTypeCache, ExceptionUtils exceptionUtils) {
+ public PropertyValidator(PropertyOperation propertyOperation, ComponentsUtils componentsUtils, ApplicationDataTypeCache applicationDataTypeCache,
+ ExceptionUtils exceptionUtils) {
this.exceptionUtils = exceptionUtils;
this.propertyOperation = propertyOperation;
this.componentsUtils = componentsUtils;
this.applicationDataTypeCache = applicationDataTypeCache;
}
- public void thinPropertiesValidator(List<PropertyDefinition> properties,
- List<PropertyDefinition> dbAnnotationTypeDefinitionProperties,
- Map<String, DataTypeDefinition> allDataTypes){
+ public void thinPropertiesValidator(List<PropertyDefinition> properties, List<PropertyDefinition> dbAnnotationTypeDefinitionProperties,
+ Map<String, DataTypeDefinition> allDataTypes) {
for (PropertyDefinition property : properties) {
- PropertyDefinition annotationTypeSpecificProperty = isPropertyInsideAnnotationTypeProperties(
- dbAnnotationTypeDefinitionProperties, property);
- if(annotationTypeSpecificProperty!=null){
+ PropertyDefinition annotationTypeSpecificProperty = isPropertyInsideAnnotationTypeProperties(dbAnnotationTypeDefinitionProperties,
+ property);
+ if (annotationTypeSpecificProperty != null) {
verifyPropertyIsOfDefinedType(property, annotationTypeSpecificProperty, allDataTypes);
}
}
}
- private void verifyPropertyIsOfDefinedType(PropertyDefinition property,
- PropertyDefinition typeSpecificProperty,
+ private void verifyPropertyIsOfDefinedType(PropertyDefinition property, PropertyDefinition typeSpecificProperty,
Map<String, DataTypeDefinition> allDataTypes) {
- propertyOperation.validateAndUpdatePropertyValue(typeSpecificProperty.getType(),
- property.getValue(), typeSpecificProperty.getSchemaType(), allDataTypes)
- .left()
- .on( error ->
- exceptionUtils.rollBackAndThrow(
- ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName())
- );
+ propertyOperation
+ .validateAndUpdatePropertyValue(typeSpecificProperty.getType(), property.getValue(), typeSpecificProperty.getSchemaType(), allDataTypes)
+ .left().on(error -> exceptionUtils.rollBackAndThrow(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName()));
}
- private PropertyDefinition isPropertyInsideAnnotationTypeProperties(
- List<PropertyDefinition> dbAnnotationTypeDefinitionProperties, PropertyDefinition property) {
+ private PropertyDefinition isPropertyInsideAnnotationTypeProperties(List<PropertyDefinition> dbAnnotationTypeDefinitionProperties,
+ PropertyDefinition property) {
Optional<PropertyDefinition> optionalResult = dbAnnotationTypeDefinitionProperties.stream()
- .filter(prop -> prop.getName()
- .equals(property.getName()))
- .findFirst();
- if (optionalResult.isPresent()){
+ .filter(prop -> prop.getName().equals(property.getName())).findFirst();
+ if (optionalResult.isPresent()) {
return optionalResult.get();
}
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(
- ActionStatus.PROPERTY_NOT_FOUND, property.getType(), property.getName());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, property.getType(), property.getName());
exceptionUtils.rollBackAndThrow(responseFormat);
return null;
}
- public Either<Boolean, ResponseFormat> iterateOverProperties(List<PropertyDefinition> properties){
+ public Either<Boolean, ResponseFormat> iterateOverProperties(List<PropertyDefinition> properties) {
Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
String type = null;
String innerType = null;
for (PropertyDefinition property : properties) {
if (!propertyOperation.isPropertyTypeValid(property)) {
log.info("Invalid type for property {}", property);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(
- ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
eitherResult = Either.right(responseFormat);
break;
}
-
Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = applicationDataTypeCache.getAll();
if (allDataTypes.isRight()) {
JanusGraphOperationStatus status = allDataTypes.right().value();
- BeEcompErrorManager.getInstance().logInternalFlowError("AddPropertyToGroup", "Failed to validate property. Status is " + status, BeEcompErrorManager.ErrorSeverity.ERROR);
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status))));
+ BeEcompErrorManager.getInstance().logInternalFlowError("AddPropertyToGroup", "Failed to validate property. Status is " + status,
+ BeEcompErrorManager.ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(
+ componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status))));
}
-
type = property.getType();
-
if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
ResponseFormat responseFormat = validateMapOrListPropertyType(property, allDataTypes.left().value());
- if(responseFormat != null)
- break;
+ if (responseFormat != null) {
+ break;
+ }
}
-
if (!propertyOperation.isPropertyDefaultValueValid(property, allDataTypes.left().value())) {
log.info("Invalid default value for property {}", property);
ResponseFormat responseFormat;
if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE,
- property.getName(), type, innerType, property.getDefaultValue());
+ responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE, property.getName(), type, innerType,
+ property.getDefaultValue());
} else {
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_DEFAULT_VALUE,
- property.getName(), type, property.getDefaultValue());
+ responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.INVALID_DEFAULT_VALUE, property.getName(), type, property.getDefaultValue());
}
eitherResult = Either.right(responseFormat);
break;
-
}
}
return eitherResult;
@@ -147,15 +135,12 @@ public class PropertyValidator {
private ResponseFormat validateMapOrListPropertyType(PropertyDefinition property, Map<String, DataTypeDefinition> allDataTypes) {
ResponseFormat responseFormat = null;
- ImmutablePair<String, Boolean> propertyInnerTypeValid = propertyOperation
- .isPropertyInnerTypeValid(property, allDataTypes);
+ ImmutablePair<String, Boolean> propertyInnerTypeValid = propertyOperation.isPropertyInnerTypeValid(property, allDataTypes);
String propertyInnerType = propertyInnerTypeValid.getLeft();
if (!propertyInnerTypeValid.getRight().booleanValue()) {
log.info("Invalid inner type for property {}", property);
- responseFormat = componentsUtils.getResponseFormat(
- ActionStatus.INVALID_PROPERTY_INNER_TYPE, propertyInnerType, property.getName());
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE, propertyInnerType, property.getName());
}
return responseFormat;
}
-
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/RequirementValidation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/RequirementValidation.java
index 030684ebb5..7dd38bb2c1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/RequirementValidation.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/RequirementValidation.java
@@ -13,10 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.be.components.validation;
import fj.data.Either;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
@@ -28,13 +33,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
@Component("requirementValidation")
public class RequirementValidation {
@@ -42,13 +40,10 @@ public class RequirementValidation {
private static final String REQUIREMENT_NOT_FOUND_IN_COMPONENT = "Requirement not found in component {} ";
private static final Pattern NAME_VALIDATION_REGEX_PATTERN = Pattern.compile("^[a-zA-Z0-9_.]*$");
- public Either<Boolean, ResponseFormat> validateRequirements(
- Collection<RequirementDefinition> requirements,
- org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
-
- for(RequirementDefinition requirementDefinition : requirements) {
- Either<Boolean, ResponseFormat> requirementValidationResponse
- = validateRequirement(requirementDefinition, component, isUpdate);
+ public Either<Boolean, ResponseFormat> validateRequirements(Collection<RequirementDefinition> requirements,
+ org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
+ for (RequirementDefinition requirementDefinition : requirements) {
+ Either<Boolean, ResponseFormat> requirementValidationResponse = validateRequirement(requirementDefinition, component, isUpdate);
if (requirementValidationResponse.isRight()) {
return requirementValidationResponse;
}
@@ -56,34 +51,27 @@ public class RequirementValidation {
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> validateRequirement(
- RequirementDefinition requirementDefinition,
- org.openecomp.sdc.be.model.Component component,
- boolean isUpdate) {
+ private Either<Boolean, ResponseFormat> validateRequirement(RequirementDefinition requirementDefinition,
+ org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
ResponseFormatManager responseFormatManager = getResponseFormatManager();
- if(isUpdate) {
- Either<Boolean, ResponseFormat> requirementExistValidationEither
- = isRequirementExist(requirementDefinition, responseFormatManager, component);
+ if (isUpdate) {
+ Either<Boolean, ResponseFormat> requirementExistValidationEither = isRequirementExist(requirementDefinition, responseFormatManager,
+ component);
if (requirementExistValidationEither.isRight()) {
return Either.right(requirementExistValidationEither.right().value());
}
}
-
- Either<Boolean, ResponseFormat> requirementNameValidationResponse
- = isRequirementNameValid(requirementDefinition, responseFormatManager,
- component, isUpdate);
+ Either<Boolean, ResponseFormat> requirementNameValidationResponse = isRequirementNameValid(requirementDefinition, responseFormatManager,
+ component, isUpdate);
if (requirementNameValidationResponse.isRight()) {
return Either.right(requirementNameValidationResponse.right().value());
}
-
- Either<Boolean, ResponseFormat> requirementTypeEmptyEither =
- isRequirementCapabilityEmpty(responseFormatManager,
- requirementDefinition.getCapability());
+ Either<Boolean, ResponseFormat> requirementTypeEmptyEither = isRequirementCapabilityEmpty(responseFormatManager,
+ requirementDefinition.getCapability());
if (requirementTypeEmptyEither.isRight()) {
return Either.right(requirementTypeEmptyEither.right().value());
}
- Either<Boolean, ResponseFormat> requirementOccurrencesValidationEither =
- validateOccurrences(requirementDefinition, responseFormatManager);
+ Either<Boolean, ResponseFormat> requirementOccurrencesValidationEither = validateOccurrences(requirementDefinition, responseFormatManager);
if (requirementOccurrencesValidationEither.isRight()) {
return Either.right(requirementOccurrencesValidationEither.right().value());
}
@@ -94,10 +82,9 @@ public class RequirementValidation {
ResponseFormatManager responseFormatManager) {
String maxOccurrences = requirementDefinition.getMaxOccurrences();
String minOccurrences = requirementDefinition.getMinOccurrences();
- if(maxOccurrences != null && minOccurrences !=null) {
- Either<Boolean, ResponseFormat> requirementOccurrencesValidationEither =
- validateOccurrences(responseFormatManager, minOccurrences,
- maxOccurrences);
+ if (maxOccurrences != null && minOccurrences != null) {
+ Either<Boolean, ResponseFormat> requirementOccurrencesValidationEither = validateOccurrences(responseFormatManager, minOccurrences,
+ maxOccurrences);
if (requirementOccurrencesValidationEither.isRight()) {
return Either.right(requirementOccurrencesValidationEither.right().value());
}
@@ -105,55 +92,44 @@ public class RequirementValidation {
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> isRequirementNameValid(
- RequirementDefinition requirementDefinition,
- ResponseFormatManager responseFormatManager,
- org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
- Either<Boolean, ResponseFormat> requirementNameEmptyEither =
- isRequirementNameEmpty(responseFormatManager, requirementDefinition.getName());
+ private Either<Boolean, ResponseFormat> isRequirementNameValid(RequirementDefinition requirementDefinition,
+ ResponseFormatManager responseFormatManager,
+ org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
+ Either<Boolean, ResponseFormat> requirementNameEmptyEither = isRequirementNameEmpty(responseFormatManager, requirementDefinition.getName());
if (requirementNameEmptyEither.isRight()) {
return Either.right(requirementNameEmptyEither.right().value());
}
-
- Either<Boolean, ResponseFormat> requirementNameRegexValidationResponse =
- isRequirementNameRegexValid(responseFormatManager, requirementDefinition.getName());
+ Either<Boolean, ResponseFormat> requirementNameRegexValidationResponse = isRequirementNameRegexValid(responseFormatManager,
+ requirementDefinition.getName());
if (requirementNameRegexValidationResponse.isRight()) {
return Either.right(requirementNameRegexValidationResponse.right().value());
}
-
- Either<Boolean, ResponseFormat> requirementNameUniqueResponse
- = validateRequirementNameUnique(requirementDefinition,
- component, isUpdate );
- if(requirementNameUniqueResponse.isRight()) {
+ Either<Boolean, ResponseFormat> requirementNameUniqueResponse = validateRequirementNameUnique(requirementDefinition, component, isUpdate);
+ if (requirementNameUniqueResponse.isRight()) {
return Either.right(requirementNameUniqueResponse.right().value());
}
if (!requirementNameUniqueResponse.left().value()) {
LOGGER.error("Requirement name {} already in use ", requirementDefinition.getName());
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .REQUIREMENT_NAME_ALREADY_IN_USE, requirementDefinition.getName());
+ ResponseFormat errorResponse = responseFormatManager
+ .getResponseFormat(ActionStatus.REQUIREMENT_NAME_ALREADY_IN_USE, requirementDefinition.getName());
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> isRequirementNameEmpty(
- ResponseFormatManager responseFormatManager,
- String requirementName) {
+ private Either<Boolean, ResponseFormat> isRequirementNameEmpty(ResponseFormatManager responseFormatManager, String requirementName) {
if (StringUtils.isEmpty(requirementName)) {
LOGGER.error("Requirement Name is mandatory");
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .REQUIREMENT_NAME_MANDATORY);
+ ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus.REQUIREMENT_NAME_MANDATORY);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> validateOccurrences (
- ResponseFormatManager responseFormatManager,
- String minOccurrences, String maxOccurrences ) {
+ private Either<Boolean, ResponseFormat> validateOccurrences(ResponseFormatManager responseFormatManager, String minOccurrences,
+ String maxOccurrences) {
try {
- if (StringUtils.isNotEmpty(maxOccurrences) && "UNBOUNDED".equalsIgnoreCase(maxOccurrences)
- && Integer.parseInt(minOccurrences) >= 0) {
+ if (StringUtils.isNotEmpty(maxOccurrences) && "UNBOUNDED".equalsIgnoreCase(maxOccurrences) && Integer.parseInt(minOccurrences) >= 0) {
return Either.left(Boolean.TRUE);
} else if (Integer.parseInt(minOccurrences) < 0) {
LOGGER.debug("Invalid occurrences format.low_bound occurrence negative {}", minOccurrences);
@@ -161,8 +137,8 @@ public class RequirementValidation {
return Either.right(responseFormat);
} else if (Integer.parseInt(maxOccurrences) < Integer.parseInt(minOccurrences)) {
LOGGER.error("Requirement maxOccurrences should be greater than minOccurrences");
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .MAX_OCCURRENCES_SHOULD_BE_GREATER_THAN_MIN_OCCURRENCES);
+ ResponseFormat errorResponse = responseFormatManager
+ .getResponseFormat(ActionStatus.MAX_OCCURRENCES_SHOULD_BE_GREATER_THAN_MIN_OCCURRENCES);
return Either.right(errorResponse);
}
} catch (NumberFormatException ex) {
@@ -172,94 +148,72 @@ public class RequirementValidation {
}
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> isRequirementCapabilityEmpty(
- ResponseFormatManager responseFormatManager,
- String requirementCapability) {
+
+ private Either<Boolean, ResponseFormat> isRequirementCapabilityEmpty(ResponseFormatManager responseFormatManager, String requirementCapability) {
if (StringUtils.isEmpty(requirementCapability)) {
LOGGER.error("Requirement capability is mandatory");
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .REQUIREMENT_CAPABILITY_MANDATORY);
+ ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus.REQUIREMENT_CAPABILITY_MANDATORY);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> validateRequirementNameUnique(
- RequirementDefinition requirementDefinition,
- org.openecomp.sdc.be.model.Component component,
- boolean isUpdate) {
+ private Either<Boolean, ResponseFormat> validateRequirementNameUnique(RequirementDefinition requirementDefinition,
+ org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
boolean isRequirementNameUnique = false;
-
Map<String, List<RequirementDefinition>> componentRequirements = component.getRequirements();
- if(MapUtils.isEmpty(componentRequirements)){
+ if (MapUtils.isEmpty(componentRequirements)) {
return Either.left(true);
}
- List<RequirementDefinition> requirementDefinitionList = componentRequirements.values()
- .stream().flatMap(Collection::stream).collect(Collectors.toList());
-
- if(CollectionUtils.isEmpty(requirementDefinitionList)){
+ List<RequirementDefinition> requirementDefinitionList = componentRequirements.values().stream().flatMap(Collection::stream)
+ .collect(Collectors.toList());
+ if (CollectionUtils.isEmpty(requirementDefinitionList)) {
return Either.left(true);
}
-
Map<String, String> requirementNameMap = new HashMap<>();
- requirementDefinitionList.forEach(requirement -> requirementNameMap
- .put(requirement.getUniqueId(), requirement.getName()));
-
- if (!requirementNameMap.values().contains(requirementDefinition.getName())){
+ requirementDefinitionList.forEach(requirement -> requirementNameMap.put(requirement.getUniqueId(), requirement.getName()));
+ if (!requirementNameMap.values().contains(requirementDefinition.getName())) {
isRequirementNameUnique = true;
}
- if (!isRequirementNameUnique && isUpdate){
- List<Map.Entry<String, String>> reqNamesEntry = requirementNameMap.entrySet()
- .stream().filter(entry -> entry.getValue().equalsIgnoreCase(requirementDefinition.getName()))
- .collect(Collectors.toList());
- if(reqNamesEntry.size() == 1 && reqNamesEntry.get(0).getKey()
- .equals(requirementDefinition.getUniqueId())) {
+ if (!isRequirementNameUnique && isUpdate) {
+ List<Map.Entry<String, String>> reqNamesEntry = requirementNameMap.entrySet().stream()
+ .filter(entry -> entry.getValue().equalsIgnoreCase(requirementDefinition.getName())).collect(Collectors.toList());
+ if (reqNamesEntry.size() == 1 && reqNamesEntry.get(0).getKey().equals(requirementDefinition.getUniqueId())) {
isRequirementNameUnique = true;
}
}
return Either.left(isRequirementNameUnique);
}
- private Either<Boolean, ResponseFormat> isRequirementExist(
- RequirementDefinition definition,
- ResponseFormatManager responseFormatManager,
- org.openecomp.sdc.be.model.Component component) {
+ private Either<Boolean, ResponseFormat> isRequirementExist(RequirementDefinition definition, ResponseFormatManager responseFormatManager,
+ org.openecomp.sdc.be.model.Component component) {
Map<String, List<RequirementDefinition>> componentRequirements = component.getRequirements();
- if(MapUtils.isEmpty(componentRequirements)){
+ if (MapUtils.isEmpty(componentRequirements)) {
LOGGER.error(REQUIREMENT_NOT_FOUND_IN_COMPONENT, component.getUniqueId());
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .REQUIREMENT_NOT_FOUND, component.getUniqueId());
+ ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus.REQUIREMENT_NOT_FOUND, component.getUniqueId());
return Either.right(errorResponse);
}
-
- List<RequirementDefinition> requirementDefinitionList = componentRequirements.values()
- .stream().flatMap(Collection::stream).collect(Collectors.toList());
- if(CollectionUtils.isEmpty(requirementDefinitionList)){
+ List<RequirementDefinition> requirementDefinitionList = componentRequirements.values().stream().flatMap(Collection::stream)
+ .collect(Collectors.toList());
+ if (CollectionUtils.isEmpty(requirementDefinitionList)) {
LOGGER.error(REQUIREMENT_NOT_FOUND_IN_COMPONENT, component.getUniqueId());
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .REQUIREMENT_NOT_FOUND, component.getUniqueId());
+ ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus.REQUIREMENT_NOT_FOUND, component.getUniqueId());
return Either.right(errorResponse);
}
boolean isRequirementExist = requirementDefinitionList.stream()
- .anyMatch(requirementDefinition -> requirementDefinition.getUniqueId()
- .equalsIgnoreCase(definition.getUniqueId()));
-
- if(!isRequirementExist) {
+ .anyMatch(requirementDefinition -> requirementDefinition.getUniqueId().equalsIgnoreCase(definition.getUniqueId()));
+ if (!isRequirementExist) {
LOGGER.error(REQUIREMENT_NOT_FOUND_IN_COMPONENT, component.getUniqueId());
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .REQUIREMENT_NOT_FOUND, component.getUniqueId());
+ ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus.REQUIREMENT_NOT_FOUND, component.getUniqueId());
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> isRequirementNameRegexValid(ResponseFormatManager responseFormatManager,
- String requirementName) {
+ private Either<Boolean, ResponseFormat> isRequirementNameRegexValid(ResponseFormatManager responseFormatManager, String requirementName) {
if (!isValidRequirementName(requirementName)) {
- LOGGER.error("Requirement name {} is invalid, Only alphanumeric chars, underscore and dot allowed",
- requirementName);
- ResponseFormat errorResponse = responseFormatManager
- .getResponseFormat(ActionStatus.INVALID_REQUIREMENT_NAME, requirementName);
+ LOGGER.error("Requirement name {} is invalid, Only alphanumeric chars, underscore and dot allowed", requirementName);
+ ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus.INVALID_REQUIREMENT_NAME, requirementName);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
@@ -272,6 +226,4 @@ public class RequirementValidation {
protected ResponseFormatManager getResponseFormatManager() {
return ResponseFormatManager.getInstance();
}
-
}
-
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidation.java
index 695ee58300..b8ef79e21a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidation.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidation.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,10 +17,12 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation;
import fj.data.Either;
+import java.util.Arrays;
+import java.util.List;
+import javax.annotation.Resource;
import org.apache.commons.lang.StringUtils;
import org.openecomp.sdc.be.components.distribution.engine.IDistributionEngine;
import org.openecomp.sdc.be.components.impl.ActivationRequestInformation;
@@ -38,15 +40,12 @@ import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
-import javax.annotation.Resource;
-import java.util.Arrays;
-import java.util.List;
-
/**
* Created by chaya on 10/18/2017.
*/
@org.springframework.stereotype.Component("serviceDistributionValidation")
public class ServiceDistributionValidation {
+
private static final Logger log = Logger.getLogger(ServiceDistributionValidation.class);
@Resource
private ComponentsUtils componentsUtils;
@@ -57,14 +56,16 @@ public class ServiceDistributionValidation {
@Resource
private IDistributionEngine distributionEngine;
- public Either<ActivationRequestInformation, ResponseFormat> validateActivateServiceRequest(String serviceUUID, String opEnvId, User modifier, ServiceDistributionReqInfo data) {
+ public Either<ActivationRequestInformation, ResponseFormat> validateActivateServiceRequest(String serviceUUID, String opEnvId, User modifier,
+ ServiceDistributionReqInfo data) {
try {
validateUserExists(modifier.getUserId());
Service serviceToActivate = validateServiceExists(serviceUUID);
validateDistributionServiceLifeCycleState(serviceToActivate);
OperationalEnvironmentEntry operationalEnvironmentEntry = validateOperationalEnvExists(opEnvId);
String workloadContext = validateWorkloadContext(data);
- ActivationRequestInformation activationRequestInformation = new ActivationRequestInformation(serviceToActivate, workloadContext, operationalEnvironmentEntry.getTenant());
+ ActivationRequestInformation activationRequestInformation = new ActivationRequestInformation(serviceToActivate, workloadContext,
+ operationalEnvironmentEntry.getTenant());
return Either.left(activationRequestInformation);
} catch (ValidationException e) {
log.error("failed while validating activate service UUID {} request. error {}", serviceUUID, e.getExceptionResponseFormat(), e);
@@ -77,7 +78,7 @@ public class ServiceDistributionValidation {
Service abstractService = validateServiceExists(serviceUUID);
validateDistributionServiceLifeCycleState(abstractService);
}
-
+
private Service validateServiceExists(String serviceUUID) {
if (StringUtils.isEmpty(serviceUUID.trim())) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.BAD_REQUEST_MISSING_RESOURCE);
@@ -86,10 +87,11 @@ public class ServiceDistributionValidation {
Either<Component, StorageOperationStatus> latestComponentByUuid = toscaOperationFacade.getLatestServiceByUuid(serviceUUID);
if (latestComponentByUuid.isRight()) {
log.error("failed retrieving service {}", serviceUUID);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.API_RESOURCE_NOT_FOUND, ApiResourceEnum.SERVICE_ID.getValue());
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.API_RESOURCE_NOT_FOUND, ApiResourceEnum.SERVICE_ID.getValue());
throw new ValidationException(responseFormat);
}
- return (Service)latestComponentByUuid.left().value();
+ return (Service) latestComponentByUuid.left().value();
}
private String validateWorkloadContext(ServiceDistributionReqInfo data) {
@@ -112,15 +114,19 @@ public class ServiceDistributionValidation {
return failOnEnvNotExist(opEnvId);
}
if (!operationalEnvironment.getStatus().equals(EnvironmentStatusEnum.COMPLETED.getName())) {
- log.error("the operational environment is not ready to receive distributions. environment status: {}", operationalEnvironment.getStatus());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.API_RESOURCE_NOT_FOUND , ApiResourceEnum.ENVIRONMENT_ID.getValue());
+ log.error("the operational environment is not ready to receive distributions. environment status: {}",
+ operationalEnvironment.getStatus());
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.API_RESOURCE_NOT_FOUND, ApiResourceEnum.ENVIRONMENT_ID.getValue());
throw new ValidationException(responseFormat);
}
return operationalEnvironment;
}
private OperationalEnvironmentEntry failOnEnvNotExist(String opEnvId) {
- return ValidationUtils.throwValidationException(componentsUtils.getResponseFormat(ActionStatus.API_RESOURCE_NOT_FOUND, ApiResourceEnum.ENVIRONMENT_ID.getValue()), "failed to get operational environment {}", opEnvId);
+ return ValidationUtils.throwValidationException(
+ componentsUtils.getResponseFormat(ActionStatus.API_RESOURCE_NOT_FOUND, ApiResourceEnum.ENVIRONMENT_ID.getValue()),
+ "failed to get operational environment {}", opEnvId);
}
private void validateServiceState(Service service, List<LifecycleStateEnum> allowedStates) {
@@ -131,12 +137,12 @@ public class ServiceDistributionValidation {
throw new ValidationException(responseFormat);
}
}
+
private void validateUserExists(String userId) {
userValidations.validateUserExists(userId);
}
private void validateDistributionServiceLifeCycleState(Service serviceToActivate) {
- validateServiceState(serviceToActivate,
- Arrays.asList(LifecycleStateEnum.CERTIFIED));
+ validateServiceState(serviceToActivate, Arrays.asList(LifecycleStateEnum.CERTIFIED));
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java
index 29ed858031..cf4f84884f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java
@@ -40,51 +40,46 @@ import org.springframework.stereotype.Component;
public class UserValidations {
private static final Logger log = Logger.getLogger(UserValidations.class);
- private final UserBusinessLogic userAdmin;
+ private final UserBusinessLogic userAdmin;
public UserValidations(final UserBusinessLogic userAdmin) {
- this.userAdmin = userAdmin;
+ this.userAdmin = userAdmin;
}
public void validateUserRole(final User user, final List<Role> roles) {
- final Role userRole = Role.valueOf(user.getRole());
- if (roles != null && !roles.contains(userRole)) {
- log.error(EcompLoggerErrorCode.PERMISSION_ERROR, this.getClass().getName(),
- "user is not in appropriate role to perform action");
- throw new ByActionStatusComponentException(ActionStatus.RESTRICTED_OPERATION);
- }
- }
+ final Role userRole = Role.valueOf(user.getRole());
+ if (roles != null && !roles.contains(userRole)) {
+ log.error(EcompLoggerErrorCode.PERMISSION_ERROR, this.getClass().getName(), "user is not in appropriate role to perform action");
+ throw new ByActionStatusComponentException(ActionStatus.RESTRICTED_OPERATION);
+ }
+ }
- public ActionStatus validateUserExistsActionStatus(final String userId) {
- if (!userAdmin.hasActiveUser(userId)) {
- return ActionStatus.RESTRICTED_OPERATION;
- }
- return ActionStatus.OK;
- }
+ public ActionStatus validateUserExistsActionStatus(final String userId) {
+ if (!userAdmin.hasActiveUser(userId)) {
+ return ActionStatus.RESTRICTED_OPERATION;
+ }
+ return ActionStatus.OK;
+ }
- public User validateUserNotEmpty(final User user,
- final String ecompErrorContext) {
- final String userId = user.getUserId();
- if (StringUtils.isEmpty(userId)) {
- log.error(EcompLoggerErrorCode.PERMISSION_ERROR, this.getClass().getName(),
- "User header is missing ");
- BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, user.getUserId());
+ public User validateUserNotEmpty(final User user, final String ecompErrorContext) {
+ final String userId = user.getUserId();
+ if (StringUtils.isEmpty(userId)) {
+ log.error(EcompLoggerErrorCode.PERMISSION_ERROR, this.getClass().getName(), "User header is missing ");
+ BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, user.getUserId());
throw new ByActionStatusComponentException(ActionStatus.MISSING_USER_ID);
- }
+ }
return user;
- }
-
- public User validateUserExists(final String userId) {
- final User user = userAdmin.getUser(userId);
- if (UserStatusEnum.INACTIVE == user.getStatus()) {
- throw new ByActionStatusComponentException(USER_INACTIVE, userId);
- }
- return user;
- }
-
- public User validateUserExists(final User user) {
- return validateUserExists(user.getUserId());
- }
+ }
+ public User validateUserExists(final String userId) {
+ final User user = userAdmin.getUser(userId);
+ if (UserStatusEnum.INACTIVE == user.getStatus()) {
+ throw new ByActionStatusComponentException(USER_INACTIVE, userId);
+ }
+ return user;
+ }
+ public User validateUserExists(final User user) {
+ return validateUserExists(user.getUserId());
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ValidationException.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ValidationException.java
index d65551a486..e2fed1ef63 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ValidationException.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ValidationException.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation;
import org.openecomp.sdc.exception.ResponseFormat;
@@ -37,5 +36,4 @@ public class ValidationException extends RuntimeException {
public ResponseFormat getExceptionResponseFormat() {
return exceptionResponseFormat;
}
-
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ValidationUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ValidationUtils.java
index 085001f308..51603f6012 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ValidationUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ValidationUtils.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation;
import org.openecomp.sdc.common.log.wrappers.Logger;
@@ -27,9 +26,8 @@ public class ValidationUtils {
private static final Logger log = Logger.getLogger(ValidationUtils.class);
- public static <T> T throwValidationException(ResponseFormat responseFormat, String logMessage, Object ... logParams){
+ public static <T> T throwValidationException(ResponseFormat responseFormat, String logMessage, Object... logParams) {
log.error(logMessage, logParams);
throw new ValidationException(responseFormat);
}
-
}
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 0c1face3ea..2a177c632e 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
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation.component;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
@@ -46,7 +45,6 @@ public class ComponentContactIdValidator implements ComponentFieldValidator {
log.debug("validate component contactId");
ComponentTypeEnum type = component.getComponentType();
String contactId = component.getContactId();
-
if (!ValidationUtils.validateStringNotEmpty(contactId)) {
log.info("contact is missing.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue());
@@ -56,7 +54,8 @@ public class ComponentContactIdValidator implements ComponentFieldValidator {
validateContactId(contactId, user, component, actionEnum, type);
}
- private void validateContactId(String contactId, User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum actionEnum, ComponentTypeEnum type) {
+ private void validateContactId(String contactId, User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum actionEnum,
+ ComponentTypeEnum type) {
if (contactId != null && !ValidationUtils.validateContactId(contactId)) {
log.info("contact is invalid.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CONTACT, type.getValue());
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 47d9f8beee..8cf985feb6 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
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation.component;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
@@ -47,13 +46,12 @@ public class ComponentDescriptionValidator implements ComponentFieldValidator {
ComponentTypeEnum type = component.getComponentType();
String description = component.getDescription();
if (!ValidationUtils.validateStringNotEmpty(description)) {
- auditErrorAndThrow(user,component, actionEnum, ActionStatus.COMPONENT_MISSING_DESCRIPTION);
+ auditErrorAndThrow(user, component, actionEnum, ActionStatus.COMPONENT_MISSING_DESCRIPTION);
}
-
description = ValidationUtils.cleanUpText(description);
- try{
+ try {
validateComponentDescription(description, type);
- } catch(ComponentException e){
+ } catch (ComponentException e) {
ResponseFormat errorResponse = componentsUtils.getResponseFormat(e.getActionStatus(), component.getComponentType().getValue());
componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, component.getComponentType());
throw e;
@@ -61,7 +59,8 @@ public class ComponentDescriptionValidator implements ComponentFieldValidator {
component.setDescription(description);
}
- private void auditErrorAndThrow(User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum actionEnum, ActionStatus actionStatus) {
+ private void auditErrorAndThrow(User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum actionEnum,
+ ActionStatus actionStatus) {
ResponseFormat errorResponse = componentsUtils.getResponseFormat(actionStatus, component.getComponentType().getValue());
componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, component.getComponentType());
throw new ByActionStatusComponentException(actionStatus, component.getComponentType().getValue());
@@ -70,9 +69,9 @@ public class ComponentDescriptionValidator implements ComponentFieldValidator {
private void validateComponentDescription(String description, ComponentTypeEnum type) {
if (description != null) {
if (!ValidationUtils.validateDescriptionLength(description)) {
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, type.getValue(),
+ "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
}
-
if (!ValidationUtils.validateCommentPattern(description)) {
throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_DESCRIPTION, type.getValue());
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentFieldValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentFieldValidator.java
index b8d6117f1b..c0bea45c3e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentFieldValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentFieldValidator.java
@@ -17,13 +17,11 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation.component;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-
public interface ComponentFieldValidator {
void validateAndCorrectField(User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum actionEnum);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentIconValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentIconValidator.java
index 432ff41ebb..6bda4eac56 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentIconValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentIconValidator.java
@@ -17,9 +17,9 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation.component;
+import java.util.Arrays;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
@@ -33,8 +33,6 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.util.Arrays;
-
@org.springframework.stereotype.Component
public class ComponentIconValidator implements ComponentFieldValidator {
@@ -59,12 +57,11 @@ public class ComponentIconValidator implements ComponentFieldValidator {
if (component.getComponentType().equals(ComponentTypeEnum.SERVICE)) {
validateAndSetDefaultIcon(icon, component);
} else {
- validateIcon(icon,component.getComponentType());
+ validateIcon(icon, component.getComponentType());
}
-
- } catch(ComponentException e){
- ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat()
- : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ } catch (ComponentException e) {
+ ResponseFormat responseFormat =
+ e.getResponseFormat() != null ? e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, type);
throw e;
}
@@ -81,8 +78,7 @@ public class ComponentIconValidator implements ComponentFieldValidator {
}
}
} catch (NullPointerException exp) {
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY,
- ComponentTypeEnum.SERVICE.getValue());
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
}
componnet.setIcon(DEFAULT_ICON);
}
@@ -91,9 +87,9 @@ public class ComponentIconValidator implements ComponentFieldValidator {
if (icon != null) {
if (!ValidationUtils.validateIconLength(icon)) {
log.debug("icon exceeds max length");
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, type.getValue(),
+ "" + ValidationUtils.ICON_MAX_LENGTH);
}
-
if (!ValidationUtils.validateIcon(icon)) {
log.info("icon is invalid.");
throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_ICON, type.getValue());
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentNameValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentNameValidator.java
index 7b13d2ec5f..c9aa5fb42e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentNameValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentNameValidator.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation.component;
import fj.data.Either;
@@ -56,20 +55,18 @@ public class ComponentNameValidator implements ComponentFieldValidator {
String componentName = component.getName();
if (StringUtils.isEmpty(componentName)) {
log.debug("component name is empty");
- auditErrorAndThrow(user,component, actionEnum, ActionStatus.MISSING_COMPONENT_NAME);
+ auditErrorAndThrow(user, component, actionEnum, ActionStatus.MISSING_COMPONENT_NAME);
}
-
if (!ValidationUtils.validateComponentNameLength(componentName)) {
log.debug("Component name exceeds max length {} ", ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
- auditErrorAndThrow(user,component, actionEnum, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT);
+ auditErrorAndThrow(user, component, actionEnum, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT);
}
-
if (!ValidationUtils.validateComponentNamePattern(componentName)) {
log.debug("Component name {} has invalid format", componentName);
- auditErrorAndThrow(user,component, actionEnum, ActionStatus.INVALID_COMPONENT_NAME);
+ auditErrorAndThrow(user, component, actionEnum, ActionStatus.INVALID_COMPONENT_NAME);
}
if (component.getComponentType().equals(ComponentTypeEnum.SERVICE)) {
- validateComponentNameUnique(user,component,actionEnum);
+ validateComponentNameUnique(user, component, actionEnum);
}
//TODO remove assignment here
component.setNormalizedName(ValidationUtils.normaliseComponentName(componentName));
@@ -80,15 +77,16 @@ public class ComponentNameValidator implements ComponentFieldValidator {
log.debug("validate component name uniqueness for: {}", component.getName());
ComponentTypeEnum type = component.getComponentType();
ResourceTypeEnum resourceType = null;
- if(component instanceof Resource){
- resourceType = ((Resource)component).getResourceType();
+ if (component instanceof Resource) {
+ resourceType = ((Resource) component).getResourceType();
}
- Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade.validateComponentNameExists(component.getName(), resourceType, type);
-
+ Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade
+ .validateComponentNameExists(component.getName(), resourceType, type);
if (dataModelResponse.isLeft()) {
if (dataModelResponse.left().value()) {
log.info("Component with name {} already exists", component.getName());
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, type.getValue(), component.getName());
+ ResponseFormat errorResponse = componentsUtils
+ .getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, type.getValue(), component.getName());
componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
throw new ByResponseFormatComponentException(errorResponse);
}
@@ -101,7 +99,8 @@ public class ComponentNameValidator implements ComponentFieldValidator {
throw new ByResponseFormatComponentException(errorResponse);
}
- private void auditErrorAndThrow(User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum actionEnum, ActionStatus actionStatus) {
+ private void auditErrorAndThrow(User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum actionEnum,
+ ActionStatus actionStatus) {
ResponseFormat errorResponse = componentsUtils.getResponseFormat(actionStatus, component.getComponentType().getValue());
componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, component.getComponentType());
throw new ByActionStatusComponentException(actionStatus, component.getComponentType().getValue());
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 8d0fdf173b..29b4fdab75 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
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation.component;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
@@ -34,7 +33,7 @@ import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
@org.springframework.stereotype.Component
-public class ComponentProjectCodeValidator implements ComponentFieldValidator{
+public class ComponentProjectCodeValidator implements ComponentFieldValidator {
private static final Logger log = Logger.getLogger(ComponentProjectCodeValidator.class.getName());
private ComponentsUtils componentsUtils;
@@ -50,22 +49,18 @@ public class ComponentProjectCodeValidator implements ComponentFieldValidator{
}
log.debug("validate ProjectCode name ");
String projectCode = component.getProjectCode();
-
if (!ValidationUtils.validateStringNotEmpty(projectCode)) {
log.info("projectCode is empty is allowed CR.");
return;
}
-
try {
validateProjectCode(projectCode);
} catch (ComponentException exp) {
ResponseFormat responseFormat = exp.getResponseFormat();
componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, component.getComponentType(),
- ResourceVersionInfo.newBuilder()
- .build());
+ ResourceVersionInfo.newBuilder().build());
throw exp;
}
-
}
private void validateProjectCode(String projectCode) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentTagsValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentTagsValidator.java
index 243e0409b3..c1c785e7cb 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentTagsValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentTagsValidator.java
@@ -17,9 +17,10 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation.component;
+import java.util.ArrayList;
+import java.util.List;
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;
@@ -32,9 +33,6 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.util.ArrayList;
-import java.util.List;
-
@org.springframework.stereotype.Component
public class ComponentTagsValidator implements ComponentFieldValidator {
@@ -51,16 +49,17 @@ public class ComponentTagsValidator implements ComponentFieldValidator {
List<String> tagsList = component.getTags();
try {
validateComponentTags(tagsList, component.getName(), component.getComponentType(), user, component, actionEnum);
- } catch(ComponentException e){
- ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat()
- : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ } catch (ComponentException e) {
+ ResponseFormat responseFormat =
+ e.getResponseFormat() != null ? e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, component.getComponentType());
throw e;
}
ValidationUtils.removeDuplicateFromList(component.getTags());
}
- protected void validateComponentTags(List<String> tags, String name, ComponentTypeEnum componentType, User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum action) {
+ protected void validateComponentTags(List<String> tags, String name, ComponentTypeEnum componentType, User user,
+ org.openecomp.sdc.be.model.Component component, AuditingActionEnum action) {
log.debug("validate component tags");
boolean includesComponentName = false;
int tagListSize = 0;
@@ -81,7 +80,6 @@ public class ComponentTagsValidator implements ComponentFieldValidator {
if (tagListSize > 0) {
tagListSize--;
}
-
if (!includesComponentName) {
log.debug("tags must include component name");
responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
@@ -90,7 +88,8 @@ public class ComponentTagsValidator implements ComponentFieldValidator {
}
if (!ValidationUtils.validateTagListLength(tagListSize)) {
log.debug("overall tags length exceeds limit {}", ValidationUtils.TAG_LIST_MAX_LENGTH);
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
+ responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType);
throw new ByActionStatusComponentException(ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
}
@@ -108,7 +107,8 @@ public class ComponentTagsValidator implements ComponentFieldValidator {
return includesComponentName;
}
- private void validateTagLength(ComponentTypeEnum componentType, User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum action, String tag) {
+ private void validateTagLength(ComponentTypeEnum componentType, User user, org.openecomp.sdc.be.model.Component component,
+ AuditingActionEnum action, String tag) {
ResponseFormat responseFormat;
if (!ValidationUtils.validateTagLength(tag)) {
log.debug("tag length exceeds limit {}", ValidationUtils.TAG_MAX_LENGTH);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentValidator.java
index 3f300afe03..25072e926b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentValidator.java
@@ -17,17 +17,15 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation.component;
+import java.util.List;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.stereotype.Component;
-import java.util.List;
-
@Component
public class ComponentValidator {
@@ -41,8 +39,6 @@ public class ComponentValidator {
}
public void validate(User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum actionEnum) {
- componentFieldValidators.stream().forEach(validator ->
- validator.validateAndCorrectField(user,component,actionEnum));
+ componentFieldValidators.stream().forEach(validator -> validator.validateAndCorrectField(user, component, actionEnum));
}
-
}
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 1fe14c3fda..f8b3fff6c2 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
@@ -17,10 +17,12 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation.service;
+import static org.apache.commons.collections.CollectionUtils.isEmpty;
+
import fj.data.Either;
+import java.util.List;
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;
@@ -35,16 +37,12 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.util.List;
-
-import static org.apache.commons.collections.CollectionUtils.isEmpty;
-
@org.springframework.stereotype.Component
public class ServiceCategoryValidator implements ServiceFieldValidator {
private static final Logger log = Logger.getLogger(ServiceCategoryValidator.class.getName());
- private ComponentsUtils componentsUtils;
protected IElementOperation elementDao;
+ private ComponentsUtils componentsUtils;
public ServiceCategoryValidator(ComponentsUtils componentsUtils, IElementOperation elementDao) {
this.componentsUtils = componentsUtils;
@@ -55,7 +53,8 @@ public class ServiceCategoryValidator implements ServiceFieldValidator {
public void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum) {
log.debug("validate Service category");
if (isEmpty(service.getCategories())) {
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
+ ResponseFormat errorResponse = componentsUtils
+ .getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
componentsUtils.auditComponentAdmin(errorResponse, user, service, actionEnum, ComponentTypeEnum.SERVICE);
throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
}
@@ -65,14 +64,14 @@ public class ServiceCategoryValidator implements ServiceFieldValidator {
componentsUtils.auditComponentAdmin(responseFormat, user, service, actionEnum, ComponentTypeEnum.SERVICE);
throw new ByResponseFormatComponentException(responseFormat);
}
-
}
private Either<Boolean, ResponseFormat> validateServiceCategory(List<CategoryDefinition> list) {
if (list != null) {
if (list.size() > 1) {
log.debug("Must be only one category for service");
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_TOO_MUCH_CATEGORIES, ComponentTypeEnum.SERVICE.getValue());
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.COMPONENT_TOO_MUCH_CATEGORIES, ComponentTypeEnum.SERVICE.getValue());
return Either.right(responseFormat);
}
CategoryDefinition category = list.get(0);
@@ -83,10 +82,10 @@ public class ServiceCategoryValidator implements ServiceFieldValidator {
}
if (!ValidationUtils.validateStringNotEmpty(category.getName())) {
log.debug("Resource category is empty");
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
return Either.right(responseFormat);
}
-
log.debug("validating service category {} against valid categories list", list);
Either<List<CategoryDefinition>, ActionStatus> categorys = elementDao.getAllServiceCategories();
if (categorys.isRight()) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceEnvironmentContextValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceEnvironmentContextValidator.java
index 61206735ff..9a4468bb80 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceEnvironmentContextValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceEnvironmentContextValidator.java
@@ -17,9 +17,9 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation.service;
+import java.util.List;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -27,10 +27,9 @@ import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import java.util.List;
-
@org.springframework.stereotype.Component
public class ServiceEnvironmentContextValidator implements ServiceFieldValidator {
+
@Override
public void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum) {
String environmentContext = service.getEnvironmentContext();
@@ -38,15 +37,16 @@ public class ServiceEnvironmentContextValidator implements ServiceFieldValidator
setDefaultEnvironmentContextFromConfiguration(service);
return;
}
- List<String> environmentContextValidValues =
- ConfigurationManager.getConfigurationManager().getConfiguration().getEnvironmentContext().getValidValues();
- if (!environmentContextValidValues.contains(environmentContext))
+ List<String> environmentContextValidValues = ConfigurationManager.getConfigurationManager().getConfiguration().getEnvironmentContext()
+ .getValidValues();
+ if (!environmentContextValidValues.contains(environmentContext)) {
throw new ByActionStatusComponentException(ActionStatus.INVALID_ENVIRONMENT_CONTEXT, environmentContext);
+ }
}
private void setDefaultEnvironmentContextFromConfiguration(Service service) {
- String defaultEnvironmentContext =
- ConfigurationManager.getConfigurationManager().getConfiguration().getEnvironmentContext().getDefaultValue();
+ String defaultEnvironmentContext = ConfigurationManager.getConfigurationManager().getConfiguration().getEnvironmentContext()
+ .getDefaultValue();
service.setEnvironmentContext(defaultEnvironmentContext);
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFieldValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFieldValidator.java
index 24d91c2325..4ff95a49a0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFieldValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFieldValidator.java
@@ -17,14 +17,13 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation.service;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-
public interface ServiceFieldValidator {
+
void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFunctionValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFunctionValidator.java
index ff11629584..a9ea944093 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFunctionValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFunctionValidator.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation.service;
import org.apache.commons.lang3.StringUtils;
@@ -47,7 +46,7 @@ public class ServiceFunctionValidator implements ServiceFieldValidator {
public void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum) {
log.debug("validate service function");
String serviceFunction = service.getServiceFunction();
- if(serviceFunction == null) {
+ if (serviceFunction == null) {
log.info("service function is null, assigned to empty value.");
service.setServiceFunction("");
return;
@@ -56,7 +55,7 @@ public class ServiceFunctionValidator implements ServiceFieldValidator {
}
private void validateServiceFunction(String serviceFunction) {
- if (StringUtils.isEmpty(serviceFunction)){
+ if (StringUtils.isEmpty(serviceFunction)) {
return;
} else {
if (!ValidationUtils.validateServiceFunctionLength(serviceFunction)) {
@@ -64,7 +63,6 @@ public class ServiceFunctionValidator implements ServiceFieldValidator {
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.PROPERTY_EXCEEDS_LIMIT, "" + SERVICE_FUNCTION);
throw new ByResponseFormatComponentException(errorResponse);
}
-
if (!ValidationUtils.validateServiceMetadata(serviceFunction)) {
log.info("service function is not valid.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERY, "" + SERVICE_FUNCTION);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceInstantiationTypeValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceInstantiationTypeValidator.java
index baa59a17c7..7a34528bb0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceInstantiationTypeValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceInstantiationTypeValidator.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation.service;
import org.apache.commons.lang3.StringUtils;
@@ -34,6 +33,7 @@ import org.openecomp.sdc.exception.ResponseFormat;
@org.springframework.stereotype.Component
public class ServiceInstantiationTypeValidator implements ServiceFieldValidator {
+
private static final Logger log = Logger.getLogger(ServiceInstantiationTypeValidator.class.getName());
private ComponentsUtils componentsUtils;
@@ -48,7 +48,7 @@ public class ServiceInstantiationTypeValidator implements ServiceFieldValidator
if (StringUtils.isEmpty(instantiationType)) {
service.setInstantiationType(InstantiationTypes.A_LA_CARTE.getValue());
}
- if (!InstantiationTypes.containsName(service.getInstantiationType())){
+ if (!InstantiationTypes.containsName(service.getInstantiationType())) {
log.error("Recieved Instantiation type {} is not valid.", instantiationType);
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_INSTANTIATION_TYPE, instantiationType);
componentsUtils.auditComponentAdmin(errorResponse, user, service, actionEnum, ComponentTypeEnum.SERVICE);
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 5a7654226a..73acf20c53 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
@@ -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();
@@ -50,7 +50,8 @@ public class ServiceNamingPolicyValidator implements ServiceFieldValidator {
}
if (isEcompGeneratedCurr) {
if (!ValidationUtils.validateServiceNamingPolicyLength(namingPolicyUpdate)) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NAMING_POLICY_EXCEEDS_LIMIT, "" + ValidationUtils.SERVICE_NAMING_POLICY_MAX_SIZE);
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.NAMING_POLICY_EXCEEDS_LIMIT, "" + ValidationUtils.SERVICE_NAMING_POLICY_MAX_SIZE);
throw new ByResponseFormatComponentException(responseFormat);
}
if (StringUtils.isEmpty(namingPolicyUpdate)) {
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 59d2e837c5..10c831b909 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
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation.service;
import org.apache.commons.lang3.StringUtils;
@@ -47,26 +46,23 @@ public class ServiceRoleValidator implements ServiceFieldValidator {
public void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum) {
log.debug("validate service role");
String serviceRole = service.getServiceRole();
- if (serviceRole != null){
- validateServiceRole(serviceRole);
- }
-
+ if (serviceRole != null) {
+ validateServiceRole(serviceRole);
+ }
}
private void validateServiceRole(String serviceRole) {
- if (StringUtils.isEmpty(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);
+ 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 e5e2f0a9b9..2b592d8f9c 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
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation.service;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
@@ -62,7 +61,7 @@ public class ServiceTypeValidator implements ServiceFieldValidator {
}
if (!ValidationUtils.validateServiceMetadata(serviceType)) {
log.info("service type is not valid.");
- throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERY,"" + SERVICE_TYPE);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERY, "" + SERVICE_TYPE);
}
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceValidator.java
index 5cf490dbf3..984e03d9a1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceValidator.java
@@ -17,9 +17,9 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.be.components.validation.service;
+import java.util.List;
import org.openecomp.sdc.be.components.validation.component.ComponentFieldValidator;
import org.openecomp.sdc.be.components.validation.component.ComponentValidator;
import org.openecomp.sdc.be.impl.ComponentsUtils;
@@ -28,14 +28,13 @@ import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.springframework.stereotype.Component;
-import java.util.List;
-
@Component
public class ServiceValidator extends ComponentValidator {
private List<ServiceFieldValidator> serviceFieldValidators;
- public ServiceValidator(ComponentsUtils componentsUtils, List<ComponentFieldValidator> componentFieldValidators, List<ServiceFieldValidator> serviceFieldValidators) {
+ public ServiceValidator(ComponentsUtils componentsUtils, List<ComponentFieldValidator> componentFieldValidators,
+ List<ServiceFieldValidator> serviceFieldValidators) {
super(componentsUtils, componentFieldValidators);
this.serviceFieldValidators = serviceFieldValidators;
}
@@ -43,7 +42,6 @@ public class ServiceValidator extends ComponentValidator {
@Override
public void validate(User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum actionEnum) {
super.validate(user, component, actionEnum);
- serviceFieldValidators.forEach(validator ->
- validator.validateAndCorrectField(user,(Service)component,actionEnum));
+ serviceFieldValidators.forEach(validator -> validator.validateAndCorrectField(user, (Service) component, actionEnum));
}
}