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.merge.instance;
23 import fj.data.Either;
24 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
25 import org.openecomp.sdc.be.dao.api.ActionStatus;
26 import org.openecomp.sdc.be.impl.ComponentsUtils;
27 import org.openecomp.sdc.be.model.Component;
28 import org.openecomp.sdc.be.model.ComponentInstance;
29 import org.openecomp.sdc.be.model.ComponentParametersView;
30 import org.openecomp.sdc.be.model.User;
31 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
32 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
33 import org.openecomp.sdc.common.log.wrappers.Logger;
34 import org.openecomp.sdc.exception.ResponseFormat;
35 import org.springframework.beans.factory.annotation.Autowired;
37 import java.util.List;
39 * Created by chaya on 9/12/2017.
41 @org.springframework.stereotype.Component("componentInstanceMergeDataBusinessLogic")
42 public class ComponentInstanceMergeDataBusinessLogic {
44 private static final Logger log = Logger.getLogger(ComponentInstanceMergeDataBusinessLogic.class);
47 private List<ComponentInstanceMergeInterface> componentInstancesMergeBLs;
50 private ToscaOperationFacade toscaOperationFacade;
53 private ComponentsUtils componentsUtils;
56 protected void setComponentInstancesMergeBLs(List<ComponentInstanceMergeInterface> componentInstancesMergeBLs) {
57 this.componentInstancesMergeBLs = componentInstancesMergeBLs;
61 * Saves all containerComponents data before deleting, in order to merge once creating a new instance
62 * @param containerComponent
63 * @param currentResourceInstance
65 public DataForMergeHolder saveAllDataBeforeDeleting(org.openecomp.sdc.be.model.Component containerComponent, ComponentInstance currentResourceInstance, Component originComponent) {
66 DataForMergeHolder dataHolder = new DataForMergeHolder();
67 for (ComponentInstanceMergeInterface compInstMergeBL : componentInstancesMergeBLs) {
68 compInstMergeBL.saveDataBeforeMerge(dataHolder, containerComponent, currentResourceInstance, originComponent);
74 * Merges inputs and instance inputs/props of the new Container component with the old container component data (before deleting)
75 * @param containerComponent
76 * @param newContainerComponentId
77 * @param newInstanceId
80 public Either<Component, ResponseFormat> mergeComponentUserOrigData(User user, DataForMergeHolder dataHolder, org.openecomp.sdc.be.model.Component containerComponent, String newContainerComponentId, String newInstanceId) {
82 Either<Component, StorageOperationStatus> componentWithInstancesInputsAndProperties = getComponentWithInstancesMergeEntities(newContainerComponentId);
83 if (componentWithInstancesInputsAndProperties.isRight()) {
84 log.error("Component with id {} was not found", newContainerComponentId);
85 StorageOperationStatus storageOperationStatus = componentWithInstancesInputsAndProperties.right().value();
86 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageOperationStatus, containerComponent.getComponentType());
87 return Either.right(componentsUtils.getResponseFormat(actionStatus));
89 Component updatedContainerComponent = componentWithInstancesInputsAndProperties.left().value();
91 for (ComponentInstanceMergeInterface compInstMergeBL: componentInstancesMergeBLs) {
93 Either<Component, ResponseFormat> compInstanceMergeEither = compInstMergeBL.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, newInstanceId);
94 if (compInstanceMergeEither.isRight()) {
95 return Either.right(compInstanceMergeEither.right().value());
97 } catch (ComponentException e) {
98 return Either.right(componentsUtils.getResponseFormat(e));
102 return Either.left(updatedContainerComponent);
105 private Either<Component, StorageOperationStatus> getComponentWithInstancesMergeEntities(String containerComponentId) {
106 ComponentParametersView filter = new ComponentParametersView(true);
107 filter.setIgnoreComponentInstances(false);
108 filter.setIgnoreComponentInstancesInputs(false);
109 filter.setIgnoreInputs(false);//dr
110 filter.setIgnoreComponentInstancesProperties(false);
111 filter.setIgnoreCapabilities(false);
112 filter.setIgnoreCapabiltyProperties(false);
113 filter.setIgnoreArtifacts(false);
114 filter.setIgnoreForwardingPath(false);
115 filter.setIgnoreComponentInstancesInterfaces(false);
116 return toscaOperationFacade.getToscaElement(containerComponentId, filter);