Skip to content

Commit

Permalink
batch list dao api (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvoet authored Dec 19, 2023
1 parent 07ee216 commit ebe6cf7
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
35 changes: 35 additions & 0 deletions common/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,41 @@ paths:
'500':
$ref: '#/components/responses/ServerError'

/api/policy/v1alpha1/pao/list:
post:
summary: List policy attribute objects for given ids
description: |
Gets the policy attribute objects for the given ids. If the id is not found, it is not returned.
operationId: listPaos
tags: [Tps]
requestBody:
required: true
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/TpsObjectId'
responses:
'200':
description: Policy retrieved successfully
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/TpsPaoGetResult'
'400':
$ref: '#/components/responses/BadRequest'
'403':
$ref: '#/components/responses/PermissionDenied'
'404':
$ref: '#/components/responses/NotFound'
'409':
$ref: '#/components/responses/Conflict'
'500':
$ref: '#/components/responses/ServerError'

/api/policy/v1alpha1/pao/{objectId}:
parameters:
- $ref: '#/components/parameters/TpsObjectId'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ public ResponseEntity<ApiTpsPaoUpdateResult> linkPao(UUID objectId, ApiTpsPaoSou
return new ResponseEntity<>(apiResult, HttpStatus.OK);
}

@Override
public ResponseEntity<List<ApiTpsPaoGetResult>> listPaos(List<UUID> objectIds) {
return new ResponseEntity<>(
paoService.listPaos(objectIds).stream().map(ConversionUtils::paoToApi).toList(),
HttpStatus.OK);
}

@Override
public ResponseEntity<ApiTpsRegions> listValidByPolicyInput(
String platform, ApiTpsPolicyInputs policyInputs) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package bio.terra.policy.service.pao;

import bio.terra.common.db.ReadTransaction;
import bio.terra.common.db.WriteTransaction;
import bio.terra.policy.common.exception.DirectConflictException;
import bio.terra.policy.common.exception.IllegalCycleException;
Expand Down Expand Up @@ -91,6 +92,11 @@ public Pao getPao(UUID objectId) {
return paoDao.getPao(objectId);
}

@ReadTransaction
public List<Pao> listPaos(List<UUID> objectIds) {
return paoDao.getPaos(objectIds);
}

/**
* Link a policy source to a PAO. For example, referencing a data collection in a workspace would
* add the data collection as a policy source of the workspace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import bio.terra.policy.testutils.TestUnitBase;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -62,6 +63,21 @@ void createPaoTest() throws Exception {
assertThrows(PolicyObjectNotFoundException.class, () -> paoService.getPao(objectId));
}

@Test
void listPaosTest() {
var objectId = UUID.randomUUID();
var objectId2 = UUID.randomUUID();

paoService.createPao(objectId, PaoComponent.WSM, PaoObjectType.WORKSPACE, new PolicyInputs());
paoService.createPao(objectId2, PaoComponent.WSM, PaoObjectType.WORKSPACE, new PolicyInputs());

// add an extra object id that doesn't exist
var paos = paoService.listPaos(List.of(objectId, objectId2, UUID.randomUUID()));
assertEquals(2, paos.size());
assertTrue(paos.stream().anyMatch(p -> p.getObjectId().equals(objectId)));
assertTrue(paos.stream().anyMatch(p -> p.getObjectId().equals(objectId2)));
}

@Test
void createPaoTest_invalidInputThrows() throws Exception {
var objectId = UUID.randomUUID();
Expand Down

0 comments on commit ebe6cf7

Please sign in to comment.