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.Collections;
25 import java.util.HashMap;
26 import java.util.List;
28 import java.util.Optional;
29 import java.util.Map.Entry;
30 import java.util.function.BiConsumer;
31 import java.util.stream.Collectors;
33 import org.json.simple.JSONObject;
34 import org.openecomp.sdc.be.components.validation.ComponentValidations;
35 import org.openecomp.sdc.be.config.BeEcompErrorManager;
36 import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
37 import org.openecomp.sdc.be.dao.api.ActionStatus;
38 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
39 import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
40 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
41 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
42 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
43 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
44 import org.openecomp.sdc.be.model.ComponentInstInputsMap;
45 import org.openecomp.sdc.be.model.ComponentInstance;
46 import org.openecomp.sdc.be.model.ComponentInstanceInput;
47 import org.openecomp.sdc.be.model.ComponentInstancePropInput;
48 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
49 import org.openecomp.sdc.be.model.ComponentParametersView;
50 import org.openecomp.sdc.be.model.DataTypeDefinition;
51 import org.openecomp.sdc.be.model.InputDefinition;
52 import org.openecomp.sdc.be.model.PropertyDefinition;
53 import org.openecomp.sdc.be.model.User;
55 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
56 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
57 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
58 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
59 import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
60 import org.openecomp.sdc.exception.ResponseFormat;
61 import org.slf4j.Logger;
62 import org.slf4j.LoggerFactory;
63 import org.springframework.stereotype.Component;
64 import org.yaml.snakeyaml.Yaml;
66 import com.google.gson.Gson;
68 import fj.data.Either;
70 @Component("inputsBusinessLogic")
71 public class InputsBusinessLogic extends BaseBusinessLogic {
73 private static final String CREATE_INPUT = "CreateInput";
74 private static final String UPDATE_INPUT = "UpdateInput";
76 private static Logger log = LoggerFactory.getLogger(InputsBusinessLogic.class.getName());
78 private static final String GET_INPUT = "get_input";
80 private static String ASSOCIATING_INPUT_TO_PROP = "AssociatingInputToComponentInstanceProperty";
81 private Gson gson = new Gson();
85 * associate inputs to a given component with paging
93 public Either<List<InputDefinition>, ResponseFormat> getInputs(String userId, String componentId, String fromName, int amount) {
95 Either<User, ResponseFormat> resp = validateUserExists(userId, "get Inputs", false);
98 return Either.right(resp.right().value());
102 ComponentParametersView filters = new ComponentParametersView();
103 filters.disableAll();
104 filters.setIgnoreInputs(false);
106 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters);
107 if(getComponentEither.isRight()){
108 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
109 log.debug("Failed to found component {}, error: {}", componentId, actionStatus.name());
110 return Either.right(componentsUtils.getResponseFormat(actionStatus));
113 org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
114 List<InputDefinition> inputs = component.getInputs();
116 return Either.left(inputs);
120 public Either<List<ComponentInstanceInput>, ResponseFormat> getComponentInstanceInputs(String userId, String componentId, String componentInstanceId) {
122 Either<User, ResponseFormat> resp = validateUserExists(userId, "get Inputs", false);
124 if (resp.isRight()) {
125 return Either.right(resp.right().value());
129 ComponentParametersView filters = new ComponentParametersView();
130 filters.disableAll();
131 filters.setIgnoreInputs(false);
132 filters.setIgnoreComponentInstances(false);
133 filters.setIgnoreComponentInstancesInputs(false);
135 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters);
136 if(getComponentEither.isRight()){
137 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
138 log.debug("Failed to found component {}, error: {}", componentId, actionStatus.name());
139 return Either.right(componentsUtils.getResponseFormat(actionStatus));
142 org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
144 if(!ComponentValidations.validateComponentInstanceExist(component, componentInstanceId)){
145 ActionStatus actionStatus = ActionStatus.COMPONENT_INSTANCE_NOT_FOUND;
146 log.debug("Failed to found component instance inputs {}, error: {}", componentInstanceId, actionStatus.name());
147 return Either.right(componentsUtils.getResponseFormat(actionStatus));
149 Map<String, List<ComponentInstanceInput>> ciInputs = Optional.ofNullable(component.getComponentInstancesInputs()).orElse(Collections.emptyMap());
150 return Either.left(ciInputs.getOrDefault(componentInstanceId, Collections.emptyList()));
154 * associate properties to a given component instance input
162 public Either<List<ComponentInstanceProperty>, ResponseFormat> getComponentInstancePropertiesByInputId(String userId, String componentId, String instanceId, String inputId) {
163 Either<User, ResponseFormat> resp = validateUserExists(userId, "get Properties by input", false);
164 if (resp.isRight()) {
165 return Either.right(resp.right().value());
167 String parentId = componentId;
168 org.openecomp.sdc.be.model.Component component = null;
169 ComponentParametersView filters = new ComponentParametersView();
170 filters.disableAll();
171 filters.setIgnoreComponentInstances(false);
173 if(!instanceId.equals(inputId)){
176 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(parentId, filters);
178 if(getComponentEither.isRight()){
179 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
180 log.debug("Failed to found component {}, error: {}", parentId, actionStatus.name());
181 return Either.right(componentsUtils.getResponseFormat(actionStatus));
184 component = getComponentEither.left().value();
185 Optional<ComponentInstance> ciOp = component.getComponentInstances().stream().filter(ci ->ci.getUniqueId().equals(instanceId)).findAny();
186 if(ciOp.isPresent()){
187 parentId = ciOp.get().getComponentUid();
192 filters.setIgnoreInputs(false);
194 filters.setIgnoreComponentInstancesProperties(false);
195 filters.setIgnoreComponentInstancesInputs(false);
196 filters.setIgnoreProperties(false);
198 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(parentId, filters);
200 if(getComponentEither.isRight()){
201 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
202 log.debug("Failed to found component {}, error: {}", parentId, actionStatus.name());
203 return Either.right(componentsUtils.getResponseFormat(actionStatus));
206 component = getComponentEither.left().value();
208 Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
210 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
211 log.debug("Failed to found input {} under component {}, error: {}", inputId, parentId, actionStatus.name());
212 return Either.right(componentsUtils.getResponseFormat(actionStatus));
215 return Either.left(getComponentInstancePropertiesByInputId(component, inputId));
219 public Either<InputDefinition, ResponseFormat> updateInputValue(ComponentTypeEnum componentType, String componentId, InputDefinition input, String userId, boolean shouldLockComp, boolean inTransaction) {
221 Either<InputDefinition, ResponseFormat> result = null;
222 org.openecomp.sdc.be.model.Component component = null;
226 Either<User, ResponseFormat> resp = validateUserExists(userId, "get input", false);
228 if (resp.isRight()) {
229 result = Either.right(resp.right().value());
233 ComponentParametersView componentParametersView = new ComponentParametersView();
234 componentParametersView.disableAll();
235 componentParametersView.setIgnoreInputs(false);
236 componentParametersView.setIgnoreUsers(false);
238 Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(componentId, componentType, componentParametersView);
240 if (validateComponent.isRight()) {
241 result = Either.right(validateComponent.right().value());
244 component = validateComponent.left().value();
246 if (shouldLockComp) {
247 Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, UPDATE_INPUT);
248 if (lockComponent.isRight()) {
249 result = Either.right(lockComponent.right().value());
254 Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
255 if (canWork.isRight()) {
256 result = Either.right(canWork.right().value());
260 Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
261 if (allDataTypes.isRight()) {
262 result = Either.right(allDataTypes.right().value());
266 Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
268 Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(input.getUniqueId())).findFirst();
270 ActionStatus actionStatus = ActionStatus.COMPONENT_NOT_FOUND;
271 log.debug("Failed to found input {} under component {}, error: {}", input.getUniqueId(), componentId, actionStatus.name());
272 result = Either.right(componentsUtils.getResponseFormat(actionStatus));
275 InputDefinition currentInput = op.get();
277 String innerType = null;
278 String propertyType = currentInput.getType();
279 ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
280 log.debug("The type of the property {} is {}", currentInput.getUniqueId(), propertyType);
282 if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) {
283 SchemaDefinition def = currentInput.getSchema();
285 log.debug("Schema doesn't exists for property of type {}", type);
286 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)));
288 PropertyDataDefinition propDef = def.getProperty();
289 if (propDef == null) {
290 log.debug("Property in Schema Definition inside property of type {} doesn't exist", type);
291 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)));
293 innerType = propDef.getType();
295 // Specific Update Logic
297 Either<Object, Boolean> isValid = propertyOperation.validateAndUpdatePropertyValue(propertyType, input.getDefaultValue(), true, innerType, allDataTypes.left().value());
299 String newValue = currentInput.getDefaultValue();
300 if (isValid.isRight()) {
301 Boolean res = isValid.right().value();
303 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(TitanOperationStatus.ILLEGAL_ARGUMENT))));
306 Object object = isValid.left().value();
307 if (object != null) {
308 newValue = object.toString();
312 currentInput.setDefaultValue(newValue);
314 Either<InputDefinition, StorageOperationStatus> status = toscaOperationFacade.updateInputOfComponent(component, currentInput);
316 if(status.isRight()){
317 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status.right().value());
318 result = Either.right(componentsUtils.getResponseFormat(actionStatus, ""));
323 result = Either.left(status.left().value());
330 if (false == inTransaction) {
332 if (result == null || result.isRight()) {
333 log.debug("Going to execute rollback on create group.");
336 log.debug("Going to execute commit on create group.");
342 if (shouldLockComp && component != null) {
343 graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
351 public Either<List<ComponentInstanceInput>, ResponseFormat> getInputsForComponentInput(String userId, String componentId, String inputId) {
352 Either<User, ResponseFormat> resp = validateUserExists(userId, "get Properties by input", false);
353 if (resp.isRight()) {
354 return Either.right(resp.right().value());
356 String parentId = componentId;
357 org.openecomp.sdc.be.model.Component component = null;
358 ComponentParametersView filters = new ComponentParametersView();
359 filters.disableAll();
360 filters.setIgnoreComponentInstances(false);
361 filters.setIgnoreInputs(false);
362 filters.setIgnoreComponentInstancesInputs(false);
363 filters.setIgnoreProperties(false);
365 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(parentId, filters);
367 if(getComponentEither.isRight()){
368 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
369 log.debug("Failed to found component {}, error: {}", parentId, actionStatus.name());
370 return Either.right(componentsUtils.getResponseFormat(actionStatus));
373 component = getComponentEither.left().value();
375 Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
377 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
378 log.debug("Failed to found input {} under component {}, error: {}", inputId, parentId, actionStatus.name());
379 return Either.right(componentsUtils.getResponseFormat(actionStatus));
382 return Either.left(getComponentInstanceInputsByInputId(component, inputId));
386 public Either<List<InputDefinition>, ResponseFormat> createMultipleInputs(String userId, String componentId, ComponentTypeEnum componentType, ComponentInstInputsMap componentInstInputsMapUi, boolean shouldLockComp, boolean inTransaction) {
388 Either<List<InputDefinition>, ResponseFormat> result = null;
389 org.openecomp.sdc.be.model.Component component = null;
391 Map<String, List<ComponentInstanceInput>> inputsValueToCreateMap = new HashMap<>();
392 Map<String, List<ComponentInstanceProperty>> propertiesToCreateMap = new HashMap<>();
393 Map<String, InputDefinition> inputsToCreate = new HashMap<>();
396 Either<User, ResponseFormat> resp = validateUserExists(userId, "get Properties by input", false);
398 if (resp.isRight()) {
399 result = Either.right(resp.right().value());
403 ComponentParametersView componentParametersView = new ComponentParametersView();
404 componentParametersView.disableAll();
405 componentParametersView.setIgnoreInputs(false);
406 componentParametersView.setIgnoreComponentInstancesInputs(false);
407 componentParametersView.setIgnoreComponentInstances(false);
408 componentParametersView.setIgnoreComponentInstancesProperties(false);
409 componentParametersView.setIgnoreUsers(false);
411 Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(componentId, componentType, componentParametersView);
413 if (validateComponent.isRight()) {
414 result = Either.right(validateComponent.right().value());
417 component = validateComponent.left().value();
419 if (shouldLockComp) {
420 Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, CREATE_INPUT);
421 if (lockComponent.isRight()) {
422 result = Either.right(lockComponent.right().value());
427 Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
428 if (canWork.isRight()) {
429 result = Either.right(canWork.right().value());
433 Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
434 if (allDataTypes.isRight()) {
435 result = Either.right(allDataTypes.right().value());
439 Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
440 Map<String, org.openecomp.sdc.be.model.Component> origComponentMap = new HashMap<>();
443 //////////////////////////////////////////////////////////////////////////////////////////////////////
445 List<InputDefinition> resList = new ArrayList<InputDefinition>();
446 Map<String, List<InputDefinition>> newInputsMap = componentInstInputsMapUi.getComponentInstanceInputsMap();
447 List<ComponentInstance> ciList = component.getComponentInstances();
448 if (newInputsMap != null && !newInputsMap.isEmpty()) {
450 for (Entry<String, List<InputDefinition>> entry : newInputsMap.entrySet()) {
451 List<ComponentInstanceInput> inputsValueToCreate = new ArrayList<>();
452 String compInstId = entry.getKey();
454 Optional<ComponentInstance> op = ciList.stream().filter(ci -> ci.getUniqueId().equals(compInstId)).findAny();
456 ActionStatus actionStatus = ActionStatus.INVALID_CONTENT;
457 log.debug("Failed to find component instance {} under component {}", compInstId, componentId);
458 result = Either.right(componentsUtils.getResponseFormat(actionStatus));
461 ComponentInstance ci = op.get();
462 String compInstname = ci.getNormalizedName();
463 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> origComponentEither = getOriginComponent(ci, origComponentMap);
464 if(origComponentEither.isRight()){
465 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(origComponentEither.right().value());
466 log.debug("Failed to create inputs value under component {}, error: {}", componentId, actionStatus.name());
467 result = Either.right(componentsUtils.getResponseFormat(actionStatus));
470 org.openecomp.sdc.be.model.Component origComponent = origComponentEither.left().value();
472 List<InputDefinition> inputs = entry.getValue();
474 if (inputs != null && !inputs.isEmpty()) {
476 for (InputDefinition input : inputs) {
478 StorageOperationStatus status = addInputsToComponent(componentId, inputsToCreate, allDataTypes.left().value(), resList, index, inputsValueToCreate, compInstId, compInstname, origComponent, input);
479 if(status != StorageOperationStatus.OK ){
480 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(status);
481 log.debug("Failed to create inputs value under component {}, error: {}", componentId, actionStatus.name());
482 result = Either.right(componentsUtils.getResponseFormat(actionStatus));
488 if(!inputsValueToCreate.isEmpty()){
489 inputsValueToCreateMap.put(compInstId, inputsValueToCreate);
495 Map<String, List<ComponentInstancePropInput>> newInputsPropsMap = componentInstInputsMapUi.getComponentInstanceProperties();
496 if (newInputsPropsMap != null && !newInputsPropsMap.isEmpty()) {
498 result = createInputsFromProperty(component, origComponentMap, inputsToCreate, propertiesToCreateMap, dataTypes, resList, newInputsPropsMap);
500 if (result.isRight()) {
501 log.debug("Failed to create inputs of resource for id {} error {}", component.getUniqueId(), result.right().value());
504 resList = result.left().value();
509 Either<List<InputDefinition>, StorageOperationStatus> assotiateInputsEither = toscaOperationFacade.addInputsToComponent(inputsToCreate, component.getUniqueId());
510 if(assotiateInputsEither.isRight()){
511 log.debug("Failed to create inputs under component {}. Status is {}", component.getUniqueId(), assotiateInputsEither.right().value());
512 result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(assotiateInputsEither.right().value())));
516 Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> assotiatePropsEither = toscaOperationFacade.addComponentInstancePropertiesToComponent(component, propertiesToCreateMap, component.getUniqueId());
517 if(assotiatePropsEither.isRight()){
518 log.debug("Failed to add inputs values under component {}. Status is {}", component.getUniqueId(), assotiateInputsEither.right().value());
519 result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(assotiateInputsEither.right().value())));
523 Either<Map<String, List<ComponentInstanceInput>>, StorageOperationStatus> addciInputsEither = toscaOperationFacade.addComponentInstanceInputsToComponent(component, inputsValueToCreateMap);
524 if(addciInputsEither.isRight()){
525 log.debug("Failed to add inputs values under component {}. Status is {}", component.getUniqueId(), assotiateInputsEither.right().value());
526 result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(assotiateInputsEither.right().value())));
533 result = Either.left(resList);
535 ///////////////////////////////////////////////////////////////////////////////////////////
539 if (false == inTransaction) {
541 if (result == null || result.isRight()) {
542 log.debug("Going to execute rollback on create group.");
545 log.debug("Going to execute commit on create group.");
551 if (shouldLockComp && component != null) {
552 graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
559 private StorageOperationStatus addInputsToComponent(String componentId, Map<String, InputDefinition> inputsToCreate, Map<String, DataTypeDefinition> allDataTypes, List<InputDefinition> resList, int index,
560 List<ComponentInstanceInput> inputsValueToCreate, String compInstId, String compInstname, org.openecomp.sdc.be.model.Component origComponent, InputDefinition input) {
562 Either<List<InputDefinition>, ResponseFormat> result;
563 String innerType = null;
564 InputDefinition oldInput = origComponent.getInputs().stream().filter(ciIn -> ciIn.getUniqueId().equals(input.getUniqueId())).findAny().get();
565 String serviceInputName = compInstname + "_" + input.getName();
566 input.setName(serviceInputName);
568 JSONObject jobject = new JSONObject();
569 jobject.put(GET_INPUT, input.getName());
571 ComponentInstanceInput inputValue = new ComponentInstanceInput(oldInput, jobject.toJSONString(), null);
573 Either<String, StorageOperationStatus> validatevalueEiter = validateInputValueBeforeCreate(inputValue, jobject.toJSONString(), false, innerType, allDataTypes);
574 if (validatevalueEiter.isRight()) {
576 return validatevalueEiter.right().value();
579 String uniqueId = UniqueIdBuilder.buildResourceInstanceInputValueUid(compInstId, index++);
580 inputValue.setUniqueId(uniqueId);
581 inputValue.setValue(validatevalueEiter.left().value());
584 input.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(componentId, input.getName()));
585 input.setSchema(oldInput.getSchema());
586 input.setDefaultValue(oldInput.getDefaultValue());
587 input.setConstraints(oldInput.getConstraints());
588 input.setDescription(oldInput.getDescription());
589 input.setHidden(oldInput.isHidden());
590 input.setImmutable(oldInput.isImmutable());
591 input.setDefinition(oldInput.isDefinition());
592 input.setRequired(oldInput.isRequired());
593 input.setOwnerId(null);
594 input.setParentUniqueId(null);
595 inputsToCreate.put(input.getName(), input);
599 List<GetInputValueDataDefinition> getInputValues = new ArrayList<>();
600 GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition();
601 getInputValueDataDefinition.setInputId(input.getUniqueId());
602 getInputValueDataDefinition.setInputName(input.getName());
603 getInputValues.add(getInputValueDataDefinition);
604 inputValue.setGetInputValues(getInputValues);
606 inputsValueToCreate.add(inputValue);
607 input.setInputs(inputsValueToCreate);
610 return StorageOperationStatus.OK;
613 public Either<List<InputDefinition>, ResponseFormat> createInputs(String componentId, String userId, ComponentTypeEnum componentType, List<InputDefinition> inputsDefinitions, boolean shouldLockComp, boolean inTransaction) {
615 Either<List<InputDefinition>, ResponseFormat> result = null;
617 org.openecomp.sdc.be.model.Component component = null;
620 if (inputsDefinitions != null && false == inputsDefinitions.isEmpty()) {
622 if (shouldLockComp == true && inTransaction == true) {
623 BeEcompErrorManager.getInstance().logInternalFlowError("createGroups", "Cannot lock component since we are inside a transaction", ErrorSeverity.ERROR);
624 // Cannot lock component since we are in a middle of another
626 ActionStatus actionStatus = ActionStatus.INVALID_CONTENT;
627 result = Either.right(componentsUtils.getResponseFormat(actionStatus));
631 Either<User, ResponseFormat> validateUserExists = validateUserExists(userId, CREATE_INPUT, true);
632 if (validateUserExists.isRight()) {
633 result = Either.right(validateUserExists.right().value());
637 User user = validateUserExists.left().value();
639 Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(componentId, componentType, null);
640 if (validateComponent.isRight()) {
641 result = Either.right(validateComponent.right().value());
644 component = validateComponent.left().value();
646 if (shouldLockComp) {
647 Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, CREATE_INPUT);
648 if (lockComponent.isRight()) {
649 return Either.right(lockComponent.right().value());
653 Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
654 if (canWork.isRight()) {
655 result = Either.right(canWork.right().value());
658 Map<String, InputDefinition> inputs = inputsDefinitions.stream().collect(Collectors.toMap( o -> o.getName(), o -> o));
660 result = createInputsInGraph(inputs, component, user, inTransaction);
667 if (false == inTransaction) {
669 if (result == null || result.isRight()) {
670 log.debug("Going to execute rollback on create group.");
673 log.debug("Going to execute commit on create group.");
679 if (shouldLockComp && component != null) {
680 graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
687 public Either<List<InputDefinition>, ResponseFormat> createInputsInGraph(Map<String, InputDefinition> inputs, org.openecomp.sdc.be.model.Component component, User user, boolean inTransaction) {
689 List<InputDefinition> resList = inputs.values().stream().collect(Collectors.toList());
690 Either<List<InputDefinition>, ResponseFormat> result = Either.left(resList);
691 List<InputDefinition> resourceProperties = component.getInputs();
693 if(inputs != null && !inputs.isEmpty()){
694 Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
695 if (allDataTypes.isRight()) {
696 return Either.right(allDataTypes.right().value());
699 Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
701 for (Map.Entry<String, InputDefinition> inputDefinition : inputs.entrySet()) {
702 String inputName = inputDefinition.getKey();
703 inputDefinition.getValue().setName(inputName);
705 Either<InputDefinition, ResponseFormat> preparedInputEither = prepareAndValidateInputBeforeCreate(inputDefinition.getValue(), dataTypes);
706 if(preparedInputEither.isRight()){
707 return Either.right(preparedInputEither.right().value());
711 if (resourceProperties != null) {
712 Map<String, InputDefinition> generatedInputs = resourceProperties.stream().collect(Collectors.toMap(i -> i.getName(), i -> i));
713 Either<Map<String, InputDefinition>, String> mergeEither = ToscaDataDefinition.mergeDataMaps(generatedInputs, inputs);
714 if(mergeEither.isRight()){
715 return Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_ALREADY_EXIST, mergeEither.right().value()));
717 inputs = mergeEither.left().value();
720 Either<List<InputDefinition>, StorageOperationStatus> assotiateInputsEither = toscaOperationFacade.createAndAssociateInputs(inputs, component.getUniqueId());
721 if(assotiateInputsEither.isRight()){
722 log.debug("Failed to create inputs under component {}. Status is {}", component.getUniqueId(), assotiateInputsEither.right().value());
723 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(assotiateInputsEither.right().value())));
725 result = Either.left(assotiateInputsEither.left().value());
734 * Delete input from service
736 * @param componentType
743 public Either<InputDefinition, ResponseFormat> deleteInput(String componentType, String componentId, String userId, String inputId) {
745 Either<InputDefinition, ResponseFormat> deleteEither = null;
746 if (log.isDebugEnabled())
747 log.debug("Going to delete input id: {}", inputId);
749 // Validate user (exists)
750 Either<User, ResponseFormat> userEither = validateUserExists(userId, "Delete input", true);
751 if (userEither.isRight()) {
752 deleteEither = Either.right(userEither.right().value());
756 // Get component using componentType, componentId
758 ComponentParametersView componentParametersView = new ComponentParametersView();
759 componentParametersView.disableAll();
760 componentParametersView.setIgnoreInputs(false);
761 componentParametersView.setIgnoreComponentInstances(false);
762 componentParametersView.setIgnoreComponentInstancesInputs(false);
763 componentParametersView.setIgnoreComponentInstancesProperties(false);
764 componentParametersView.setIgnoreUsers(false);
766 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentEither = toscaOperationFacade.getToscaElement(componentId, componentParametersView);
767 if (componentEither.isRight()) {
768 deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(componentEither.right().value())));
771 org.openecomp.sdc.be.model.Component component = componentEither.left().value();
773 // Validate inputId is child of the component
774 Optional<InputDefinition> optionalInput = component.getInputs().stream().
776 filter(input -> input.getUniqueId().equals(inputId)).
779 if (!optionalInput.isPresent()) {
780 return Either.right(componentsUtils.getResponseFormat(ActionStatus.INPUT_IS_NOT_CHILD_OF_COMPONENT, inputId, componentId));
783 InputDefinition inputForDelete = optionalInput.get();
786 Either<Boolean, ResponseFormat> lockResultEither = lockComponent(componentId, component, "deleteInput");
787 if (lockResultEither.isRight()) {
788 ResponseFormat responseFormat = lockResultEither.right().value();
789 deleteEither = Either.right(responseFormat);
793 // Delete input operations
795 StorageOperationStatus status = toscaOperationFacade.deleteInputOfResource(component, inputForDelete.getName());
796 if(status != StorageOperationStatus.OK){
797 log.debug("Component id: {} delete input id: {} failed", componentId, inputId);
798 deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), component.getName()));
802 List<ComponentInstanceInput> inputsValue= getComponentInstanceInputsByInputId(component, inputId);
803 Map<String, List<ComponentInstanceInput>> insInputsMatToDelete = new HashMap<>();
805 if(inputsValue != null && !inputsValue.isEmpty()){
806 for(ComponentInstanceInput inputValue: inputsValue){
807 List<ComponentInstanceInput> inputList = null;
808 String ciId = inputValue.getComponentInstanceId();
809 if(!insInputsMatToDelete.containsKey(ciId)){
810 inputList = new ArrayList<>();
812 inputList = insInputsMatToDelete.get(ciId);
814 inputList.add(inputValue);
815 insInputsMatToDelete.put(ciId, inputList);
817 status = toscaOperationFacade.deleteComponentInstanceInputsToComponent(insInputsMatToDelete, component.getUniqueId());
818 if(status != StorageOperationStatus.OK){
819 log.debug("Component id: {} delete component instance input id: {} failed", componentId, inputId);
820 deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), component.getName()));
825 // US848813 delete service input that relates to VL / CP property
827 List<ComponentInstanceProperty> propertiesValue = getComponentInstancePropertiesByInputId(component, inputId);
828 if(propertiesValue != null && !propertiesValue.isEmpty()){
829 //propertyList = propertyValueStatus.left().value();
830 for(ComponentInstanceProperty propertyValue: propertiesValue){
832 String value = propertyValue.getValue();
833 Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(value);
835 resetInputName(mappedToscaTemplate, inputForDelete.getName());
838 if(!mappedToscaTemplate.isEmpty())
839 value = gson.toJson(mappedToscaTemplate);
840 propertyValue.setValue(value);
841 String compInstId = propertyValue.getComponentInstanceId();
842 propertyValue.setRules(null);
843 List<GetInputValueDataDefinition> getInputsValues = propertyValue.getGetInputValues();
844 if(getInputsValues != null && !getInputsValues.isEmpty()){
845 Optional<GetInputValueDataDefinition> op = getInputsValues.stream().filter(gi -> gi.getInputId().equals(inputForDelete.getUniqueId())).findAny();
847 getInputsValues.remove(op.get());
850 propertyValue.setGetInputValues(getInputsValues);
851 if(status != StorageOperationStatus.OK){
852 log.debug("Component id: {} delete component instance property {} id: {} failed", componentId, propertyValue.getUniqueId(), inputId);
853 deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), component.getName()));
856 Either<String, TitanOperationStatus> findDefaultValue = propertyOperation.findDefaultValueFromSecondPosition(propertyValue.getPath(), propertyValue.getUniqueId(), propertyValue.getDefaultValue());
857 if (findDefaultValue.isRight()) {
858 deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(findDefaultValue.right().value()))));
862 String defaultValue = findDefaultValue.left().value();
863 propertyValue.setDefaultValue(defaultValue);
864 log.debug("The returned default value in ResourceInstanceProperty is {}", defaultValue);
865 status = toscaOperationFacade.updateComponentInstanceProperty(component, compInstId, propertyValue);
866 if(status != StorageOperationStatus.OK){
867 log.debug("Component id: {} update component instance property {} id: {} failed", componentId, propertyValue.getUniqueId(), inputId);
868 deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), component.getName()));
876 deleteEither = Either.left(inputForDelete);
879 if (deleteEither == null || deleteEither.isRight()) {
880 log.debug("Component id: {} delete input id: {} failed", componentId, inputId);
883 log.debug("Component id: {} delete input id: {} success", componentId, inputId);
886 unlockComponent(deleteEither, component);
890 private Either<InputDefinition, ResponseFormat> prepareAndValidateInputBeforeCreate(InputDefinition newInputDefinition, Map<String, DataTypeDefinition> dataTypes) {
893 // validate input default values
894 Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(newInputDefinition, dataTypes);
895 if (defaultValuesValidation.isRight()) {
896 return Either.right(defaultValuesValidation.right().value());
899 ToscaPropertyType type = getType(newInputDefinition.getType());
901 PropertyValueConverter converter = type.getConverter();
903 String innerType = null;
904 if (newInputDefinition != null) {
905 SchemaDefinition schema = newInputDefinition.getSchema();
906 if (schema != null) {
907 PropertyDataDefinition prop = schema.getProperty();
909 innerType = prop.getType();
912 String convertedValue = null;
913 if (newInputDefinition.getDefaultValue() != null) {
914 convertedValue = converter.convert(newInputDefinition.getDefaultValue(), innerType, dataTypes);
915 newInputDefinition.setDefaultValue(convertedValue);
919 return Either.left(newInputDefinition);
922 public boolean isInputExist(List<InputDefinition> inputs, String resourceUid, String inputName) {
924 if (inputs == null) {
928 for (InputDefinition propertyDefinition : inputs) {
929 String parentUniqueId = propertyDefinition.getParentUniqueId();
930 String name = propertyDefinition.getName();
932 if (parentUniqueId.equals(resourceUid) && name.equals(inputName)) {
942 public Either<InputDefinition, ResponseFormat> getInputsAndPropertiesForComponentInput(String userId, String componentId, String inputId, boolean inTransaction) {
943 Either<InputDefinition, ResponseFormat> result = null;
946 Either<User, ResponseFormat> resp = validateUserExists(userId, "get Properties by input", false);
947 if (resp.isRight()) {
948 return Either.right(resp.right().value());
950 Either<List<ComponentInstanceProperty>, StorageOperationStatus> propertiesEitherRes = null;
952 ComponentParametersView filters = new ComponentParametersView();
953 filters.disableAll();
954 filters.setIgnoreComponentInstances(false);
955 filters.setIgnoreInputs(false);
956 filters.setIgnoreComponentInstancesInputs(false);
957 filters.setIgnoreComponentInstancesProperties(false);
958 filters.setIgnoreProperties(false);
959 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters);
960 if(getComponentEither.isRight()){
961 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
962 log.debug("Failed to found component {}, error: {}", componentId, actionStatus.name());
963 return Either.right(componentsUtils.getResponseFormat(actionStatus));
966 org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
967 Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
969 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
970 log.debug("Failed to found input {} under component {}, error: {}", inputId, componentId, actionStatus.name());
971 return Either.right(componentsUtils.getResponseFormat(actionStatus));
974 InputDefinition resObj = op.get();
976 List<ComponentInstanceInput> inputCIInput = getComponentInstanceInputsByInputId(component, inputId) ;
978 resObj.setInputs(inputCIInput);
981 List<ComponentInstanceProperty> inputProps = getComponentInstancePropertiesByInputId(component, inputId) ;
983 resObj.setProperties(inputProps);
986 result = Either.left(resObj);
992 if (false == inTransaction) {
994 if (result == null || result.isRight()) {
995 log.debug("Going to execute rollback on create group.");
998 log.debug("Going to execute commit on create group.");
1008 private List<ComponentInstanceProperty> getComponentInstancePropertiesByInputId(org.openecomp.sdc.be.model.Component component, String inputId){
1009 List<ComponentInstanceProperty> resList = new ArrayList<>();
1010 Map<String, List<ComponentInstanceProperty>> ciPropertiesMap = component.getComponentInstancesProperties();
1011 if(ciPropertiesMap != null && !ciPropertiesMap.isEmpty()){
1012 ciPropertiesMap.forEach(new BiConsumer<String, List<ComponentInstanceProperty>>() {
1014 public void accept(String s, List<ComponentInstanceProperty> ciPropList) {
1016 Optional<ComponentInstance> ciOp = component.getComponentInstances().stream().filter(ci ->ci.getUniqueId().equals(s)).findAny();
1017 if(ciOp.isPresent())
1018 ciName = ciOp.get().getName();
1019 if (ciPropList != null && !ciPropList.isEmpty()) {
1020 for(ComponentInstanceProperty prop: ciPropList){
1021 List<GetInputValueDataDefinition> inputsValues = prop.getGetInputValues();
1022 if(inputsValues != null && !inputsValues.isEmpty()){
1023 for(GetInputValueDataDefinition inputData: inputsValues){
1024 if(inputData.getInputId().equals(inputId) || (inputData.getGetInputIndex() != null && inputData.getGetInputIndex().getInputId().equals(inputId))){
1025 prop.setComponentInstanceId(s);
1026 prop.setComponentInstanceName(ciName);
1042 private List<ComponentInstanceInput> getComponentInstanceInputsByInputId(org.openecomp.sdc.be.model.Component component, String inputId){
1043 List<ComponentInstanceInput> resList = new ArrayList<>();
1044 Map<String, List<ComponentInstanceInput>> ciInputsMap = component.getComponentInstancesInputs();
1045 if(ciInputsMap != null && !ciInputsMap.isEmpty()){
1046 ciInputsMap.forEach(new BiConsumer<String, List<ComponentInstanceInput>>() {
1048 public void accept(String s, List<ComponentInstanceInput> ciPropList) {
1050 Optional<ComponentInstance> ciOp = component.getComponentInstances().stream().filter(ci ->ci.getUniqueId().equals(s)).findAny();
1051 if(ciOp.isPresent())
1052 ciName = ciOp.get().getName();
1053 if (ciPropList != null && !ciPropList.isEmpty()) {
1054 for(ComponentInstanceInput prop: ciPropList){
1055 List<GetInputValueDataDefinition> inputsValues = prop.getGetInputValues();
1056 if(inputsValues != null && !inputsValues.isEmpty()){
1057 for(GetInputValueDataDefinition inputData: inputsValues){
1058 if(inputData.getInputId().equals(inputId) || (inputData.getGetInputIndex() != null && inputData.getGetInputIndex().getInputId().equals(inputId))){
1059 prop.setComponentInstanceId(s);
1060 prop.setComponentInstanceName(ciName);
1076 private Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getOriginComponent(ComponentInstance ci, Map<String, org.openecomp.sdc.be.model.Component> origComponentMap){
1077 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> result = null;
1078 String compInstname = ci.getNormalizedName();
1080 ComponentParametersView componentParametersView = new ComponentParametersView();
1081 componentParametersView.disableAll();
1082 componentParametersView.setIgnoreInputs(false);
1083 org.openecomp.sdc.be.model.Component origComponent = null;
1084 if(!origComponentMap.containsKey(ci.getComponentUid())){
1085 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentFound = toscaOperationFacade.getToscaElement(ci.getComponentUid(), componentParametersView);
1087 if (componentFound.isRight()) {
1088 result = Either.right(componentFound.right().value());
1091 origComponent = componentFound.left().value();
1092 origComponentMap.put(origComponent.getUniqueId(), origComponent);
1094 origComponent = origComponentMap.get(ci.getComponentUid());
1096 result = Either.left(origComponent);
1102 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) {
1103 List<ComponentInstance> ciList = component.getComponentInstances();
1104 String componentId = component.getUniqueId();
1105 for (Entry<String, List<ComponentInstancePropInput>> entry : newInputsPropsMap.entrySet()) {
1106 List<ComponentInstanceProperty> propertiesToCreate = new ArrayList<>();
1107 String compInstId = entry.getKey();
1108 List<ComponentInstancePropInput> properties = entry.getValue();
1110 Optional<ComponentInstance> op = ciList.stream().filter(ci -> ci.getUniqueId().equals(compInstId)).findAny();
1111 if(!op.isPresent()){
1112 ActionStatus actionStatus = ActionStatus.INVALID_CONTENT;
1113 log.debug("Failed to find component instance {} under component {}", compInstId, componentId);
1114 return Either.right(componentsUtils.getResponseFormat(actionStatus));
1117 ComponentInstance ci = op.get();
1118 String compInstname = ci.getNormalizedName();
1119 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> origComponentEither = getOriginComponent(ci, origComponentMap);
1120 if(origComponentEither.isRight()){
1121 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(origComponentEither.right().value());
1122 log.debug("Failed to create inputs value under component {}, error: {}", componentId, actionStatus.name());
1123 return Either.right(componentsUtils.getResponseFormat(actionStatus));
1126 org.openecomp.sdc.be.model.Component origComponent = origComponentEither.left().value();
1129 //String originType = (String) titanGenericDao.getProperty(originVertex, GraphPropertiesDictionary.LABEL.getProperty());
1131 String inputName = compInstname;
1133 if (properties != null && !properties.isEmpty()) {
1134 for (ComponentInstancePropInput propInput : properties) {
1135 propInput.setOwnerId(null);
1136 propInput.setParentUniqueId(null);
1137 Either<InputDefinition, StorageOperationStatus> createInputRes = createInputForComponentInstance(component, origComponent,ci, inputsToCreate, propertiesToCreate, dataTypes, inputName, propInput);
1139 if (createInputRes.isRight()) {
1140 log.debug("Failed to create input of resource instance for id {} error {}", compInstId, createInputRes.right().value());
1141 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(createInputRes.right().value())));
1145 resList.add(createInputRes.left().value());
1148 propertiesToCreateMap.put(compInstId, propertiesToCreate);
1152 return Either.left(resList);
1155 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) {
1156 String propertiesName = propInput.getPropertiesName() ;
1157 PropertyDefinition selectedProp = propInput.getInput();
1158 String[] parsedPropNames = propInput.getParsedPropNames();
1160 if(parsedPropNames != null){
1161 for(String str: parsedPropNames){
1162 inputName += "_" + str;
1165 inputName += "_" + propInput.getName();
1168 InputDefinition input = null;
1169 ComponentInstanceProperty prop = propInput;
1171 if(propertiesName != null && !propertiesName.isEmpty() && selectedProp != null){
1172 input = new InputDefinition(selectedProp);
1174 input = new InputDefinition(prop);
1175 input.setName(inputName + "_" + prop.getName());
1178 input.setName(inputName);
1179 input.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(component.getUniqueId(), input.getName()));
1180 input.setInputPath(propertiesName);
1182 JSONObject jobject = new JSONObject();
1185 if(prop.getValue() == null || prop.getValue().isEmpty()){
1186 if(propertiesName != null && !propertiesName.isEmpty() && selectedProp != null){
1188 jobject = createJSONValueForProperty(parsedPropNames.length -1, parsedPropNames, jobject, inputName);
1189 prop.setValue(jobject.toJSONString());
1193 jobject.put(GET_INPUT, input.getName());
1194 prop.setValue(jobject.toJSONString());
1200 String value = prop.getValue();
1201 Object objValue = new Yaml().load(value);
1202 if( objValue instanceof Map || objValue instanceof List ){
1203 if(propertiesName == null ||propertiesName.isEmpty()){
1204 jobject.put(GET_INPUT, input.getName());
1205 prop.setValue(jobject.toJSONString());
1206 prop.setRules(null);
1209 Map<String, Object> mappedToscaTemplate = (Map<String, Object>) objValue;
1210 createInputValue(mappedToscaTemplate, 1, parsedPropNames, inputName);
1212 String json = gson.toJson(mappedToscaTemplate);
1213 prop.setValue(json);
1214 prop.setRules(null);
1218 jobject.put(GET_INPUT, input.getName());
1219 prop.setValue(jobject.toJSONString());
1220 prop.setRules(null);
1224 prop.setComponentInstanceId(ci.getUniqueId());
1225 prop.setComponentInstanceName(ci.getName());
1227 List<GetInputValueDataDefinition> getInputValues = new ArrayList<>();
1228 GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition();
1229 getInputValueDataDefinition.setInputId(input.getUniqueId());
1230 getInputValueDataDefinition.setInputName(input.getName());
1231 getInputValues.add(getInputValueDataDefinition);
1232 prop.setGetInputValues(getInputValues);
1234 propertiesToCreate.add(prop);
1236 inputsToCreate.put(input.getName(), input);
1238 List<ComponentInstanceProperty> propertiesList = new ArrayList<>(); // adding the property with the new value for UI
1239 propertiesList.add(prop);
1240 input.setProperties(propertiesList);
1242 return Either.left(input);
1246 private JSONObject createJSONValueForProperty (int i, String [] parsedPropNames, JSONObject ooj, String inputName){
1249 if( i == parsedPropNames.length -1){
1250 JSONObject jobProp = new JSONObject();
1251 jobProp.put(GET_INPUT, inputName);
1252 ooj.put(parsedPropNames[i], jobProp);
1254 return createJSONValueForProperty (i, parsedPropNames, ooj, inputName);
1256 JSONObject res = new JSONObject();
1257 res.put(parsedPropNames[i], ooj);
1259 res = createJSONValueForProperty (i, parsedPropNames, res, inputName);
1267 public void resetInputName(Map<String, Object> lhm1, String inputName){
1268 for (Map.Entry<String, Object> entry : lhm1.entrySet()) {
1269 String key = entry.getKey();
1270 Object value = entry.getValue();
1271 if (value instanceof String && ((String) value).equalsIgnoreCase(inputName) && key.equals(GET_INPUT)) {
1274 } else if (value instanceof Map) {
1275 Map<String, Object> subMap = (Map<String, Object>)value;
1276 resetInputName(subMap, inputName);
1284 private Map<String, Object> createInputValue(Map<String, Object> lhm1, int index, String[] inputNames, String inputName){
1285 while(index < inputNames.length){
1286 if(lhm1.containsKey(inputNames[index])){
1287 Object value = lhm1.get(inputNames[index]);
1288 if (value instanceof Map){
1289 if(index == inputNames.length -1){
1290 ((Map) value).put(GET_INPUT, inputName);
1291 return ((Map) value);
1295 return createInputValue((Map)value, index, inputNames, inputName);
1298 Map<String, Object> jobProp = new HashMap<>();
1299 if(index == inputNames.length -1){
1300 jobProp.put(GET_INPUT, inputName);
1301 lhm1.put(inputNames[index], jobProp);
1304 lhm1.put(inputNames[index], jobProp);
1306 return createInputValue(jobProp, index, inputNames, inputName);
1310 Map<String, Object> jobProp = new HashMap<>();
1311 lhm1.put(inputNames[index], jobProp);
1312 if(index == inputNames.length -1){
1313 jobProp.put(GET_INPUT, inputName);
1317 return createInputValue(jobProp, index, inputNames, inputName);