* Modifications copyright (c) 2019 Nokia
* ================================================================================
*/
-
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 java.util.ArrayList;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.validation.UserValidations;
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.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
-import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
+import org.openecomp.sdc.be.dao.janusgraph.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;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstInputsMap;
+import org.openecomp.sdc.be.model.ComponentInstOutputsMap;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.AttributeOperation;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.impl.PolicyTypeOperation;
public abstract class BaseBusinessLogic {
private static final String FAILED_TO_LOCK_COMPONENT_ERROR = "Failed to lock component {} error - {}";
-
- private static final Logger log = Logger.getLogger(BaseBusinessLogic.class.getName());
+ private static final Logger log = Logger.getLogger(BaseBusinessLogic.class);
private static final String EMPTY_VALUE = null;
private static final String SCHEMA_DOESN_T_EXISTS_FOR_PROPERTY_OF_TYPE = "Schema doesn't exists for property of type {}";
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 JanusGraphDao janusGraphDao;
protected JanusGraphGenericDao janusGraphGenericDao;
protected PropertyOperation propertyOperation;
+ protected AttributeOperation attributeOperation;
protected ApplicationDataTypeCache applicationDataTypeCache;
protected ToscaOperationFacade toscaOperationFacade;
- protected ApplicationDataTypeCache dataTypeCache;
protected IGroupOperation groupOperation;
protected IGroupInstanceOperation groupInstanceOperation;
protected InterfaceLifecycleOperation interfaceLifecycleTypeOperation;
protected PolicyTypeOperation policyTypeOperation;
- protected ArtifactsOperations artifactToscaOperation;
+ protected ArtifactsOperations artifactToscaOperation;
protected UserValidations userValidations;
-
DataTypeValidatorConverter dataTypeValidatorConverter = DataTypeValidatorConverter.getInstance();
- public BaseBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation,
- IGroupInstanceOperation groupInstanceOperation, IGroupTypeOperation groupTypeOperation, InterfaceOperation interfaceOperation,
- InterfaceLifecycleOperation interfaceLifecycleTypeOperation, ArtifactsOperations artifactToscaOperation) {
+ protected BaseBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation,
+ IGroupTypeOperation groupTypeOperation, InterfaceOperation interfaceOperation,
+ InterfaceLifecycleOperation interfaceLifecycleTypeOperation, ArtifactsOperations artifactToscaOperation) {
this.elementDao = elementDao;
this.groupOperation = groupOperation;
this.groupInstanceOperation = groupInstanceOperation;
this.artifactToscaOperation = artifactToscaOperation;
}
+ @SafeVarargs
+ static <T extends Enum<T>> boolean enumHasValueFilter(String name, Function<String, T> enumGetter, T... enumValues) {
+ T enumFound = enumGetter.apply(name);
+ return Arrays.asList(enumValues).contains(enumFound);
+ }
+
@Autowired
public void setUserAdmin(UserBusinessLogic userAdmin) {
this.userAdmin = userAdmin;
}
@Autowired
- public void setDataTypeCache(ApplicationDataTypeCache dataTypeCache) {
- this.dataTypeCache = dataTypeCache;
+ public void setPropertyOperation(PropertyOperation propertyOperation) {
+ this.propertyOperation = propertyOperation;
}
@Autowired
- public void setPropertyOperation(PropertyOperation propertyOperation) {
- this.propertyOperation = propertyOperation;
+ public void setAttributeOperation(AttributeOperation attributeOperation) {
+ this.attributeOperation = attributeOperation;
}
User validateUserNotEmpty(User user, String ecompErrorContext) {
lockComponent(component.getUniqueId(), component, ecompErrorContext);
}
- protected boolean isVolumeGroup(List<String> artifactsInGroup,List <ArtifactDefinition> deploymentArtifacts) {
+ protected boolean isVolumeGroup(List<String> artifactsInGroup, List<ArtifactDefinition> deploymentArtifacts) {
for (String artifactId : artifactsInGroup) {
ArtifactDefinition artifactDef = ArtifactUtils.findArtifactInList(deploymentArtifacts, artifactId);
- if (artifactDef != null
- && artifactDef.getArtifactType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType())) {
+ if (artifactDef != null && artifactDef.getArtifactType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType())) {
return true;
}
}
}
protected void lockComponent(Component component, boolean shouldLock, String ecompErrorContext) {
- if(shouldLock){
+ if (shouldLock) {
lockComponent(component.getUniqueId(), component, ecompErrorContext);
}
}
protected void lockComponent(String componentId, Component component, String ecompErrorContext) {
ActionStatus lock = lockElement(componentId, component, ecompErrorContext);
- if (lock!= ActionStatus.OK) {
- logAndThrowComponentException(lock, component.getUniqueId(), component.getName());
- }
- }
-
- protected ActionStatus lockComponentAndReturnStatus(final String componentId,
- final Component component,
- final String ecompErrorContext) {
- final ActionStatus lock = lockElement(componentId, component, ecompErrorContext);
- if (lock!= ActionStatus.OK) {
+ if (lock != ActionStatus.OK) {
logAndThrowComponentException(lock, component.getUniqueId(), component.getName());
}
- return ActionStatus.OK;
}
protected void lockComponent(String componentId, Component component, boolean needLock, String ecompErrorContext) {
}
}
- private ResponseFormat logAndThrowComponentException(ActionStatus status, String componentId, String name){
+ private ResponseFormat logAndThrowComponentException(ActionStatus status, String componentId, String name) {
log.debug(FAILED_TO_LOCK_COMPONENT_ERROR, componentId, status);
throw new ByActionStatusComponentException(status, name);
}
ComponentTypeEnum componentType = component.getComponentType();
NodeTypeEnum nodeType = componentType.getNodeType();
StorageOperationStatus lockResourceStatus = graphLockOperation.lockComponent(componentId, nodeType);
-
if (lockResourceStatus == StorageOperationStatus.OK) {
return ActionStatus.OK;
} else {
}
// unlock resource
graphLockOperation.unlockComponent(component.getUniqueId(), nodeType);
+ } else {
+ log.debug("component is NULL");
}
- else log.debug("component is NULL");
}
protected void unlockComponent(boolean failed, Component component) {
unlockComponent(failed, component, false);
}
+
void unlockComponentById(boolean failed, String componentId) {
Either<Component, StorageOperationStatus> component = toscaOperationFacade.getToscaElement(componentId);
- if(component.isLeft()) {
+ if (component.isLeft()) {
unlockComponent(failed, component.left().value(), false);
}
}
}
}
-
ComponentTypeEnum validateComponentType(String componentType) {
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
if (componentTypeEnum == null) {
}
Component validateComponentExists(String componentId, ComponentTypeEnum componentType, ComponentParametersView filter) {
-
- Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade.getToscaElement(componentId, filter == null ? new ComponentParametersView() : filter);
- if(toscaElement.isRight()){
+ Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade
+ .getToscaElement(componentId, filter == null ? new ComponentParametersView() : filter);
+ if (toscaElement.isRight()) {
handleGetComponentError(componentId, componentType, toscaElement.right().value());
}
return validateComponentType(toscaElement.left().value(), componentType);
}
<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, (String) property.getValue(), true,
- innerType, allDataTypes);
+ Either<Object, Boolean> isValid = propertyOperation
+ .validateAndUpdatePropertyValue(propertyType, property.getValue(), true, innerType,
+ componentsUtils.getAllDataTypes(applicationDataTypeCache, property.getModel()));
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)));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(
+ DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.ILLEGAL_ARGUMENT)));
}
} else {
Object object = isValid.left().value();
return newValue;
}
- <T extends PropertyDataDefinition> String getInnerType(T property){
+ <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());
String innerType = null;
public void validateCanWorkOnComponent(Component component, String userId) {
ActionStatus actionStatus = ActionStatus.RESTRICTED_OPERATION;
// verify resource is not archived
- if (component.isArchived() == true){
+ if (Boolean.TRUE.equals(component.isArchived())) {
actionStatus = ActionStatus.COMPONENT_IS_ARCHIVED;
throw new ByActionStatusComponentException(actionStatus, component.getName());
}
-
if (component.getLifecycleState() != LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) {
log.debug("Component {} is not checked-out", component.getName());
throw new ByActionStatusComponentException(actionStatus);
}
-
// verify userId is not null
if (userId == null) {
log.debug("Current user userId is null");
throw new ByActionStatusComponentException(actionStatus);
}
-
// verify component last update user is the current user
String lastUpdaterUserId = component.getLastUpdaterUserId();
if (!userId.equals(lastUpdaterUserId)) {
log.debug("Current user is not last updater, last updater userId: {}, current user userId: {}", lastUpdaterUserId, userId);
throw new ByActionStatusComponentException(actionStatus);
}
-
// verify resource is not deleted
if (Boolean.TRUE.equals(component.getIsDeleted())) {
log.debug("Component {} is marked as deleted", component.getUniqueId());
throw new ByActionStatusComponentException(actionStatus);
}
-
}
-
ComponentTypeEnum getComponentTypeByParentComponentType(ComponentTypeEnum parentComponentType) {
switch (parentComponentType) {
case SERVICE:
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, null)) {
log.info("Invalid type for property '{}' type '{}'", property.getName(), property.getType());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
return Either.right(responseFormat);
}
type = property.getType();
if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
ImmutablePair<String, Boolean> propertyInnerTypeValid = propertyOperation.isPropertyInnerTypeValid(property, dataTypes);
innerType = propertyInnerTypeValid.getLeft();
- if (!propertyInnerTypeValid.getRight()) {
- log.info("Invalid inner type for property '{}' type '{}', dataTypeCount '{}'", property.getName(), property.getType(), dataTypes.size());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE, innerType, property.getName());
+ if (Boolean.FALSE.equals(propertyInnerTypeValid.getRight())) {
+ log.info("Invalid inner type for property '{}' type '{}', dataTypeCount '{}'", property.getName(), property.getType(),
+ dataTypes.size());
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE, innerType, property.getName());
return Either.right(responseFormat);
}
}
log.info("Invalid default value for property '{}' type '{}'", property.getName(), property.getType());
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());
}
return Either.right(responseFormat);
-
}
return Either.left(true);
}
-
- void handleDefaultValue(IComplexDefaultValue newAttributeDef, Map<String, DataTypeDefinition> dataTypes) {
- // convert property
- ToscaPropertyType type = ToscaPropertyType.isValidType(newAttributeDef.getType());
- PropertyValueConverter converter = type.getConverter();
- // get inner type
- String innerType = null;
-
- SchemaDefinition schema = newAttributeDef.getSchema();
- if (schema != null) {
- PropertyDataDefinition prop = schema.getProperty();
- if (schema.getProperty() != null) {
- innerType = prop.getType();
- }
- }
- String convertedValue;
- if (newAttributeDef.getDefaultValue() != null) {
- convertedValue = converter.convert(newAttributeDef.getDefaultValue(), innerType, dataTypes);
- newAttributeDef.setDefaultValue(convertedValue);
- }
- }
-
void validateComponentTypeEnum(ComponentTypeEnum componentTypeEnum, String errorContext, Wrapper<ResponseFormat> errorWrapper) {
if (componentTypeEnum == null) {
BeEcompErrorManager.getInstance().logInvalidInputError(errorContext, "invalid component type", ErrorSeverity.INFO);
errorWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
}
-
}
- protected void validateCanWorkOnComponent(String componentId, ComponentTypeEnum componentTypeEnum, String userId, Wrapper<ResponseFormat> errorWrapper) {
+ protected void validateCanWorkOnComponent(String componentId, ComponentTypeEnum componentTypeEnum, String userId,
+ Wrapper<ResponseFormat> errorWrapper) {
if (!ComponentValidationUtils.canWorkOnComponent(componentId, toscaOperationFacade, userId)) {
log.info("Restricted operation for user {} on {} {}", userId, componentTypeEnum.getValue(), componentId);
errorWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
}
-
}
void validateComponentLock(String componentId, ComponentTypeEnum componentTypeEnum, Wrapper<ResponseFormat> errorWrapper) {
log.debug("Failed to lock {} {}", componentTypeEnum.getValue(), componentId);
errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
}
-
}
protected ToscaPropertyType getType(String propertyType) {
ComponentTypeEnum componentType = component.getComponentType();
NodeTypeEnum nodeType = componentType.getNodeType();
StorageOperationStatus lockResourceStatus = graphLockOperation.lockComponentByName(name, nodeType);
-
if (lockResourceStatus == StorageOperationStatus.OK) {
return Either.left(true);
} else {
}
}
- protected Component validateComponentExistsByFilter(String componentId, ComponentTypeEnum componentType, ComponentParametersView componentParametersView) {
- return toscaOperationFacade.getToscaElement(componentId, componentParametersView)
- .left()
- .on(err -> handleGetComponentError(componentId, componentType, err));
-
+ protected Component validateComponentExistsByFilter(String componentId, ComponentTypeEnum componentType,
+ ComponentParametersView componentParametersView) {
+ return toscaOperationFacade.getToscaElement(componentId, componentParametersView).left()
+ .on(err -> handleGetComponentError(componentId, componentType, err));
}
private Component handleGetComponentError(String componentId, ComponentTypeEnum componentType, StorageOperationStatus getComponentError) {
throw new ByActionStatusComponentException(actionStatus, componentId);
}
- @SafeVarargs
- static <T extends Enum<T>> boolean enumHasValueFilter(String name, Function<String, T> enumGetter, T... enumValues) {
- T enumFound = enumGetter.apply(name);
- return Arrays.asList(enumValues).contains(enumFound);
- }
-
String validatePropValueBeforeCreate(IPropertyInputCommon property, String value, boolean isValidate,
- Map<String, DataTypeDefinition> allDataTypes) {
+ Map<String, DataTypeDefinition> allDataTypes) {
String propertyType = property.getType();
String updatedInnerType = updateInnerType(property);
Either<Object, Boolean> isValid = validateAndUpdatePropertyValue(propertyType, value, isValidate, updatedInnerType, allDataTypes);
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();
log.trace("After validateAndUpdateRules. pair = {}", pair);
if (Boolean.FALSE.equals(pair.getRight())) {
BeEcompErrorManager.getInstance().logBeInvalidValueError(ADD_PROPERTY_VALUE, pair.getLeft(), property.getName(), propertyType);
- throw new StorageException(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(
- JanusGraphOperationStatus.ILLEGAL_ARGUMENT));
+ throw new StorageException(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.ILLEGAL_ARGUMENT));
}
return newValue;
}
}
private void failOnIllegalArgument() {
- throw new ByActionStatusComponentException(
- componentsUtils.convertFromStorageResponse(
- DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.ILLEGAL_ARGUMENT)));
+ throw new ByActionStatusComponentException(componentsUtils
+ .convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.ILLEGAL_ARGUMENT)));
}
- public Either<Object, Boolean> validateAndUpdatePropertyValue(String propertyType, String value, boolean isValidate, String innerType, Map<String, DataTypeDefinition> dataTypes) {
+ public Either<Object, Boolean> validateAndUpdatePropertyValue(String propertyType, String value, boolean isValidate, String innerType,
+ Map<String, DataTypeDefinition> dataTypes) {
log.trace("Going to validate property value and its type. type = {}, value = {}", propertyType, value);
ToscaPropertyType type = getType(propertyType);
-
if (isValidate) {
-
if (type == null) {
DataTypeDefinition dataTypeDefinition = dataTypes.get(propertyType);
- ImmutablePair<JsonElement, Boolean> validateResult = dataTypeValidatorConverter.validateAndUpdate(value, dataTypeDefinition, dataTypes);
+ 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)) {
log.debug(THE_VALUE_OF_PROPERTY_FROM_TYPE_IS_INVALID, value, propertyType);
return Either.right(false);
return Either.left(convertedValue);
}
- private ImmutablePair<String, Boolean> validateAndUpdateRules(String propertyType, List<PropertyRule> rules, String innerType, Map<String, DataTypeDefinition> dataTypes, boolean isValidate) {
-
+ private ImmutablePair<String, Boolean> validateAndUpdateRules(String propertyType, List<PropertyRule> rules, String innerType,
+ Map<String, DataTypeDefinition> dataTypes, boolean isValidate) {
if (rules == null || rules.isEmpty()) {
return ImmutablePair.of(null, true);
}
-
for (PropertyRule rule : rules) {
String value = rule.getValue();
Either<Object, Boolean> updateResult = validateAndUpdatePropertyValue(propertyType, value, isValidate, innerType, dataTypes);
rule.setValue(newValue);
}
}
-
return ImmutablePair.of(null, true);
}
if (isEmptyValue(value)) {
return true;
}
-
PropertyTypeValidator validator = type.getValidator();
-
return validator.isValid(value, innerType, dataTypes);
}
throw new ByActionStatusComponentException(actionStatus, params);
}
- public <T extends ToscaDataDefinition> Either<List<T>, ResponseFormat> declareProperties(String userId, String componentId,
- ComponentTypeEnum componentTypeEnum, ComponentInstInputsMap componentInstInputsMap) {
+ public <T extends ToscaDataDefinition> Either<List<T>, ResponseFormat> declareProperties(final String userId, final String componentId,
+ final ComponentTypeEnum componentTypeEnum,
+ final ComponentInstInputsMap componentInstInputsMap) {
+ return Either.left(new ArrayList<>());
+ }
+ public <T extends ToscaDataDefinition> Either<List<T>, ResponseFormat> declareAttributes(final String userId, final String componentId,
+ final ComponentTypeEnum componentTypeEnum,
+ final ComponentInstOutputsMap componentInstOutputsMap) {
return Either.left(new ArrayList<>());
}
public <T extends PropertyDataDefinition> List<PropertyConstraint> setInputConstraint(T inputDefinition) {
- if (StringUtils.isNotBlank(inputDefinition.getParentPropertyType())
- && StringUtils.isNotBlank(inputDefinition.getSubPropertyInputPath())) {
+ if (StringUtils.isNotBlank(inputDefinition.getParentPropertyType()) && StringUtils.isNotBlank(inputDefinition.getSubPropertyInputPath())) {
return setConstraint(inputDefinition);
}
-
return Collections.emptyList();
}
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)) {
- constraints.addAll(
- dataTypeDefinitionMap.get(propertyType).getConstraints());
+ constraints.addAll(dataTypeDefinitionMap.get(propertyType).getConstraints());
} else if (!ToscaType.isCollectionType(propertyType)) {
- propertyType = setConstraintForComplexType(dataTypeDefinitionMap, propertyType, anInputPathArr,
- constraints);
+ propertyType = setConstraintForComplexType(dataTypeDefinitionMap, propertyType, anInputPathArr, constraints);
}
}
-
return constraints;
}
- private String setConstraintForComplexType(Map<String, DataTypeDefinition> dataTypeDefinitionMap,
- String propertyType,
- String anInputPathArr,
+ private String setConstraintForComplexType(Map<String, DataTypeDefinition> dataTypeDefinitionMap, String propertyType, String anInputPathArr,
List<PropertyConstraint> constraints) {
String type = null;
- List<PropertyDefinition> propertyDefinitions =
- dataTypeDefinitionMap.get(propertyType).getProperties();
+ List<PropertyDefinition> propertyDefinitions = dataTypeDefinitionMap.get(propertyType).getProperties();
for (PropertyDefinition propertyDefinition : propertyDefinitions) {
if (propertyDefinition.getName().equals(anInputPathArr)) {
if (ToscaType.isPrimitiveType(propertyDefinition.getType())) {
break;
}
}
-
return type;
}
-
- protected void rollbackWithException(StorageException e) {
- janusGraphDao.rollback();
- throw e;
- }
-
- protected void rollbackWithException(ComponentException e) {
- janusGraphDao.rollback();
- throw e;
- }
-
protected void unlockRollbackWithException(Component component, RuntimeException e) {
janusGraphDao.rollback();
graphLockOperation.unlockComponent(component.getUniqueId(), component.getComponentType().getNodeType());
throw e;
}
- protected void unlockWithCommit(Component component){
+ protected void unlockWithCommit(Component component) {
ComponentTypeEnum componentType = component.getComponentType();
NodeTypeEnum nodeType = componentType.getNodeType();
janusGraphDao.commit();
throw new StorageException(storageOperationStatus);
}
- protected PolicyDefinition storageExceptionPolicyDefinition(StorageOperationStatus storageOperationStatus) {
- throw new StorageException(storageOperationStatus);
- }
-
protected PolicyDefinition componentExceptionPolicyDefinition(ResponseFormat responseFormat) {
throw new ByResponseFormatComponentException(responseFormat);
}
- protected Component componentException(ResponseFormat responseFormat) {
- throw new ByResponseFormatComponentException(responseFormat);
- }
-
protected List<ComponentInstanceProperty> componentInstancePropertyListException(StorageOperationStatus storageOperationStatus) {
throw new StorageException(storageOperationStatus);
}
+ protected Component getComponent(final String componentId) throws BusinessLogicException {
+ final Either<Component, StorageOperationStatus> result = toscaOperationFacade.getToscaElement(componentId);
+ if (result.isRight()) {
+ final StorageOperationStatus errorStatus = result.right().value();
+ log.error(BUSINESS_PROCESS_ERROR, this.getClass().getName(), "Failed to fetch component information by component id, error {}",
+ errorStatus);
+ throw new BusinessLogicException(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus)));
+ }
+ return result.left().value();
+ }
+
+ public String getComponentModelByComponentId(final String componentId) throws BusinessLogicException {
+ return getComponent(componentId).getModel();
+ }
}