Sync Integ to Master
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / impl / InputsBusinessLogic.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.components.impl;
22
23 import fj.data.Either;
24 import org.openecomp.sdc.be.components.property.PropertyDecelerationOrchestrator;
25 import org.openecomp.sdc.be.components.validation.ComponentValidations;
26 import org.openecomp.sdc.be.dao.api.ActionStatus;
27 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
28 import org.openecomp.sdc.be.dao.utils.MapUtil;
29 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
30 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
31 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
32 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
33 import org.openecomp.sdc.be.model.ComponentInstInputsMap;
34 import org.openecomp.sdc.be.model.ComponentInstance;
35 import org.openecomp.sdc.be.model.ComponentInstanceInput;
36 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
37 import org.openecomp.sdc.be.model.ComponentParametersView;
38 import org.openecomp.sdc.be.model.DataTypeDefinition;
39 import org.openecomp.sdc.be.model.InputDefinition;
40 import org.openecomp.sdc.be.model.User;
41 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
42 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
43 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
44 import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
45 import org.openecomp.sdc.exception.ResponseFormat;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
48 import org.springframework.stereotype.Component;
49
50 import javax.inject.Inject;
51 import java.util.ArrayList;
52 import java.util.Collections;
53 import java.util.List;
54 import java.util.Map;
55 import java.util.Optional;
56 import java.util.stream.Collectors;
57
58 @Component("inputsBusinessLogic")
59 public class InputsBusinessLogic extends BaseBusinessLogic {
60
61     private static final String CREATE_INPUT = "CreateInput";
62     private static final String UPDATE_INPUT = "UpdateInput";
63
64     private static final Logger log = LoggerFactory.getLogger(InputsBusinessLogic.class);
65
66     @Inject
67     private PropertyDecelerationOrchestrator propertyDecelerationOrchestrator;
68     @Inject
69     private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
70
71     /**
72      * associate inputs to a given component with paging
73      *
74      * @param userId
75      * @param componentId
76      * @return
77      */
78     public Either<List<InputDefinition>, ResponseFormat> getInputs(String userId, String componentId) {
79
80         Either<User, ResponseFormat> resp = validateUserExists(userId, "get Inputs", false);
81
82         if (resp.isRight()) {
83             return Either.right(resp.right().value());
84         }
85
86
87         ComponentParametersView filters = new ComponentParametersView();
88         filters.disableAll();
89         filters.setIgnoreInputs(false);
90
91         Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters);
92         if(getComponentEither.isRight()){
93             ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
94             log.debug("Failed to found component {}, error: {}", componentId, actionStatus);
95             return Either.right(componentsUtils.getResponseFormat(actionStatus));
96
97         }
98         org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
99         List<InputDefinition> inputs = component.getInputs();
100
101         return Either.left(inputs);
102
103     }
104
105     public Either<List<ComponentInstanceInput>, ResponseFormat> getComponentInstanceInputs(String userId, String componentId, String componentInstanceId) {
106
107         Either<User, ResponseFormat> resp = validateUserExists(userId, "get Inputs", false);
108
109         if (resp.isRight()) {
110             return Either.right(resp.right().value());
111         }
112
113
114         ComponentParametersView filters = new ComponentParametersView();
115         filters.disableAll();
116         filters.setIgnoreInputs(false);
117         filters.setIgnoreComponentInstances(false);
118         filters.setIgnoreComponentInstancesInputs(false);
119
120         Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters);
121         if(getComponentEither.isRight()){
122             ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
123             log.debug("Failed to found component {}, error: {}", componentId, actionStatus);
124             return Either.right(componentsUtils.getResponseFormat(actionStatus));
125
126         }
127         org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
128
129         if(!ComponentValidations.validateComponentInstanceExist(component, componentInstanceId)){
130             ActionStatus actionStatus = ActionStatus.COMPONENT_INSTANCE_NOT_FOUND;
131             log.debug("Failed to found component instance inputs {}, error: {}", componentInstanceId, actionStatus);
132             return Either.right(componentsUtils.getResponseFormat(actionStatus));
133         }
134         Map<String, List<ComponentInstanceInput>> ciInputs = Optional.ofNullable(component.getComponentInstancesInputs()).orElse(Collections.emptyMap());
135         return Either.left(ciInputs.getOrDefault(componentInstanceId, Collections.emptyList()));
136     }
137
138     /**
139      * associate properties to a given component instance input
140      *
141      * @param instanceId
142      * @param userId
143      * @param inputId
144      * @return
145      */
146
147     public Either<List<ComponentInstanceProperty>, ResponseFormat> getComponentInstancePropertiesByInputId(String userId, String componentId, String instanceId, String inputId) {
148         Either<User, ResponseFormat> resp = validateUserExists(userId, "get Properties by input", false);
149         if (resp.isRight()) {
150             return Either.right(resp.right().value());
151         }
152         String parentId = componentId;
153         org.openecomp.sdc.be.model.Component component = null;
154         ComponentParametersView filters = new ComponentParametersView();
155         filters.disableAll();
156         filters.setIgnoreComponentInstances(false);
157
158         if(!instanceId.equals(inputId)){
159
160
161             Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(parentId, filters);
162
163             if(getComponentEither.isRight()){
164                 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
165                 log.debug("Failed to found component {}, error: {}", parentId, actionStatus);
166                 return Either.right(componentsUtils.getResponseFormat(actionStatus));
167
168             }
169             component = getComponentEither.left().value();
170             Optional<ComponentInstance> ciOp = component.getComponentInstances().stream().filter(ci ->ci.getUniqueId().equals(instanceId)).findAny();
171             if(ciOp.isPresent()){
172                 parentId = ciOp.get().getComponentUid();
173             }
174
175         }
176
177         filters.setIgnoreInputs(false);
178
179         filters.setIgnoreComponentInstancesProperties(false);
180         filters.setIgnoreComponentInstancesInputs(false);
181         filters.setIgnoreProperties(false);
182
183         Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(parentId, filters);
184
185         if(getComponentEither.isRight()){
186             ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
187             log.debug("Failed to found component {}, error: {}", parentId, actionStatus);
188             return Either.right(componentsUtils.getResponseFormat(actionStatus));
189
190         }
191         component = getComponentEither.left().value();
192
193         Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
194         if(!op.isPresent()){
195             ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
196             log.debug("Failed to found input {} under component {}, error: {}", inputId, parentId, actionStatus);
197             return Either.right(componentsUtils.getResponseFormat(actionStatus));
198         }
199
200         return Either.left(componentInstanceBusinessLogic.getComponentInstancePropertiesByInputId(component, inputId));
201
202     }
203
204     private Either<String,ResponseFormat> updateInputObjectValue(InputDefinition currentInput, InputDefinition newInput, Map<String, DataTypeDefinition> dataTypes) {
205         String innerType = null;
206         String propertyType = currentInput.getType();
207         ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
208         log.debug("The type of the property {} is {}", currentInput.getUniqueId(), propertyType);
209
210         if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) {
211             SchemaDefinition def = currentInput.getSchema();
212             if (def == null) {
213                 log.debug("Schema doesn't exists for property of type {}", type);
214                 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)));
215             }
216             PropertyDataDefinition propDef = def.getProperty();
217             if (propDef == null) {
218                 log.debug("Property in Schema Definition inside property of type {} doesn't exist", type);
219                 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)));
220             }
221             innerType = propDef.getType();
222         }
223         // Specific Update Logic
224
225         Either<Object, Boolean> isValid = propertyOperation.validateAndUpdatePropertyValue(propertyType, newInput.getDefaultValue(), true, innerType, dataTypes);
226
227         String newValue = currentInput.getDefaultValue();
228         if (isValid.isRight()) {
229             Boolean res = isValid.right().value();
230             if (Boolean.FALSE.equals(res)) {
231                 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(TitanOperationStatus.ILLEGAL_ARGUMENT))));
232             }
233         } else {
234             Object object = isValid.left().value();
235             if (object != null) {
236                 newValue = object.toString();
237             }
238         }
239         return Either.left(newValue);
240     }
241
242     private InputDefinition getInputFromInputsListById(List<InputDefinition> componentsOldInputs, InputDefinition input) {
243         Optional<InputDefinition> foundInput = componentsOldInputs.stream().filter(in -> in.getUniqueId().equals(input.getUniqueId())).findFirst();
244         return foundInput.isPresent() ? foundInput.get() : null;
245     }
246
247     public Either<List<InputDefinition>, ResponseFormat> updateInputsValue(ComponentTypeEnum componentType, String componentId, List<InputDefinition> inputs, String userId, boolean shouldLockComp, boolean inTransaction) {
248
249         List<InputDefinition> returnInputs = new ArrayList<>();
250         Either<List<InputDefinition>, ResponseFormat> result = null;
251         org.openecomp.sdc.be.model.Component component = null;
252
253         try {
254             Either<User, ResponseFormat> resp = validateUserExists(userId, "get input", false);
255
256             if (resp.isRight()) {
257                 result = Either.right(resp.right().value());
258                 return result;
259             }
260
261             ComponentParametersView componentParametersView = new ComponentParametersView();
262             componentParametersView.disableAll();
263             componentParametersView.setIgnoreInputs(false);
264             componentParametersView.setIgnoreUsers(false);
265
266             Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(componentId, componentType, componentParametersView);
267
268             if (validateComponent.isRight()) {
269                 result = Either.right(validateComponent.right().value());
270                 return result;
271             }
272             component = validateComponent.left().value();
273
274             if (shouldLockComp) {
275                 Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, UPDATE_INPUT);
276                 if (lockComponent.isRight()) {
277                     result = Either.right(lockComponent.right().value());
278                     return result;
279                 }
280             }
281
282             Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
283             if (canWork.isRight()) {
284                 result = Either.right(canWork.right().value());
285                 return result;
286             }
287
288             Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
289             if (allDataTypes.isRight()) {
290                 result = Either.right(allDataTypes.right().value());
291                 return result;
292             }
293
294             Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
295             List<InputDefinition> componentsOldInputs = Optional.ofNullable(component.getInputs()).orElse(Collections.emptyList());
296             for (InputDefinition newInput: inputs) {
297                 InputDefinition currInput = getInputFromInputsListById(componentsOldInputs, newInput);
298                 if (currInput == null) {
299                     ActionStatus actionStatus = ActionStatus.COMPONENT_NOT_FOUND;
300                     log.debug("Failed to found newInput {} under component {}, error: {}", newInput.getUniqueId(), componentId, actionStatus.name());
301                     result = Either.right(componentsUtils.getResponseFormat(actionStatus));
302                     return result;
303                 }
304                 Either<String, ResponseFormat> updateInputObjectValue = updateInputObjectValue(currInput, newInput, dataTypes);
305                 if ( updateInputObjectValue.isRight()) {
306                     return Either.right(updateInputObjectValue.right().value());
307                 }
308                 String newValue = updateInputObjectValue.left().value();
309                 currInput.setDefaultValue(newValue);
310                 currInput.setOwnerId(userId);
311                 Either<InputDefinition, StorageOperationStatus> status = toscaOperationFacade.updateInputOfComponent(component, currInput);
312                 if(status.isRight()){
313                     ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status.right().value());
314                     result = Either.right(componentsUtils.getResponseFormat(actionStatus, ""));
315                     return result;
316                 } else {
317                     returnInputs.add(status.left().value());
318                 }
319             }
320             result = Either.left(returnInputs);
321             return result;
322         } finally {
323                 if (false == inTransaction) {
324                     if (result == null || result.isRight()) {
325                         log.debug("Going to execute rollback on create group.");
326                         titanDao.rollback();
327                     } else {
328                         log.debug("Going to execute commit on create group.");
329                         titanDao.commit();
330                     }
331                 }
332                 // unlock resource
333                 if (shouldLockComp && component != null) {
334                     graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
335                 }
336             }
337     }
338
339     public Either<List<ComponentInstanceInput>, ResponseFormat> getInputsForComponentInput(String userId, String componentId, String inputId) {
340         Either<User, ResponseFormat> resp = validateUserExists(userId, "get Properties by input", false);
341         if (resp.isRight()) {
342             return Either.right(resp.right().value());
343         }
344         String parentId = componentId;
345         org.openecomp.sdc.be.model.Component component = null;
346         ComponentParametersView filters = new ComponentParametersView();
347         filters.disableAll();
348         filters.setIgnoreComponentInstances(false);
349         filters.setIgnoreInputs(false);
350         filters.setIgnoreComponentInstancesInputs(false);
351         filters.setIgnoreProperties(false);
352
353         Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(parentId, filters);
354
355         if(getComponentEither.isRight()){
356             ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
357             log.debug("Failed to found component {}, error: {}", parentId, actionStatus);
358             return Either.right(componentsUtils.getResponseFormat(actionStatus));
359
360         }
361         component = getComponentEither.left().value();
362
363         Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
364         if(!op.isPresent()){
365             ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
366             log.debug("Failed to found input {} under component {}, error: {}", inputId, parentId, actionStatus);
367             return Either.right(componentsUtils.getResponseFormat(actionStatus));
368         }
369
370         return Either.left(componentInstanceBusinessLogic.getComponentInstanceInputsByInputId(component, inputId));
371
372     }
373
374     public Either<List<InputDefinition>, ResponseFormat> createMultipleInputs(String userId, String componentId, ComponentTypeEnum componentType, ComponentInstInputsMap componentInstInputsMapUi, boolean shouldLockComp, boolean inTransaction) {
375
376         Either<List<InputDefinition>, ResponseFormat> result = null;
377         org.openecomp.sdc.be.model.Component component = null;
378
379         try {
380             Either<User, ResponseFormat> resp = validateUserExists(userId, "get Properties by input", false);
381
382             if (resp.isRight()) {
383                 result = Either.right(resp.right().value());
384                 return result;
385             }
386
387             ComponentParametersView componentParametersView = new ComponentParametersView();
388             componentParametersView.disableAll();
389             componentParametersView.setIgnoreInputs(false);
390             componentParametersView.setIgnoreComponentInstancesInputs(false);
391             componentParametersView.setIgnoreComponentInstances(false);
392             componentParametersView.setIgnoreComponentInstancesProperties(false);
393             componentParametersView.setIgnoreUsers(false);
394
395             Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(componentId, componentType, componentParametersView);
396
397             if (validateComponent.isRight()) {
398                 result = Either.right(validateComponent.right().value());
399                 return result;
400             }
401             component = validateComponent.left().value();
402
403             if (shouldLockComp) {
404                 Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, CREATE_INPUT);
405                 if (lockComponent.isRight()) {
406                     result = Either.right(lockComponent.right().value());
407                     return result;
408                 }
409             }
410
411             Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
412             if (canWork.isRight()) {
413                 result = Either.right(canWork.right().value());
414                 return result;
415             }
416
417             result =  propertyDecelerationOrchestrator.declarePropertiesToInputs(component, componentInstInputsMapUi)
418                     .left()
419                     .bind(inputsToCreate -> prepareInputsForCreation(userId, componentId, inputsToCreate))
420                     .right()
421                     .map(err -> componentsUtils.getResponseFormat(err));
422
423             return result;
424
425         } finally {
426
427             if (!inTransaction) {
428                 if (result == null || result.isRight()) {
429                     log.debug("Going to execute rollback on create group.");
430                     titanDao.rollback();
431                 } else {
432                     log.debug("Going to execute commit on create group.");
433                     titanDao.commit();
434                 }
435             }
436             // unlock resource
437             if (shouldLockComp && component != null) {
438                 graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
439             }
440
441         }
442     }
443
444     private  Either<List<InputDefinition>, StorageOperationStatus> prepareInputsForCreation(String userId, String cmptId, List<InputDefinition> inputsToCreate) {
445         Map<String, InputDefinition> inputsToPersist = MapUtil.toMap(inputsToCreate, InputDefinition::getName);
446         assignOwnerIdToInputs(userId, inputsToPersist);
447         return toscaOperationFacade.addInputsToComponent(inputsToPersist, cmptId)
448                 .left()
449                 .map(persistedInputs -> inputsToCreate);
450     }
451
452     private void assignOwnerIdToInputs(String userId, Map<String, InputDefinition> inputsToCreate) {
453         inputsToCreate.values().forEach(inputDefinition -> inputDefinition.setOwnerId(userId));
454     }
455
456     public Either<List<InputDefinition>, ResponseFormat> createInputsInGraph(Map<String, InputDefinition> inputs, org.openecomp.sdc.be.model.Component component) {
457
458         List<InputDefinition> resList = inputs.values().stream().collect(Collectors.toList());
459         Either<List<InputDefinition>, ResponseFormat> result = Either.left(resList);
460         List<InputDefinition> resourceProperties = component.getInputs();
461
462         Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
463         if (allDataTypes.isRight()) {
464             return Either.right(allDataTypes.right().value());
465         }
466
467         Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
468
469         for (Map.Entry<String, InputDefinition> inputDefinition : inputs.entrySet()) {
470             String inputName = inputDefinition.getKey();
471             inputDefinition.getValue().setName(inputName);
472
473             Either<InputDefinition, ResponseFormat> preparedInputEither = prepareAndValidateInputBeforeCreate(inputDefinition.getValue(), dataTypes);
474             if(preparedInputEither.isRight()){
475                 return Either.right(preparedInputEither.right().value());
476             }
477
478         }
479         if (resourceProperties != null) {
480             Map<String, InputDefinition> generatedInputs = resourceProperties.stream().collect(Collectors.toMap(i -> i.getName(), i -> i));
481             Either<Map<String, InputDefinition>, String> mergeEither = ToscaDataDefinition.mergeDataMaps(generatedInputs, inputs);
482             if(mergeEither.isRight()){
483                 return Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_ALREADY_EXIST, mergeEither.right().value()));
484             }
485             inputs = mergeEither.left().value();
486         }
487
488         Either<List<InputDefinition>, StorageOperationStatus> assotiateInputsEither = toscaOperationFacade.createAndAssociateInputs(inputs, component.getUniqueId());
489         if(assotiateInputsEither.isRight()){
490             log.debug("Failed to create inputs under component {}. Status is {}", component.getUniqueId(), assotiateInputsEither.right().value());
491             return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(assotiateInputsEither.right().value())));
492         }
493         result  = Either.left(assotiateInputsEither.left().value());
494
495         return result;
496     }
497
498     /**
499      * Delete input from service
500      *
501      * @param componentId
502      * @param userId
503      *
504      * @param inputId
505      * @return
506      */
507     public Either<InputDefinition, ResponseFormat> deleteInput(String componentId, String userId, String inputId) {
508
509         Either<InputDefinition, ResponseFormat> deleteEither = null;
510         if (log.isDebugEnabled())
511             log.debug("Going to delete input id: {}", inputId);
512
513         // Validate user (exists)
514         Either<User, ResponseFormat> userEither = validateUserExists(userId, "Delete input", true);
515         if (userEither.isRight()) {
516             deleteEither = Either.right(userEither.right().value());
517             return deleteEither;
518         }
519
520         // Get component using componentType, componentId
521
522         ComponentParametersView componentParametersView = new ComponentParametersView();
523         componentParametersView.disableAll();
524         componentParametersView.setIgnoreInputs(false);
525         componentParametersView.setIgnoreComponentInstances(false);
526         componentParametersView.setIgnoreComponentInstancesInputs(false);
527         componentParametersView.setIgnoreComponentInstancesProperties(false);
528         componentParametersView.setIgnorePolicies(false);
529         componentParametersView.setIgnoreUsers(false);
530
531         Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentEither = toscaOperationFacade.getToscaElement(componentId, componentParametersView);
532         if (componentEither.isRight()) {
533             deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(componentEither.right().value())));
534             return deleteEither;
535         }
536         org.openecomp.sdc.be.model.Component component = componentEither.left().value();
537
538         // Validate inputId is child of the component
539         Optional<InputDefinition> optionalInput = component.getInputs().stream().
540                 // filter by ID
541                         filter(input -> input.getUniqueId().equals(inputId)).
542                 // Get the input
543                         findAny();
544         if (!optionalInput.isPresent()) {
545             return Either.right(componentsUtils.getResponseFormat(ActionStatus.INPUT_IS_NOT_CHILD_OF_COMPONENT, inputId, componentId));
546         }
547
548         InputDefinition inputForDelete = optionalInput.get();
549
550         // Lock component
551         Either<Boolean, ResponseFormat> lockResultEither = lockComponent(componentId, component, "deleteInput");
552         if (lockResultEither.isRight()) {
553             ResponseFormat responseFormat = lockResultEither.right().value();
554             deleteEither = Either.right(responseFormat);
555             return deleteEither;
556         }
557
558         // Delete input operations
559         try {
560             StorageOperationStatus status = toscaOperationFacade.deleteInputOfResource(component, inputForDelete.getName());
561             if (status != StorageOperationStatus.OK) {
562                 log.debug("Component id: {} delete input id: {} failed", componentId, inputId);
563                 deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), component.getName()));
564                 return deleteEither;
565             }
566             StorageOperationStatus storageOperationStatus = propertyDecelerationOrchestrator.unDeclarePropertiesAsInputs(component, inputForDelete);
567             if (storageOperationStatus != StorageOperationStatus.OK) {
568                 log.debug("Component id: {} update properties declared as input for input id: {} failed", componentId, inputId);
569                 deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), component.getName()));
570                 return deleteEither;
571             }
572             deleteEither = Either.left(inputForDelete);
573             return deleteEither;
574         } finally {
575             if (deleteEither == null || deleteEither.isRight()) {
576                 log.debug("Component id: {} delete input id: {} failed", componentId, inputId);
577                 titanDao.rollback();
578             } else {
579                 log.debug("Component id: {} delete input id: {} success", componentId, inputId);
580                 titanDao.commit();
581             }
582             unlockComponent(deleteEither, component);
583         }
584     }
585
586     private Either<InputDefinition, ResponseFormat> prepareAndValidateInputBeforeCreate(InputDefinition newInputDefinition, Map<String, DataTypeDefinition> dataTypes) {
587
588
589         // validate input default values
590         Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(newInputDefinition, dataTypes);
591         if (defaultValuesValidation.isRight()) {
592             return Either.right(defaultValuesValidation.right().value());
593         }
594         // convert property
595         ToscaPropertyType type = getType(newInputDefinition.getType());
596         if (type != null) {
597             PropertyValueConverter converter = type.getConverter();
598             // get inner type
599             String innerType = null;
600             if (newInputDefinition != null) {
601                 SchemaDefinition schema = newInputDefinition.getSchema();
602                 if (schema != null) {
603                     PropertyDataDefinition prop = schema.getProperty();
604                     if (prop != null) {
605                         innerType = prop.getType();
606                     }
607                 }
608                 String convertedValue = null;
609                 if (newInputDefinition.getDefaultValue() != null) {
610                     convertedValue = converter.convert(newInputDefinition.getDefaultValue(), innerType, dataTypes);
611                     newInputDefinition.setDefaultValue(convertedValue);
612                 }
613             }
614         }
615         return Either.left(newInputDefinition);
616     }
617
618     public Either<InputDefinition, ResponseFormat> getInputsAndPropertiesForComponentInput(String userId, String componentId, String inputId, boolean inTransaction) {
619         Either<InputDefinition, ResponseFormat> result = null;
620         try {
621
622             Either<User, ResponseFormat> resp = validateUserExists(userId, "get Properties by input", false);
623             if (resp.isRight()) {
624                 return Either.right(resp.right().value());
625             }
626             ComponentParametersView filters = new ComponentParametersView();
627             filters.disableAll();
628             filters.setIgnoreComponentInstances(false);
629             filters.setIgnoreInputs(false);
630             filters.setIgnoreComponentInstancesInputs(false);
631             filters.setIgnoreComponentInstancesProperties(false);
632             filters.setIgnoreProperties(false);
633             Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade.getToscaElement(componentId, filters);
634             if(getComponentEither.isRight()){
635                 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
636                 log.debug("Failed to found component {}, error: {}", componentId, actionStatus);
637                 return Either.right(componentsUtils.getResponseFormat(actionStatus));
638
639             }
640             org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
641             Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
642             if(!op.isPresent()){
643                 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
644                 log.debug("Failed to found input {} under component {}, error: {}", inputId, componentId, actionStatus);
645                 return Either.right(componentsUtils.getResponseFormat(actionStatus));
646             }
647
648             InputDefinition resObj = op.get();
649
650             List<ComponentInstanceInput> inputCIInput = componentInstanceBusinessLogic.getComponentInstanceInputsByInputId(component, inputId) ;
651
652             resObj.setInputs(inputCIInput);
653
654
655             List<ComponentInstanceProperty> inputProps = componentInstanceBusinessLogic.getComponentInstancePropertiesByInputId(component, inputId) ;
656
657             resObj.setProperties(inputProps);
658
659
660             result = Either.left(resObj);
661
662             return result;
663
664         } finally {
665
666             if (false == inTransaction) {
667
668                 if (result == null || result.isRight()) {
669                     log.debug("Going to execute rollback on create group.");
670                     titanDao.rollback();
671                 } else {
672                     log.debug("Going to execute commit on create group.");
673                     titanDao.commit();
674                 }
675
676             }
677
678         }
679
680     }
681
682
683 }