summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java31
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java21
2 files changed, 45 insertions, 7 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java
index a5f819d9b0..62ef98b985 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
@@ -26,6 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.commons.collections4.CollectionUtils;
+import org.jetbrains.annotations.NotNull;
import org.openecomp.sdc.be.components.attribute.AttributeDeclarationOrchestrator;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
@@ -43,6 +45,7 @@ import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
import org.openecomp.sdc.be.model.ComponentInstanceOutput;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.OutputDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
@@ -68,7 +71,8 @@ public class OutputsBusinessLogic extends BaseBusinessLogic {
private static final String GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_OUTPUTS = "Going to execute rollback on create outputs.";
private static final String GOING_TO_EXECUTE_COMMIT_ON_CREATE_OUTPUTS = "Going to execute commit on create outputs.";
private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(OutputsBusinessLogic.class);
- private static final String FAILED_TO_FOUND_COMPONENT_INSTANCE_OUTPUTS_COMPONENT_INSTANCE_ID = "Failed to found component instance outputs componentInstanceId: {}";
+ private static final String FAILED_TO_FOUND_COMPONENT_INSTANCE_OUTPUTS_COMPONENT_INSTANCE_ID =
+ "Failed to found component instance outputs componentInstanceId: {}";
private static final String FAILED_TO_FOUND_COMPONENT_INSTANCE_OUTPUTS_ERROR = "Failed to found component instance outputs {}, error: {}";
private final AttributeDeclarationOrchestrator attributeDeclarationOrchestrator;
@@ -301,7 +305,32 @@ public class OutputsBusinessLogic extends BaseBusinessLogic {
result.addAll(createdOutputs.left().value());
}
}
+ final List<PropertyDefinition> componentInstanceProperties = componentInstance.getProperties();
+ if (CollectionUtils.isNotEmpty(componentInstanceProperties)) {
+ final Optional<PropertyDefinition> componentInstancePropertyOptional = componentInstanceProperties.stream()
+ .filter(prop -> prop.getName().equals(attributeName)).findFirst();
+ if (componentInstancePropertyOptional.isPresent()) {
+ PropertyDefinition propertyDefinition = componentInstancePropertyOptional.get();
+ final ComponentInstOutputsMap componentInstOutputsMap = new ComponentInstOutputsMap();
+ ComponentInstanceAttribOutput attribute = getComponentInstanceAttribOutput(propertyDefinition);
+ componentInstOutputsMap.setComponentInstanceAttributes(Collections.singletonMap(componentInstance.getUniqueId(),
+ Collections.singletonList(new ComponentInstanceAttribOutput(attribute))));
+ return createMultipleOutputs(userId, componentUniqueId, ComponentTypeEnum.SERVICE, componentInstOutputsMap, true, false);
+ }
+ }
return Either.left(result);
}
+ @NotNull
+ private ComponentInstanceAttribOutput getComponentInstanceAttribOutput(PropertyDefinition propertyDefinition) {
+ ComponentInstanceAttribOutput attribute = new ComponentInstanceAttribOutput();
+ attribute.setParentUniqueId(propertyDefinition.getParentUniqueId());
+ attribute.setName(propertyDefinition.getName());
+ attribute.setOwnerId(propertyDefinition.getOwnerId());
+ attribute.setType(propertyDefinition.getType());
+ attribute.setSchema(propertyDefinition.getSchema());
+ attribute.setUniqueId(propertyDefinition.getUniqueId());
+ return attribute;
+ }
+
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java
index ddef267c8d..0519d41302 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.openecomp.sdc.be.components.impl;
import static org.assertj.core.api.Assertions.assertThat;
@@ -46,7 +47,6 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.attribute.AttributeDeclarationOrchestrator;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
@@ -67,6 +67,7 @@ import org.openecomp.sdc.be.model.ComponentInstanceOutput;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.OutputDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
@@ -149,6 +150,9 @@ class OutputsBusinessLogicTest {
final AttributeDefinition attributeDefinition = new AttributeDefinition();
attributeDefinition.setName("attribName");
componentInstance.setAttributes(Collections.singletonList(attributeDefinition));
+ final PropertyDefinition propertyDefinition = new PropertyDefinition();
+ propertyDefinition.setName("propName");
+ componentInstance.setProperties(Collections.singletonList(propertyDefinition));
service.setComponentInstances(Collections.singletonList(componentInstance));
instanceOutputMap = new HashMap<>();
@@ -160,7 +164,7 @@ class OutputsBusinessLogicTest {
instanceOutputMap.put("someOutputId", Collections.singletonList(new ComponentInstanceOutput()));
service.setComponentInstancesOutputs(instanceOutputMap);
when(userValidations.validateUserExists(USER_ID)).thenReturn(new User());
- when(userValidations.isSameUser(eq(USER_ID),eq(USER_ID))).thenReturn(true);
+ when(userValidations.isSameUser(eq(USER_ID), eq(USER_ID))).thenReturn(true);
when(userAdminMock.getUser(USER_ID, false)).thenReturn(new User());
}
@@ -409,8 +413,12 @@ class OutputsBusinessLogicTest {
final var out_2 = new OutputDefinition();
out_2.setName("out-2");
out_2.setValue("{ get_attribute: [ SELF, oneMoreAttribute ] }");
+ final var out_4 = new OutputDefinition();
+ out_4.setName("out_4");
+ out_4.setValue("{ get_attribute: [ instanceId, propName ] }");
outputs.put(out_1.getName(), out_1);
outputs.put(out_2.getName(), out_2);
+ outputs.put(out_4.getName(), out_4);
final List<OutputDefinition> serviceOutputs = new ArrayList<>();
final var out_3 = new OutputDefinition();
@@ -418,17 +426,18 @@ class OutputsBusinessLogicTest {
serviceOutputs.add(out_3);
service.setOutputs(serviceOutputs);
- final List<OutputDefinition> list = Arrays.asList(out_1, out_2, out_3);
+ final List<OutputDefinition> list = Arrays.asList(out_2, out_3, out_4);
+ final List<OutputDefinition> expetedList = Arrays.asList(out_1, out_2, out_3, out_4);
when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(Either.left(service));
when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
when(attributeDeclarationOrchestrator.declareAttributesToOutputs(eq(service), any(ComponentInstOutputsMap.class)))
- .thenReturn(Either.left(list));
+ .thenReturn(Either.left(Collections.singletonList(out_1))).thenReturn(Either.left(list));
when(toscaOperationFacadeMock.addOutputsToComponent(anyMap(), anyString())).thenReturn(Either.left(list));
final var result = testInstance.createOutputsInGraph(outputs, service, USER_ID);
assertTrue(result.isLeft());
- assertEquals(3, result.left().value().size());
- assertEquals(list, result.left().value());
+ assertEquals(4, result.left().value().size());
+ assertEquals(expetedList, result.left().value());
}
@Test