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.List;
27 import java.util.Optional;
28 import java.util.stream.Collectors;
30 import fj.data.Either;
31 import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
32 import org.openecomp.sdc.be.components.validation.ComponentValidations;
33 import org.openecomp.sdc.be.dao.api.ActionStatus;
34 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
35 import org.openecomp.sdc.be.dao.utils.MapUtil;
36 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
37 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
38 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
39 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
40 import org.openecomp.sdc.be.model.ComponentInstInputsMap;
41 import org.openecomp.sdc.be.model.ComponentInstance;
42 import org.openecomp.sdc.be.model.ComponentInstanceInput;
43 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
44 import org.openecomp.sdc.be.model.ComponentParametersView;
45 import org.openecomp.sdc.be.model.DataTypeDefinition;
46 import org.openecomp.sdc.be.model.InputDefinition;
47 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
48 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
49 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
50 import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
51 import org.openecomp.sdc.common.log.wrappers.Logger;
52 import org.openecomp.sdc.exception.ResponseFormat;
53 import org.springframework.stereotype.Component;
55 import javax.inject.Inject;
57 @Component("inputsBusinessLogic")
58 public class InputsBusinessLogic extends BaseBusinessLogic {
60 private static final String CREATE_INPUT = "CreateInput";
61 private static final String UPDATE_INPUT = "UpdateInput";
63 private static final Logger log = Logger.getLogger(InputsBusinessLogic.class);
64 private static final String FAILED_TO_FOUND_COMPONENT_ERROR = "Failed to found component {}, error: {}";
65 private static final String GET_PROPERTIES_BY_INPUT = "get Properties by input";
66 private static final String FAILED_TO_FOUND_INPUT_UNDER_COMPONENT_ERROR = "Failed to found input {} under component {}, error: {}";
67 private static final String GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_GROUP = "Going to execute rollback on create group.";
68 private static final String GOING_TO_EXECUTE_COMMIT_ON_CREATE_GROUP = "Going to execute commit on create group.";
71 private PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
73 private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
76 * associate inputs to a given component with paging
82 public Either<List<InputDefinition>, ResponseFormat> getInputs(String userId, String componentId) {
84 validateUserExists(userId, "get Inputs", false);
86 ComponentParametersView filters = new ComponentParametersView();
88 filters.setIgnoreInputs(false);
90 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters);
91 if(getComponentEither.isRight()){
92 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
93 log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, componentId, actionStatus);
94 return Either.right(componentsUtils.getResponseFormat(actionStatus));
97 org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
98 List<InputDefinition> inputs = component.getInputs();
100 return Either.left(inputs);
104 public Either<List<ComponentInstanceInput>, ResponseFormat> getComponentInstanceInputs(String userId, String componentId, String componentInstanceId) {
106 validateUserExists(userId, "get Inputs", false);
107 ComponentParametersView filters = new ComponentParametersView();
108 filters.disableAll();
109 filters.setIgnoreInputs(false);
110 filters.setIgnoreComponentInstances(false);
111 filters.setIgnoreComponentInstancesInputs(false);
113 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters);
114 if(getComponentEither.isRight()){
115 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
116 log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, componentId, actionStatus);
117 return Either.right(componentsUtils.getResponseFormat(actionStatus));
120 org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
122 if(!ComponentValidations.validateComponentInstanceExist(component, componentInstanceId)){
123 ActionStatus actionStatus = ActionStatus.COMPONENT_INSTANCE_NOT_FOUND;
124 log.debug("Failed to found component instance inputs {}, error: {}", componentInstanceId, actionStatus);
125 return Either.right(componentsUtils.getResponseFormat(actionStatus));
127 Map<String, List<ComponentInstanceInput>> ciInputs = Optional.ofNullable(component.getComponentInstancesInputs()).orElse(Collections.emptyMap());
128 return Either.left(ciInputs.getOrDefault(componentInstanceId, Collections.emptyList()));
132 * associate properties to a given component instance input
140 public Either<List<ComponentInstanceProperty>, ResponseFormat> getComponentInstancePropertiesByInputId(String userId, String componentId, String instanceId, String inputId) {
141 validateUserExists(userId, GET_PROPERTIES_BY_INPUT, false);
142 String parentId = componentId;
143 org.openecomp.sdc.be.model.Component component = null;
144 ComponentParametersView filters = new ComponentParametersView();
145 filters.disableAll();
146 filters.setIgnoreComponentInstances(false);
148 if(!instanceId.equals(inputId)){
151 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(parentId, filters);
153 if(getComponentEither.isRight()){
154 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
155 log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, parentId, actionStatus);
156 return Either.right(componentsUtils.getResponseFormat(actionStatus));
159 component = getComponentEither.left().value();
160 Optional<ComponentInstance> ciOp = component.getComponentInstances().stream().filter(ci ->ci.getUniqueId().equals(instanceId)).findAny();
161 if(ciOp.isPresent()){
162 parentId = ciOp.get().getComponentUid();
167 filters.setIgnoreInputs(false);
169 filters.setIgnoreComponentInstancesProperties(false);
170 filters.setIgnoreComponentInstancesInputs(false);
171 filters.setIgnoreProperties(false);
173 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(parentId, filters);
175 if(getComponentEither.isRight()){
176 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
177 log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, parentId, actionStatus);
178 return Either.right(componentsUtils.getResponseFormat(actionStatus));
181 component = getComponentEither.left().value();
183 Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
185 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
186 log.debug(FAILED_TO_FOUND_INPUT_UNDER_COMPONENT_ERROR, inputId, parentId, actionStatus);
187 return Either.right(componentsUtils.getResponseFormat(actionStatus));
190 return Either.left(componentInstanceBusinessLogic.getComponentInstancePropertiesByInputId(component, inputId));
194 private Either<String,ResponseFormat> updateInputObjectValue(InputDefinition currentInput, InputDefinition newInput, Map<String, DataTypeDefinition> dataTypes) {
195 String innerType = null;
196 String propertyType = currentInput.getType();
197 ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
198 log.debug("The type of the property {} is {}", currentInput.getUniqueId(), propertyType);
200 if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) {
201 SchemaDefinition def = currentInput.getSchema();
203 log.debug("Schema doesn't exists for property of type {}", type);
204 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)));
206 PropertyDataDefinition propDef = def.getProperty();
207 if (propDef == null) {
208 log.debug("Property in Schema Definition inside property of type {} doesn't exist", type);
209 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)));
211 innerType = propDef.getType();
213 // Specific Update Logic
215 Either<Object, Boolean> isValid = propertyOperation.validateAndUpdatePropertyValue(propertyType, newInput.getDefaultValue(), true, innerType, dataTypes);
217 String newValue = currentInput.getDefaultValue();
218 if (isValid.isRight()) {
219 Boolean res = isValid.right().value();
220 if (Boolean.FALSE.equals(res)) {
221 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(TitanOperationStatus.ILLEGAL_ARGUMENT))));
224 Object object = isValid.left().value();
225 if (object != null) {
226 newValue = object.toString();
229 return Either.left(newValue);
232 private InputDefinition getInputFromInputsListById(List<InputDefinition> componentsOldInputs, InputDefinition input) {
233 return componentsOldInputs.stream().filter(in -> in.getUniqueId().equals(input.getUniqueId())).findFirst().orElse(null);
236 public Either<List<InputDefinition>, ResponseFormat> updateInputsValue(ComponentTypeEnum componentType, String componentId, List<InputDefinition> inputs, String userId, boolean shouldLockComp, boolean inTransaction) {
238 List<InputDefinition> returnInputs = new ArrayList<>();
239 Either<List<InputDefinition>, ResponseFormat> result = null;
240 org.openecomp.sdc.be.model.Component component = null;
243 validateUserExists(userId, "get input", false);
245 ComponentParametersView componentParametersView = new ComponentParametersView();
246 componentParametersView.disableAll();
247 componentParametersView.setIgnoreInputs(false);
248 componentParametersView.setIgnoreUsers(false);
250 Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(componentId, componentType, componentParametersView);
252 if (validateComponent.isRight()) {
253 result = Either.right(validateComponent.right().value());
256 component = validateComponent.left().value();
258 if (shouldLockComp) {
259 Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, UPDATE_INPUT);
260 if (lockComponent.isRight()) {
261 result = Either.right(lockComponent.right().value());
266 Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
267 if (canWork.isRight()) {
268 result = Either.right(canWork.right().value());
272 Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
273 if (allDataTypes.isRight()) {
274 result = Either.right(allDataTypes.right().value());
278 Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
279 List<InputDefinition> componentsOldInputs = Optional.ofNullable(component.getInputs()).orElse(Collections.emptyList());
280 for (InputDefinition newInput: inputs) {
281 InputDefinition currInput = getInputFromInputsListById(componentsOldInputs, newInput);
282 if (currInput == null) {
283 ActionStatus actionStatus = ActionStatus.COMPONENT_NOT_FOUND;
284 log.debug("Failed to found newInput {} under component {}, error: {}", newInput.getUniqueId(), componentId, actionStatus);
285 result = Either.right(componentsUtils.getResponseFormat(actionStatus));
288 Either<String, ResponseFormat> updateInputObjectValue = updateInputObjectValue(currInput, newInput, dataTypes);
289 if ( updateInputObjectValue.isRight()) {
290 return Either.right(updateInputObjectValue.right().value());
292 String newValue = updateInputObjectValue.left().value();
293 currInput.setValue(newValue);
294 currInput.setDefaultValue(newValue);
295 currInput.setOwnerId(userId);
296 Either<InputDefinition, StorageOperationStatus> status = toscaOperationFacade.updateInputOfComponent(component, currInput);
297 if(status.isRight()){
298 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status.right().value());
299 result = Either.right(componentsUtils.getResponseFormat(actionStatus, ""));
302 returnInputs.add(status.left().value());
305 result = Either.left(returnInputs);
308 if (!inTransaction) {
309 if (result == null || result.isRight()) {
310 log.debug(GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_GROUP);
313 log.debug(GOING_TO_EXECUTE_COMMIT_ON_CREATE_GROUP);
318 if (shouldLockComp && component != null) {
319 graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
324 public Either<List<ComponentInstanceInput>, ResponseFormat> getInputsForComponentInput(String userId, String componentId, String inputId) {
325 validateUserExists(userId, GET_PROPERTIES_BY_INPUT, false);
326 org.openecomp.sdc.be.model.Component component = null;
327 ComponentParametersView filters = new ComponentParametersView();
328 filters.disableAll();
329 filters.setIgnoreComponentInstances(false);
330 filters.setIgnoreInputs(false);
331 filters.setIgnoreComponentInstancesInputs(false);
332 filters.setIgnoreProperties(false);
334 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters);
336 if(getComponentEither.isRight()){
337 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
338 log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, componentId, actionStatus);
339 return Either.right(componentsUtils.getResponseFormat(actionStatus));
342 component = getComponentEither.left().value();
344 Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
346 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
347 log.debug(FAILED_TO_FOUND_INPUT_UNDER_COMPONENT_ERROR, inputId, componentId, actionStatus);
348 return Either.right(componentsUtils.getResponseFormat(actionStatus));
351 return Either.left(componentInstanceBusinessLogic.getComponentInstanceInputsByInputId(component, inputId));
355 public Either<List<InputDefinition>, ResponseFormat> createMultipleInputs(String userId, String componentId, ComponentTypeEnum componentType, ComponentInstInputsMap componentInstInputsMapUi, boolean shouldLockComp, boolean inTransaction) {
357 Either<List<InputDefinition>, ResponseFormat> result = null;
358 org.openecomp.sdc.be.model.Component component = null;
361 validateUserExists(userId, GET_PROPERTIES_BY_INPUT, false);
363 ComponentParametersView componentParametersView = new ComponentParametersView();
364 componentParametersView.disableAll();
365 componentParametersView.setIgnoreInputs(false);
366 componentParametersView.setIgnoreComponentInstancesInputs(false);
367 componentParametersView.setIgnoreComponentInstances(false);
368 componentParametersView.setIgnoreComponentInstancesProperties(false);
369 componentParametersView.setIgnorePolicies(false);
370 componentParametersView.setIgnoreGroups(false);
371 componentParametersView.setIgnoreUsers(false);
373 Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(componentId, componentType, componentParametersView);
375 if (validateComponent.isRight()) {
376 result = Either.right(validateComponent.right().value());
379 component = validateComponent.left().value();
381 if (shouldLockComp) {
382 Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, CREATE_INPUT);
383 if (lockComponent.isRight()) {
384 result = Either.right(lockComponent.right().value());
389 Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
390 if (canWork.isRight()) {
391 result = Either.right(canWork.right().value());
395 result = propertyDeclarationOrchestrator.declarePropertiesToInputs(component, componentInstInputsMapUi)
397 .bind(inputsToCreate -> prepareInputsForCreation(userId, componentId, inputsToCreate))
399 .map(err -> componentsUtils.getResponseFormat(err));
405 if (!inTransaction) {
406 if (result == null || result.isRight()) {
407 log.debug(GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_GROUP);
410 log.debug(GOING_TO_EXECUTE_COMMIT_ON_CREATE_GROUP);
415 if (shouldLockComp && component != null) {
416 graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
422 private Either<List<InputDefinition>, StorageOperationStatus> prepareInputsForCreation(String userId, String cmptId, List<InputDefinition> inputsToCreate) {
423 Map<String, InputDefinition> inputsToPersist = MapUtil.toMap(inputsToCreate, InputDefinition::getName);
424 assignOwnerIdToInputs(userId, inputsToPersist);
425 return toscaOperationFacade.addInputsToComponent(inputsToPersist, cmptId)
427 .map(persistedInputs -> inputsToCreate);
430 private void assignOwnerIdToInputs(String userId, Map<String, InputDefinition> inputsToCreate) {
431 inputsToCreate.values().forEach(inputDefinition -> inputDefinition.setOwnerId(userId));
434 public Either<List<InputDefinition>, ResponseFormat> createInputsInGraph(Map<String, InputDefinition> inputs, org.openecomp.sdc.be.model.Component component) {
436 List<InputDefinition> resourceProperties = component.getInputs();
437 Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
438 if (allDataTypes.isRight()) {
439 return Either.right(allDataTypes.right().value());
442 Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
444 for (Map.Entry<String, InputDefinition> inputDefinition : inputs.entrySet()) {
445 String inputName = inputDefinition.getKey();
446 inputDefinition.getValue().setName(inputName);
448 Either<InputDefinition, ResponseFormat> preparedInputEither = prepareAndValidateInputBeforeCreate(inputDefinition.getValue(), dataTypes);
449 if(preparedInputEither.isRight()){
450 return Either.right(preparedInputEither.right().value());
454 if (resourceProperties != null) {
455 Map<String, InputDefinition> generatedInputs = resourceProperties.stream().collect(Collectors.toMap(PropertyDataDefinition::getName, i -> i));
456 Either<Map<String, InputDefinition>, String> mergeEither = ToscaDataDefinition.mergeDataMaps(generatedInputs, inputs);
457 if(mergeEither.isRight()){
458 return Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_ALREADY_EXIST, mergeEither.right().value()));
460 inputs = mergeEither.left().value();
463 Either<List<InputDefinition>, StorageOperationStatus> associateInputsEither = toscaOperationFacade.createAndAssociateInputs(inputs, component.getUniqueId());
464 if(associateInputsEither.isRight()){
465 log.debug("Failed to create inputs under component {}. Status is {}", component.getUniqueId(), associateInputsEither.right().value());
466 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(associateInputsEither.right().value())));
468 return Either.left(associateInputsEither.left().value());
472 * Delete input from service
479 public Either<InputDefinition, ResponseFormat> deleteInput(String componentId, String userId, String inputId) {
481 Either<InputDefinition, ResponseFormat> deleteEither = null;
482 if (log.isDebugEnabled()) {
483 log.debug("Going to delete input id: {}", inputId);
486 validateUserExists(userId, "Delete input", true);
488 ComponentParametersView componentParametersView = new ComponentParametersView();
489 componentParametersView.disableAll();
490 componentParametersView.setIgnoreInputs(false);
491 componentParametersView.setIgnoreComponentInstances(false);
492 componentParametersView.setIgnoreComponentInstancesInputs(false);
493 componentParametersView.setIgnoreComponentInstancesProperties(false);
494 componentParametersView.setIgnorePolicies(false);
495 componentParametersView.setIgnoreGroups(false);
496 componentParametersView.setIgnoreUsers(false);
498 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentEither = toscaOperationFacade.getToscaElement(componentId, componentParametersView);
499 if (componentEither.isRight()) {
500 deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(componentEither.right().value())));
503 org.openecomp.sdc.be.model.Component component = componentEither.left().value();
505 // Validate inputId is child of the component
506 Optional<InputDefinition> optionalInput = component.getInputs().stream().
508 filter(input -> input.getUniqueId().equals(inputId)).
511 if (!optionalInput.isPresent()) {
512 return Either.right(componentsUtils.getResponseFormat(ActionStatus.INPUT_IS_NOT_CHILD_OF_COMPONENT, inputId, componentId));
515 InputDefinition inputForDelete = optionalInput.get();
518 Either<Boolean, ResponseFormat> lockResultEither = lockComponent(componentId, component, "deleteInput");
519 if (lockResultEither.isRight()) {
520 ResponseFormat responseFormat = lockResultEither.right().value();
521 deleteEither = Either.right(responseFormat);
525 // Delete input operations
527 StorageOperationStatus status = toscaOperationFacade.deleteInputOfResource(component, inputForDelete.getName());
528 if (status != StorageOperationStatus.OK) {
529 log.debug("Component id: {} delete input id: {} failed", componentId, inputId);
530 deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), component.getName()));
533 StorageOperationStatus storageOperationStatus = propertyDeclarationOrchestrator.unDeclarePropertiesAsInputs(component, inputForDelete);
534 if (storageOperationStatus != StorageOperationStatus.OK) {
535 log.debug("Component id: {} update properties declared as input for input id: {} failed", componentId, inputId);
536 deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), component.getName()));
539 deleteEither = Either.left(inputForDelete);
542 if (deleteEither == null || deleteEither.isRight()) {
543 log.debug("Component id: {} delete input id: {} failed", componentId, inputId);
546 log.debug("Component id: {} delete input id: {} success", componentId, inputId);
549 unlockComponent(deleteEither, component);
553 private Either<InputDefinition, ResponseFormat> prepareAndValidateInputBeforeCreate(InputDefinition newInputDefinition, Map<String, DataTypeDefinition> dataTypes) {
556 // validate input default values
557 Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(newInputDefinition, dataTypes);
558 if (defaultValuesValidation.isRight()) {
559 return Either.right(defaultValuesValidation.right().value());
562 ToscaPropertyType type = getType(newInputDefinition.getType());
564 PropertyValueConverter converter = type.getConverter();
566 String innerType = null;
567 SchemaDefinition schema = newInputDefinition.getSchema();
568 if (schema != null) {
569 PropertyDataDefinition prop = schema.getProperty();
571 innerType = prop.getType();
574 String convertedValue;
575 if (newInputDefinition.getDefaultValue() != null) {
576 convertedValue = converter.convert(newInputDefinition.getDefaultValue(), innerType, dataTypes);
577 newInputDefinition.setDefaultValue(convertedValue);
580 return Either.left(newInputDefinition);
583 public Either<InputDefinition, ResponseFormat> getInputsAndPropertiesForComponentInput(String userId, String componentId, String inputId, boolean inTransaction) {
584 Either<InputDefinition, ResponseFormat> result = null;
587 validateUserExists(userId, GET_PROPERTIES_BY_INPUT, false);
588 ComponentParametersView filters = new ComponentParametersView();
589 filters.disableAll();
590 filters.setIgnoreComponentInstances(false);
591 filters.setIgnoreInputs(false);
592 filters.setIgnoreComponentInstancesInputs(false);
593 filters.setIgnoreComponentInstancesProperties(false);
594 filters.setIgnoreProperties(false);
595 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters);
596 if(getComponentEither.isRight()){
597 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
598 log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, componentId, actionStatus);
599 return Either.right(componentsUtils.getResponseFormat(actionStatus));
602 org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
603 Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
605 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
606 log.debug(FAILED_TO_FOUND_INPUT_UNDER_COMPONENT_ERROR, inputId, componentId, actionStatus);
607 return Either.right(componentsUtils.getResponseFormat(actionStatus));
610 InputDefinition resObj = op.get();
612 List<ComponentInstanceInput> inputCIInput = componentInstanceBusinessLogic.getComponentInstanceInputsByInputId(component, inputId) ;
614 resObj.setInputs(inputCIInput);
617 List<ComponentInstanceProperty> inputProps = componentInstanceBusinessLogic.getComponentInstancePropertiesByInputId(component, inputId) ;
619 resObj.setProperties(inputProps);
622 result = Either.left(resObj);
628 if (!inTransaction) {
630 if (result == null || result.isRight()) {
631 log.debug(GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_GROUP);
634 log.debug(GOING_TO_EXECUTE_COMMIT_ON_CREATE_GROUP);