summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java427
1 files changed, 160 insertions, 267 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
index 2f43a5b736..da84921a5b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.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,10 +19,18 @@
* Modifications copyright (c) 2019 Nokia
* ================================================================================
*/
-
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.collections4.MapUtils;
@@ -76,22 +84,11 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
@org.springframework.stereotype.Component("inputsBusinessLogic")
public class InputsBusinessLogic extends BaseBusinessLogic {
private static final String CREATE_INPUT = "CreateInput";
private static final String UPDATE_INPUT = "UpdateInput";
-
private static final Logger log = Logger.getLogger(InputsBusinessLogic.class);
private static final String FAILED_TO_FOUND_COMPONENT_ERROR = "Failed to found component {}, error: {}";
private static final String GET_PROPERTIES_BY_INPUT = "get Properties by input";
@@ -101,23 +98,19 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
private static final String GOING_TO_EXECUTE_ROLLBACK_ON_UPDATE_INPUT = "Going to execute rollback on update input.";
private static final String GOING_TO_EXECUTE_COMMIT_ON_UPDATE_INPUT = "Going to execute commit on update input.";
private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(InputsBusinessLogic.class.getName());
-
private final PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
private final DataTypeBusinessLogic dataTypeBusinessLogic;
@Autowired
- public InputsBusinessLogic(IElementOperation elementDao,
- IGroupOperation groupOperation,
- IGroupInstanceOperation groupInstanceOperation,
- IGroupTypeOperation groupTypeOperation,
- InterfaceOperation interfaceOperation,
- InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
- PropertyDeclarationOrchestrator propertyDeclarationOrchestrator,
- ComponentInstanceBusinessLogic componentInstanceBusinessLogic, DataTypeBusinessLogic dataTypeBusinessLogic,
- ArtifactsOperations artifactToscaOperation) {
- super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
- interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
+ public InputsBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation,
+ IGroupTypeOperation groupTypeOperation, InterfaceOperation interfaceOperation,
+ InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
+ PropertyDeclarationOrchestrator propertyDeclarationOrchestrator,
+ ComponentInstanceBusinessLogic componentInstanceBusinessLogic, DataTypeBusinessLogic dataTypeBusinessLogic,
+ ArtifactsOperations artifactToscaOperation) {
+ super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation,
+ artifactToscaOperation);
this.propertyDeclarationOrchestrator = propertyDeclarationOrchestrator;
this.componentInstanceBusinessLogic = componentInstanceBusinessLogic;
this.dataTypeBusinessLogic = dataTypeBusinessLogic;
@@ -131,59 +124,50 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
* @return
*/
public Either<List<InputDefinition>, ResponseFormat> getInputs(String userId, String componentId) {
-
validateUserExists(userId);
-
ComponentParametersView filters = new ComponentParametersView();
filters.disableAll();
filters.setIgnoreInputs(false);
-
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters);
- if(getComponentEither.isRight()){
+ Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
+ .getToscaElement(componentId, filters);
+ if (getComponentEither.isRight()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, componentId, actionStatus);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
-
}
org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
List<InputDefinition> inputs = component.getInputs();
-
return Either.left(inputs);
-
}
- public Either<List<ComponentInstanceInput>, ResponseFormat> getComponentInstanceInputs(String userId, String componentId, String componentInstanceId) {
-
+ public Either<List<ComponentInstanceInput>, ResponseFormat> getComponentInstanceInputs(String userId, String componentId,
+ String componentInstanceId) {
validateUserExists(userId);
ComponentParametersView filters = new ComponentParametersView();
filters.disableAll();
filters.setIgnoreInputs(false);
filters.setIgnoreComponentInstances(false);
filters.setIgnoreComponentInstancesInputs(false);
-
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters);
- if(getComponentEither.isRight()){
+ Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
+ .getToscaElement(componentId, filters);
+ if (getComponentEither.isRight()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, componentId, actionStatus);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
-
}
org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
-
- if(!ComponentValidations.validateComponentInstanceExist(component, componentInstanceId)){
+ if (!ComponentValidations.validateComponentInstanceExist(component, componentInstanceId)) {
ActionStatus actionStatus = ActionStatus.COMPONENT_INSTANCE_NOT_FOUND;
log.debug("Failed to found component instance inputs {}, error: {}", componentInstanceId, actionStatus);
- loggerSupportability.log(LoggerSupportabilityActions.CREATE_INPUTS,component.getComponentMetadataForSupportLog(),
- StatusCode.ERROR,"Failed to found component instance inputs componentInstanceId: {}",componentInstanceId);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_INPUTS, component.getComponentMetadataForSupportLog(), StatusCode.ERROR,
+ "Failed to found component instance inputs componentInstanceId: {}", componentInstanceId);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
}
- Map<String, List<ComponentInstanceInput>> ciInputs =
- Optional.ofNullable(component.getComponentInstancesInputs()).orElse(Collections.emptyMap());
-
- // Set Constraints on Input
- MapUtils.emptyIfNull(ciInputs).values()
- .forEach(inputs -> ListUtils.emptyIfNull(inputs)
- .forEach(input -> input.setConstraints(setInputConstraint(input))));
+ Map<String, List<ComponentInstanceInput>> ciInputs = Optional.ofNullable(component.getComponentInstancesInputs())
+ .orElse(Collections.emptyMap());
+ // Set Constraints on Input
+ MapUtils.emptyIfNull(ciInputs).values()
+ .forEach(inputs -> ListUtils.emptyIfNull(inputs).forEach(input -> input.setConstraints(setInputConstraint(input))));
return Either.left(ciInputs.getOrDefault(componentInstanceId, Collections.emptyList()));
}
@@ -195,59 +179,47 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
* @param inputId
* @return
*/
-
- public Either<List<ComponentInstanceProperty>, ResponseFormat> getComponentInstancePropertiesByInputId(String userId, String componentId, String instanceId, String inputId) {
+ public Either<List<ComponentInstanceProperty>, ResponseFormat> getComponentInstancePropertiesByInputId(String userId, String componentId,
+ String instanceId, String inputId) {
validateUserExists(userId);
String parentId = componentId;
org.openecomp.sdc.be.model.Component component;
ComponentParametersView filters = new ComponentParametersView();
filters.disableAll();
filters.setIgnoreComponentInstances(false);
-
- if(!instanceId.equals(inputId)){
-
-
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(parentId, filters);
-
- if(getComponentEither.isRight()){
+ if (!instanceId.equals(inputId)) {
+ Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
+ .getToscaElement(parentId, filters);
+ if (getComponentEither.isRight()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, parentId, actionStatus);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
-
}
component = getComponentEither.left().value();
- Optional<ComponentInstance> ciOp = component.getComponentInstances().stream().filter(ci ->ci.getUniqueId().equals(instanceId)).findAny();
- if(ciOp.isPresent()){
+ Optional<ComponentInstance> ciOp = component.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(instanceId)).findAny();
+ if (ciOp.isPresent()) {
parentId = ciOp.get().getComponentUid();
}
-
}
-
filters.setIgnoreInputs(false);
-
filters.setIgnoreComponentInstancesProperties(false);
filters.setIgnoreComponentInstancesInputs(false);
filters.setIgnoreProperties(false);
-
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(parentId, filters);
-
- if(getComponentEither.isRight()){
+ Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
+ .getToscaElement(parentId, filters);
+ if (getComponentEither.isRight()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, parentId, actionStatus);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
-
}
component = getComponentEither.left().value();
-
Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
- if(!op.isPresent()){
+ if (!op.isPresent()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
log.debug(FAILED_TO_FOUND_INPUT_UNDER_COMPONENT_ERROR, inputId, parentId, actionStatus);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
}
-
return Either.left(componentInstanceBusinessLogic.getComponentInstancePropertiesByInputId(component, inputId));
-
}
private String updateInputObjectValue(InputDefinition currentInput, InputDefinition newInput, Map<String, DataTypeDefinition> dataTypes) {
@@ -255,7 +227,6 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
String propertyType = currentInput.getType();
ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
log.debug("The type of the property {} is {}", currentInput.getUniqueId(), propertyType);
-
if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) {
SchemaDefinition def = currentInput.getSchema();
if (def == null) {
@@ -270,14 +241,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
innerType = propDef.getType();
}
// Specific Update Logic
-
- Either<Object, Boolean> isValid = propertyOperation.validateAndUpdatePropertyValue(propertyType, newInput.getDefaultValue(), true, innerType, dataTypes);
-
+ Either<Object, Boolean> isValid = propertyOperation
+ .validateAndUpdatePropertyValue(propertyType, newInput.getDefaultValue(), true, innerType, dataTypes);
String newValue = newInput.getDefaultValue();
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();
@@ -292,25 +263,22 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
return componentsOldInputs.stream().filter(in -> in.getUniqueId().equals(input.getUniqueId())).findFirst().orElse(null);
}
- public Either<List<InputDefinition>, ResponseFormat> updateInputsValue(ComponentTypeEnum componentType, String componentId, List<InputDefinition> inputs, String userId, boolean shouldLockComp, boolean inTransaction) {
-
+ public Either<List<InputDefinition>, ResponseFormat> updateInputsValue(ComponentTypeEnum componentType, String componentId,
+ List<InputDefinition> inputs, String userId, boolean shouldLockComp,
+ boolean inTransaction) {
List<InputDefinition> returnInputs = new ArrayList<>();
Either<List<InputDefinition>, ResponseFormat> result = null;
org.openecomp.sdc.be.model.Component component = null;
-
try {
validateUserExists(userId);
-
ComponentParametersView componentParametersView = new ComponentParametersView();
componentParametersView.disableAll();
componentParametersView.setIgnoreInputs(false);
componentParametersView.setIgnoreUsers(false);
- componentParametersView.setIgnoreProperties(false);
- componentParametersView.setIgnoreComponentInstancesProperties(false);
- componentParametersView.setIgnoreComponentInstances(false);
-
+ componentParametersView.setIgnoreProperties(false);
+ componentParametersView.setIgnoreComponentInstancesProperties(false);
+ componentParametersView.setIgnoreComponentInstances(false);
component = validateComponentExists(componentId, componentType, componentParametersView);
-
if (shouldLockComp) {
try {
lockComponent(component, UPDATE_INPUT);
@@ -320,21 +288,17 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
return result;
}
}
-
//Validate value and Constraint of input
- Either<Boolean, ResponseFormat> constraintValidatorResponse = validateInputValueConstraint(inputs);
+ Either<Boolean, ResponseFormat> constraintValidatorResponse = validateInputValueConstraint(inputs);
if (constraintValidatorResponse.isRight()) {
- log.error("Failed validation value and constraint of property: {}",
- constraintValidatorResponse.right().value());
+ log.error("Failed validation value and constraint of property: {}", constraintValidatorResponse.right().value());
return Either.right(constraintValidatorResponse.right().value());
}
-
validateCanWorkOnComponent(component, userId);
Map<String, DataTypeDefinition> dataTypes;
dataTypes = getAllDataTypes(applicationDataTypeCache);
-
List<InputDefinition> componentsOldInputs = Optional.ofNullable(component.getInputs()).orElse(Collections.emptyList());
- for (InputDefinition newInput: inputs) {
+ for (InputDefinition newInput : inputs) {
InputDefinition currInput = getInputFromInputsListById(componentsOldInputs, newInput);
if (currInput == null) {
ActionStatus actionStatus = ActionStatus.COMPONENT_NOT_FOUND;
@@ -350,7 +314,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
currInput.setRequired(newInput.isRequired());
}
Either<InputDefinition, StorageOperationStatus> status = toscaOperationFacade.updateInputOfComponent(component, currInput);
- if(status.isRight()){
+ if (status.isRight()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status.right().value());
result = Either.right(componentsUtils.getResponseFormat(actionStatus, ""));
return result;
@@ -362,37 +326,32 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
} catch (ComponentException e) {
log.debug(GOING_TO_EXECUTE_ROLLBACK_ON_UPDATE_INPUT);
unlockRollbackWithException(component, e);
- } catch (Exception e){
+ } catch (Exception e) {
log.debug(GOING_TO_EXECUTE_ROLLBACK_ON_UPDATE_INPUT);
unlockRollbackWithException(component, new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR));
}
log.debug(GOING_TO_EXECUTE_COMMIT_ON_UPDATE_INPUT);
unlockWithCommit(component);
return result;
-
}
private Either<Boolean, ResponseFormat> validateInputValueConstraint(List<InputDefinition> inputs) {
- PropertyValueConstraintValidationUtil propertyValueConstraintValidationUtil =
- PropertyValueConstraintValidationUtil.getInstance();
- List<InputDefinition> inputDefinitions = new ArrayList<>();
- for (InputDefinition inputDefinition : inputs) {
- InputDefinition inputDef = new InputDefinition();
- inputDefinition.setDefaultValue(inputDefinition.getDefaultValue());
- inputDefinition.setInputPath(inputDefinition.getSubPropertyInputPath());
- inputDefinition.setType(inputDefinition.getType());
- if (Objects.nonNull(inputDefinition.getParentPropertyType())) {
- ComponentInstanceProperty propertyDefinition = new ComponentInstanceProperty();
- propertyDefinition.setType(inputDefinition.getParentPropertyType());
-
- inputDefinition.setProperties(Collections.singletonList(propertyDefinition));
- }
-
- inputDefinitions.add(inputDef);
- }
-
- return propertyValueConstraintValidationUtil.validatePropertyConstraints(inputDefinitions, applicationDataTypeCache);
- }
+ PropertyValueConstraintValidationUtil propertyValueConstraintValidationUtil = PropertyValueConstraintValidationUtil.getInstance();
+ List<InputDefinition> inputDefinitions = new ArrayList<>();
+ for (InputDefinition inputDefinition : inputs) {
+ InputDefinition inputDef = new InputDefinition();
+ inputDefinition.setDefaultValue(inputDefinition.getDefaultValue());
+ inputDefinition.setInputPath(inputDefinition.getSubPropertyInputPath());
+ inputDefinition.setType(inputDefinition.getType());
+ if (Objects.nonNull(inputDefinition.getParentPropertyType())) {
+ ComponentInstanceProperty propertyDefinition = new ComponentInstanceProperty();
+ propertyDefinition.setType(inputDefinition.getParentPropertyType());
+ inputDefinition.setProperties(Collections.singletonList(propertyDefinition));
+ }
+ inputDefinitions.add(inputDef);
+ }
+ return propertyValueConstraintValidationUtil.validatePropertyConstraints(inputDefinitions, applicationDataTypeCache);
+ }
public Either<List<ComponentInstanceInput>, ResponseFormat> getInputsForComponentInput(String userId, String componentId, String inputId) {
validateUserExists(userId);
@@ -403,59 +362,46 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
filters.setIgnoreInputs(false);
filters.setIgnoreComponentInstancesInputs(false);
filters.setIgnoreProperties(false);
-
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters);
-
- if(getComponentEither.isRight()){
+ Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
+ .getToscaElement(componentId, filters);
+ if (getComponentEither.isRight()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, componentId, actionStatus);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
-
}
component = getComponentEither.left().value();
-
Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
- if(!op.isPresent()){
+ if (!op.isPresent()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
log.debug(FAILED_TO_FOUND_INPUT_UNDER_COMPONENT_ERROR, inputId, componentId, actionStatus);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
}
-
return Either.left(componentInstanceBusinessLogic.getComponentInstanceInputsByInputId(component, inputId));
-
}
@Override
- public Either<List<InputDefinition>, ResponseFormat> declareProperties(String userId, String componentId,
- ComponentTypeEnum componentTypeEnum, ComponentInstInputsMap componentInstInputsMap) {
-
+ public Either<List<InputDefinition>, ResponseFormat> declareProperties(String userId, String componentId, ComponentTypeEnum componentTypeEnum,
+ ComponentInstInputsMap componentInstInputsMap) {
return createMultipleInputs(userId, componentId, componentTypeEnum, componentInstInputsMap, true, false);
}
- public Either<List<InputDefinition>, ResponseFormat> createMultipleInputs(String userId, String componentId, ComponentTypeEnum componentType, ComponentInstInputsMap componentInstInputsMapUi, boolean shouldLockComp, boolean inTransaction) {
-
+ public Either<List<InputDefinition>, ResponseFormat> createMultipleInputs(String userId, String componentId, ComponentTypeEnum componentType,
+ ComponentInstInputsMap componentInstInputsMapUi, boolean shouldLockComp,
+ boolean inTransaction) {
Either<List<InputDefinition>, ResponseFormat> result = null;
org.openecomp.sdc.be.model.Component component = null;
-
try {
validateUserExists(userId);
-
component = getAndValidateComponentForCreate(userId, componentId, componentType, shouldLockComp);
-
- result = propertyDeclarationOrchestrator.declarePropertiesToInputs(component, componentInstInputsMapUi)
- .left()
- .bind(inputsToCreate -> prepareInputsForCreation(userId, componentId, inputsToCreate))
- .right()
- .map(componentsUtils::getResponseFormat);
-
+ result = propertyDeclarationOrchestrator.declarePropertiesToInputs(component, componentInstInputsMapUi).left()
+ .bind(inputsToCreate -> prepareInputsForCreation(userId, componentId, inputsToCreate)).right()
+ .map(componentsUtils::getResponseFormat);
return result;
-
} catch (ByResponseFormatComponentException e) {
log.error("#createMultipleInputs: Exception thrown: ", e);
result = Either.right(e.getResponseFormat());
return result;
} finally {
-
if (!inTransaction) {
if (result == null || result.isRight()) {
log.debug(GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_GROUP);
@@ -469,29 +415,25 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
if (shouldLockComp && component != null) {
graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
}
-
}
}
/**
* Creates a list input with a data type which has properties specified.
*
- * @param userId User ID
- * @param componentId Component ID
- * @param componentType Component type
+ * @param userId User ID
+ * @param componentId Component ID
+ * @param componentType Component type
* @param componentListInput Properties to be declared and input to be created
- * @param shouldLockComp true if the component should be locked
- * @param inTransaction true if already in transaction
+ * @param shouldLockComp true if the component should be locked
+ * @param inTransaction true if already in transaction
*/
- public Either<List<InputDefinition>, ResponseFormat> createListInput(String userId, String componentId,
- ComponentTypeEnum componentType, ComponentInstListInput componentListInput, boolean shouldLockComp,
- boolean inTransaction) {
-
+ public Either<List<InputDefinition>, ResponseFormat> createListInput(String userId, String componentId, ComponentTypeEnum componentType,
+ ComponentInstListInput componentListInput, boolean shouldLockComp,
+ boolean inTransaction) {
Either<List<InputDefinition>, ResponseFormat> result = null;
org.openecomp.sdc.be.model.Component component = null;
-
log.trace("#createListInput: enter");
-
try {
/* check if user exists */
validateUserExists(userId);
@@ -608,22 +550,24 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
return dataType;
}
- private Either<List<InputDefinition>, StorageOperationStatus> prepareInputsForCreation(String userId, String cmptId, List<InputDefinition> inputsToCreate) {
+ private Either<List<InputDefinition>, StorageOperationStatus> prepareInputsForCreation(String userId, String cmptId,
+ List<InputDefinition> inputsToCreate) {
Map<String, InputDefinition> inputsToPersist = MapUtil.toMap(inputsToCreate, InputDefinition::getName);
assignOwnerIdToInputs(userId, inputsToPersist);
- inputsToPersist.values()
- .forEach(input -> input.setConstraints(componentInstanceBusinessLogic.setInputConstraint(input)));
+ inputsToPersist.values()
+ .forEach(input -> input.setConstraints(componentInstanceBusinessLogic.setInputConstraint(input)));
return toscaOperationFacade.addInputsToComponent(inputsToPersist, cmptId)
- .left()
- .map(persistedInputs -> inputsToCreate);
+ .left()
+ .map(persistedInputs -> inputsToCreate);
}
private void assignOwnerIdToInputs(String userId, Map<String, InputDefinition> inputsToCreate) {
inputsToCreate.values().forEach(inputDefinition -> inputDefinition.setOwnerId(userId));
}
- public Either<List<InputDefinition>, ResponseFormat> createInputsInGraph(Map<String, InputDefinition> inputs, org.openecomp.sdc.be.model.Component component) {
+ public Either<List<InputDefinition>, ResponseFormat> createInputsInGraph(Map<String, InputDefinition> inputs,
+ org.openecomp.sdc.be.model.Component component) {
List<InputDefinition> resourceProperties = component.getInputs();
@@ -634,22 +578,24 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
inputDefinition.getValue().setName(inputName);
Either<InputDefinition, ResponseFormat> preparedInputEither = prepareAndValidateInputBeforeCreate(inputDefinition.getValue(), dataTypes);
- if(preparedInputEither.isRight()){
+ if (preparedInputEither.isRight()) {
return Either.right(preparedInputEither.right().value());
}
}
if (resourceProperties != null) {
- Map<String, InputDefinition> generatedInputs = resourceProperties.stream().collect(Collectors.toMap(PropertyDataDefinition::getName, i -> i));
+ Map<String, InputDefinition> generatedInputs = resourceProperties.stream()
+ .collect(Collectors.toMap(PropertyDataDefinition::getName, i -> i));
Either<Map<String, InputDefinition>, String> mergeEither = ToscaDataDefinition.mergeDataMaps(generatedInputs, inputs);
- if(mergeEither.isRight()){
+ if (mergeEither.isRight()) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_ALREADY_EXIST, mergeEither.right().value()));
}
inputs = mergeEither.left().value();
}
- Either<List<InputDefinition>, StorageOperationStatus> associateInputsEither = toscaOperationFacade.createAndAssociateInputs(inputs, component.getUniqueId());
- if(associateInputsEither.isRight()){
+ Either<List<InputDefinition>, StorageOperationStatus> associateInputsEither = toscaOperationFacade
+ .createAndAssociateInputs(inputs, component.getUniqueId());
+ if (associateInputsEither.isRight()) {
log.debug("Failed to create inputs under component {}. Status is {}", component.getUniqueId(), associateInputsEither.right().value());
return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(associateInputsEither.right().value())));
@@ -658,12 +604,13 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
}
private Either<List<InputDefinition>, ResponseFormat> createListInputsInGraph(Map<String, InputDefinition> inputs,
- Map<String, DataTypeDefinition> privateDataTypes, org.openecomp.sdc.be.model.Component component) {
+ Map<String, DataTypeDefinition> privateDataTypes,
+ org.openecomp.sdc.be.model.Component component) {
log.trace("#createListInputsInGraph: enter");
Map<String, DataTypeDefinition> dataTypes = getAllDataTypes(
- applicationDataTypeCache);
+ applicationDataTypeCache);
dataTypes.putAll(privateDataTypes);
for (Map.Entry<String, InputDefinition> inputDefinition : inputs.entrySet()) {
@@ -698,99 +645,86 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
* @return
*/
public InputDefinition deleteInput(String componentId, String userId, String inputId) {
-
Either<InputDefinition, ResponseFormat> deleteEither = null;
if (log.isDebugEnabled()) {
log.debug("Going to delete input id: {}", inputId);
}
-
validateUserExists(userId);
-
ComponentParametersView componentParametersView = getBaseComponentParametersView();
componentParametersView.setIgnoreInterfaces(false);
componentParametersView.setIgnoreDataType(false);
componentParametersView.setIgnoreProperties(false);
-
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentEither =
- toscaOperationFacade.getToscaElement(componentId, componentParametersView);
+ Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentEither = toscaOperationFacade
+ .getToscaElement(componentId, componentParametersView);
if (componentEither.isRight()) {
throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(componentEither.right().value()));
}
org.openecomp.sdc.be.model.Component component = componentEither.left().value();
-
// Validate inputId is child of the component
Optional<InputDefinition> optionalInput = component.getInputs().stream().
- // filter by ID
- filter(input -> input.getUniqueId().equals(inputId)).
- // Get the input
- findAny();
+ // filter by ID
+ filter(input -> input.getUniqueId().equals(inputId)).
+ // Get the input
+ findAny();
if (!optionalInput.isPresent()) {
throw new ByActionStatusComponentException(ActionStatus.INPUT_IS_NOT_CHILD_OF_COMPONENT, inputId, componentId);
}
-
InputDefinition inputForDelete = optionalInput.get();
-
// Lock component
lockComponent(componentId, component, "deleteInput");
// Delete input operations
boolean failed = false;
try {
- StorageOperationStatus status =
- toscaOperationFacade.deleteInputOfResource(component, inputForDelete.getName());
+ StorageOperationStatus status = toscaOperationFacade.deleteInputOfResource(component, inputForDelete.getName());
if (status != StorageOperationStatus.OK) {
log.debug("Component id: {} delete input id: {} failed", componentId, inputId);
throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status), component.getName());
}
-
- if (BooleanUtils.isTrue(inputForDelete.getIsDeclaredListInput())){
+ if (BooleanUtils.isTrue(inputForDelete.getIsDeclaredListInput())) {
deleteEither = deleteListInput(componentId, inputId, component, inputForDelete, status);
- if (deleteEither.isRight()){
+ if (deleteEither.isRight()) {
throw new ByResponseFormatComponentException(deleteEither.right().value());
}
return deleteEither.left().value();
}
-
- StorageOperationStatus storageOperationStatus =
- propertyDeclarationOrchestrator.unDeclarePropertiesAsInputs(component, inputForDelete);
+ StorageOperationStatus storageOperationStatus = propertyDeclarationOrchestrator.unDeclarePropertiesAsInputs(component, inputForDelete);
if (storageOperationStatus != StorageOperationStatus.OK) {
log.debug("Component id: {} update properties declared as input for input id: {} failed", componentId, inputId);
throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(storageOperationStatus), component.getName());
}
- return inputForDelete;
- }catch (ComponentException e){
+ return inputForDelete;
+ } catch (ComponentException e) {
failed = true;
throw e;
- }finally {
+ } finally {
unlockComponent(failed, component);
}
}
private Either<InputDefinition, ResponseFormat> deleteListInput(String componentId, String inputId,
- org.openecomp.sdc.be.model.Component component,
- InputDefinition inputForDelete, StorageOperationStatus status) {
+ org.openecomp.sdc.be.model.Component component, InputDefinition inputForDelete,
+ StorageOperationStatus status) {
// the input is created by 'Declare List'.
- // need to 1. undeclare properties, 2. delete input, 3. delete private data type
- StorageOperationStatus storageOperationStatus =
- propertyDeclarationOrchestrator.unDeclarePropertiesAsListInputs(component, inputForDelete);
+ // need to 1. undeclare properties, 2. delete input, 3. delete private data type
+ StorageOperationStatus storageOperationStatus = propertyDeclarationOrchestrator.unDeclarePropertiesAsListInputs(component, inputForDelete);
if (storageOperationStatus != StorageOperationStatus.OK) {
log.debug("Component id: {} update properties declared as input for input id: {} failed", componentId, inputId);
- return Either.right(componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponse(status), component.getName()));
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), component.getName()));
}
- Either<DataTypeDefinition, StorageOperationStatus> deleteResult =
- dataTypeBusinessLogic.deletePrivateDataType(component, inputForDelete.getSchemaType());
+ Either<DataTypeDefinition, StorageOperationStatus> deleteResult = dataTypeBusinessLogic
+ .deletePrivateDataType(component, inputForDelete.getSchemaType());
if (deleteResult.isRight()) {
log.debug("Component id: {} delete datatype name: {} failed", componentId, inputForDelete.getSchemaType());
- return Either.right(componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponse(deleteResult.right().value()), component.getName()));
+ return Either.right(
+ componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deleteResult.right().value()), component.getName()));
}
log.trace("deleteInput: deletePrivateDataType (OK)");
return Either.left(inputForDelete);
}
- private Either<InputDefinition, ResponseFormat> prepareAndValidateInputBeforeCreate(InputDefinition newInputDefinition, Map<String, DataTypeDefinition> dataTypes) {
-
+ private Either<InputDefinition, ResponseFormat> prepareAndValidateInputBeforeCreate(InputDefinition newInputDefinition,
+ Map<String, DataTypeDefinition> dataTypes) {
// validate input default values
Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(newInputDefinition, dataTypes);
if (defaultValuesValidation.isRight()) {
@@ -818,10 +752,10 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
return Either.left(newInputDefinition);
}
- public Either<InputDefinition, ResponseFormat> getInputsAndPropertiesForComponentInput(String userId, String componentId, String inputId, boolean inTransaction) {
+ public Either<InputDefinition, ResponseFormat> getInputsAndPropertiesForComponentInput(String userId, String componentId, String inputId,
+ boolean inTransaction) {
Either<InputDefinition, ResponseFormat> result = null;
try {
-
validateUserExists(userId);
ComponentParametersView filters = new ComponentParametersView();
filters.disableAll();
@@ -830,41 +764,29 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
filters.setIgnoreComponentInstancesInputs(false);
filters.setIgnoreComponentInstancesProperties(false);
filters.setIgnoreProperties(false);
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters);
- if(getComponentEither.isRight()){
+ Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
+ .getToscaElement(componentId, filters);
+ if (getComponentEither.isRight()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, componentId, actionStatus);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
-
}
org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
- if(!op.isPresent()){
+ if (!op.isPresent()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
log.debug(FAILED_TO_FOUND_INPUT_UNDER_COMPONENT_ERROR, inputId, componentId, actionStatus);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
}
-
InputDefinition resObj = op.get();
-
- List<ComponentInstanceInput> inputCIInput = componentInstanceBusinessLogic.getComponentInstanceInputsByInputId(component, inputId) ;
-
+ List<ComponentInstanceInput> inputCIInput = componentInstanceBusinessLogic.getComponentInstanceInputsByInputId(component, inputId);
resObj.setInputs(inputCIInput);
-
-
- List<ComponentInstanceProperty> inputProps = componentInstanceBusinessLogic.getComponentInstancePropertiesByInputId(component, inputId) ;
-
+ List<ComponentInstanceProperty> inputProps = componentInstanceBusinessLogic.getComponentInstancePropertiesByInputId(component, inputId);
resObj.setProperties(inputProps);
-
-
result = Either.left(resObj);
-
return result;
-
} finally {
-
if (!inTransaction) {
-
if (result == null || result.isRight()) {
log.debug(GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_GROUP);
janusGraphDao.rollback();
@@ -872,69 +794,48 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
log.debug(GOING_TO_EXECUTE_COMMIT_ON_CREATE_GROUP);
janusGraphDao.commit();
}
-
}
-
}
-
}
- public Either<EntryData<String, InputDefinition>, ResponseFormat> addInputToComponent(String componentId,
- String inputName,
- InputDefinition newInputDefinition,
- String userId) {
+ public Either<EntryData<String, InputDefinition>, ResponseFormat> addInputToComponent(String componentId, String inputName,
+ InputDefinition newInputDefinition, String userId) {
Either<EntryData<String, InputDefinition>, ResponseFormat> result = null;
-
validateUserExists(userId);
-
- Either<Component, StorageOperationStatus> serviceElement =
- toscaOperationFacade.getToscaElement(componentId);
+ Either<Component, StorageOperationStatus> serviceElement = toscaOperationFacade.getToscaElement(componentId);
if (serviceElement.isRight()) {
result = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, ""));
return result;
}
-
Component component = serviceElement.left().value();
NodeTypeEnum nodeType = component.getComponentType().getNodeType();
-
StorageOperationStatus lockResult = graphLockOperation.lockComponent(componentId, nodeType);
if (!lockResult.equals(StorageOperationStatus.OK)) {
- BeEcompErrorManager.getInstance()
- .logBeFailedLockObjectError(CREATE_INPUT, nodeType.name().toLowerCase(), componentId);
+ BeEcompErrorManager.getInstance().logBeFailedLockObjectError(CREATE_INPUT, nodeType.name().toLowerCase(), componentId);
log.info("Failed to lock component {}. Error - {}", componentId, lockResult);
result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
return result;
}
-
try {
if (!ComponentValidationUtils.canWorkOnComponent(component, userId)) {
result = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
return result;
}
-
List<InputDefinition> inputs = component.getInputs();
-
if (CollectionUtils.isEmpty(inputs)) {
inputs = new ArrayList<>();
}
-
if (isInputExistInComponent(inputs, inputName)) {
-
- result = Either.right(componentsUtils.getResponseFormat(ActionStatus
- .INPUT_ALREADY_EXIST, inputName));
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INPUT_ALREADY_EXIST, inputName));
return result;
}
-
Map<String, DataTypeDefinition> allDataTypes = getAllDataTypes(applicationDataTypeCache);
-
// validate input default values
- Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(
- newInputDefinition, allDataTypes);
+ Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(newInputDefinition, allDataTypes);
if (defaultValuesValidation.isRight()) {
result = Either.right(defaultValuesValidation.right().value());
return result;
}
-
// convert Input
ToscaPropertyType type = getType(newInputDefinition.getType());
if (type != null) {
@@ -949,24 +850,18 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
}
}
if (newInputDefinition.getDefaultValue() != null) {
- String convertedValue = converter
- .convert(newInputDefinition.getDefaultValue(), innerType, allDataTypes);
+ String convertedValue = converter.convert(newInputDefinition.getDefaultValue(), innerType, allDataTypes);
newInputDefinition.setDefaultValue(convertedValue);
}
}
-
newInputDefinition.setMappedToComponentProperty(false);
- Either<InputDefinition, StorageOperationStatus> addInputEither =
- toscaOperationFacade.addInputToComponent(inputName, newInputDefinition, component);
-
+ Either<InputDefinition, StorageOperationStatus> addInputEither = toscaOperationFacade
+ .addInputToComponent(inputName, newInputDefinition, component);
if (addInputEither.isRight()) {
- log.info("Failed to add new input {}. Error - {}", componentId,
- addInputEither.right().value());
- result = Either.right(componentsUtils.getResponseFormat(ActionStatus
- .GENERAL_ERROR));
+ log.info("Failed to add new input {}. Error - {}", componentId, addInputEither.right().value());
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
return result;
}
-
result = Either.left(new EntryData<>(inputName, newInputDefinition));
return result;
} finally {
@@ -977,8 +872,6 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
}
private boolean isInputExistInComponent(List<InputDefinition> inputs, String inputName) {
- return CollectionUtils.isNotEmpty(inputs) &&
- inputs.stream().anyMatch(input -> input.getName().equals(inputName));
+ return CollectionUtils.isNotEmpty(inputs) && inputs.stream().anyMatch(input -> input.getName().equals(inputName));
}
-
}