2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.components.impl;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
27 import java.util.Optional;
28 import java.util.UUID;
29 import java.util.Map.Entry;
30 import java.util.function.BiConsumer;
31 import java.util.function.Predicate;
32 import java.util.stream.Collectors;
33 import java.util.stream.Stream;
35 import org.json.simple.JSONObject;
36 import org.openecomp.sdc.be.config.BeEcompErrorManager;
37 import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
38 import org.openecomp.sdc.be.dao.api.ActionStatus;
39 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
40 import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
41 import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
42 import org.openecomp.sdc.be.dao.neo4j.GraphEdgePropertiesDictionary;
43 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
44 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
45 import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
46 import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
47 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
48 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
49 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
50 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
51 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
52 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
53 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
54 import org.openecomp.sdc.be.impl.ComponentsUtils;
55 import org.openecomp.sdc.be.model.CapabilityDefinition;
56 import org.openecomp.sdc.be.model.ComponentInstInputsMap;
57 import org.openecomp.sdc.be.model.ComponentInstance;
58 import org.openecomp.sdc.be.model.ComponentInstanceInput;
59 import org.openecomp.sdc.be.model.ComponentInstancePropInput;
60 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
61 import org.openecomp.sdc.be.model.ComponentParametersView;
62 import org.openecomp.sdc.be.model.DataTypeDefinition;
63 import org.openecomp.sdc.be.model.InputDefinition;
64 import org.openecomp.sdc.be.model.PropertyDefinition;
65 import org.openecomp.sdc.be.model.User;
67 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
68 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
69 import org.openecomp.sdc.be.model.operations.impl.InputsOperation;
70 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
71 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
72 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
73 import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
74 import org.openecomp.sdc.be.resources.data.InputValueData;
75 import org.openecomp.sdc.be.resources.data.InputsData;
76 import org.openecomp.sdc.be.resources.data.PropertyValueData;
77 import org.openecomp.sdc.be.resources.data.UniqueIdData;
78 import org.openecomp.sdc.exception.ResponseFormat;
79 import org.slf4j.Logger;
80 import org.slf4j.LoggerFactory;
81 import org.springframework.beans.factory.annotation.Autowired;
82 import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor;
83 import org.springframework.stereotype.Component;
84 import org.yaml.snakeyaml.Yaml;
86 import com.google.gson.Gson;
87 import com.thinkaurelius.titan.core.TitanVertex;
90 import fj.data.Either;
92 @Component("inputsBusinessLogic")
93 public class InputsBusinessLogic extends BaseBusinessLogic {
95 private static final String CREATE_INPUT = "CreateInput";
96 private static final String UPDATE_INPUT = "UpdateInput";
98 private static Logger log = LoggerFactory.getLogger(InputsBusinessLogic.class.getName());
102 @javax.annotation.Resource
103 private PropertyOperation propertyOperation = null;
107 private ComponentsUtils componentsUtils;
109 private static final String GET_INPUT = "get_input";
111 private static String ASSOCIATING_INPUT_TO_PROP = "AssociatingInputToComponentInstanceProperty";
112 private Gson gson = new Gson();
116 * associate inputs to a given component with paging
124 public Either<List<InputDefinition>, ResponseFormat> getInputs(String userId, String componentId, String fromName, int amount) {
126 Either<User, ResponseFormat> resp = validateUserExists(userId, "get Inputs", false);
128 if (resp.isRight()) {
129 return Either.right(resp.right().value());
133 ComponentParametersView filters = new ComponentParametersView();
134 filters.disableAll();
135 filters.setIgnoreInputs(false);
137 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters);
138 if(getComponentEither.isRight()){
139 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
140 log.debug("Failed to found component {}, error: {}", componentId, actionStatus.name());
141 return Either.right(componentsUtils.getResponseFormat(actionStatus));
144 org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
145 List<InputDefinition> inputs = component.getInputs();
147 return Either.left(inputs);
151 public Either<List<ComponentInstanceInput>, ResponseFormat> getComponentInstanceInputs(String userId, String componentId, String componentInstanceId,String fromName, int amount) {
153 Either<User, ResponseFormat> resp = validateUserExists(userId, "get Inputs", false);
155 if (resp.isRight()) {
156 return Either.right(resp.right().value());
160 ComponentParametersView filters = new ComponentParametersView();
161 filters.disableAll();
162 filters.setIgnoreInputs(false);
163 filters.setIgnoreComponentInstances(false);
164 filters.setIgnoreComponentInstancesInputs(false);
166 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters);
167 if(getComponentEither.isRight()){
168 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
169 log.debug("Failed to found component {}, error: {}", componentId, actionStatus.name());
170 return Either.right(componentsUtils.getResponseFormat(actionStatus));
173 org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
174 Map<String, List<ComponentInstanceInput>> ciInputs = component.getComponentInstancesInputs();
175 if(!ciInputs.containsKey(componentInstanceId)){
176 ActionStatus actionStatus = ActionStatus.COMPONENT_INSTANCE_NOT_FOUND;
177 log.debug("Failed to found component instance inputs {}, error: {}", componentInstanceId, actionStatus.name());
178 return Either.right(componentsUtils.getResponseFormat(actionStatus));
181 return Either.left(ciInputs.get(componentInstanceId));
186 * associate properties to a given component instance input
194 public Either<List<ComponentInstanceProperty>, ResponseFormat> getComponentInstancePropertiesByInputId(String userId, String componentId, String instanceId, String inputId) {
195 Either<User, ResponseFormat> resp = validateUserExists(userId, "get Properties by input", false);
196 if (resp.isRight()) {
197 return Either.right(resp.right().value());
199 String parentId = componentId;
200 org.openecomp.sdc.be.model.Component component = null;
201 ComponentParametersView filters = new ComponentParametersView();
202 filters.disableAll();
203 filters.setIgnoreComponentInstances(false);
205 if(!instanceId.equals(inputId)){
208 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(parentId, filters);
210 if(getComponentEither.isRight()){
211 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
212 log.debug("Failed to found component {}, error: {}", parentId, actionStatus.name());
213 return Either.right(componentsUtils.getResponseFormat(actionStatus));
216 component = getComponentEither.left().value();
217 Optional<ComponentInstance> ciOp = component.getComponentInstances().stream().filter(ci ->ci.getUniqueId().equals(instanceId)).findAny();
218 if(ciOp.isPresent()){
219 parentId = ciOp.get().getComponentUid();
224 filters.setIgnoreInputs(false);
226 filters.setIgnoreComponentInstancesProperties(false);
227 filters.setIgnoreComponentInstancesInputs(false);
228 filters.setIgnoreProperties(false);
230 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(parentId, filters);
232 if(getComponentEither.isRight()){
233 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
234 log.debug("Failed to found component {}, error: {}", parentId, actionStatus.name());
235 return Either.right(componentsUtils.getResponseFormat(actionStatus));
238 component = getComponentEither.left().value();
240 Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
242 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
243 log.debug("Failed to found input {} under component {}, error: {}", inputId, parentId, actionStatus.name());
244 return Either.right(componentsUtils.getResponseFormat(actionStatus));
247 return Either.left(getComponentInstancePropertiesByInputId(component, inputId));
251 public Either<InputDefinition, ResponseFormat> updateInputValue(ComponentTypeEnum componentType, String componentId, InputDefinition input, String userId, boolean shouldLockComp, boolean inTransaction) {
253 Either<InputDefinition, ResponseFormat> result = null;
254 org.openecomp.sdc.be.model.Component component = null;
258 Either<User, ResponseFormat> resp = validateUserExists(userId, "get input", false);
260 if (resp.isRight()) {
261 result = Either.right(resp.right().value());
265 ComponentParametersView componentParametersView = new ComponentParametersView();
266 componentParametersView.disableAll();
267 componentParametersView.setIgnoreInputs(false);
268 componentParametersView.setIgnoreUsers(false);
270 Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(componentId, componentType, componentParametersView);
272 if (validateComponent.isRight()) {
273 result = Either.right(validateComponent.right().value());
276 component = validateComponent.left().value();
278 if (shouldLockComp) {
279 Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, UPDATE_INPUT);
280 if (lockComponent.isRight()) {
281 result = Either.right(lockComponent.right().value());
286 Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
287 if (canWork.isRight()) {
288 result = Either.right(canWork.right().value());
292 Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
293 if (allDataTypes.isRight()) {
294 result = Either.right(allDataTypes.right().value());
298 Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
300 Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(input.getUniqueId())).findFirst();
302 ActionStatus actionStatus = ActionStatus.COMPONENT_NOT_FOUND;
303 log.debug("Failed to found input {} under component {}, error: {}", input.getUniqueId(), componentId, actionStatus.name());
304 result = Either.right(componentsUtils.getResponseFormat(actionStatus));
307 InputDefinition currentInput = op.get();
309 String innerType = null;
310 String propertyType = currentInput.getType();
311 ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
312 log.debug("The type of the property {} is {}", currentInput.getUniqueId(), propertyType);
314 if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) {
315 SchemaDefinition def = currentInput.getSchema();
317 log.debug("Schema doesn't exists for property of type {}", type);
318 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)));
320 PropertyDataDefinition propDef = def.getProperty();
321 if (propDef == null) {
322 log.debug("Property in Schema Definition inside property of type {} doesn't exist", type);
323 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)));
325 innerType = propDef.getType();
327 // Specific Update Logic
329 Either<Object, Boolean> isValid = propertyOperation.validateAndUpdatePropertyValue(propertyType, input.getDefaultValue(), true, innerType, allDataTypes.left().value());
331 String newValue = currentInput.getDefaultValue();
332 if (isValid.isRight()) {
333 Boolean res = isValid.right().value();
335 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(TitanOperationStatus.ILLEGAL_ARGUMENT))));
338 Object object = isValid.left().value();
339 if (object != null) {
340 newValue = object.toString();
344 currentInput.setDefaultValue(newValue);
346 Either<InputDefinition, StorageOperationStatus> status = toscaOperationFacade.updateInputOfComponent(component, currentInput);
348 if(status.isRight()){
349 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status.right().value());
350 result = Either.right(componentsUtils.getResponseFormat(actionStatus, ""));
355 result = Either.left(status.left().value());
362 if (false == inTransaction) {
364 if (result == null || result.isRight()) {
365 log.debug("Going to execute rollback on create group.");
368 log.debug("Going to execute commit on create group.");
374 if (shouldLockComp && component != null) {
375 graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
383 public Either<List<ComponentInstanceInput>, ResponseFormat> getInputsForComponentInput(String userId, String componentId, String inputId) {
384 Either<User, ResponseFormat> resp = validateUserExists(userId, "get Properties by input", false);
385 if (resp.isRight()) {
386 return Either.right(resp.right().value());
388 String parentId = componentId;
389 org.openecomp.sdc.be.model.Component component = null;
390 ComponentParametersView filters = new ComponentParametersView();
391 filters.disableAll();
392 filters.setIgnoreComponentInstances(false);
393 filters.setIgnoreInputs(false);
394 filters.setIgnoreComponentInstancesInputs(false);
395 filters.setIgnoreProperties(false);
397 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(parentId, filters);
399 if(getComponentEither.isRight()){
400 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
401 log.debug("Failed to found component {}, error: {}", parentId, actionStatus.name());
402 return Either.right(componentsUtils.getResponseFormat(actionStatus));
405 component = getComponentEither.left().value();
407 Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
409 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
410 log.debug("Failed to found input {} under component {}, error: {}", inputId, parentId, actionStatus.name());
411 return Either.right(componentsUtils.getResponseFormat(actionStatus));
414 return Either.left(getComponentInstanceInputsByInputId(component, inputId));
418 public Either<List<InputDefinition>, ResponseFormat> createMultipleInputs(String userId, String componentId, ComponentTypeEnum componentType, ComponentInstInputsMap componentInstInputsMapUi, boolean shouldLockComp, boolean inTransaction) {
420 Either<List<InputDefinition>, ResponseFormat> result = null;
421 org.openecomp.sdc.be.model.Component component = null;
423 Map<String, List<ComponentInstanceInput>> inputsValueToCreateMap = new HashMap<>();
424 Map<String, List<ComponentInstanceProperty>> propertiesToCreateMap = new HashMap<>();
425 Map<String, InputDefinition> inputsToCreate = new HashMap<>();
428 Either<User, ResponseFormat> resp = validateUserExists(userId, "get Properties by input", false);
430 if (resp.isRight()) {
431 result = Either.right(resp.right().value());
435 ComponentParametersView componentParametersView = new ComponentParametersView();
436 componentParametersView.disableAll();
437 componentParametersView.setIgnoreInputs(false);
438 componentParametersView.setIgnoreComponentInstancesInputs(false);
439 componentParametersView.setIgnoreComponentInstances(false);
440 componentParametersView.setIgnoreComponentInstancesProperties(false);
441 componentParametersView.setIgnoreUsers(false);
443 Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(componentId, componentType, componentParametersView);
445 if (validateComponent.isRight()) {
446 result = Either.right(validateComponent.right().value());
449 component = validateComponent.left().value();
451 if (shouldLockComp) {
452 Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, CREATE_INPUT);
453 if (lockComponent.isRight()) {
454 result = Either.right(lockComponent.right().value());
459 Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
460 if (canWork.isRight()) {
461 result = Either.right(canWork.right().value());
465 Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
466 if (allDataTypes.isRight()) {
467 result = Either.right(allDataTypes.right().value());
471 Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
472 Map<String, org.openecomp.sdc.be.model.Component> origComponentMap = new HashMap<>();
475 //////////////////////////////////////////////////////////////////////////////////////////////////////
477 List<InputDefinition> resList = new ArrayList<InputDefinition>();
478 Map<String, List<InputDefinition>> newInputsMap = componentInstInputsMapUi.getComponentInstanceInputsMap();
479 List<ComponentInstance> ciList = component.getComponentInstances();
480 if (newInputsMap != null && !newInputsMap.isEmpty()) {
482 for (Entry<String, List<InputDefinition>> entry : newInputsMap.entrySet()) {
483 List<ComponentInstanceInput> inputsValueToCreate = new ArrayList<>();
484 String compInstId = entry.getKey();
486 Optional<ComponentInstance> op = ciList.stream().filter(ci -> ci.getUniqueId().equals(compInstId)).findAny();
488 ActionStatus actionStatus = ActionStatus.INVALID_CONTENT;
489 log.debug("Failed to find component instance {} under component {}", compInstId, componentId);
490 result = Either.right(componentsUtils.getResponseFormat(actionStatus));
493 ComponentInstance ci = op.get();
494 String compInstname = ci.getNormalizedName();
495 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> origComponentEither = getOriginComponent(ci, origComponentMap);
496 if(origComponentEither.isRight()){
497 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(origComponentEither.right().value());
498 log.debug("Failed to create inputs value under component {}, error: {}", componentId, actionStatus.name());
499 result = Either.right(componentsUtils.getResponseFormat(actionStatus));
502 org.openecomp.sdc.be.model.Component origComponent = origComponentEither.left().value();
504 List<InputDefinition> inputs = entry.getValue();
506 if (inputs != null && !inputs.isEmpty()) {
508 for (InputDefinition input : inputs) {
510 StorageOperationStatus status = addInputsToComponent(componentId, inputsToCreate, allDataTypes.left().value(), resList, index, inputsValueToCreate, compInstId, compInstname, origComponent, input);
511 if(status != StorageOperationStatus.OK ){
512 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(status);
513 log.debug("Failed to create inputs value under component {}, error: {}", componentId, actionStatus.name());
514 result = Either.right(componentsUtils.getResponseFormat(actionStatus));
520 if(!inputsValueToCreate.isEmpty()){
521 inputsValueToCreateMap.put(compInstId, inputsValueToCreate);
527 Map<String, List<ComponentInstancePropInput>> newInputsPropsMap = componentInstInputsMapUi.getComponentInstanceProperties();
528 if (newInputsPropsMap != null && !newInputsPropsMap.isEmpty()) {
530 result = createInputsFromProperty(component, origComponentMap, inputsToCreate, propertiesToCreateMap, dataTypes, resList, newInputsPropsMap);
532 if (result.isRight()) {
533 log.debug("Failed to create inputs of resource for id {} error {}", component.getUniqueId(), result.right().value());
536 resList = result.left().value();
541 Either<List<InputDefinition>, StorageOperationStatus> assotiateInputsEither = toscaOperationFacade.addInputsToComponent(inputsToCreate, component.getUniqueId());
542 if(assotiateInputsEither.isRight()){
543 log.debug("Failed to create inputs under component {}. Status is {}", component.getUniqueId(), assotiateInputsEither.right().value());
544 result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(assotiateInputsEither.right().value())));
548 Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> assotiatePropsEither = toscaOperationFacade.addComponentInstancePropertiesToComponent(component, propertiesToCreateMap, component.getUniqueId());
549 if(assotiatePropsEither.isRight()){
550 log.debug("Failed to add inputs values under component {}. Status is {}", component.getUniqueId(), assotiateInputsEither.right().value());
551 result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(assotiateInputsEither.right().value())));
555 Either<Map<String, List<ComponentInstanceInput>>, StorageOperationStatus> addciInputsEither = toscaOperationFacade.addComponentInstanceInputsToComponent(component, inputsValueToCreateMap);
556 if(addciInputsEither.isRight()){
557 log.debug("Failed to add inputs values under component {}. Status is {}", component.getUniqueId(), assotiateInputsEither.right().value());
558 result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(assotiateInputsEither.right().value())));
565 result = Either.left(resList);
567 ///////////////////////////////////////////////////////////////////////////////////////////
571 if (false == inTransaction) {
573 if (result == null || result.isRight()) {
574 log.debug("Going to execute rollback on create group.");
577 log.debug("Going to execute commit on create group.");
583 if (shouldLockComp && component != null) {
584 graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
591 private StorageOperationStatus addInputsToComponent(String componentId, Map<String, InputDefinition> inputsToCreate, Map<String, DataTypeDefinition> allDataTypes, List<InputDefinition> resList, int index,
592 List<ComponentInstanceInput> inputsValueToCreate, String compInstId, String compInstname, org.openecomp.sdc.be.model.Component origComponent, InputDefinition input) {
594 Either<List<InputDefinition>, ResponseFormat> result;
595 String innerType = null;
596 InputDefinition oldInput = origComponent.getInputs().stream().filter(ciIn -> ciIn.getUniqueId().equals(input.getUniqueId())).findAny().get();
597 String serviceInputName = compInstname + "_" + input.getName();
598 input.setName(serviceInputName);
600 JSONObject jobject = new JSONObject();
601 jobject.put(GET_INPUT, input.getName());
603 ComponentInstanceInput inputValue = new ComponentInstanceInput(oldInput, jobject.toJSONString(), null);
605 Either<String, StorageOperationStatus> validatevalueEiter = validateInputValueBeforeCreate(inputValue, jobject.toJSONString(), false, innerType, allDataTypes);
606 if (validatevalueEiter.isRight()) {
608 return validatevalueEiter.right().value();
611 String uniqueId = UniqueIdBuilder.buildResourceInstanceInputValueUid(compInstId, index++);
612 inputValue.setUniqueId(uniqueId);
613 inputValue.setValue(validatevalueEiter.left().value());
616 input.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(componentId, input.getName()));
617 input.setSchema(oldInput.getSchema());
618 input.setDefaultValue(oldInput.getDefaultValue());
619 input.setConstraints(oldInput.getConstraints());
620 input.setDescription(oldInput.getDescription());
621 input.setHidden(oldInput.isHidden());
622 input.setImmutable(oldInput.isImmutable());
623 input.setDefinition(oldInput.isDefinition());
624 input.setRequired(oldInput.isRequired());
625 input.setOwnerId(null);
626 input.setParentUniqueId(null);
627 inputsToCreate.put(input.getName(), input);
631 List<GetInputValueDataDefinition> getInputValues = new ArrayList<>();
632 GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition();
633 getInputValueDataDefinition.setInputId(input.getUniqueId());
634 getInputValueDataDefinition.setInputName(input.getName());
635 getInputValues.add(getInputValueDataDefinition);
636 inputValue.setGetInputValues(getInputValues);
638 inputsValueToCreate.add(inputValue);
639 input.setInputs(inputsValueToCreate);
642 return StorageOperationStatus.OK;
645 public Either<List<InputDefinition>, ResponseFormat> createInputs(String componentId, String userId, ComponentTypeEnum componentType, List<InputDefinition> inputsDefinitions, boolean shouldLockComp, boolean inTransaction) {
647 Either<List<InputDefinition>, ResponseFormat> result = null;
649 org.openecomp.sdc.be.model.Component component = null;
652 if (inputsDefinitions != null && false == inputsDefinitions.isEmpty()) {
654 if (shouldLockComp == true && inTransaction == true) {
655 BeEcompErrorManager.getInstance().logInternalFlowError("createGroups", "Cannot lock component since we are inside a transaction", ErrorSeverity.ERROR);
656 // Cannot lock component since we are in a middle of another
658 ActionStatus actionStatus = ActionStatus.INVALID_CONTENT;
659 result = Either.right(componentsUtils.getResponseFormat(actionStatus));
663 Either<User, ResponseFormat> validateUserExists = validateUserExists(userId, CREATE_INPUT, true);
664 if (validateUserExists.isRight()) {
665 result = Either.right(validateUserExists.right().value());
669 User user = validateUserExists.left().value();
671 Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(componentId, componentType, null);
672 if (validateComponent.isRight()) {
673 result = Either.right(validateComponent.right().value());
676 component = validateComponent.left().value();
678 if (shouldLockComp) {
679 Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, CREATE_INPUT);
680 if (lockComponent.isRight()) {
681 return Either.right(lockComponent.right().value());
685 Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
686 if (canWork.isRight()) {
687 result = Either.right(canWork.right().value());
690 Map<String, InputDefinition> inputs = inputsDefinitions.stream().collect(Collectors.toMap( o -> o.getName(), o -> o));
692 result = createInputsInGraph(inputs, component, user, inTransaction);
699 if (false == inTransaction) {
701 if (result == null || result.isRight()) {
702 log.debug("Going to execute rollback on create group.");
705 log.debug("Going to execute commit on create group.");
711 if (shouldLockComp && component != null) {
712 graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
719 public Either<List<InputDefinition>, ResponseFormat> createInputsInGraph(Map<String, InputDefinition> inputs, org.openecomp.sdc.be.model.Component component, User user, boolean inTransaction) {
721 List<InputDefinition> resList = inputs.values().stream().collect(Collectors.toList());
722 Either<List<InputDefinition>, ResponseFormat> result = Either.left(resList);
723 List<InputDefinition> resourceProperties = component.getInputs();
725 if(inputs != null && !inputs.isEmpty()){
726 Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
727 if (allDataTypes.isRight()) {
728 return Either.right(allDataTypes.right().value());
731 Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
733 for (Map.Entry<String, InputDefinition> inputDefinition : inputs.entrySet()) {
734 String inputName = inputDefinition.getKey();
735 inputDefinition.getValue().setName(inputName);
737 Either<InputDefinition, ResponseFormat> preparedInputEither = prepareAndValidateInputBeforeCreate(inputDefinition.getValue(), dataTypes);
738 if(preparedInputEither.isRight()){
739 return Either.right(preparedInputEither.right().value());
743 if (resourceProperties != null) {
744 Map<String, InputDefinition> generatedInputs = resourceProperties.stream().collect(Collectors.toMap(i -> i.getName(), i -> i));
745 Either<Map<String, InputDefinition>, String> mergeEither = ToscaDataDefinition.mergeDataMaps(generatedInputs, inputs);
746 if(mergeEither.isRight()){
747 return Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_ALREADY_EXIST, mergeEither.right().value()));
749 inputs = mergeEither.left().value();
752 Either<List<InputDefinition>, StorageOperationStatus> assotiateInputsEither = toscaOperationFacade.createAndAssociateInputs(inputs, component.getUniqueId());
753 if(assotiateInputsEither.isRight()){
754 log.debug("Failed to create inputs under component {}. Status is {}", component.getUniqueId(), assotiateInputsEither.right().value());
755 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(assotiateInputsEither.right().value())));
757 result = Either.left(assotiateInputsEither.left().value());
766 * Delete input from service
768 * @param componentType
775 public Either<InputDefinition, ResponseFormat> deleteInput(String componentType, String componentId, String userId, String inputId) {
777 Either<InputDefinition, ResponseFormat> deleteEither = null;
778 if (log.isDebugEnabled())
779 log.debug("Going to delete input id: {}", inputId);
781 // Validate user (exists)
782 Either<User, ResponseFormat> userEither = validateUserExists(userId, "Delete input", true);
783 if (userEither.isRight()) {
784 deleteEither = Either.right(userEither.right().value());
788 // Get component using componentType, componentId
790 ComponentParametersView componentParametersView = new ComponentParametersView();
791 componentParametersView.disableAll();
792 componentParametersView.setIgnoreInputs(false);
793 componentParametersView.setIgnoreComponentInstances(false);
794 componentParametersView.setIgnoreComponentInstancesInputs(false);
795 componentParametersView.setIgnoreComponentInstancesProperties(false);
796 componentParametersView.setIgnoreUsers(false);
798 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentEither = toscaOperationFacade.getToscaElement(componentId, componentParametersView);
799 if (componentEither.isRight()) {
800 deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(componentEither.right().value())));
803 org.openecomp.sdc.be.model.Component component = componentEither.left().value();
805 // Validate inputId is child of the component
806 Optional<InputDefinition> optionalInput = component.getInputs().stream().
808 filter(input -> input.getUniqueId().equals(inputId)).
811 if (!optionalInput.isPresent()) {
812 return Either.right(componentsUtils.getResponseFormat(ActionStatus.INPUT_IS_NOT_CHILD_OF_COMPONENT, inputId, componentId));
815 InputDefinition inputForDelete = optionalInput.get();
818 Either<Boolean, ResponseFormat> lockResultEither = lockComponent(componentId, component, "deleteInput");
819 if (lockResultEither.isRight()) {
820 ResponseFormat responseFormat = lockResultEither.right().value();
821 deleteEither = Either.right(responseFormat);
825 // Delete input operations
827 StorageOperationStatus status = toscaOperationFacade.deleteInputOfResource(component, inputForDelete.getName());
828 if(status != StorageOperationStatus.OK){
829 log.debug("Component id: {} delete input id: {} failed", componentId, inputId);
830 deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), component.getName()));
834 List<ComponentInstanceInput> inputsValue= getComponentInstanceInputsByInputId(component, inputId);
835 Map<String, List<ComponentInstanceInput>> insInputsMatToDelete = new HashMap<>();
837 if(inputsValue != null && !inputsValue.isEmpty()){
838 for(ComponentInstanceInput inputValue: inputsValue){
839 List<ComponentInstanceInput> inputList = null;
840 String ciId = inputValue.getComponentInstanceId();
841 if(!insInputsMatToDelete.containsKey(ciId)){
842 inputList = new ArrayList<>();
844 inputList = insInputsMatToDelete.get(ciId);
846 inputList.add(inputValue);
847 insInputsMatToDelete.put(ciId, inputList);
849 status = toscaOperationFacade.deleteComponentInstanceInputsToComponent(insInputsMatToDelete, component.getUniqueId());
850 if(status != StorageOperationStatus.OK){
851 log.debug("Component id: {} delete component instance input id: {} failed", componentId, inputId);
852 deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), component.getName()));
857 // US848813 delete service input that relates to VL / CP property
859 List<ComponentInstanceProperty> propertiesValue = getComponentInstancePropertiesByInputId(component, inputId);
860 if(propertiesValue != null && !propertiesValue.isEmpty()){
861 //propertyList = propertyValueStatus.left().value();
862 for(ComponentInstanceProperty propertyValue: propertiesValue){
864 String value = propertyValue.getValue();
865 Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(value);
867 resetInputName(mappedToscaTemplate, inputForDelete.getName());
870 if(!mappedToscaTemplate.isEmpty())
871 value = gson.toJson(mappedToscaTemplate);
872 propertyValue.setValue(value);
873 String compInstId = propertyValue.getComponentInstanceId();
874 propertyValue.setRules(null);
875 List<GetInputValueDataDefinition> getInputsValues = propertyValue.getGetInputValues();
876 if(getInputsValues != null && !getInputsValues.isEmpty()){
877 Optional<GetInputValueDataDefinition> op = getInputsValues.stream().filter(gi -> gi.getInputId().equals(inputForDelete.getUniqueId())).findAny();
879 getInputsValues.remove(op.get());
882 propertyValue.setGetInputValues(getInputsValues);
883 if(status != StorageOperationStatus.OK){
884 log.debug("Component id: {} delete component instance property {} id: {} failed", componentId, propertyValue.getUniqueId(), inputId);
885 deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), component.getName()));
888 Either<String, TitanOperationStatus> findDefaultValue = propertyOperation.findDefaultValueFromSecondPosition(propertyValue.getPath(), propertyValue.getUniqueId(), propertyValue.getDefaultValue());
889 if (findDefaultValue.isRight()) {
890 deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(findDefaultValue.right().value()))));
894 String defaultValue = findDefaultValue.left().value();
895 propertyValue.setDefaultValue(defaultValue);
896 log.debug("The returned default value in ResourceInstanceProperty is {}", defaultValue);
897 status = toscaOperationFacade.updateComponentInstanceProperty(component, compInstId, propertyValue);
898 if(status != StorageOperationStatus.OK){
899 log.debug("Component id: {} update component instance property {} id: {} failed", componentId, propertyValue.getUniqueId(), inputId);
900 deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), component.getName()));
908 deleteEither = Either.left(inputForDelete);
911 if (deleteEither == null || deleteEither.isRight()) {
912 log.debug("Component id: {} delete input id: {} failed", componentId, inputId);
915 log.debug("Component id: {} delete input id: {} success", componentId, inputId);
918 unlockComponent(deleteEither, component);
922 private Either<InputDefinition, ResponseFormat> prepareAndValidateInputBeforeCreate(InputDefinition newInputDefinition, Map<String, DataTypeDefinition> dataTypes) {
925 // validate input default values
926 Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(newInputDefinition, dataTypes);
927 if (defaultValuesValidation.isRight()) {
928 return Either.right(defaultValuesValidation.right().value());
931 ToscaPropertyType type = getType(newInputDefinition.getType());
933 PropertyValueConverter converter = type.getConverter();
935 String innerType = null;
936 if (newInputDefinition != null) {
937 SchemaDefinition schema = newInputDefinition.getSchema();
938 if (schema != null) {
939 PropertyDataDefinition prop = schema.getProperty();
941 innerType = prop.getType();
944 String convertedValue = null;
945 if (newInputDefinition.getDefaultValue() != null) {
946 convertedValue = converter.convert(newInputDefinition.getDefaultValue(), innerType, dataTypes);
947 newInputDefinition.setDefaultValue(convertedValue);
951 return Either.left(newInputDefinition);
954 public boolean isInputExist(List<InputDefinition> inputs, String resourceUid, String inputName) {
956 if (inputs == null) {
960 for (InputDefinition propertyDefinition : inputs) {
961 String parentUniqueId = propertyDefinition.getParentUniqueId();
962 String name = propertyDefinition.getName();
964 if (parentUniqueId.equals(resourceUid) && name.equals(inputName)) {
974 public Either<InputDefinition, ResponseFormat> getInputsAndPropertiesForComponentInput(String userId, String componentId, String inputId, boolean inTransaction) {
975 Either<InputDefinition, ResponseFormat> result = null;
978 Either<User, ResponseFormat> resp = validateUserExists(userId, "get Properties by input", false);
979 if (resp.isRight()) {
980 return Either.right(resp.right().value());
982 Either<List<ComponentInstanceProperty>, StorageOperationStatus> propertiesEitherRes = null;
984 ComponentParametersView filters = new ComponentParametersView();
985 filters.disableAll();
986 filters.setIgnoreComponentInstances(false);
987 filters.setIgnoreInputs(false);
988 filters.setIgnoreComponentInstancesInputs(false);
989 filters.setIgnoreComponentInstancesProperties(false);
990 filters.setIgnoreProperties(false);
991 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters);
992 if(getComponentEither.isRight()){
993 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
994 log.debug("Failed to found component {}, error: {}", componentId, actionStatus.name());
995 return Either.right(componentsUtils.getResponseFormat(actionStatus));
998 org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
999 Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
1000 if(!op.isPresent()){
1001 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
1002 log.debug("Failed to found input {} under component {}, error: {}", inputId, componentId, actionStatus.name());
1003 return Either.right(componentsUtils.getResponseFormat(actionStatus));
1006 InputDefinition resObj = op.get();
1008 List<ComponentInstanceInput> inputCIInput = getComponentInstanceInputsByInputId(component, inputId) ;
1010 resObj.setInputs(inputCIInput);
1013 List<ComponentInstanceProperty> inputProps = getComponentInstancePropertiesByInputId(component, inputId) ;
1015 resObj.setProperties(inputProps);
1018 result = Either.left(resObj);
1024 if (false == inTransaction) {
1026 if (result == null || result.isRight()) {
1027 log.debug("Going to execute rollback on create group.");
1028 titanDao.rollback();
1030 log.debug("Going to execute commit on create group.");
1040 private List<ComponentInstanceProperty> getComponentInstancePropertiesByInputId(org.openecomp.sdc.be.model.Component component, String inputId){
1041 List<ComponentInstanceProperty> resList = new ArrayList<>();
1042 Map<String, List<ComponentInstanceProperty>> ciPropertiesMap = component.getComponentInstancesProperties();
1043 if(ciPropertiesMap != null && !ciPropertiesMap.isEmpty()){
1044 ciPropertiesMap.forEach(new BiConsumer<String, List<ComponentInstanceProperty>>() {
1046 public void accept(String s, List<ComponentInstanceProperty> ciPropList) {
1048 Optional<ComponentInstance> ciOp = component.getComponentInstances().stream().filter(ci ->ci.getUniqueId().equals(s)).findAny();
1049 if(ciOp.isPresent())
1050 ciName = ciOp.get().getName();
1051 if (ciPropList != null && !ciPropList.isEmpty()) {
1052 for(ComponentInstanceProperty prop: ciPropList){
1053 List<GetInputValueDataDefinition> inputsValues = prop.getGetInputValues();
1054 if(inputsValues != null && !inputsValues.isEmpty()){
1055 for(GetInputValueDataDefinition inputData: inputsValues){
1056 if(inputData.getInputId().equals(inputId) || (inputData.getGetInputIndex() != null && inputData.getGetInputIndex().getInputId().equals(inputId))){
1057 prop.setComponentInstanceId(s);
1058 prop.setComponentInstanceName(ciName);
1074 private List<ComponentInstanceInput> getComponentInstanceInputsByInputId(org.openecomp.sdc.be.model.Component component, String inputId){
1075 List<ComponentInstanceInput> resList = new ArrayList<>();
1076 Map<String, List<ComponentInstanceInput>> ciInputsMap = component.getComponentInstancesInputs();
1077 if(ciInputsMap != null && !ciInputsMap.isEmpty()){
1078 ciInputsMap.forEach(new BiConsumer<String, List<ComponentInstanceInput>>() {
1080 public void accept(String s, List<ComponentInstanceInput> ciPropList) {
1082 Optional<ComponentInstance> ciOp = component.getComponentInstances().stream().filter(ci ->ci.getUniqueId().equals(s)).findAny();
1083 if(ciOp.isPresent())
1084 ciName = ciOp.get().getName();
1085 if (ciPropList != null && !ciPropList.isEmpty()) {
1086 for(ComponentInstanceInput prop: ciPropList){
1087 List<GetInputValueDataDefinition> inputsValues = prop.getGetInputValues();
1088 if(inputsValues != null && !inputsValues.isEmpty()){
1089 for(GetInputValueDataDefinition inputData: inputsValues){
1090 if(inputData.getInputId().equals(inputId) || (inputData.getGetInputIndex() != null && inputData.getGetInputIndex().getInputId().equals(inputId))){
1091 prop.setComponentInstanceId(s);
1092 prop.setComponentInstanceName(ciName);
1108 private Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getOriginComponent(ComponentInstance ci, Map<String, org.openecomp.sdc.be.model.Component> origComponentMap){
1109 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> result = null;
1110 String compInstname = ci.getNormalizedName();
1112 ComponentParametersView componentParametersView = new ComponentParametersView();
1113 componentParametersView.disableAll();
1114 componentParametersView.setIgnoreInputs(false);
1115 org.openecomp.sdc.be.model.Component origComponent = null;
1116 if(!origComponentMap.containsKey(ci.getComponentUid())){
1117 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentFound = toscaOperationFacade.getToscaElement(ci.getComponentUid(), componentParametersView);
1119 if (componentFound.isRight()) {
1120 result = Either.right(componentFound.right().value());
1123 origComponent = componentFound.left().value();
1124 origComponentMap.put(origComponent.getUniqueId(), origComponent);
1126 origComponent = origComponentMap.get(ci.getComponentUid());
1128 result = Either.left(origComponent);
1134 private Either<List<InputDefinition>, ResponseFormat> createInputsFromProperty(org.openecomp.sdc.be.model.Component component, Map<String, org.openecomp.sdc.be.model.Component> origComponentMap, Map<String, InputDefinition> inputsToCreate, Map<String, List<ComponentInstanceProperty>> propertiesToCreateMap, Map<String, DataTypeDefinition> dataTypes, List<InputDefinition> resList, Map<String, List<ComponentInstancePropInput>> newInputsPropsMap) {
1135 List<ComponentInstance> ciList = component.getComponentInstances();
1136 String componentId = component.getUniqueId();
1137 for (Entry<String, List<ComponentInstancePropInput>> entry : newInputsPropsMap.entrySet()) {
1138 List<ComponentInstanceProperty> propertiesToCreate = new ArrayList<>();
1139 String compInstId = entry.getKey();
1140 List<ComponentInstancePropInput> properties = entry.getValue();
1142 Optional<ComponentInstance> op = ciList.stream().filter(ci -> ci.getUniqueId().equals(compInstId)).findAny();
1143 if(!op.isPresent()){
1144 ActionStatus actionStatus = ActionStatus.INVALID_CONTENT;
1145 log.debug("Failed to find component instance {} under component {}", compInstId, componentId);
1146 return Either.right(componentsUtils.getResponseFormat(actionStatus));
1149 ComponentInstance ci = op.get();
1150 String compInstname = ci.getNormalizedName();
1151 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> origComponentEither = getOriginComponent(ci, origComponentMap);
1152 if(origComponentEither.isRight()){
1153 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(origComponentEither.right().value());
1154 log.debug("Failed to create inputs value under component {}, error: {}", componentId, actionStatus.name());
1155 return Either.right(componentsUtils.getResponseFormat(actionStatus));
1158 org.openecomp.sdc.be.model.Component origComponent = origComponentEither.left().value();
1161 //String originType = (String) titanGenericDao.getProperty(originVertex, GraphPropertiesDictionary.LABEL.getProperty());
1163 String inputName = compInstname;
1165 if (properties != null && !properties.isEmpty()) {
1166 for (ComponentInstancePropInput propInput : properties) {
1167 propInput.setOwnerId(null);
1168 propInput.setParentUniqueId(null);
1169 Either<InputDefinition, StorageOperationStatus> createInputRes = createInputForComponentInstance(component, origComponent,ci, inputsToCreate, propertiesToCreate, dataTypes, inputName, propInput);
1171 if (createInputRes.isRight()) {
1172 log.debug("Failed to create input of resource instance for id {} error {}", compInstId, createInputRes.right().value());
1173 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(createInputRes.right().value())));
1177 resList.add(createInputRes.left().value());
1180 propertiesToCreateMap.put(compInstId, propertiesToCreate);
1184 return Either.left(resList);
1187 private Either<InputDefinition, StorageOperationStatus> createInputForComponentInstance(org.openecomp.sdc.be.model.Component component,org.openecomp.sdc.be.model.Component orignComponent, ComponentInstance ci, Map<String, InputDefinition> inputsToCreate, List<ComponentInstanceProperty> propertiesToCreate, Map<String, DataTypeDefinition> dataTypes, String inputName, ComponentInstancePropInput propInput) {
1188 String propertiesName = propInput.getPropertiesName() ;
1189 PropertyDefinition selectedProp = propInput.getInput();
1190 String[] parsedPropNames = propInput.getParsedPropNames();
1192 if(parsedPropNames != null){
1193 for(String str: parsedPropNames){
1194 inputName += "_" + str;
1197 inputName += "_" + propInput.getName();
1200 InputDefinition input = null;
1201 ComponentInstanceProperty prop = propInput;
1203 if(propertiesName != null && !propertiesName.isEmpty() && selectedProp != null){
1204 input = new InputDefinition(selectedProp);
1206 input = new InputDefinition(prop);
1207 input.setName(inputName + "_" + prop.getName());
1210 input.setName(inputName);
1211 input.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(component.getUniqueId(), input.getName()));
1212 input.setInputPath(propertiesName);
1214 JSONObject jobject = new JSONObject();
1217 if(prop.getValue() == null || prop.getValue().isEmpty()){
1218 if(propertiesName != null && !propertiesName.isEmpty() && selectedProp != null){
1220 jobject = createJSONValueForProperty(parsedPropNames.length -1, parsedPropNames, jobject, inputName);
1221 prop.setValue(jobject.toJSONString());
1225 jobject.put(GET_INPUT, input.getName());
1226 prop.setValue(jobject.toJSONString());
1232 String value = prop.getValue();
1233 Object objValue = new Yaml().load(value);
1234 if( objValue instanceof Map || objValue instanceof List ){
1235 if(propertiesName == null ||propertiesName.isEmpty()){
1236 jobject.put(GET_INPUT, input.getName());
1237 prop.setValue(jobject.toJSONString());
1238 prop.setRules(null);
1241 Map<String, Object> mappedToscaTemplate = (Map<String, Object>) objValue;
1242 createInputValue(mappedToscaTemplate, 1, parsedPropNames, inputName);
1244 String json = gson.toJson(mappedToscaTemplate);
1245 prop.setValue(json);
1246 prop.setRules(null);
1250 jobject.put(GET_INPUT, input.getName());
1251 prop.setValue(jobject.toJSONString());
1252 prop.setRules(null);
1256 prop.setComponentInstanceId(ci.getUniqueId());
1257 prop.setComponentInstanceName(ci.getName());
1259 List<GetInputValueDataDefinition> getInputValues = new ArrayList<>();
1260 GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition();
1261 getInputValueDataDefinition.setInputId(input.getUniqueId());
1262 getInputValueDataDefinition.setInputName(input.getName());
1263 getInputValues.add(getInputValueDataDefinition);
1264 prop.setGetInputValues(getInputValues);
1266 propertiesToCreate.add(prop);
1268 inputsToCreate.put(input.getName(), input);
1270 List<ComponentInstanceProperty> propertiesList = new ArrayList<>(); // adding the property with the new value for UI
1271 propertiesList.add(prop);
1272 input.setProperties(propertiesList);
1274 return Either.left(input);
1278 private JSONObject createJSONValueForProperty (int i, String [] parsedPropNames, JSONObject ooj, String inputName){
1281 if( i == parsedPropNames.length -1){
1282 JSONObject jobProp = new JSONObject();
1283 jobProp.put(GET_INPUT, inputName);
1284 ooj.put(parsedPropNames[i], jobProp);
1286 return createJSONValueForProperty (i, parsedPropNames, ooj, inputName);
1288 JSONObject res = new JSONObject();
1289 res.put(parsedPropNames[i], ooj);
1291 res = createJSONValueForProperty (i, parsedPropNames, res, inputName);
1299 public void resetInputName(Map<String, Object> lhm1, String inputName){
1300 for (Map.Entry<String, Object> entry : lhm1.entrySet()) {
1301 String key = entry.getKey();
1302 Object value = entry.getValue();
1303 if (value instanceof String && ((String) value).equalsIgnoreCase(inputName) && key.equals(GET_INPUT)) {
1306 } else if (value instanceof Map) {
1307 Map<String, Object> subMap = (Map<String, Object>)value;
1308 resetInputName(subMap, inputName);
1316 private Map<String, Object> createInputValue(Map<String, Object> lhm1, int index, String[] inputNames, String inputName){
1317 while(index < inputNames.length){
1318 if(lhm1.containsKey(inputNames[index])){
1319 Object value = lhm1.get(inputNames[index]);
1320 if (value instanceof Map){
1321 if(index == inputNames.length -1){
1322 ((Map) value).put(GET_INPUT, inputName);
1323 return ((Map) value);
1327 return createInputValue((Map)value, index, inputNames, inputName);
1330 Map<String, Object> jobProp = new HashMap<>();
1331 if(index == inputNames.length -1){
1332 jobProp.put(GET_INPUT, inputName);
1333 lhm1.put(inputNames[index], jobProp);
1336 lhm1.put(inputNames[index], jobProp);
1338 return createInputValue(jobProp, index, inputNames, inputName);
1342 Map<String, Object> jobProp = new HashMap<>();
1343 lhm1.put(inputNames[index], jobProp);
1344 if(index == inputNames.length -1){
1345 jobProp.put(GET_INPUT, inputName);
1349 return createInputValue(jobProp, index, inputNames, inputName);