package org.openecomp.sdc.be.components.impl;
import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR;
+import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.DATA_ERROR;
import com.google.gson.JsonElement;
import fj.data.Either;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
-import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.datamodel.utils.ArtifactUtils;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyRule;
private static final String PROPERTY_IN_SCHEMA_DEFINITION_INSIDE_PROPERTY_OF_TYPE_DOESN_T_EXIST = "Property in Schema Definition inside property of type {} doesn't exist";
private static final String ADD_PROPERTY_VALUE = "Add property value";
private static final String THE_VALUE_OF_PROPERTY_FROM_TYPE_IS_INVALID = "The value {} of property from type {} is invalid";
+ private static final String INVALID_PROPERTY_TYPE = "The property type {} is invalid";
protected IGroupTypeOperation groupTypeOperation;
protected InterfaceOperation interfaceOperation;
protected IElementOperation elementDao;
protected AttributeOperation attributeOperation;
protected ApplicationDataTypeCache applicationDataTypeCache;
protected ToscaOperationFacade toscaOperationFacade;
- protected ApplicationDataTypeCache dataTypeCache;
protected IGroupOperation groupOperation;
protected IGroupInstanceOperation groupInstanceOperation;
protected InterfaceLifecycleOperation interfaceLifecycleTypeOperation;
this.policyTypeOperation = policyTypeOperation;
}
- @Autowired
- public void setDataTypeCache(ApplicationDataTypeCache dataTypeCache) {
- this.dataTypeCache = dataTypeCache;
- }
-
@Autowired
public void setPropertyOperation(PropertyOperation propertyOperation) {
this.propertyOperation = propertyOperation;
return cmpt;
}
- <T extends PropertyDataDefinition> String updateInputPropertyObjectValue(T property) {
- Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypesEither = dataTypeCache.getAll();
- if (allDataTypesEither.isRight()) {
- JanusGraphOperationStatus status = allDataTypesEither.right().value();
- BeEcompErrorManager.getInstance()
- .logInternalFlowError("UpdatePropertyValueOnComponentInstance", "Failed to update property value on instance. Status is " + status,
- ErrorSeverity.ERROR);
- throw new ByActionStatusComponentException(
- componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)));
- }
- Map<String, DataTypeDefinition> allDataTypes = allDataTypesEither.left().value();
- String propertyType = property.getType();
- String innerType = getInnerType(property);
- // Specific Update Logic
- Either<Object, Boolean> isValid = propertyOperation
- .validateAndUpdatePropertyValue(propertyType, property.getValue(), true, innerType, allDataTypes);
- String newValue = property.getValue();
- if (isValid.isRight()) {
- Boolean res = isValid.right().value();
- if (Boolean.FALSE.equals(res)) {
- throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(
- DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.ILLEGAL_ARGUMENT)));
- }
- } else {
- Object object = isValid.left().value();
- if (object != null) {
- newValue = object.toString();
- }
- }
- return newValue;
- }
-
<T extends PropertyDataDefinition> String getInnerType(T property) {
ToscaPropertyType type = ToscaPropertyType.isValidType(property.getType());
log.debug("#getInnerType - The type of the property {} is {}", property.getUniqueId(), property.getType());
return null;
}
- protected Map<String, DataTypeDefinition> getAllDataTypes(ApplicationDataTypeCache applicationDataTypeCache) {
- Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = applicationDataTypeCache.getAll();
- if (allDataTypes.isRight()) {
- JanusGraphOperationStatus operationStatus = allDataTypes.right().value();
- if (operationStatus == JanusGraphOperationStatus.NOT_FOUND) {
- BeEcompErrorManager.getInstance().logInternalDataError("FetchDataTypes", "Data types are not loaded", ErrorSeverity.ERROR);
- throw new ByActionStatusComponentException(ActionStatus.DATA_TYPE_CANNOT_BE_EMPTY);
- } else {
- BeEcompErrorManager.getInstance().logInternalFlowError("FetchDataTypes", "Failed to fetch data types", ErrorSeverity.ERROR);
- throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
- }
- }
- return allDataTypes.left().value();
- }
-
Either<Boolean, ResponseFormat> validatePropertyDefaultValue(IComplexDefaultValue property, Map<String, DataTypeDefinition> dataTypes) {
String type;
String innerType = null;
- if (!propertyOperation.isPropertyTypeValid(property)) {
+ if (!propertyOperation.isPropertyTypeValid(property, dataTypes)) {
log.info("Invalid type for property '{}' type '{}'", property.getName(), property.getType());
ResponseFormat responseFormat = componentsUtils
.getResponseFormat(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
if (isValid.isRight()) {
Boolean res = isValid.right().value();
if (Boolean.FALSE.equals(res)) {
- throw new StorageException(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.ILLEGAL_ARGUMENT));
+ log.error(DATA_ERROR, this.getClass().getName(), "Dropping invalid value for property: {} , value: ", property, value);
+ return "";
}
} else {
Object object = isValid.left().value();
if (isValidate) {
if (type == null) {
DataTypeDefinition dataTypeDefinition = dataTypes.get(propertyType);
+ if (dataTypeDefinition == null) {
+ log.debug(INVALID_PROPERTY_TYPE, propertyType);
+ return Either.right(false);
+ }
ImmutablePair<JsonElement, Boolean> validateResult = dataTypeValidatorConverter
.validateAndUpdate(value, dataTypeDefinition, dataTypes);
if (Boolean.FALSE.equals(validateResult.right)) {
if (inputPathArr.length > 1) {
inputPathArr = ArrayUtils.remove(inputPathArr, 0);
}
- Map<String, DataTypeDefinition> dataTypeDefinitionMap = applicationDataTypeCache.getAll().left().value();
+ final Map<String, DataTypeDefinition> dataTypeDefinitionMap =
+ componentsUtils.getAllDataTypes(applicationDataTypeCache, inputDefinition.getModel());
String propertyType = inputDefinition.getParentPropertyType();
for (String anInputPathArr : inputPathArr) {
if (ToscaType.isPrimitiveType(propertyType)) {
}
return result.left().value();
}
+
+ public String getComponentModelByComponentId(final String componentId) throws BusinessLogicException {
+ return getComponent(componentId).getModel();
+ }
}