summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrupaNagabhushan <krupa.nagabhushan@est.tech>2021-07-14 14:21:47 +0100
committerMichael Morris <michael.morris@est.tech>2021-07-21 14:13:29 +0000
commit0514ec6635a08cdbaac5d664c3a4f13bcb0cbf51 (patch)
tree8ece729ff236e5011b705c3c79536eb482a44a7c
parenta3da4a7625f75f719a0ef1ffe1c2bef87828d2f3 (diff)
Consider component model when retrieving relationship types
Issue-ID: SDC-3640 Signed-off-by: MichaelMorris <michael.morris@est.tech> Change-Id: Ic06a9085b8aa2f44b8d33d7de12eadf691106131 Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech>
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeBusinessLogic.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java8
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java61
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperation.java9
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java20
-rw-r--r--catalog-ui/src/app/ng2/pages/workspace/req-and-capabilities/req-and-capabilities.service.ts2
-rw-r--r--catalog-ui/src/app/ng2/services/tosca-types.service.ts46
7 files changed, 92 insertions, 58 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeBusinessLogic.java
index 9a83566166..195e43de26 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeBusinessLogic.java
@@ -39,9 +39,9 @@ public class RelationshipTypeBusinessLogic {
this.componentsUtils = componentsUtils;
}
- public Either<Map<String, RelationshipTypeDefinition>, ResponseFormat> getAllRelationshipTypes() {
+ public Either<Map<String, RelationshipTypeDefinition>, ResponseFormat> getAllRelationshipTypes(final String model) {
Either<Map<String, RelationshipTypeDefinition>, JanusGraphOperationStatus> allRelationshipTypes = relationshipTypeOperation
- .getAllRelationshipTypes();
+ .getAllRelationshipTypes(model);
if (allRelationshipTypes.isRight()) {
JanusGraphOperationStatus operationStatus = allRelationshipTypes.right().value();
if (JanusGraphOperationStatus.NOT_FOUND == operationStatus) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java
index 6fbdbaf217..cafcbfd211 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.be.servlets;
import com.jcabi.aspects.Loggable;
import fj.data.Either;
import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
@@ -42,10 +43,12 @@ import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.collections4.ListUtils;
+import org.glassfish.jersey.media.multipart.FormDataParam;
import org.openecomp.sdc.be.components.impl.CapabilitiesBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
@@ -223,7 +226,8 @@ public class TypesFetchServlet extends AbstractValidationsServlet {
@ApiResponse(responseCode = "404", description = "Relationship types not found")})
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response getAllRelationshipTypesServlet(@Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "model", required = false) @QueryParam("model") String modelName) {
Wrapper<Response> responseWrapper = new Wrapper<>();
Wrapper<User> userWrapper = new Wrapper<>();
try {
@@ -233,7 +237,7 @@ public class TypesFetchServlet extends AbstractValidationsServlet {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug("Start handle request of {} | modifier id is {}", url, userId);
Either<Map<String, RelationshipTypeDefinition>, ResponseFormat> allDataTypes = relationshipTypeBusinessLogic
- .getAllRelationshipTypes();
+ .getAllRelationshipTypes(modelName);
if (allDataTypes.isRight()) {
log.info("Failed to get all relationship types. Reason - {}", allDataTypes.right().value());
Response errorResponse = buildErrorResponse(allDataTypes.right().value());
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java
index c6ad5f2c26..b2492cdb1a 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java
@@ -805,36 +805,59 @@ public class JanusGraphGenericDao {
public <T extends GraphNode> Either<List<T>, JanusGraphOperationStatus> getByCriteria(NodeTypeEnum type, Map<String, Object> props,
Class<T> clazz) {
- Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
- if (graph.isLeft()) {
- try {
- JanusGraph tGraph = graph.left().value();
- JanusGraphQuery<? extends JanusGraphQuery> query = tGraph.query();
- query = query.has(GraphPropertiesDictionary.LABEL.getProperty(), type.getName());
- if (props != null && !props.isEmpty()) {
- for (Map.Entry<String, Object> entry : props.entrySet()) {
- query = query.has(entry.getKey(), entry.getValue());
- }
- }
- Iterable<JanusGraphVertex> vertices = query.vertices();
- if (vertices == null) {
+ return getByCriteriaForModel(type, props, null, clazz);
+ }
+
+ public <T extends GraphNode> Either<List<T>, JanusGraphOperationStatus> getByCriteriaForModel(final NodeTypeEnum type, final Map<String, Object> props,
+ final String model, final Class<T> clazz) {
+ try {
+ final Either<Iterable<JanusGraphVertex>, JanusGraphOperationStatus> vertices = getVerticesByCriteria(type, props);
+
+ if (vertices.isLeft()) {
+ final Predicate<? super JanusGraphVertex> filterPredicate = StringUtils.isEmpty(model) ? this::vertexNotConnectedToAnyModel : vertex -> vertexValidForModel(vertex, model);
+ final List<JanusGraphVertex> verticesForModel = StreamSupport.stream(vertices.left().value().spliterator(), false).filter(filterPredicate).collect(Collectors.toList());
+
+ if (CollectionUtils.isEmpty(verticesForModel)) {
+ log.debug("No vertex in graph for props ={} ", props);
return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
- Iterator<JanusGraphVertex> iterator = vertices.iterator();
- List<T> result = new ArrayList<>();
+
+ final Iterator<JanusGraphVertex> iterator = verticesForModel.iterator();
+ final List<T> result = new ArrayList<>();
while (iterator.hasNext()) {
Vertex vertex = iterator.next();
Map<String, Object> newProp = getProperties(vertex);
T element = GraphElementFactory.createElement(type.getName(), GraphElementTypeEnum.Node, newProp, clazz);
result.add(element);
}
- if (log.isDebugEnabled()) {
- log.debug("Number of fetced nodes in graph for criteria : from type = {} and properties = {} is {}", type, props, result.size());
+ log.debug("Number of fetced nodes in graph for criteria : from type = {} and properties = {} is {}", type, props, result.size());
+ return Either.left(result);
+
+ }
+ return Either.right(vertices.right().value());
+ } catch (Exception e) {
+ log.debug("Failed get by criteria for type = {} and properties = {}", type, props, e);
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
+ }
+ }
+
+ private Either<Iterable<JanusGraphVertex>, JanusGraphOperationStatus> getVerticesByCriteria(final NodeTypeEnum type, final Map<String, Object> props) {
+ final Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
+ if (graph.isLeft()) {
+ try {
+ final JanusGraph tGraph = graph.left().value();
+ JanusGraphQuery<? extends JanusGraphQuery> query = tGraph.query();
+ query = query.has(GraphPropertiesDictionary.LABEL.getProperty(), type.getName());
+ if (props != null && !props.isEmpty()) {
+ for (Map.Entry<String, Object> entry : props.entrySet()) {
+ query = query.has(entry.getKey(), entry.getValue());
+ }
}
- if (result.size() == 0) {
+ final Iterable<JanusGraphVertex> vertices = query.vertices();
+ if (vertices == null || !vertices.iterator().hasNext()) {
return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
- return Either.left(result);
+ return Either.left(vertices);
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("Failed get by criteria for type = {} and properties = {}", type, props, e);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperation.java
index f02fc2da7d..1b3fee97c1 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperation.java
@@ -20,8 +20,6 @@
package org.openecomp.sdc.be.model.operations.impl;
import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR;
-
-import fj.data.Either;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -47,6 +45,7 @@ import org.openecomp.sdc.be.resources.data.UniqueIdData;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import fj.data.Either;
@Component("relationship-type-operation")
public class RelationshipTypeOperation extends AbstractOperation {
@@ -72,7 +71,7 @@ public class RelationshipTypeOperation extends AbstractOperation {
return getRelationshipTypeDefinition(relationshipTypesRes.left().value());
}
- public Either<RelationshipTypeDefinition, JanusGraphOperationStatus> getRelationshipTypeDefinition(final RelationshipTypeData relationshipTypeData) {
+ private Either<RelationshipTypeDefinition, JanusGraphOperationStatus> getRelationshipTypeDefinition(final RelationshipTypeData relationshipTypeData) {
RelationshipTypeDefinition relationshipTypeDefinition = new RelationshipTypeDefinition(
relationshipTypeData.getRelationshipTypeDataDefinition());
Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> propertiesStatus = OperationUtils
@@ -364,11 +363,11 @@ public class RelationshipTypeOperation extends AbstractOperation {
DaoStatusConverter::convertJanusGraphStatusToStorageStatus);
}
- public Either<Map<String, RelationshipTypeDefinition>, JanusGraphOperationStatus> getAllRelationshipTypes() {
+ public Either<Map<String, RelationshipTypeDefinition>, JanusGraphOperationStatus> getAllRelationshipTypes(final String model) {
Map<String, RelationshipTypeDefinition> relationshipTypeDefinitionMap = new HashMap<>();
Either<Map<String, RelationshipTypeDefinition>, JanusGraphOperationStatus> result = Either.left(relationshipTypeDefinitionMap);
Either<List<RelationshipTypeData>, JanusGraphOperationStatus> getAllRelationshipTypes = janusGraphGenericDao
- .getByCriteria(NodeTypeEnum.RelationshipType, null, RelationshipTypeData.class);
+ .getByCriteriaForModel(NodeTypeEnum.RelationshipType, null, model, RelationshipTypeData.class);
if (getAllRelationshipTypes.isRight()) {
JanusGraphOperationStatus status = getAllRelationshipTypes.right().value();
if (status != JanusGraphOperationStatus.NOT_FOUND) {
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java
index 1cc13364a5..6551a13981 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java
@@ -32,6 +32,7 @@ import java.util.Map;
import java.util.Map.Entry;
import fj.data.Either;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.Before;
@@ -155,9 +156,9 @@ public class RelationshipTypeOperationTest extends ModelTestBase {
@Test
public void testGetAllRelationshipTypesNotFound() {
Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(
- janusGraphGenericDao).getByCriteria(NodeTypeEnum.RelationshipType, null,
+ janusGraphGenericDao).getByCriteriaForModel(NodeTypeEnum.RelationshipType, null, null,
RelationshipTypeData.class);
- Either<Map<String, RelationshipTypeDefinition>, JanusGraphOperationStatus> either = relationshipTypeOperation.getAllRelationshipTypes();
+ Either<Map<String, RelationshipTypeDefinition>, JanusGraphOperationStatus> either = relationshipTypeOperation.getAllRelationshipTypes(null);
assertTrue(either.isLeft() && MapUtils.isEmpty(either.left().value()));
}
@@ -165,9 +166,9 @@ public class RelationshipTypeOperationTest extends ModelTestBase {
@Test
public void testGetAllRelationshipTypesNotConnnected() {
Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_CONNECTED)).when(
- janusGraphGenericDao).getByCriteria(NodeTypeEnum.RelationshipType, null,
+ janusGraphGenericDao).getByCriteriaForModel(NodeTypeEnum.RelationshipType, null, null,
RelationshipTypeData.class);
- Either<Map<String, RelationshipTypeDefinition>, JanusGraphOperationStatus> either = relationshipTypeOperation.getAllRelationshipTypes();
+ Either<Map<String, RelationshipTypeDefinition>, JanusGraphOperationStatus> either = relationshipTypeOperation.getAllRelationshipTypes(null);
assertTrue(either.isRight() && JanusGraphOperationStatus.NOT_CONNECTED == either.right().value());
}
@@ -185,7 +186,7 @@ public class RelationshipTypeOperationTest extends ModelTestBase {
relationshipTypeDataList.add(relationshipTypeData1);
Mockito.doReturn(Either.left(relationshipTypeDataList))
- .when(janusGraphGenericDao).getByCriteria(NodeTypeEnum.RelationshipType, null,
+ .when(janusGraphGenericDao).getByCriteriaForModel(NodeTypeEnum.RelationshipType, null, null,
RelationshipTypeData.class);
Mockito.doReturn(Either.left(relationshipTypeData1)).when(janusGraphGenericDao)
@@ -203,11 +204,18 @@ public class RelationshipTypeOperationTest extends ModelTestBase {
.getDerivedFromChild("tosca.relationships.Root1", NodeTypeEnum.RelationshipType, RelationshipTypeData.class);
Either<Map<String, RelationshipTypeDefinition>, JanusGraphOperationStatus> either =
- relationshipTypeOperation.getAllRelationshipTypes();
+ relationshipTypeOperation.getAllRelationshipTypes(null);
assertTrue(either.isLeft());
RelationshipTypeDefinition relationshipTypeDefinition = either.left().value().get("tosca.relationships.Root1");
assertEquals("tosca.relationships.Parent", relationshipTypeDefinition.getDerivedFrom());
+
+ Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND))
+ .when(janusGraphGenericDao).getByCriteriaForModel(NodeTypeEnum.RelationshipType, null, "modelA",
+ RelationshipTypeData.class);
+ either = relationshipTypeOperation.getAllRelationshipTypes("modelA");
+ assertTrue(either.isLeft());
+ assertTrue(MapUtils.isEmpty(either.left().value()));
}
public RelationshipTypeDefinition createRelationship(String relationshipTypeName) {
diff --git a/catalog-ui/src/app/ng2/pages/workspace/req-and-capabilities/req-and-capabilities.service.ts b/catalog-ui/src/app/ng2/pages/workspace/req-and-capabilities/req-and-capabilities.service.ts
index 470aac75a6..f9b98c6b96 100644
--- a/catalog-ui/src/app/ng2/pages/workspace/req-and-capabilities/req-and-capabilities.service.ts
+++ b/catalog-ui/src/app/ng2/pages/workspace/req-and-capabilities/req-and-capabilities.service.ts
@@ -52,7 +52,7 @@ export class ReqAndCapabilitiesService {
if (initInputsFor === 'INPUTS_FOR_REQUIREMENTS') {
if (!this.requirementsListUpdated){
this.relationshipTypesList = [];
- let relationshipTypesResult = await this.toscaTypesServiceNg2.fetchRelationshipTypes();
+ let relationshipTypesResult = await this.toscaTypesServiceNg2.fetchRelationshipTypes(this.workspaceService.metadata.model);
Object.keys(relationshipTypesResult).forEach(key => {this.relationshipTypesList.push(relationshipTypesResult[key])});
this.requirementsListUpdated = true;
}
diff --git a/catalog-ui/src/app/ng2/services/tosca-types.service.ts b/catalog-ui/src/app/ng2/services/tosca-types.service.ts
index 83b833b1ab..2fc2e7a089 100644
--- a/catalog-ui/src/app/ng2/services/tosca-types.service.ts
+++ b/catalog-ui/src/app/ng2/services/tosca-types.service.ts
@@ -14,18 +14,18 @@
* permissions and limitations under the License.
*/
-import { HttpClient } from '@angular/common/http';
-import { Inject, Injectable } from '@angular/core';
-import { Response } from '@angular/http';
+import {HttpClient} from '@angular/common/http';
+import {Inject, Injectable} from '@angular/core';
+import {Response} from '@angular/http';
import {
- CapabilityTypeModel,
- CapabilityTypesMap,
- IComponentsArray,
- NodeTypesMap,
- RelationshipTypesMap
+ CapabilityTypeModel,
+ CapabilityTypesMap,
+ IComponentsArray,
+ NodeTypesMap,
+ RelationshipTypesMap
} from 'app/models';
-import { Observable } from 'rxjs/Observable';
-import { ISdcConfig, SdcConfigToken } from '../config/sdc-config.config';
+import {Observable} from 'rxjs/Observable';
+import {ISdcConfig, SdcConfigToken} from '../config/sdc-config.config';
import 'rxjs/add/operator/toPromise';
declare var angular: angular.IAngularStatic;
@@ -33,22 +33,22 @@ declare var angular: angular.IAngularStatic;
@Injectable()
export class ToscaTypesServiceNg2 {
- protected baseUrl;
+ protected baseUrl;
- constructor(protected http: HttpClient, @Inject(SdcConfigToken) sdcConfig: ISdcConfig) {
- this.baseUrl = sdcConfig.api.root + sdcConfig.api.component_api_root;
- }
+ constructor(protected http: HttpClient, @Inject(SdcConfigToken) sdcConfig: ISdcConfig) {
+ this.baseUrl = sdcConfig.api.root + sdcConfig.api.component_api_root;
+ }
- async fetchRelationshipTypes(): Promise<RelationshipTypesMap> {
- return this.http.get<RelationshipTypesMap>(this.baseUrl + 'relationshipTypes').toPromise();
- }
+ async fetchRelationshipTypes(modelName: string): Promise<RelationshipTypesMap> {
+ return this.http.get<RelationshipTypesMap>(this.baseUrl + 'relationshipTypes', {params: {model: modelName}}).toPromise();
+ }
- async fetchNodeTypes(): Promise<NodeTypesMap> {
- return this.http.get<NodeTypesMap>(this.baseUrl + 'nodeTypes').toPromise();
- }
+ async fetchNodeTypes(): Promise<NodeTypesMap> {
+ return this.http.get<NodeTypesMap>(this.baseUrl + 'nodeTypes').toPromise();
+ }
- async fetchCapabilityTypes(): Promise<CapabilityTypesMap>{
- return this.http.get<CapabilityTypesMap>(this.baseUrl + 'capabilityTypes').toPromise();
- }
+ async fetchCapabilityTypes(): Promise<CapabilityTypesMap> {
+ return this.http.get<CapabilityTypesMap>(this.baseUrl + 'capabilityTypes').toPromise();
+ }
}