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 java.util.Collections;
25 import java.util.List;
27 import java.util.Optional;
28 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
29 import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
30 import org.openecomp.sdc.be.components.property.DefaultPropertyDeclarator;
31 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
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.ComponentInstanceProperty;
36 import org.openecomp.sdc.be.model.InputDefinition;
37 import org.openecomp.sdc.be.model.PolicyDefinition;
38 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
39 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
40 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
42 @org.springframework.stereotype.Component
43 public class ComponentInstancePropertyToPolicyDeclarator extends
44 DefaultPropertyDeclarator<ComponentInstance, ComponentInstanceProperty> {
46 private ToscaOperationFacade toscaOperationFacade;
47 PropertyBusinessLogic propertyBl;
48 private ComponentInstanceBusinessLogic componentInstanceBl;
50 public ComponentInstancePropertyToPolicyDeclarator(ComponentsUtils componentsUtils,
51 PropertyOperation propertyOperation, ToscaOperationFacade toscaOperationFacade,
52 PropertyBusinessLogic propertyBl, ComponentInstanceBusinessLogic componentInstanceBl) {
53 super(componentsUtils, propertyOperation);
54 this.toscaOperationFacade = toscaOperationFacade;
55 this.propertyBl = propertyBl;
56 this.componentInstanceBl = componentInstanceBl;
60 protected ComponentInstanceProperty createDeclaredProperty(PropertyDataDefinition prop) {
61 return new ComponentInstanceProperty(prop);
65 protected Either<?, StorageOperationStatus> updatePropertiesValues(Component component, String componentInstanceId,
66 List<ComponentInstanceProperty> properties) {
67 Map<String, List<ComponentInstanceProperty>>
68 instProperties = Collections.singletonMap(componentInstanceId, properties);
69 return toscaOperationFacade.addComponentInstancePropertiesToComponent(component, instProperties);
73 protected Optional<ComponentInstance> resolvePropertiesOwner(Component component, String componentInstanceId) {
74 return component.getComponentInstanceById(componentInstanceId);
78 protected void addPropertiesListToInput(ComponentInstanceProperty declaredProp, InputDefinition input) {
83 public StorageOperationStatus unDeclarePropertiesAsInputs(Component component, InputDefinition input) {
84 return StorageOperationStatus.OK;
88 public StorageOperationStatus unDeclarePropertiesAsListInputs(Component component, InputDefinition input) {
89 return StorageOperationStatus.OK;
93 public StorageOperationStatus unDeclarePropertiesAsPolicies(Component component, PolicyDefinition policy) {
95 Optional<ComponentInstanceProperty> propertyCandidate =
96 componentInstanceBl.getComponentInstancePropertyByPolicyId(component, policy);
99 if(propertyCandidate.isPresent()) {
100 return toscaOperationFacade
101 .updateComponentInstanceProperty(component, policy.getInstanceUniqueId(), propertyCandidate.get());
104 return StorageOperationStatus.OK;