Respect permissions by owning-entity-id when searching instances by owning entity
[vid.git] / vid-app-common / src / main / java / org / onap / vid / services / AaiServiceImpl.java
index a992519..1e79ab4 100644 (file)
@@ -179,33 +179,36 @@ public class AaiServiceImpl implements AaiService {
         if (owningEntityResponse.getT() != null) {
             for (OwningEntity owningEntity : owningEntityResponse.getT().getOwningEntity()) {
                 if (owningEntity.getRelationshipList() != null) {
-                    serviceInstanceSearchResultList = convertRelationshipToSearchResult(owningEntity, serviceInstanceSearchResultList, roleValidator);
+                    serviceInstanceSearchResultList.addAll(convertRelationshipToSearchResult(owningEntity, roleValidator, owningEntity.getOwningEntityId()));
                 }
             }
         }
         return serviceInstanceSearchResultList;
     }
 
-    private List<ServiceInstanceSearchResult> getServicesByProjectNames(List<String> projectNames, RoleValidator roleValidator) {
+    List<ServiceInstanceSearchResult> getServicesByProjectNames(List<String> projectNames, RoleValidator roleValidator) {
         AaiResponse<ProjectResponse> projectByIdResponse = aaiClient.getServicesByProjectNames(projectNames);
         List<ServiceInstanceSearchResult> serviceInstanceSearchResultList = new ArrayList<>();
         if (projectByIdResponse.getT() != null) {
             for (Project project : projectByIdResponse.getT().getProject()) {
                 if (project.getRelationshipList() != null) {
-                    serviceInstanceSearchResultList = convertRelationshipToSearchResult(project, serviceInstanceSearchResultList, roleValidator);
+                    serviceInstanceSearchResultList.addAll(convertRelationshipToSearchResult(project, roleValidator, null));
                 }
             }
         }
         return serviceInstanceSearchResultList;
     }
 
-    private List<ServiceInstanceSearchResult> convertRelationshipToSearchResult(AaiRelationResponse owningEntityResponse, List<ServiceInstanceSearchResult> serviceInstanceSearchResultList, RoleValidator roleValidator) {
-        if (owningEntityResponse.getRelationshipList().getRelationship() != null) {
-            List<Relationship> relationshipList = owningEntityResponse.getRelationshipList().getRelationship();
+    private List<ServiceInstanceSearchResult> convertRelationshipToSearchResult(AaiRelationResponse aaiRelationResponse, RoleValidator roleValidator, String owningEntityId) {
+        List<ServiceInstanceSearchResult> serviceInstanceSearchResultList = new ArrayList<>();
+        if (aaiRelationResponse.getRelationshipList().getRelationship() != null) {
+            List<Relationship> relationshipList = aaiRelationResponse.getRelationshipList().getRelationship();
             for (Relationship relationship : relationshipList) {
                 ServiceInstanceSearchResult serviceInstanceSearchResult = new ServiceInstanceSearchResult();
                 extractRelationshipData(relationship, serviceInstanceSearchResult, roleValidator);
                 extractRelatedToProperty(relationship, serviceInstanceSearchResult);
+                serviceInstanceSearchResult.setOwningEntityId(owningEntityId);
+                serviceInstanceSearchResult.setIsPermitted(roleValidator.isServicePermitted(serviceInstanceSearchResult));
                 serviceInstanceSearchResultList.add(serviceInstanceSearchResult);
             }
         }
@@ -226,9 +229,6 @@ public class AaiServiceImpl implements AaiService {
                     serviceInstanceSearchResult.setSubscriberId(relationshipData.getRelationshipValue());
                 }
             }
-
-            boolean isPermitted = roleValidator.isServicePermitted(serviceInstanceSearchResult);
-            serviceInstanceSearchResult.setIsPermitted(isPermitted);
         }
     }