2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2021, Nordix Foundation. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.components.attribute;
23 import static org.apache.commons.collections4.CollectionUtils.isEmpty;
25 import fj.data.Either;
26 import java.util.Collections;
27 import java.util.List;
29 import java.util.Optional;
30 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
31 import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
32 import org.openecomp.sdc.be.impl.ComponentsUtils;
33 import org.openecomp.sdc.be.model.Component;
34 import org.openecomp.sdc.be.model.ComponentInstance;
35 import org.openecomp.sdc.be.model.ComponentInstanceOutput;
36 import org.openecomp.sdc.be.model.OutputDefinition;
37 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
38 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
39 import org.openecomp.sdc.be.model.operations.impl.AttributeOperation;
40 import org.openecomp.sdc.common.log.wrappers.Logger;
42 @org.springframework.stereotype.Component
43 public class ComponentInstanceOutputAttributeDeclarator extends DefaultAttributeDeclarator<ComponentInstance, ComponentInstanceOutput> {
45 private static final Logger log = Logger.getLogger(ComponentInstanceOutputAttributeDeclarator.class);
46 private final ToscaOperationFacade toscaOperationFacade;
47 private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
49 public ComponentInstanceOutputAttributeDeclarator(final ComponentsUtils componentsUtils,
50 final AttributeOperation attributeOperation,
51 final ToscaOperationFacade toscaOperationFacade,
52 final ComponentInstanceBusinessLogic componentInstanceBusinessLogic) {
53 // super(componentsUtils, attributeOperation);
54 this.toscaOperationFacade = toscaOperationFacade;
55 this.componentInstanceBusinessLogic = componentInstanceBusinessLogic;
59 public ComponentInstanceOutput createDeclaredAttribute(final AttributeDataDefinition attributeDataDefinition) {
60 return new ComponentInstanceOutput(attributeDataDefinition);
64 public Either<?, StorageOperationStatus> updateAttributesValues(final Component component,
65 final String cmptInstanceId,
66 final List<ComponentInstanceOutput> attributetypeList) {
67 log.debug("#updateAttributesValues - updating component instance outputs for instance {} on component {}", cmptInstanceId,
68 component.getUniqueId());
69 Map<String, List<ComponentInstanceOutput>> instAttributes = Collections.singletonMap(cmptInstanceId, attributetypeList);
70 return toscaOperationFacade.addComponentInstanceOutputsToComponent(component, instAttributes);
74 public Optional<ComponentInstance> resolvePropertiesOwner(final Component component, final String propertiesOwnerId) {
75 log.debug("#resolvePropertiesOwner - fetching component instance {} of component {}", propertiesOwnerId, component.getUniqueId());
76 return component.getComponentInstanceById(propertiesOwnerId);
79 public StorageOperationStatus unDeclareAttributesAsOutputs(final Component component, final OutputDefinition output) {
80 List<ComponentInstanceOutput> componentInstanceInputsByInputId = componentInstanceBusinessLogic
81 .getComponentInstanceOutputsByOutputId(component, output
83 if (isEmpty(componentInstanceInputsByInputId)) {
84 return StorageOperationStatus.OK;
86 componentInstanceInputsByInputId
87 .forEach(cmptInstanceInput -> prepareValueBeforeDelete(output, cmptInstanceInput, cmptInstanceInput.getPath()));
88 return toscaOperationFacade.updateComponentInstanceOutputs(component, componentInstanceInputsByInputId.get(0).getComponentInstanceId(),
89 componentInstanceInputsByInputId);