Support adding data types to model
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / validation / PropertyValidator.java
index bdb6799..33cba4f 100644 (file)
  */
 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;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
 import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
 import org.openecomp.sdc.be.impl.ComponentsUtils;
 import org.openecomp.sdc.be.model.DataTypeDefinition;
 import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
-import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
-import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
 import org.openecomp.sdc.exception.ResponseFormat;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
 
 @Component
@@ -46,16 +36,13 @@ public class PropertyValidator {
 
     private final PropertyOperation propertyOperation;
     private final ComponentsUtils componentsUtils;
-    private final ApplicationDataTypeCache applicationDataTypeCache;
     private final ExceptionUtils exceptionUtils;
-    private static final Logger log = LoggerFactory.getLogger(ResourceBusinessLogic.class);
 
-    public PropertyValidator(PropertyOperation propertyOperation, ComponentsUtils componentsUtils, ApplicationDataTypeCache applicationDataTypeCache,
+    public PropertyValidator(PropertyOperation propertyOperation, ComponentsUtils componentsUtils,
                              ExceptionUtils exceptionUtils) {
         this.exceptionUtils = exceptionUtils;
         this.propertyOperation = propertyOperation;
         this.componentsUtils = componentsUtils;
-        this.applicationDataTypeCache = applicationDataTypeCache;
     }
 
     public void thinPropertiesValidator(List<PropertyDefinition> properties, List<PropertyDefinition> dbAnnotationTypeDefinitionProperties,
@@ -87,60 +74,4 @@ public class PropertyValidator {
         exceptionUtils.rollBackAndThrow(responseFormat);
         return null;
     }
-
-    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());
-                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))));
-            }
-            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 (!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());
-                } else {
-                    responseFormat = componentsUtils
-                        .getResponseFormat(ActionStatus.INVALID_DEFAULT_VALUE, property.getName(), type, property.getDefaultValue());
-                }
-                eitherResult = Either.right(responseFormat);
-                break;
-            }
-        }
-        return eitherResult;
-    }
-
-    private ResponseFormat validateMapOrListPropertyType(PropertyDefinition property, Map<String, DataTypeDefinition> allDataTypes) {
-        ResponseFormat responseFormat = null;
-        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());
-        }
-        return responseFormat;
-    }
 }