-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Matt Bemis <[email protected]>
- Loading branch information
1 parent
c855e6b
commit 9ff8b5d
Showing
44 changed files
with
1,218 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
api-admin/src/main/java/bio/terra/pearl/api/admin/controller/kit/KitController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package bio.terra.pearl.api.admin.controller.kit; | ||
|
||
import bio.terra.pearl.api.admin.api.KitApi; | ||
import bio.terra.pearl.api.admin.service.AuthUtilService; | ||
import bio.terra.pearl.api.admin.service.kit.KitExtService; | ||
import bio.terra.pearl.core.model.EnvironmentName; | ||
import bio.terra.pearl.core.model.admin.AdminUser; | ||
import javax.servlet.http.HttpServletRequest; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
|
||
@Controller | ||
public class KitController implements KitApi { | ||
private final AuthUtilService authUtilService; | ||
private final KitExtService kitExtService; | ||
private final HttpServletRequest request; | ||
|
||
public KitController( | ||
AuthUtilService authUtilService, KitExtService kitExtService, HttpServletRequest request) { | ||
this.authUtilService = authUtilService; | ||
this.kitExtService = kitExtService; | ||
this.request = request; | ||
} | ||
|
||
@Override | ||
public ResponseEntity<Object> kitsByStudyEnvironment( | ||
String portalShortcode, String studyShortcode, String envName) { | ||
AdminUser adminUser = authUtilService.requireAdminUser(request); | ||
EnvironmentName environmentName = EnvironmentName.valueOfCaseInsensitive(envName); | ||
|
||
var kits = | ||
kitExtService.getKitRequestsByStudyEnvironment( | ||
adminUser, portalShortcode, studyShortcode, environmentName); | ||
|
||
return ResponseEntity.ok(kits); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
api-admin/src/main/java/bio/terra/pearl/api/admin/service/kit/KitExtService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package bio.terra.pearl.api.admin.service.kit; | ||
|
||
import bio.terra.pearl.api.admin.service.AuthUtilService; | ||
import bio.terra.pearl.core.model.EnvironmentName; | ||
import bio.terra.pearl.core.model.admin.AdminUser; | ||
import bio.terra.pearl.core.model.kit.KitRequest; | ||
import bio.terra.pearl.core.model.study.StudyEnvironment; | ||
import bio.terra.pearl.core.service.kit.KitRequestService; | ||
import bio.terra.pearl.core.service.study.StudyEnvironmentService; | ||
import java.util.Collection; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class KitExtService { | ||
private final AuthUtilService authUtilService; | ||
private final KitRequestService kitRequestService; | ||
private final StudyEnvironmentService studyEnvironmentService; | ||
|
||
public KitExtService( | ||
AuthUtilService authUtilService, | ||
KitRequestService kitRequestService, | ||
StudyEnvironmentService studyEnvironmentService) { | ||
this.authUtilService = authUtilService; | ||
this.kitRequestService = kitRequestService; | ||
this.studyEnvironmentService = studyEnvironmentService; | ||
} | ||
|
||
public Collection<KitRequest> getKitRequestsByStudyEnvironment( | ||
AdminUser adminUser, | ||
String portalShortcode, | ||
String studyShortcode, | ||
EnvironmentName environmentName) { | ||
authUtilService.authUserToStudy(adminUser, portalShortcode, studyShortcode); | ||
|
||
StudyEnvironment studyEnvironment = | ||
studyEnvironmentService.findByStudy(studyShortcode, environmentName).get(); | ||
|
||
return kitRequestService.getSampleKitsByStudyEnvironment(studyEnvironment); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
api-admin/src/test/java/bio/terra/pearl/api/admin/service/kit/KitExtServiceTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package bio.terra.pearl.api.admin.service.kit; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
|
||
import bio.terra.pearl.api.admin.BaseSpringBootTest; | ||
import bio.terra.pearl.api.admin.service.AuthUtilService; | ||
import bio.terra.pearl.core.model.EnvironmentName; | ||
import bio.terra.pearl.core.model.admin.AdminUser; | ||
import bio.terra.pearl.core.service.exception.PermissionDeniedException; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
public class KitExtServiceTests extends BaseSpringBootTest { | ||
@Autowired private KitExtService kitExtService; | ||
|
||
@Test | ||
@Transactional | ||
public void testGetKitRequestsForStudyEnvironmentRequiresAdmin() { | ||
when(mockAuthUtilService.authUserToStudy(any(), any(), any())) | ||
.thenThrow(new PermissionDeniedException("")); | ||
AdminUser adminUser = new AdminUser(); | ||
Assertions.assertThrows( | ||
PermissionDeniedException.class, | ||
() -> | ||
kitExtService.getKitRequestsByStudyEnvironment( | ||
adminUser, "someportal", "somestudy", EnvironmentName.sandbox)); | ||
} | ||
|
||
@MockBean private AuthUtilService mockAuthUtilService; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.