Service Consumption BE
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / impl / InterfaceOperationBusinessLogic.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 package org.openecomp.sdc.be.components.impl;
19
20 import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedInputPropertyDefaultValue;
21 import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedOutputDefaultValue;
22 import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId;
23 import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType;
24 import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOperationFromInterfaceDefinition;
25 import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.isOperationInputMappedToComponentInput;
26 import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.SELF;
27
28 import com.google.gson.Gson;
29
30 import java.util.ArrayList;
31 import java.util.Collection;
32 import java.util.Collections;
33 import java.util.HashMap;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.Objects;
37 import java.util.Optional;
38 import java.util.UUID;
39 import java.util.stream.Collectors;
40
41 import fj.data.Either;
42 import org.apache.commons.collections4.CollectionUtils;
43 import org.apache.commons.collections4.MapUtils;
44 import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation;
45 import org.openecomp.sdc.be.dao.api.ActionStatus;
46 import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
47 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
48 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
49 import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
50 import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
51 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
52 import org.openecomp.sdc.be.model.ArtifactDefinition;
53 import org.openecomp.sdc.be.model.ComponentInstanceInterface;
54 import org.openecomp.sdc.be.model.InputDefinition;
55 import org.openecomp.sdc.be.model.InterfaceDefinition;
56 import org.openecomp.sdc.be.model.Operation;
57 import org.openecomp.sdc.be.model.User;
58 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
59 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
60 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
61 import org.openecomp.sdc.exception.ResponseFormat;
62 import org.slf4j.Logger;
63 import org.slf4j.LoggerFactory;
64 import org.springframework.beans.factory.annotation.Autowired;
65 import org.springframework.stereotype.Component;
66
67 @Component("interfaceOperationBusinessLogic")
68 public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
69
70     private static final Logger LOGGER = LoggerFactory.getLogger(InterfaceOperationBusinessLogic.class);
71     private static final String EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION =
72             "Exception occurred during {}. Response is {}";
73     private static final String DELETE_INTERFACE_OPERATION = "deleteInterfaceOperation";
74     private static final String GET_INTERFACE_OPERATION = "getInterfaceOperation";
75     private static final String CREATE_INTERFACE_OPERATION = "createInterfaceOperation";
76     private static final String UPDATE_INTERFACE_OPERATION = "updateInterfaceOperation";
77
78     @Autowired
79     private ArtifactCassandraDao artifactCassandraDao;
80
81     @Autowired
82     private InterfaceOperationValidation interfaceOperationValidation;
83
84     public Either<List<InterfaceDefinition>, ResponseFormat> deleteInterfaceOperation(String componentId,
85             String interfaceId, List<String> operationsToDelete, User user, boolean lock) {
86         validateUserExists(user.getUserId(), DELETE_INTERFACE_OPERATION, true);
87
88         Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
89         if (componentEither.isRight()) {
90             return Either.right(componentEither.right().value());
91         }
92         org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
93
94         Either<Boolean, ResponseFormat> lockResult =
95                 lockComponentResult(lock, storedComponent, DELETE_INTERFACE_OPERATION);
96         if (lockResult.isRight()) {
97             return Either.right(lockResult.right().value());
98         }
99
100         try {
101             Optional<InterfaceDefinition> optionalInterface = getInterfaceDefinitionFromComponentByInterfaceId(
102                     storedComponent, interfaceId);
103             if (!optionalInterface.isPresent()) {
104                 return Either.right(
105                         componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceId));
106             }
107             InterfaceDefinition interfaceDefinition = optionalInterface.get();
108
109             Map<String, Operation> operationsCollection = new HashMap<>();
110             for (String operationId : operationsToDelete) {
111                 Optional<Map.Entry<String, Operation>> optionalOperation =
112                         getOperationFromInterfaceDefinition(interfaceDefinition, operationId);
113                 if (!optionalOperation.isPresent()) {
114                     return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND,
115                             storedComponent.getUniqueId()));
116                 }
117
118                 Operation storedOperation = optionalOperation.get().getValue();
119                 Either<Boolean, ResponseFormat> validateDeleteOperationContainsNoMappedOutputResponse =
120                         interfaceOperationValidation.validateDeleteOperationContainsNoMappedOutput(storedOperation,
121                                 storedComponent, interfaceDefinition);
122                 if (validateDeleteOperationContainsNoMappedOutputResponse.isRight()) {
123                     return Either.right(validateDeleteOperationContainsNoMappedOutputResponse.right().value());
124                 }
125                 String artifactUuId = storedOperation.getImplementation().getArtifactUUID();
126                 CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUuId);
127                 if (cassandraStatus != CassandraOperationStatus.OK) {
128                     ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
129                             componentsUtils.convertFromStorageResponse(
130                                     componentsUtils.convertToStorageOperationStatus(cassandraStatus)),
131                             storedOperation.getImplementation().getArtifactDisplayName());
132                     return Either.right(responseFormatByArtifactId);
133                 }
134
135                 operationsCollection.put(operationId, interfaceDefinition.getOperationsMap().get(operationId));
136                 interfaceDefinition.getOperations().remove(operationId);
137             }
138
139             Either<List<InterfaceDefinition>, StorageOperationStatus> deleteOperationEither =
140                     interfaceOperation.updateInterfaces(storedComponent.getUniqueId(),
141                             Collections.singletonList(interfaceDefinition));
142             if (deleteOperationEither.isRight()) {
143                 titanDao.rollback();
144                 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
145                         deleteOperationEither.right().value(), storedComponent.getComponentType())));
146             }
147
148             if (interfaceDefinition.getOperations().isEmpty()) {
149                 Either<String, StorageOperationStatus> deleteInterfaceEither = interfaceOperation.deleteInterface(
150                         storedComponent.getUniqueId(), interfaceDefinition.getUniqueId());
151                 if (deleteInterfaceEither.isRight()) {
152                     titanDao.rollback();
153                     return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
154                             deleteInterfaceEither.right().value(), storedComponent.getComponentType())));
155                 }
156             }
157
158             titanDao.commit();
159             interfaceDefinition.getOperations().putAll(operationsCollection);
160             interfaceDefinition.getOperations().keySet().removeIf(key -> !(operationsToDelete.contains(key)));
161             return Either.left(Collections.singletonList(interfaceDefinition));
162         } catch (Exception e) {
163             LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "delete", e);
164             titanDao.rollback();
165             return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_DELETED));
166         } finally {
167             if (lockResult.isLeft() && lockResult.left().value()) {
168                 graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
169                         NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
170             }
171         }
172     }
173
174     private Either<org.openecomp.sdc.be.model.Component, ResponseFormat> getComponentDetails(String componentId) {
175         Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentStorageOperationStatusEither =
176                 toscaOperationFacade.getToscaElement(componentId);
177         if (componentStorageOperationStatusEither.isRight()) {
178             return Either.right(componentsUtils.getResponseFormat(
179                     componentsUtils.convertFromStorageResponse(componentStorageOperationStatusEither.right().value())));
180         }
181         return Either.left(componentStorageOperationStatusEither.left().value());
182     }
183
184     private Either<Boolean, ResponseFormat> lockComponentResult(boolean lock,
185             org.openecomp.sdc.be.model.Component component, String action) {
186         if (lock) {
187             Either<Boolean, ResponseFormat> lockResult = lockComponent(component.getUniqueId(), component, action);
188             if (lockResult.isRight()) {
189                 titanDao.rollback();
190                 return Either.right(lockResult.right().value());
191             }
192         }
193         return Either.left(true);
194     }
195
196     public Either<List<InterfaceDefinition>, ResponseFormat> getInterfaceOperation(String componentId,
197             String interfaceId, List<String> operationsToGet, User user, boolean lock) {
198         validateUserExists(user.getUserId(), GET_INTERFACE_OPERATION, true);
199
200         Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
201         if (componentEither.isRight()) {
202             return Either.right(componentEither.right().value());
203         }
204         org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
205
206         Either<Boolean, ResponseFormat> lockResult =
207                 lockComponentResult(lock, storedComponent, GET_INTERFACE_OPERATION);
208         if (lockResult.isRight()) {
209             return Either.right(lockResult.right().value());
210         }
211
212         try {
213             Optional<InterfaceDefinition> optionalInterface = getInterfaceDefinitionFromComponentByInterfaceId(
214                     storedComponent, interfaceId);
215             if (!optionalInterface.isPresent()) {
216                 return Either.right(
217                         componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceId));
218             }
219             InterfaceDefinition interfaceDefinition = optionalInterface.get();
220
221             for (String operationId : operationsToGet) {
222                 Optional<Map.Entry<String, Operation>> optionalOperation =
223                         getOperationFromInterfaceDefinition(interfaceDefinition, operationId);
224                 if (!optionalOperation.isPresent()) {
225                     return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND,
226                             storedComponent.getUniqueId()));
227                 }
228             }
229
230             titanDao.commit();
231             interfaceDefinition.getOperations().keySet().removeIf(key -> !(operationsToGet.contains(key)));
232             return Either.left(Collections.singletonList(interfaceDefinition));
233         } catch (Exception e) {
234             LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "get", e);
235             titanDao.rollback();
236             return Either.right(
237                     componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentId));
238         } finally {
239             if (lockResult.isLeft() && lockResult.left().value()) {
240                 graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
241                         NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
242             }
243         }
244     }
245
246     public Either<List<InterfaceDefinition>, ResponseFormat> createInterfaceOperation(String componentId,
247             List<InterfaceDefinition> interfaceDefinitions, User user, boolean lock) {
248         return createOrUpdateInterfaceOperation(componentId, interfaceDefinitions, user, false,
249                 CREATE_INTERFACE_OPERATION, lock);
250     }
251
252     private Either<List<InterfaceDefinition>, ResponseFormat> createOrUpdateInterfaceOperation(String componentId,
253             List<InterfaceDefinition> interfaceDefinitions, User user, boolean isUpdate, String errorContext,
254             boolean lock) {
255         validateUserExists(user.getUserId(), errorContext, true);
256
257         Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
258         if (componentEither.isRight()) {
259             return Either.right(componentEither.right().value());
260         }
261         org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
262
263         Either<Boolean, ResponseFormat> lockResult = lockComponentResult(lock, storedComponent, errorContext);
264         if (lockResult.isRight()) {
265             return Either.right(lockResult.right().value());
266         }
267
268         Either<Map<String, InterfaceDefinition>, ResponseFormat> interfaceLifecycleTypes =
269                 getAllInterfaceLifecycleTypes();
270         if (interfaceLifecycleTypes.isRight()) {
271             return Either.right(interfaceLifecycleTypes.right().value());
272         }
273
274         try {
275             List<InterfaceDefinition> interfacesCollection = new ArrayList<>();
276             Map<String, Operation> operationsCollection = new HashMap<>();
277             for (InterfaceDefinition inputInterfaceDefinition : interfaceDefinitions) {
278                 Optional<InterfaceDefinition> optionalInterface =
279                         getInterfaceDefinitionFromComponentByInterfaceType(
280                                 storedComponent, inputInterfaceDefinition.getType());
281                 Either<Boolean, ResponseFormat> interfaceOperationValidationResponseEither =
282                         interfaceOperationValidation
283                                 .validateInterfaceOperations(inputInterfaceDefinition, storedComponent,
284                                         optionalInterface.orElse(null), interfaceLifecycleTypes.left().value(),
285                                         isUpdate);
286                 if (interfaceOperationValidationResponseEither.isRight()) {
287                     return Either.right(interfaceOperationValidationResponseEither.right().value());
288                 }
289
290                 Map<String, Operation> operationsToAddOrUpdate = inputInterfaceDefinition.getOperationsMap();
291                 operationsCollection.putAll(operationsToAddOrUpdate);
292                 inputInterfaceDefinition.getOperations().clear();
293
294                 Either<InterfaceDefinition, ResponseFormat> getInterfaceEither =
295                         getOrCreateInterfaceDefinition(storedComponent, inputInterfaceDefinition,
296                                 optionalInterface.orElse(null));
297                 if (getInterfaceEither.isRight()) {
298                     return Either.right(getInterfaceEither.right().value());
299                 }
300                 InterfaceDefinition interfaceDef = getInterfaceEither.left().value();
301
302                 updateOperationInputDefs(storedComponent, operationsToAddOrUpdate.values());
303
304                 for (Operation operation : operationsToAddOrUpdate.values()) {
305                     if (!isUpdate) {
306                         addOperationToInterface(interfaceDef, operation);
307                     } else {
308                         Optional<Map.Entry<String, Operation>> optionalOperation =
309                                 getOperationFromInterfaceDefinition(interfaceDef,
310                                         operation.getUniqueId());
311                         if (!optionalOperation.isPresent()) {
312                             titanDao.rollback();
313                             return Either.right(componentsUtils
314                                                         .getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND,
315                                                                 storedComponent.getUniqueId()));
316                         }
317
318                         Operation storedOperation = optionalOperation.get().getValue();
319                         String artifactUuId = storedOperation.getImplementation().getArtifactUUID();
320                         Either<Long, CassandraOperationStatus> artifactCount =
321                                 artifactCassandraDao.getCountOfArtifactById(artifactUuId);
322                         if (artifactCount.isLeft()) {
323                             CassandraOperationStatus cassandraStatus =
324                                     artifactCassandraDao.deleteArtifact(artifactUuId);
325                             if (cassandraStatus != CassandraOperationStatus.OK) {
326                                 titanDao.rollback();
327                                 ResponseFormat responseFormatByArtifactId =
328                                         componentsUtils.getResponseFormatByArtifactId(
329                                                 componentsUtils.convertFromStorageResponse(
330                                                         componentsUtils.convertToStorageOperationStatus(
331                                                                 cassandraStatus)),
332                                                 storedOperation.getImplementation().getArtifactDisplayName());
333                                 return Either.right(responseFormatByArtifactId);
334                             }
335                         }
336                         updateOperationOnInterface(interfaceDef, operation, artifactUuId);
337                     }
338                 }
339                 interfacesCollection.add(interfaceDef);
340             }
341
342             Either<List<InterfaceDefinition>, StorageOperationStatus> addCreateOperationEither =
343                     interfaceOperation.updateInterfaces(storedComponent.getUniqueId(), interfacesCollection);
344             if (addCreateOperationEither.isRight()) {
345                 titanDao.rollback();
346                 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
347                         addCreateOperationEither.right().value(), storedComponent.getComponentType())));
348             }
349
350             titanDao.commit();
351             interfacesCollection.forEach(interfaceDefinition -> interfaceDefinition.getOperations().entrySet().removeIf(
352                     entry -> !operationsCollection.values().stream().map(OperationDataDefinition::getName)
353                                       .collect(Collectors.toList()).contains(entry.getValue().getName())));
354             return Either.left(interfacesCollection);
355         } catch (Exception e) {
356             titanDao.rollback();
357             LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "addOrUpdate", e);
358             return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
359         } finally {
360             if (lockResult.isLeft() && lockResult.left().value()) {
361                 graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
362                         NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
363             }
364         }
365     }
366
367     public Either<Map<String, InterfaceDefinition>, ResponseFormat> getAllInterfaceLifecycleTypes() {
368
369         Either<Map<String, InterfaceDefinition>, StorageOperationStatus> interfaceLifecycleTypes =
370                 interfaceLifecycleTypeOperation.getAllInterfaceLifecycleTypes();
371         if (interfaceLifecycleTypes.isRight()) {
372             return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_LIFECYCLE_TYPES_NOT_FOUND));
373         }
374         interfaceLifecycleTypes.left().value().values().forEach(id -> id.setOperations(
375                 id.getOperations().keySet().stream().collect(Collectors.toMap(key -> key.replaceFirst(
376                         id.getUniqueId() + ".", ""), i -> id.getOperations().get(i)))));
377
378         return Either.left(interfaceLifecycleTypes.left().value());
379     }
380
381     private Either<InterfaceDefinition, ResponseFormat> getOrCreateInterfaceDefinition(
382             org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDefinition,
383             InterfaceDefinition storedInterfaceDef) {
384         if (storedInterfaceDef != null) {
385             return Either.left(storedInterfaceDef);
386         }
387         interfaceDefinition.setUniqueId(UUID.randomUUID().toString());
388         interfaceDefinition.setToscaResourceName(interfaceDefinition.getType());
389         Either<List<InterfaceDefinition>, StorageOperationStatus> interfaceCreateEither =
390                 interfaceOperation.addInterfaces(component.getUniqueId(),
391                         Collections.singletonList(interfaceDefinition));
392         if (interfaceCreateEither.isRight()) {
393             titanDao.rollback();
394             return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
395                     interfaceCreateEither.right().value(), component.getComponentType())));
396         }
397         return Either.left(interfaceCreateEither.left().value().get(0));
398     }
399
400     private void updateOperationInputDefs(org.openecomp.sdc.be.model.Component component,
401                                           Collection<Operation> interfaceOperations) {
402         interfaceOperations.stream().filter(operation -> Objects.nonNull(operation.getInputs())).forEach(
403                 operation -> operation.getInputs().getListToscaDataDefinition().forEach(
404                         inp -> component.getInputs()
405                                 .forEach(in -> updateOperationInputDefinition(component, inp, in))));
406     }
407
408     private void updateOperationInputDefinition(org.openecomp.sdc.be.model.Component component,
409                                                 OperationInputDefinition operationInput,
410                                                 InputDefinition componentInput) {
411         if (operationInput.getInputId().equals(componentInput.getUniqueId())) {
412             //Set the default value, value and schema only for inputs mapped to component inputs
413             operationInput.setDefaultValue(componentInput.getDefaultValue());
414             operationInput.setToscaDefaultValue(getInputToscaDefaultValue(operationInput, component));
415             operationInput.setValue(componentInput.getValue());
416             operationInput.setSchema(componentInput.getSchema());
417         }
418         //Set the tosca default value for inputs mapped to component inputs as well as other outputs
419         operationInput.setToscaDefaultValue(getInputToscaDefaultValue(operationInput, component));
420     }
421
422     private String getInputToscaDefaultValue(OperationInputDefinition input,
423                                              org.openecomp.sdc.be.model.Component component) {
424         Map<String, List<String>> defaultInputValue;
425         if (isOperationInputMappedToComponentInput(input, component.getInputs())) {
426             String propertyName = input.getInputId().substring(input.getInputId().indexOf('.') + 1);
427             defaultInputValue = createMappedInputPropertyDefaultValue(propertyName);
428         } else {
429             //Currently inputs can only be mapped to a declared input or an other operation outputs
430             defaultInputValue = createMappedOutputDefaultValue(SELF, input.getInputId());
431         }
432         return new Gson().toJson(defaultInputValue);
433     }
434
435     private void addOperationToInterface(InterfaceDefinition interfaceDefinition, Operation interfaceOperation) {
436         interfaceOperation.setUniqueId(UUID.randomUUID().toString());
437         interfaceOperation.setImplementation(createArtifactDefinition(UUID.randomUUID().toString()));
438         interfaceDefinition.getOperations()
439                 .put(interfaceOperation.getUniqueId(), new OperationDataDefinition(interfaceOperation));
440     }
441
442     private void updateOperationOnInterface(InterfaceDefinition interfaceDefinition, Operation interfaceOperation,
443             String artifactUuId) {
444         interfaceOperation.setImplementation(createArtifactDefinition(artifactUuId));
445         interfaceDefinition.getOperations()
446                 .put(interfaceOperation.getUniqueId(), new OperationDataDefinition(interfaceOperation));
447     }
448
449     private ArtifactDefinition createArtifactDefinition(String artifactUuId) {
450         ArtifactDefinition artifactDefinition = new ArtifactDefinition();
451         artifactDefinition.setArtifactUUID(artifactUuId);
452         artifactDefinition.setUniqueId(artifactUuId);
453         artifactDefinition.setArtifactType(ArtifactTypeEnum.WORKFLOW.getType());
454         artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
455         return artifactDefinition;
456     }
457
458     public Either<List<InterfaceDefinition>, ResponseFormat> updateInterfaceOperation(String componentId,
459             List<InterfaceDefinition> interfaceDefinitions, User user, boolean lock) {
460         return createOrUpdateInterfaceOperation(componentId, interfaceDefinitions, user, true,
461                 UPDATE_INTERFACE_OPERATION, lock);
462     }
463
464     public Either<List<OperationInputDefinition>, ResponseFormat> getInputsListForOperation(String componentId,
465                                                                                             String componentInstanceId, String interfaceId, String operationId, User user) {
466         Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
467         if (componentEither.isRight()){
468             return Either.right(componentEither.right().value());
469         }
470
471         org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
472         validateUserExists(user.getUserId(), GET_INTERFACE_OPERATION, true);
473
474         Either<Boolean, ResponseFormat> lockResult = lockComponentResult(true, storedComponent, GET_INTERFACE_OPERATION);
475         if (lockResult.isRight()) {
476             return Either.right(lockResult.right().value());
477         }
478
479         try{
480             org.openecomp.sdc.be.model.Component parentComponent = componentEither.left().value();
481             Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces =
482                     parentComponent.getComponentInstancesInterfaces();
483             if(MapUtils.isEmpty(componentInstanceInterfaces)) {
484                 return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND,
485                         componentInstanceId));
486             }
487
488             List<ComponentInstanceInterface> componentInstanceInterfaceList =
489                     componentInstanceInterfaces.get(componentInstanceId);
490             for(ComponentInstanceInterface componentInstanceInterface : componentInstanceInterfaceList) {
491                 if(componentInstanceInterface.getInterfaceId().equals(interfaceId)){
492                     Map<String, OperationDataDefinition> operations = componentInstanceInterface.getOperations();
493                     if(MapUtils.isNotEmpty(operations) && operations.containsKey(operationId)) {
494                         ListDataDefinition<OperationInputDefinition> inputs = operations.get(operationId).getInputs();
495                         return Either.left(CollectionUtils.isEmpty(inputs.getListToscaDataDefinition())
496                                 ? new ArrayList<>() : inputs.getListToscaDataDefinition());
497                     }
498                 }
499             }
500             return Either.left(new ArrayList<>());
501         }
502         catch (Exception e) {
503             LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "get", e);
504             titanDao.rollback();
505             return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND));
506         }
507         finally {
508             if (lockResult.isLeft() && lockResult.left().value()) {
509                 graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
510                         NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
511             }
512         }
513     }
514
515 }