From 3849231a17930b1bb2ba09af15673bfd07538b9d Mon Sep 17 00:00:00 2001 From: KrupaNagabhushan Date: Thu, 19 Nov 2020 14:28:00 +0000 Subject: Create inputs independent of properties Issue-ID: SDC-3431 Signed-off-by: KrupaNagabhushan Change-Id: I4f29d0e490a14292fd1aa9f96ca6621b37f325d8 --- .../operations/ToscaOperationFacade.java | 43 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'catalog-model/src/main') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java index 957c5f9d66..532a641e2f 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java @@ -2482,6 +2482,46 @@ public class ToscaOperationFacade { return Either.left(newProperty); } + public Either addInputToComponent(String inputName, + InputDefinition newInputDefinition, + Component component) { + newInputDefinition.setName(inputName); + + StorageOperationStatus status = getToscaElementOperation(component) + .addToscaDataToToscaElement(component.getUniqueId(), EdgeLabelEnum.INPUTS, VertexTypeEnum.INPUTS, newInputDefinition, JsonPresentationFields.NAME); + if (status != StorageOperationStatus.OK) { + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the input {} to the component {}. Status is {}. ", inputName, component.getName(), status); + return Either.right(status); + } + + ComponentParametersView filter = new ComponentParametersView(true); + filter.setIgnoreProperties(false); + filter.setIgnoreInputs(false); + Either getUpdatedComponentRes = getToscaElement(component.getUniqueId(), filter); + if (getUpdatedComponentRes.isRight()) { + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated component {}. Status is {}. ", component.getUniqueId(), getUpdatedComponentRes.right().value()); + return Either.right(status); + } + + InputDefinition newInput = null; + List inputs = + (getUpdatedComponentRes.left().value()).getInputs(); + if (CollectionUtils.isNotEmpty(inputs)) { + Optional inputOptional = inputs.stream().filter( + inputEntry -> inputEntry.getName().equals(inputName)).findAny(); + if (inputOptional.isPresent()) { + newInput = inputOptional.get(); + } + } + if (newInput == null) { + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added input {} " + + "on the component {}. Status is {}. ", inputs, component.getUniqueId(), StorageOperationStatus.NOT_FOUND); + return Either.right(StorageOperationStatus.NOT_FOUND); + } + + return Either.left(newInput); + } + public StorageOperationStatus deletePropertyOfComponent(Component component, String propertyName) { return getToscaElementOperation(component).deleteToscaDataElement(component.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, propertyName, JsonPresentationFields.NAME); } @@ -2536,8 +2576,7 @@ public class ToscaOperationFacade { return result; } - - public Either addAttributeOfResource(Component component, AttributeDataDefinition newAttributeDef) { + public Either addAttributeOfResource(Component component, AttributeDataDefinition newAttributeDef) { Either getUpdatedComponentRes = null; Either result = null; -- cgit 1.2.3-korg