2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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
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.property.propertytopolicydeclarators;
23 import fj.data.Either;
24 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
25 import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
26 import org.openecomp.sdc.be.components.property.DefaultPropertyDeclarator;
27 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
28 import org.openecomp.sdc.be.impl.ComponentsUtils;
29 import org.openecomp.sdc.be.model.Component;
30 import org.openecomp.sdc.be.model.ComponentInstance;
31 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
32 import org.openecomp.sdc.be.model.InputDefinition;
33 import org.openecomp.sdc.be.model.PolicyDefinition;
34 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
35 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
36 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
38 import java.util.Collections;
39 import java.util.List;
41 import java.util.Optional;
43 @org.springframework.stereotype.Component
44 public class ComponentInstancePropertyToPolicyDeclarator extends
45 DefaultPropertyDeclarator<ComponentInstance, ComponentInstanceProperty> {
47 private ToscaOperationFacade toscaOperationFacade;
48 PropertyBusinessLogic propertyBl;
49 private ComponentInstanceBusinessLogic componentInstanceBl;
51 public ComponentInstancePropertyToPolicyDeclarator(ComponentsUtils componentsUtils,
52 PropertyOperation propertyOperation, ToscaOperationFacade toscaOperationFacade,
53 PropertyBusinessLogic propertyBl, ComponentInstanceBusinessLogic componentInstanceBl) {
54 super(componentsUtils, propertyOperation);
55 this.toscaOperationFacade = toscaOperationFacade;
56 this.propertyBl = propertyBl;
57 this.componentInstanceBl = componentInstanceBl;
61 protected ComponentInstanceProperty createDeclaredProperty(PropertyDataDefinition prop) {
62 return new ComponentInstanceProperty(prop);
66 protected Either<?, StorageOperationStatus> updatePropertiesValues(Component component, String componentInstanceId,
67 List<ComponentInstanceProperty> properties) {
68 Map<String, List<ComponentInstanceProperty>>
69 instProperties = Collections.singletonMap(componentInstanceId, properties);
70 return toscaOperationFacade.addComponentInstancePropertiesToComponent(component, instProperties);
74 protected Optional<ComponentInstance> resolvePropertiesOwner(Component component, String componentInstanceId) {
75 return component.getComponentInstanceById(componentInstanceId);
79 protected void addPropertiesListToInput(ComponentInstanceProperty declaredProp, InputDefinition input) {
84 public StorageOperationStatus unDeclarePropertiesAsInputs(Component component, InputDefinition input) {
85 return StorageOperationStatus.OK;
89 public StorageOperationStatus unDeclarePropertiesAsListInputs(Component component, InputDefinition input) {
90 return StorageOperationStatus.OK;
94 public StorageOperationStatus unDeclarePropertiesAsPolicies(Component component, PolicyDefinition policy) {
96 Optional<ComponentInstanceProperty> propertyCandidate =
97 componentInstanceBl.getComponentInstancePropertyByPolicyId(component, policy);
100 if(propertyCandidate.isPresent()) {
101 return toscaOperationFacade
102 .updateComponentInstanceProperty(component, policy.getInstanceUniqueId(), propertyCandidate.get());
105 return StorageOperationStatus.OK;