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 com.google.gson.Gson;
21 import fj.data.Either;
22 import org.apache.commons.collections4.CollectionUtils;
23 import org.apache.commons.collections4.MapUtils;
24 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
25 import org.openecomp.sdc.be.components.utils.InterfaceOperationUtils;
26 import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation;
27 import org.openecomp.sdc.be.dao.api.ActionStatus;
28 import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
29 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
30 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
31 import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
32 import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
33 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
34 import org.openecomp.sdc.be.model.ArtifactDefinition;
35 import org.openecomp.sdc.be.model.CapabilityDefinition;
36 import org.openecomp.sdc.be.model.ComponentInstanceInterface;
37 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
38 import org.openecomp.sdc.be.model.InputDefinition;
39 import org.openecomp.sdc.be.model.InterfaceDefinition;
40 import org.openecomp.sdc.be.model.Operation;
41 import org.openecomp.sdc.be.model.User;
42 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
43 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
44 import org.openecomp.sdc.be.model.operations.api.IElementOperation;
45 import org.openecomp.sdc.be.model.operations.api.IGroupInstanceOperation;
46 import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
47 import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
48 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
49 import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
50 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
51 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
52 import org.openecomp.sdc.exception.ResponseFormat;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
55 import org.springframework.beans.factory.annotation.Autowired;
56 import org.springframework.stereotype.Component;
58 import java.util.ArrayList;
59 import java.util.Collection;
60 import java.util.Collections;
61 import java.util.HashMap;
62 import java.util.List;
64 import java.util.Objects;
65 import java.util.Optional;
66 import java.util.UUID;
67 import java.util.stream.Collectors;
69 import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedCapabilityPropertyDefaultValue;
70 import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedInputPropertyDefaultValue;
71 import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedOutputDefaultValue;
72 import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId;
73 import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType;
74 import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOperationFromInterfaceDefinition;
75 import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.isOperationInputMappedToComponentInput;
76 import static org.openecomp.sdc.be.components.utils.PropertiesUtils.getPropertyCapabilityFromAllCapProps;
77 import static org.openecomp.sdc.be.components.utils.PropertiesUtils.isCapabilityProperty;
78 import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.SELF;
80 @Component("interfaceOperationBusinessLogic")
81 public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
83 private static final Logger LOGGER = LoggerFactory.getLogger(InterfaceOperationBusinessLogic.class);
84 private static final String EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION =
85 "Exception occurred during {}. Response is {}";
86 private static final String DELETE_INTERFACE_OPERATION = "deleteInterfaceOperation";
87 private static final String GET_INTERFACE_OPERATION = "getInterfaceOperation";
88 private static final String CREATE_INTERFACE_OPERATION = "createInterfaceOperation";
89 private static final String UPDATE_INTERFACE_OPERATION = "updateInterfaceOperation";
91 private final ArtifactCassandraDao artifactCassandraDao;
92 private final InterfaceOperationValidation interfaceOperationValidation;
95 public InterfaceOperationBusinessLogic(IElementOperation elementDao,
96 IGroupOperation groupOperation,
97 IGroupInstanceOperation groupInstanceOperation,
98 IGroupTypeOperation groupTypeOperation,
99 InterfaceOperation interfaceOperation,
100 InterfaceLifecycleOperation interfaceLifecycleTypeOperation, ArtifactCassandraDao artifactCassandraDao,
101 InterfaceOperationValidation interfaceOperationValidation, ArtifactsOperations artifactToscaOperation) {
102 super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
103 interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
104 this.artifactCassandraDao = artifactCassandraDao;
105 this.interfaceOperationValidation = interfaceOperationValidation;
108 public Either<List<InterfaceDefinition>, ResponseFormat> deleteInterfaceOperation(String componentId,
109 String interfaceId, List<String> operationsToDelete, User user, boolean lock) {
110 validateUserExists(user.getUserId());
112 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
113 if (componentEither.isRight()) {
114 return Either.right(componentEither.right().value());
116 org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
118 lockComponentResult(lock, storedComponent, DELETE_INTERFACE_OPERATION);
122 Optional<InterfaceDefinition> optionalInterface = getInterfaceDefinitionFromComponentByInterfaceId(
123 storedComponent, interfaceId);
124 if (!optionalInterface.isPresent()) {
126 componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceId));
128 InterfaceDefinition interfaceDefinition = optionalInterface.get();
130 Map<String, Operation> operationsCollection = new HashMap<>();
131 for (String operationId : operationsToDelete) {
132 Optional<Map.Entry<String, Operation>> optionalOperation =
133 getOperationFromInterfaceDefinition(interfaceDefinition, operationId);
134 if (!optionalOperation.isPresent()) {
135 return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND,
136 storedComponent.getUniqueId()));
139 Operation storedOperation = optionalOperation.get().getValue();
140 Either<Boolean, ResponseFormat> validateDeleteOperationContainsNoMappedOutputResponse =
141 interfaceOperationValidation.validateDeleteOperationContainsNoMappedOutput(storedOperation,
142 storedComponent, interfaceDefinition);
143 if (validateDeleteOperationContainsNoMappedOutputResponse.isRight()) {
144 return Either.right(validateDeleteOperationContainsNoMappedOutputResponse.right().value());
147 String artifactUniqueId = storedOperation.getImplementation().getUniqueId();
148 if(!InterfaceOperationUtils.isArtifactInUse(storedComponent, operationId, artifactUniqueId)){
149 Either<ArtifactDefinition, StorageOperationStatus> getArtifactEither =
150 artifactToscaOperation.getArtifactById(storedComponent.getUniqueId(), artifactUniqueId);
151 if(getArtifactEither.isLeft()){
152 Either<ArtifactDefinition, StorageOperationStatus> removeArifactFromComponent =
153 artifactToscaOperation.removeArifactFromResource(componentId, artifactUniqueId,
154 NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()),
156 if(removeArifactFromComponent.isRight()){
157 janusGraphDao.rollback();
158 ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
159 componentsUtils.convertFromStorageResponse(removeArifactFromComponent.right().value()),
160 storedOperation.getImplementation().getArtifactDisplayName());
161 return Either.right(responseFormatByArtifactId);
164 CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUniqueId);
165 if (cassandraStatus != CassandraOperationStatus.OK) {
166 janusGraphDao.rollback();
167 ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
168 componentsUtils.convertFromStorageResponse(
169 componentsUtils.convertToStorageOperationStatus(cassandraStatus)),
170 storedOperation.getImplementation().getArtifactDisplayName());
171 return Either.right(responseFormatByArtifactId);
176 operationsCollection.put(operationId, interfaceDefinition.getOperationsMap().get(operationId));
177 interfaceDefinition.getOperations().remove(operationId);
180 Either<List<InterfaceDefinition>, StorageOperationStatus> deleteOperationEither =
181 interfaceOperation.updateInterfaces(storedComponent.getUniqueId(),
182 Collections.singletonList(interfaceDefinition));
183 if (deleteOperationEither.isRight()) {
184 janusGraphDao.rollback();
185 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
186 deleteOperationEither.right().value(), storedComponent.getComponentType())));
189 if (interfaceDefinition.getOperations().isEmpty()) {
190 Either<String, StorageOperationStatus> deleteInterfaceEither = interfaceOperation.deleteInterface(
191 storedComponent.getUniqueId(), interfaceDefinition.getUniqueId());
192 if (deleteInterfaceEither.isRight()) {
193 janusGraphDao.rollback();
194 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
195 deleteInterfaceEither.right().value(), storedComponent.getComponentType())));
199 janusGraphDao.commit();
200 interfaceDefinition.getOperations().putAll(operationsCollection);
201 interfaceDefinition.getOperations().keySet().removeIf(key -> !(operationsToDelete.contains(key)));
202 return Either.left(Collections.singletonList(interfaceDefinition));
203 } catch (Exception e) {
204 LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "delete", e);
205 janusGraphDao.rollback();
206 return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_DELETED));
208 graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
209 NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
213 private Either<org.openecomp.sdc.be.model.Component, ResponseFormat> getComponentDetails(String componentId) {
214 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentStorageOperationStatusEither =
215 toscaOperationFacade.getToscaElement(componentId);
216 if (componentStorageOperationStatusEither.isRight()) {
217 return Either.right(componentsUtils.getResponseFormat(
218 componentsUtils.convertFromStorageResponse(componentStorageOperationStatusEither.right().value())));
220 return Either.left(componentStorageOperationStatusEither.left().value());
223 private Either<Boolean, ResponseFormat> lockComponentResult(boolean lock,
224 org.openecomp.sdc.be.model.Component component, String action) {
227 lockComponent(component.getUniqueId(), component, action);
228 } catch (ComponentException e) {
229 janusGraphDao.rollback();
233 return Either.left(true);
236 public Either<List<InterfaceDefinition>, ResponseFormat> getInterfaceOperation(String componentId,
237 String interfaceId, List<String> operationsToGet, User user, boolean lock) {
238 validateUserExists(user);
240 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
241 if (componentEither.isRight()) {
242 return Either.right(componentEither.right().value());
244 org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
246 lockComponentResult(lock, storedComponent, GET_INTERFACE_OPERATION);
249 Optional<InterfaceDefinition> optionalInterface = getInterfaceDefinitionFromComponentByInterfaceId(
250 storedComponent, interfaceId);
251 if (!optionalInterface.isPresent()) {
253 componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceId));
255 InterfaceDefinition interfaceDefinition = optionalInterface.get();
257 for (String operationId : operationsToGet) {
258 Optional<Map.Entry<String, Operation>> optionalOperation =
259 getOperationFromInterfaceDefinition(interfaceDefinition, operationId);
260 if (!optionalOperation.isPresent()) {
261 return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND,
262 storedComponent.getUniqueId()));
266 janusGraphDao.commit();
267 interfaceDefinition.getOperations().keySet().removeIf(key -> !(operationsToGet.contains(key)));
268 return Either.left(Collections.singletonList(interfaceDefinition));
269 } catch (Exception e) {
270 LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "get", e);
271 janusGraphDao.rollback();
273 componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentId));
275 graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
276 NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
280 public Either<List<InterfaceDefinition>, ResponseFormat> createInterfaceOperation(String componentId,
281 List<InterfaceDefinition> interfaceDefinitions, User user, boolean lock) {
282 return createOrUpdateInterfaceOperation(componentId, interfaceDefinitions, user, false,
283 CREATE_INTERFACE_OPERATION, lock);
286 private Either<List<InterfaceDefinition>, ResponseFormat> createOrUpdateInterfaceOperation(String componentId,
287 List<InterfaceDefinition> interfaceDefinitions, User user, boolean isUpdate, String errorContext,
289 validateUserExists(user);
291 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
292 if (componentEither.isRight()) {
293 return Either.right(componentEither.right().value());
295 org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
297 lockComponentResult(lock, storedComponent, errorContext);
300 Either<Map<String, InterfaceDefinition>, ResponseFormat> interfaceLifecycleTypes =
301 getAllInterfaceLifecycleTypes();
302 if (interfaceLifecycleTypes.isRight()) {
303 return Either.right(interfaceLifecycleTypes.right().value());
307 List<InterfaceDefinition> interfacesCollection = new ArrayList<>();
308 Map<String, Operation> operationsCollection = new HashMap<>();
309 for (InterfaceDefinition inputInterfaceDefinition : interfaceDefinitions) {
310 Optional<InterfaceDefinition> optionalInterface =
311 getInterfaceDefinitionFromComponentByInterfaceType(
312 storedComponent, inputInterfaceDefinition.getType());
313 Either<Boolean, ResponseFormat> interfaceOperationValidationResponseEither =
314 interfaceOperationValidation
315 .validateInterfaceOperations(inputInterfaceDefinition, storedComponent,
316 optionalInterface.orElse(null), interfaceLifecycleTypes.left().value(),
318 if (interfaceOperationValidationResponseEither.isRight()) {
319 return Either.right(interfaceOperationValidationResponseEither.right().value());
322 Map<String, Operation> operationsToAddOrUpdate = inputInterfaceDefinition.getOperationsMap();
323 operationsCollection.putAll(operationsToAddOrUpdate);
324 inputInterfaceDefinition.getOperations().clear();
326 Either<InterfaceDefinition, ResponseFormat> getInterfaceEither =
327 getOrCreateInterfaceDefinition(storedComponent, inputInterfaceDefinition,
328 optionalInterface.orElse(null));
329 if (getInterfaceEither.isRight()) {
330 return Either.right(getInterfaceEither.right().value());
332 InterfaceDefinition interfaceDef = getInterfaceEither.left().value();
334 updateOperationInputDefs(storedComponent, operationsToAddOrUpdate.values());
336 for (Operation operation : operationsToAddOrUpdate.values()) {
338 addOperationToInterface(interfaceDef, operation);
340 Optional<Map.Entry<String, Operation>> optionalOperation =
341 getOperationFromInterfaceDefinition(interfaceDef,
342 operation.getUniqueId());
343 if (!optionalOperation.isPresent()) {
344 janusGraphDao.rollback();
345 return Either.right(componentsUtils
346 .getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND,
347 storedComponent.getUniqueId()));
350 Operation storedOperation = optionalOperation.get().getValue();
351 String artifactUuId = storedOperation.getImplementation().getArtifactUUID();
352 String artifactUniqueId = storedOperation.getImplementation().getUniqueId();
354 if(!InterfaceOperationUtils.isArtifactInUse(storedComponent, storedOperation.getUniqueId(), artifactUniqueId)){
355 Either<ArtifactDefinition, StorageOperationStatus> getArtifactEither =
356 artifactToscaOperation.getArtifactById(storedComponent.getUniqueId(), artifactUniqueId);
357 if(getArtifactEither.isLeft()){
358 Either<ArtifactDefinition, StorageOperationStatus> removeArifactFromComponent =
359 artifactToscaOperation.removeArifactFromResource(componentId, artifactUniqueId,
360 NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()),
362 if(removeArifactFromComponent.isRight()){
363 janusGraphDao.rollback();
364 ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
365 componentsUtils.convertFromStorageResponse(removeArifactFromComponent.right().value()),
366 storedOperation.getImplementation().getArtifactDisplayName());
367 return Either.right(responseFormatByArtifactId);
370 CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUniqueId);
371 if (cassandraStatus != CassandraOperationStatus.OK) {
372 janusGraphDao.rollback();
373 ResponseFormat responseFormatByArtifactId =
374 componentsUtils.getResponseFormatByArtifactId(
375 componentsUtils.convertFromStorageResponse(
376 componentsUtils.convertToStorageOperationStatus(
378 storedOperation.getImplementation().getArtifactDisplayName());
379 return Either.right(responseFormatByArtifactId);
383 updateOperationOnInterface(interfaceDef, operation, artifactUuId);
386 interfacesCollection.add(interfaceDef);
389 Either<List<InterfaceDefinition>, StorageOperationStatus> addCreateOperationEither =
390 interfaceOperation.updateInterfaces(storedComponent.getUniqueId(), interfacesCollection);
391 if (addCreateOperationEither.isRight()) {
392 janusGraphDao.rollback();
393 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
394 addCreateOperationEither.right().value(), storedComponent.getComponentType())));
397 janusGraphDao.commit();
398 interfacesCollection.forEach(interfaceDefinition -> interfaceDefinition.getOperations().entrySet().removeIf(
399 entry -> !operationsCollection.values().stream().map(OperationDataDefinition::getName)
400 .collect(Collectors.toList()).contains(entry.getValue().getName())));
401 return Either.left(interfacesCollection);
402 } catch (Exception e) {
403 janusGraphDao.rollback();
404 LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "addOrUpdate", e);
405 return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
407 graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
408 NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
412 public Either<Map<String, InterfaceDefinition>, ResponseFormat> getAllInterfaceLifecycleTypes() {
414 Either<Map<String, InterfaceDefinition>, StorageOperationStatus> interfaceLifecycleTypes =
415 interfaceLifecycleTypeOperation.getAllInterfaceLifecycleTypes();
416 if (interfaceLifecycleTypes.isRight()) {
417 return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_LIFECYCLE_TYPES_NOT_FOUND));
419 interfaceLifecycleTypes.left().value().values().forEach(id -> id.setOperations(
420 id.getOperations().keySet().stream().collect(Collectors.toMap(key -> key.replaceFirst(
421 id.getUniqueId() + ".", ""), i -> id.getOperations().get(i)))));
423 return Either.left(interfaceLifecycleTypes.left().value());
426 private Either<InterfaceDefinition, ResponseFormat> getOrCreateInterfaceDefinition(
427 org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDefinition,
428 InterfaceDefinition storedInterfaceDef) {
429 if (storedInterfaceDef != null) {
430 return Either.left(storedInterfaceDef);
432 interfaceDefinition.setUniqueId(UUID.randomUUID().toString());
433 interfaceDefinition.setToscaResourceName(interfaceDefinition.getType());
434 Either<List<InterfaceDefinition>, StorageOperationStatus> interfaceCreateEither =
435 interfaceOperation.addInterfaces(component.getUniqueId(),
436 Collections.singletonList(interfaceDefinition));
437 if (interfaceCreateEither.isRight()) {
438 janusGraphDao.rollback();
439 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
440 interfaceCreateEither.right().value(), component.getComponentType())));
442 return Either.left(interfaceCreateEither.left().value().get(0));
445 private void updateOperationInputDefs(org.openecomp.sdc.be.model.Component component,
446 Collection<Operation> interfaceOperations) {
447 interfaceOperations.stream().filter(operation -> Objects.nonNull(operation.getInputs())).forEach(
448 operation -> operation.getInputs().getListToscaDataDefinition().forEach(
449 inp -> component.getInputs()
450 .forEach(in -> updateOperationInputDefinition(component, inp, in))));
453 private void updateOperationInputDefinition(org.openecomp.sdc.be.model.Component component,
454 OperationInputDefinition operationInput,
455 InputDefinition componentInput) {
456 if (operationInput.getInputId().equals(componentInput.getUniqueId())) {
457 //Set the default value, value and schema only for inputs mapped to component inputs
458 operationInput.setDefaultValue(componentInput.getDefaultValue());
459 operationInput.setToscaDefaultValue(getInputToscaDefaultValue(operationInput, component));
460 operationInput.setValue(componentInput.getValue());
461 operationInput.setSchema(componentInput.getSchema());
462 operationInput.setParentPropertyType(componentInput.getParentPropertyType());
463 operationInput.setSubPropertyInputPath(componentInput.getSubPropertyInputPath());
465 //Set the tosca default value for inputs mapped to component inputs as well as other outputs
466 operationInput.setToscaDefaultValue(getInputToscaDefaultValue(operationInput, component));
469 private String getInputToscaDefaultValue(OperationInputDefinition input,
470 org.openecomp.sdc.be.model.Component component) {
471 Map<String, List<String>> defaultInputValue = null;
472 if (isOperationInputMappedToComponentInput(input, component.getInputs())) {
473 String propertyName = input.getInputId().substring(input.getInputId().indexOf('.') + 1);
474 setParentPropertyTypeAndInputPath(input, component);
475 defaultInputValue = createMappedInputPropertyDefaultValue(propertyName);
476 } else if (isCapabilityProperty(input.getInputId(), component).isPresent()) {
477 ComponentInstanceProperty instanceProperty = isCapabilityProperty(input.getInputId(), component).get();
478 String parentPropertyId = instanceProperty.getParentUniqueId();
479 Map<String, List<CapabilityDefinition>> componentCapabilities = component.getCapabilities();
480 if(MapUtils.isNotEmpty(componentCapabilities)) {
481 List<CapabilityDefinition> capabilityDefinitionList = componentCapabilities.values().stream()
482 .flatMap(Collection::stream).filter(capabilityDefinition -> capabilityDefinition.getOwnerId()
483 .equals(component.getUniqueId())).collect(Collectors.toList());
484 Optional<CapabilityDefinition> propertyCapability = getPropertyCapabilityFromAllCapProps(parentPropertyId,
485 capabilityDefinitionList);
486 if (propertyCapability.isPresent()) {
487 String propertyName = instanceProperty.getName();
488 defaultInputValue = createMappedCapabilityPropertyDefaultValue(propertyCapability.get().getName(),
494 //Currently inputs can only be mapped to a declared input or an other operation outputs
495 defaultInputValue = createMappedOutputDefaultValue(SELF, input.getInputId());
497 return new Gson().toJson(defaultInputValue);
500 private void setParentPropertyTypeAndInputPath(OperationInputDefinition input,
501 org.openecomp.sdc.be.model.Component component) {
502 if (CollectionUtils.isEmpty(component.getInputs())) {
506 component.getInputs()
508 .filter(inp -> inp.getUniqueId().equals(
509 input.getInputId().substring(0, input.getInputId().lastIndexOf('.'))))
511 input.setParentPropertyType(inp.getParentPropertyType());
512 if (Objects.nonNull(input.getName())) {
513 input.setSubPropertyInputPath(input.getName().replaceAll("\\.", "#"));
518 private void addOperationToInterface(InterfaceDefinition interfaceDefinition, Operation interfaceOperation) {
519 interfaceOperation.setUniqueId(UUID.randomUUID().toString());
520 interfaceOperation.setImplementation(createArtifactDefinition(UUID.randomUUID().toString()));
521 interfaceDefinition.getOperations()
522 .put(interfaceOperation.getUniqueId(), new OperationDataDefinition(interfaceOperation));
525 private void updateOperationOnInterface(InterfaceDefinition interfaceDefinition, Operation interfaceOperation,
526 String artifactUuId) {
527 interfaceOperation.setImplementation(createArtifactDefinition(artifactUuId));
528 interfaceDefinition.getOperations()
529 .put(interfaceOperation.getUniqueId(), new OperationDataDefinition(interfaceOperation));
532 private ArtifactDefinition createArtifactDefinition(String artifactUuId) {
533 ArtifactDefinition artifactDefinition = new ArtifactDefinition();
534 artifactDefinition.setArtifactUUID(artifactUuId);
535 artifactDefinition.setUniqueId(artifactUuId);
536 artifactDefinition.setArtifactType(ArtifactTypeEnum.WORKFLOW.getType());
537 artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
538 return artifactDefinition;
541 public Either<List<InterfaceDefinition>, ResponseFormat> updateInterfaceOperation(String componentId,
542 List<InterfaceDefinition> interfaceDefinitions, User user, boolean lock) {
543 return createOrUpdateInterfaceOperation(componentId, interfaceDefinitions, user, true,
544 UPDATE_INTERFACE_OPERATION, lock);
547 public Either<List<OperationInputDefinition>, ResponseFormat> getInputsListForOperation(String componentId,
548 String componentInstanceId, String interfaceId, String operationId, User user) {
549 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
550 if (componentEither.isRight()){
551 return Either.right(componentEither.right().value());
554 org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
555 validateUserExists(user.getUserId());
557 Either<Boolean, ResponseFormat> lockResult = lockComponentResult(true, storedComponent, GET_INTERFACE_OPERATION);
558 if (lockResult.isRight()) {
559 return Either.right(lockResult.right().value());
563 org.openecomp.sdc.be.model.Component parentComponent = componentEither.left().value();
564 Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces =
565 parentComponent.getComponentInstancesInterfaces();
566 if(MapUtils.isEmpty(componentInstanceInterfaces)) {
567 return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND,
568 componentInstanceId));
571 List<ComponentInstanceInterface> componentInstanceInterfaceList =
572 componentInstanceInterfaces.get(componentInstanceId);
573 for(ComponentInstanceInterface componentInstanceInterface : componentInstanceInterfaceList) {
574 if(componentInstanceInterface.getInterfaceId().equals(interfaceId)){
575 Map<String, OperationDataDefinition> operations = componentInstanceInterface.getOperations();
576 if(MapUtils.isNotEmpty(operations) && operations.containsKey(operationId)) {
577 ListDataDefinition<OperationInputDefinition> inputs = operations.get(operationId).getInputs();
578 return Either.left(CollectionUtils.isEmpty(inputs.getListToscaDataDefinition())
579 ? new ArrayList<>() : inputs.getListToscaDataDefinition());
583 return Either.left(new ArrayList<>());
585 catch (Exception e) {
586 LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "get", e);
587 janusGraphDao.rollback();
588 return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND));
591 if (lockResult.isLeft() && lockResult.left().value()) {
592 graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
593 NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));