2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.openecomp.sdc.be.components.impl;
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;
28 import com.google.gson.Gson;
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;
36 import java.util.Objects;
37 import java.util.Optional;
38 import java.util.UUID;
39 import java.util.stream.Collectors;
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.utils.InterfaceOperationUtils;
45 import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation;
46 import org.openecomp.sdc.be.dao.api.ActionStatus;
47 import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
48 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
49 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
50 import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
51 import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
52 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
53 import org.openecomp.sdc.be.model.ArtifactDefinition;
54 import org.openecomp.sdc.be.model.ComponentInstanceInterface;
55 import org.openecomp.sdc.be.model.InputDefinition;
56 import org.openecomp.sdc.be.model.InterfaceDefinition;
57 import org.openecomp.sdc.be.model.Operation;
58 import org.openecomp.sdc.be.model.User;
59 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
60 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
61 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
62 import org.openecomp.sdc.exception.ResponseFormat;
63 import org.slf4j.Logger;
64 import org.slf4j.LoggerFactory;
65 import org.springframework.beans.factory.annotation.Autowired;
66 import org.springframework.stereotype.Component;
68 @Component("interfaceOperationBusinessLogic")
69 public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
71 private static final Logger LOGGER = LoggerFactory.getLogger(InterfaceOperationBusinessLogic.class);
72 private static final String EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION =
73 "Exception occurred during {}. Response is {}";
74 private static final String DELETE_INTERFACE_OPERATION = "deleteInterfaceOperation";
75 private static final String GET_INTERFACE_OPERATION = "getInterfaceOperation";
76 private static final String CREATE_INTERFACE_OPERATION = "createInterfaceOperation";
77 private static final String UPDATE_INTERFACE_OPERATION = "updateInterfaceOperation";
80 private ArtifactCassandraDao artifactCassandraDao;
83 private InterfaceOperationValidation interfaceOperationValidation;
85 public Either<List<InterfaceDefinition>, ResponseFormat> deleteInterfaceOperation(String componentId,
86 String interfaceId, List<String> operationsToDelete, User user, boolean lock) {
87 validateUserExists(user.getUserId(), DELETE_INTERFACE_OPERATION, true);
89 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
90 if (componentEither.isRight()) {
91 return Either.right(componentEither.right().value());
93 org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
95 Either<Boolean, ResponseFormat> lockResult =
96 lockComponentResult(lock, storedComponent, DELETE_INTERFACE_OPERATION);
97 if (lockResult.isRight()) {
98 return Either.right(lockResult.right().value());
102 Optional<InterfaceDefinition> optionalInterface = getInterfaceDefinitionFromComponentByInterfaceId(
103 storedComponent, interfaceId);
104 if (!optionalInterface.isPresent()) {
106 componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceId));
108 InterfaceDefinition interfaceDefinition = optionalInterface.get();
110 Map<String, Operation> operationsCollection = new HashMap<>();
111 for (String operationId : operationsToDelete) {
112 Optional<Map.Entry<String, Operation>> optionalOperation =
113 getOperationFromInterfaceDefinition(interfaceDefinition, operationId);
114 if (!optionalOperation.isPresent()) {
115 return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND,
116 storedComponent.getUniqueId()));
119 Operation storedOperation = optionalOperation.get().getValue();
120 Either<Boolean, ResponseFormat> validateDeleteOperationContainsNoMappedOutputResponse =
121 interfaceOperationValidation.validateDeleteOperationContainsNoMappedOutput(storedOperation,
122 storedComponent, interfaceDefinition);
123 if (validateDeleteOperationContainsNoMappedOutputResponse.isRight()) {
124 return Either.right(validateDeleteOperationContainsNoMappedOutputResponse.right().value());
127 String artifactUniqueId = storedOperation.getImplementation().getUniqueId();
128 if(!InterfaceOperationUtils.isArtifactInUse(storedComponent, operationId, artifactUniqueId)){
129 Either<ArtifactDefinition, StorageOperationStatus> getArtifactEither =
130 artifactToscaOperation.getArtifactById(storedComponent.getUniqueId(), artifactUniqueId);
131 if(getArtifactEither.isLeft()){
132 Either<ArtifactDefinition, StorageOperationStatus> removeArifactFromComponent =
133 artifactToscaOperation.removeArifactFromResource(componentId, artifactUniqueId,
134 NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()),
136 if(removeArifactFromComponent.isRight()){
138 ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
139 componentsUtils.convertFromStorageResponse(removeArifactFromComponent.right().value()),
140 storedOperation.getImplementation().getArtifactDisplayName());
141 return Either.right(responseFormatByArtifactId);
144 CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUniqueId);
145 if (cassandraStatus != CassandraOperationStatus.OK) {
147 ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
148 componentsUtils.convertFromStorageResponse(
149 componentsUtils.convertToStorageOperationStatus(cassandraStatus)),
150 storedOperation.getImplementation().getArtifactDisplayName());
151 return Either.right(responseFormatByArtifactId);
156 operationsCollection.put(operationId, interfaceDefinition.getOperationsMap().get(operationId));
157 interfaceDefinition.getOperations().remove(operationId);
160 Either<List<InterfaceDefinition>, StorageOperationStatus> deleteOperationEither =
161 interfaceOperation.updateInterfaces(storedComponent.getUniqueId(),
162 Collections.singletonList(interfaceDefinition));
163 if (deleteOperationEither.isRight()) {
165 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
166 deleteOperationEither.right().value(), storedComponent.getComponentType())));
169 if (interfaceDefinition.getOperations().isEmpty()) {
170 Either<String, StorageOperationStatus> deleteInterfaceEither = interfaceOperation.deleteInterface(
171 storedComponent.getUniqueId(), interfaceDefinition.getUniqueId());
172 if (deleteInterfaceEither.isRight()) {
174 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
175 deleteInterfaceEither.right().value(), storedComponent.getComponentType())));
180 interfaceDefinition.getOperations().putAll(operationsCollection);
181 interfaceDefinition.getOperations().keySet().removeIf(key -> !(operationsToDelete.contains(key)));
182 return Either.left(Collections.singletonList(interfaceDefinition));
183 } catch (Exception e) {
184 LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "delete", e);
186 return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_DELETED));
188 if (lockResult.isLeft() && lockResult.left().value()) {
189 graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
190 NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
195 private Either<org.openecomp.sdc.be.model.Component, ResponseFormat> getComponentDetails(String componentId) {
196 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentStorageOperationStatusEither =
197 toscaOperationFacade.getToscaElement(componentId);
198 if (componentStorageOperationStatusEither.isRight()) {
199 return Either.right(componentsUtils.getResponseFormat(
200 componentsUtils.convertFromStorageResponse(componentStorageOperationStatusEither.right().value())));
202 return Either.left(componentStorageOperationStatusEither.left().value());
205 private Either<Boolean, ResponseFormat> lockComponentResult(boolean lock,
206 org.openecomp.sdc.be.model.Component component, String action) {
208 Either<Boolean, ResponseFormat> lockResult = lockComponent(component.getUniqueId(), component, action);
209 if (lockResult.isRight()) {
211 return Either.right(lockResult.right().value());
214 return Either.left(true);
217 public Either<List<InterfaceDefinition>, ResponseFormat> getInterfaceOperation(String componentId,
218 String interfaceId, List<String> operationsToGet, User user, boolean lock) {
219 validateUserExists(user.getUserId(), GET_INTERFACE_OPERATION, true);
221 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
222 if (componentEither.isRight()) {
223 return Either.right(componentEither.right().value());
225 org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
227 Either<Boolean, ResponseFormat> lockResult =
228 lockComponentResult(lock, storedComponent, GET_INTERFACE_OPERATION);
229 if (lockResult.isRight()) {
230 return Either.right(lockResult.right().value());
234 Optional<InterfaceDefinition> optionalInterface = getInterfaceDefinitionFromComponentByInterfaceId(
235 storedComponent, interfaceId);
236 if (!optionalInterface.isPresent()) {
238 componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceId));
240 InterfaceDefinition interfaceDefinition = optionalInterface.get();
242 for (String operationId : operationsToGet) {
243 Optional<Map.Entry<String, Operation>> optionalOperation =
244 getOperationFromInterfaceDefinition(interfaceDefinition, operationId);
245 if (!optionalOperation.isPresent()) {
246 return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND,
247 storedComponent.getUniqueId()));
252 interfaceDefinition.getOperations().keySet().removeIf(key -> !(operationsToGet.contains(key)));
253 return Either.left(Collections.singletonList(interfaceDefinition));
254 } catch (Exception e) {
255 LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "get", e);
258 componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentId));
260 if (lockResult.isLeft() && lockResult.left().value()) {
261 graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
262 NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
267 public Either<List<InterfaceDefinition>, ResponseFormat> createInterfaceOperation(String componentId,
268 List<InterfaceDefinition> interfaceDefinitions, User user, boolean lock) {
269 return createOrUpdateInterfaceOperation(componentId, interfaceDefinitions, user, false,
270 CREATE_INTERFACE_OPERATION, lock);
273 private Either<List<InterfaceDefinition>, ResponseFormat> createOrUpdateInterfaceOperation(String componentId,
274 List<InterfaceDefinition> interfaceDefinitions, User user, boolean isUpdate, String errorContext,
276 validateUserExists(user.getUserId(), errorContext, true);
278 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
279 if (componentEither.isRight()) {
280 return Either.right(componentEither.right().value());
282 org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
284 Either<Boolean, ResponseFormat> lockResult = lockComponentResult(lock, storedComponent, errorContext);
285 if (lockResult.isRight()) {
286 return Either.right(lockResult.right().value());
289 Either<Map<String, InterfaceDefinition>, ResponseFormat> interfaceLifecycleTypes =
290 getAllInterfaceLifecycleTypes();
291 if (interfaceLifecycleTypes.isRight()) {
292 return Either.right(interfaceLifecycleTypes.right().value());
296 List<InterfaceDefinition> interfacesCollection = new ArrayList<>();
297 Map<String, Operation> operationsCollection = new HashMap<>();
298 for (InterfaceDefinition inputInterfaceDefinition : interfaceDefinitions) {
299 Optional<InterfaceDefinition> optionalInterface =
300 getInterfaceDefinitionFromComponentByInterfaceType(
301 storedComponent, inputInterfaceDefinition.getType());
302 Either<Boolean, ResponseFormat> interfaceOperationValidationResponseEither =
303 interfaceOperationValidation
304 .validateInterfaceOperations(inputInterfaceDefinition, storedComponent,
305 optionalInterface.orElse(null), interfaceLifecycleTypes.left().value(),
307 if (interfaceOperationValidationResponseEither.isRight()) {
308 return Either.right(interfaceOperationValidationResponseEither.right().value());
311 Map<String, Operation> operationsToAddOrUpdate = inputInterfaceDefinition.getOperationsMap();
312 operationsCollection.putAll(operationsToAddOrUpdate);
313 inputInterfaceDefinition.getOperations().clear();
315 Either<InterfaceDefinition, ResponseFormat> getInterfaceEither =
316 getOrCreateInterfaceDefinition(storedComponent, inputInterfaceDefinition,
317 optionalInterface.orElse(null));
318 if (getInterfaceEither.isRight()) {
319 return Either.right(getInterfaceEither.right().value());
321 InterfaceDefinition interfaceDef = getInterfaceEither.left().value();
323 updateOperationInputDefs(storedComponent, operationsToAddOrUpdate.values());
325 for (Operation operation : operationsToAddOrUpdate.values()) {
327 addOperationToInterface(interfaceDef, operation);
329 Optional<Map.Entry<String, Operation>> optionalOperation =
330 getOperationFromInterfaceDefinition(interfaceDef,
331 operation.getUniqueId());
332 if (!optionalOperation.isPresent()) {
334 return Either.right(componentsUtils
335 .getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND,
336 storedComponent.getUniqueId()));
339 Operation storedOperation = optionalOperation.get().getValue();
340 String artifactUuId = storedOperation.getImplementation().getArtifactUUID();
341 String artifactUniqueId = storedOperation.getImplementation().getUniqueId();
343 if(!InterfaceOperationUtils.isArtifactInUse(storedComponent, storedOperation.getUniqueId(), artifactUniqueId)){
344 Either<ArtifactDefinition, StorageOperationStatus> getArtifactEither =
345 artifactToscaOperation.getArtifactById(storedComponent.getUniqueId(), artifactUniqueId);
346 if(getArtifactEither.isLeft()){
347 Either<ArtifactDefinition, StorageOperationStatus> removeArifactFromComponent =
348 artifactToscaOperation.removeArifactFromResource(componentId, artifactUniqueId,
349 NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()),
351 if(removeArifactFromComponent.isRight()){
353 ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
354 componentsUtils.convertFromStorageResponse(removeArifactFromComponent.right().value()),
355 storedOperation.getImplementation().getArtifactDisplayName());
356 return Either.right(responseFormatByArtifactId);
359 CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUniqueId);
360 if (cassandraStatus != CassandraOperationStatus.OK) {
362 ResponseFormat responseFormatByArtifactId =
363 componentsUtils.getResponseFormatByArtifactId(
364 componentsUtils.convertFromStorageResponse(
365 componentsUtils.convertToStorageOperationStatus(
367 storedOperation.getImplementation().getArtifactDisplayName());
368 return Either.right(responseFormatByArtifactId);
372 updateOperationOnInterface(interfaceDef, operation, artifactUuId);
375 interfacesCollection.add(interfaceDef);
378 Either<List<InterfaceDefinition>, StorageOperationStatus> addCreateOperationEither =
379 interfaceOperation.updateInterfaces(storedComponent.getUniqueId(), interfacesCollection);
380 if (addCreateOperationEither.isRight()) {
382 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
383 addCreateOperationEither.right().value(), storedComponent.getComponentType())));
387 interfacesCollection.forEach(interfaceDefinition -> interfaceDefinition.getOperations().entrySet().removeIf(
388 entry -> !operationsCollection.values().stream().map(OperationDataDefinition::getName)
389 .collect(Collectors.toList()).contains(entry.getValue().getName())));
390 return Either.left(interfacesCollection);
391 } catch (Exception e) {
393 LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "addOrUpdate", e);
394 return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
396 if (lockResult.isLeft() && lockResult.left().value()) {
397 graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
398 NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
403 public Either<Map<String, InterfaceDefinition>, ResponseFormat> getAllInterfaceLifecycleTypes() {
405 Either<Map<String, InterfaceDefinition>, StorageOperationStatus> interfaceLifecycleTypes =
406 interfaceLifecycleTypeOperation.getAllInterfaceLifecycleTypes();
407 if (interfaceLifecycleTypes.isRight()) {
408 return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_LIFECYCLE_TYPES_NOT_FOUND));
410 interfaceLifecycleTypes.left().value().values().forEach(id -> id.setOperations(
411 id.getOperations().keySet().stream().collect(Collectors.toMap(key -> key.replaceFirst(
412 id.getUniqueId() + ".", ""), i -> id.getOperations().get(i)))));
414 return Either.left(interfaceLifecycleTypes.left().value());
417 private Either<InterfaceDefinition, ResponseFormat> getOrCreateInterfaceDefinition(
418 org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDefinition,
419 InterfaceDefinition storedInterfaceDef) {
420 if (storedInterfaceDef != null) {
421 return Either.left(storedInterfaceDef);
423 interfaceDefinition.setUniqueId(UUID.randomUUID().toString());
424 interfaceDefinition.setToscaResourceName(interfaceDefinition.getType());
425 Either<List<InterfaceDefinition>, StorageOperationStatus> interfaceCreateEither =
426 interfaceOperation.addInterfaces(component.getUniqueId(),
427 Collections.singletonList(interfaceDefinition));
428 if (interfaceCreateEither.isRight()) {
430 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
431 interfaceCreateEither.right().value(), component.getComponentType())));
433 return Either.left(interfaceCreateEither.left().value().get(0));
436 private void updateOperationInputDefs(org.openecomp.sdc.be.model.Component component,
437 Collection<Operation> interfaceOperations) {
438 interfaceOperations.stream().filter(operation -> Objects.nonNull(operation.getInputs())).forEach(
439 operation -> operation.getInputs().getListToscaDataDefinition().forEach(
440 inp -> component.getInputs()
441 .forEach(in -> updateOperationInputDefinition(component, inp, in))));
444 private void updateOperationInputDefinition(org.openecomp.sdc.be.model.Component component,
445 OperationInputDefinition operationInput,
446 InputDefinition componentInput) {
447 if (operationInput.getInputId().equals(componentInput.getUniqueId())) {
448 //Set the default value, value and schema only for inputs mapped to component inputs
449 operationInput.setDefaultValue(componentInput.getDefaultValue());
450 operationInput.setToscaDefaultValue(getInputToscaDefaultValue(operationInput, component));
451 operationInput.setValue(componentInput.getValue());
452 operationInput.setSchema(componentInput.getSchema());
454 //Set the tosca default value for inputs mapped to component inputs as well as other outputs
455 operationInput.setToscaDefaultValue(getInputToscaDefaultValue(operationInput, component));
458 private String getInputToscaDefaultValue(OperationInputDefinition input,
459 org.openecomp.sdc.be.model.Component component) {
460 Map<String, List<String>> defaultInputValue;
461 if (isOperationInputMappedToComponentInput(input, component.getInputs())) {
462 String propertyName = input.getInputId().substring(input.getInputId().indexOf('.') + 1);
463 defaultInputValue = createMappedInputPropertyDefaultValue(propertyName);
465 //Currently inputs can only be mapped to a declared input or an other operation outputs
466 defaultInputValue = createMappedOutputDefaultValue(SELF, input.getInputId());
468 return new Gson().toJson(defaultInputValue);
471 private void addOperationToInterface(InterfaceDefinition interfaceDefinition, Operation interfaceOperation) {
472 interfaceOperation.setUniqueId(UUID.randomUUID().toString());
473 interfaceOperation.setImplementation(createArtifactDefinition(UUID.randomUUID().toString()));
474 interfaceDefinition.getOperations()
475 .put(interfaceOperation.getUniqueId(), new OperationDataDefinition(interfaceOperation));
478 private void updateOperationOnInterface(InterfaceDefinition interfaceDefinition, Operation interfaceOperation,
479 String artifactUuId) {
480 interfaceOperation.setImplementation(createArtifactDefinition(artifactUuId));
481 interfaceDefinition.getOperations()
482 .put(interfaceOperation.getUniqueId(), new OperationDataDefinition(interfaceOperation));
485 private ArtifactDefinition createArtifactDefinition(String artifactUuId) {
486 ArtifactDefinition artifactDefinition = new ArtifactDefinition();
487 artifactDefinition.setArtifactUUID(artifactUuId);
488 artifactDefinition.setUniqueId(artifactUuId);
489 artifactDefinition.setArtifactType(ArtifactTypeEnum.WORKFLOW.getType());
490 artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
491 return artifactDefinition;
494 public Either<List<InterfaceDefinition>, ResponseFormat> updateInterfaceOperation(String componentId,
495 List<InterfaceDefinition> interfaceDefinitions, User user, boolean lock) {
496 return createOrUpdateInterfaceOperation(componentId, interfaceDefinitions, user, true,
497 UPDATE_INTERFACE_OPERATION, lock);
500 public Either<List<OperationInputDefinition>, ResponseFormat> getInputsListForOperation(String componentId,
501 String componentInstanceId, String interfaceId, String operationId, User user) {
502 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
503 if (componentEither.isRight()){
504 return Either.right(componentEither.right().value());
507 org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
508 validateUserExists(user.getUserId(), GET_INTERFACE_OPERATION, true);
510 Either<Boolean, ResponseFormat> lockResult = lockComponentResult(true, storedComponent, GET_INTERFACE_OPERATION);
511 if (lockResult.isRight()) {
512 return Either.right(lockResult.right().value());
516 org.openecomp.sdc.be.model.Component parentComponent = componentEither.left().value();
517 Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces =
518 parentComponent.getComponentInstancesInterfaces();
519 if(MapUtils.isEmpty(componentInstanceInterfaces)) {
520 return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND,
521 componentInstanceId));
524 List<ComponentInstanceInterface> componentInstanceInterfaceList =
525 componentInstanceInterfaces.get(componentInstanceId);
526 for(ComponentInstanceInterface componentInstanceInterface : componentInstanceInterfaceList) {
527 if(componentInstanceInterface.getInterfaceId().equals(interfaceId)){
528 Map<String, OperationDataDefinition> operations = componentInstanceInterface.getOperations();
529 if(MapUtils.isNotEmpty(operations) && operations.containsKey(operationId)) {
530 ListDataDefinition<OperationInputDefinition> inputs = operations.get(operationId).getInputs();
531 return Either.left(CollectionUtils.isEmpty(inputs.getListToscaDataDefinition())
532 ? new ArrayList<>() : inputs.getListToscaDataDefinition());
536 return Either.left(new ArrayList<>());
538 catch (Exception e) {
539 LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "get", e);
541 return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND));
544 if (lockResult.isLeft() && lockResult.left().value()) {
545 graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
546 NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));