diff options
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstancePropsAndInputsMerge.java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstancePropsAndInputsMerge.java | 56 |
1 files changed, 34 insertions, 22 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstancePropsAndInputsMerge.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstancePropsAndInputsMerge.java index cbfc97013a..d896e4a8a0 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstancePropsAndInputsMerge.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstancePropsAndInputsMerge.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,10 +17,13 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.components.merge.instance; +import static org.apache.commons.collections.CollectionUtils.isNotEmpty; + import fj.data.Either; +import java.util.ArrayList; +import java.util.List; import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.impl.ComponentsUtils; @@ -35,11 +38,6 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.common.log.wrappers.Logger; -import java.util.ArrayList; -import java.util.List; - -import static org.apache.commons.collections.CollectionUtils.isNotEmpty; - /** * Created by chaya on 9/20/2017. */ @@ -47,14 +45,16 @@ import static org.apache.commons.collections.CollectionUtils.isNotEmpty; public class ComponentInstancePropsAndInputsMerge implements ComponentInstanceMergeInterface { private static final Logger log = Logger.getLogger(ComponentInstancePropsAndInputsMerge.class); - private final ToscaOperationFacade toscaOperationFacade; private final ComponentsUtils componentsUtils; private final ComponentInstancePropertiesMergeBL componentInstancePropertiesMergeBL; private final ComponentInstanceInputsMergeBL resourceInstanceInputsMergeBL; private final ComponentInstanceInputsRedeclareHandler instanceInputsRedeclareHandler; - public ComponentInstancePropsAndInputsMerge(ToscaOperationFacade toscaOperationFacade, ComponentsUtils componentsUtils, ComponentInstancePropertiesMergeBL componentInstancePropertiesMergeBL, ComponentInstanceInputsMergeBL resourceInstanceInputsMergeBL, ComponentInstanceInputsRedeclareHandler instanceInputsRedeclareHandler) { + public ComponentInstancePropsAndInputsMerge(ToscaOperationFacade toscaOperationFacade, ComponentsUtils componentsUtils, + ComponentInstancePropertiesMergeBL componentInstancePropertiesMergeBL, + ComponentInstanceInputsMergeBL resourceInstanceInputsMergeBL, + ComponentInstanceInputsRedeclareHandler instanceInputsRedeclareHandler) { this.toscaOperationFacade = toscaOperationFacade; this.componentsUtils = componentsUtils; this.componentInstancePropertiesMergeBL = componentInstancePropertiesMergeBL; @@ -63,7 +63,8 @@ public class ComponentInstancePropsAndInputsMerge implements ComponentInstanceMe } @Override - public void saveDataBeforeMerge(DataForMergeHolder dataHolder, Component containerComponent, ComponentInstance currentResourceInstance, Component originComponent) { + public void saveDataBeforeMerge(DataForMergeHolder dataHolder, Component containerComponent, ComponentInstance currentResourceInstance, + Component originComponent) { dataHolder.setOrigComponentInstanceInputs(containerComponent.safeGetComponentInstanceInputsByName(currentResourceInstance.getName())); dataHolder.setOrigComponentInstanceProperties(containerComponent.safeGetComponentInstanceProperties(currentResourceInstance.getUniqueId())); dataHolder.setOrigComponentInputs(containerComponent.getInputs()); @@ -71,17 +72,20 @@ public class ComponentInstancePropsAndInputsMerge implements ComponentInstanceMe @Override public Component mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId) { - Either<List<ComponentInstanceInput>, ActionStatus> instanceInputsEither = mergeComponentInstanceInputsIntoContainer(dataHolder, updatedContainerComponent, newInstanceId); + Either<List<ComponentInstanceInput>, ActionStatus> instanceInputsEither = mergeComponentInstanceInputsIntoContainer(dataHolder, + updatedContainerComponent, newInstanceId); if (instanceInputsEither.isRight()) { ActionStatus actionStatus = instanceInputsEither.right().value(); throw new ByActionStatusComponentException(actionStatus); } - Either<List<ComponentInstanceProperty>, ActionStatus> instancePropsEither = mergeComponentInstancePropsIntoContainer(dataHolder, updatedContainerComponent, newInstanceId); + Either<List<ComponentInstanceProperty>, ActionStatus> instancePropsEither = mergeComponentInstancePropsIntoContainer(dataHolder, + updatedContainerComponent, newInstanceId); if (instancePropsEither.isRight()) { ActionStatus actionStatus = instancePropsEither.right().value(); throw new ByActionStatusComponentException(actionStatus); } - Either<List<InputDefinition>, ActionStatus> inputsEither = mergeComponentInputsIntoContainer(dataHolder, updatedContainerComponent.getUniqueId(), newInstanceId); + Either<List<InputDefinition>, ActionStatus> inputsEither = mergeComponentInputsIntoContainer(dataHolder, + updatedContainerComponent.getUniqueId(), newInstanceId); if (inputsEither.isRight()) { ActionStatus actionStatus = inputsEither.right().value(); throw new ByActionStatusComponentException(actionStatus); @@ -89,12 +93,14 @@ public class ComponentInstancePropsAndInputsMerge implements ComponentInstanceMe return updatedContainerComponent; } - private Either<List<ComponentInstanceProperty>, ActionStatus> mergeComponentInstancePropsIntoContainer(DataForMergeHolder dataHolder, Component updatedComponent, String instanceId) { + private Either<List<ComponentInstanceProperty>, ActionStatus> mergeComponentInstancePropsIntoContainer(DataForMergeHolder dataHolder, + Component updatedComponent, + String instanceId) { List<ComponentInstanceProperty> originComponentInstanceProps = dataHolder.getOrigComponentInstanceProperties(); List<InputDefinition> originComponentsInputs = dataHolder.getOrigComponentInputs(); List<ComponentInstanceProperty> newComponentInstancesProps = updatedComponent.safeGetComponentInstanceProperties(instanceId); - ActionStatus actionStatus = componentInstancePropertiesMergeBL.mergeComponentInstanceProperties(originComponentInstanceProps, originComponentsInputs, updatedComponent, instanceId); - + ActionStatus actionStatus = componentInstancePropertiesMergeBL + .mergeComponentInstanceProperties(originComponentInstanceProps, originComponentsInputs, updatedComponent, instanceId); if (actionStatus != ActionStatus.OK) { log.error("Failed to update component {} with merged instance properties", updatedComponent.getUniqueId(), newComponentInstancesProps); return Either.right(actionStatus); @@ -102,11 +108,14 @@ public class ComponentInstancePropsAndInputsMerge implements ComponentInstanceMe return Either.left(newComponentInstancesProps); } - private Either<List<ComponentInstanceInput>, ActionStatus> mergeComponentInstanceInputsIntoContainer(DataForMergeHolder dataHolder, Component updatedComponent, String instanceId) { + private Either<List<ComponentInstanceInput>, ActionStatus> mergeComponentInstanceInputsIntoContainer(DataForMergeHolder dataHolder, + Component updatedComponent, + String instanceId) { List<ComponentInstanceInput> originComponentInstanceInputs = dataHolder.getOrigComponentInstanceInputs(); List<InputDefinition> originComponentsInputs = dataHolder.getOrigComponentInputs(); List<ComponentInstanceInput> newComponentInstancesInputs = updatedComponent.safeGetComponentInstanceInput(instanceId); - ActionStatus actionStatus = resourceInstanceInputsMergeBL.mergeComponentInstanceInputs(originComponentInstanceInputs, originComponentsInputs, updatedComponent, instanceId); + ActionStatus actionStatus = resourceInstanceInputsMergeBL + .mergeComponentInstanceInputs(originComponentInstanceInputs, originComponentsInputs, updatedComponent, instanceId); if (actionStatus != ActionStatus.OK) { log.error("Failed to update component {} with merged instance properties", updatedComponent.getUniqueId(), newComponentInstancesInputs); return Either.right(actionStatus); @@ -114,19 +123,22 @@ public class ComponentInstancePropsAndInputsMerge implements ComponentInstanceMe return Either.left(newComponentInstancesInputs); } - private Either<List<InputDefinition>, ActionStatus> mergeComponentInputsIntoContainer(DataForMergeHolder dataHolder, String newContainerComponentId, String newInstanceId) { + private Either<List<InputDefinition>, ActionStatus> mergeComponentInputsIntoContainer(DataForMergeHolder dataHolder, + String newContainerComponentId, String newInstanceId) { List<InputDefinition> origComponentInputs = dataHolder.getOrigComponentInputs(); List<InputDefinition> inputsToAddToContainer = new ArrayList<>(); if (isNotEmpty(origComponentInputs)) { // get instance inputs and properties after merge - Either<Component, StorageOperationStatus> componentWithInstancesInputsAndProperties = getComponentWithInstancesInputsAndProperties(newContainerComponentId); + Either<Component, StorageOperationStatus> componentWithInstancesInputsAndProperties = getComponentWithInstancesInputsAndProperties( + newContainerComponentId); if (componentWithInstancesInputsAndProperties.isRight()) { log.error("Component %s was not found", newContainerComponentId); return Either.right(componentsUtils.convertFromStorageResponse(componentWithInstancesInputsAndProperties.right().value())); } Component updatedContainerComponent = componentWithInstancesInputsAndProperties.left().value(); Component currInstanceOriginType = dataHolder.getCurrInstanceNode(); - ActionStatus redeclareStatus = instanceInputsRedeclareHandler.redeclareComponentInputsForInstance(updatedContainerComponent, newInstanceId, currInstanceOriginType, origComponentInputs); + ActionStatus redeclareStatus = instanceInputsRedeclareHandler + .redeclareComponentInputsForInstance(updatedContainerComponent, newInstanceId, currInstanceOriginType, origComponentInputs); if (redeclareStatus != ActionStatus.OK) { log.error("Failed to update component {} with merged inputs {}", newContainerComponentId, inputsToAddToContainer); return Either.right(redeclareStatus); |