Search in sources :

Example 1 with UploadView

use of org.sagebionetworks.bridge.models.upload.UploadView in project BridgeServer2 by Sage-Bionetworks.

the class UploadService method uploadToUploadView.

private UploadView uploadToUploadView(Upload upload, boolean includeHealthDataRecord) {
    UploadView.Builder builder = new UploadView.Builder();
    builder.withUpload(upload);
    if (upload.getRecordId() != null) {
        HealthDataRecord record = healthDataService.getRecordById(upload.getRecordId());
        if (record != null) {
            if (includeHealthDataRecord) {
                builder.withHealthDataRecord(record);
            } else {
                builder.withSchemaId(record.getSchemaId());
                builder.withSchemaRevision(record.getSchemaRevision());
                builder.withHealthRecordExporterStatus(record.getSynapseExporterStatus());
            }
        }
    }
    return builder.build();
}
Also used : UploadView(org.sagebionetworks.bridge.models.upload.UploadView) HealthDataRecord(org.sagebionetworks.bridge.models.healthdata.HealthDataRecord)

Example 2 with UploadView

use of org.sagebionetworks.bridge.models.upload.UploadView in project BridgeServer2 by Sage-Bionetworks.

the class UploadControllerTest method getUploadByRecordIdRejectsAppAdmin.

@Test(expectedExceptions = UnauthorizedException.class, expectedExceptionsMessageRegExp = ".*Caller does not have permission to access upload.*")
public void getUploadByRecordIdRejectsAppAdmin() throws Exception {
    doReturn(mockResearcherSession).when(controller).getAuthenticatedSession(DEVELOPER, WORKER);
    doReturn(true).when(mockResearcherSession).isInRole(ADMIN);
    doReturn(TEST_USER_ID).when(mockResearcherSession).getId();
    when(mockResearcherSession.getAppId()).thenReturn(TEST_APP_ID);
    HealthDataRecord record = HealthDataRecord.create();
    record.setAppId(TEST_APP_ID);
    record.setUploadId(UPLOAD_ID);
    record.setHealthCode(HEALTH_CODE);
    when(mockHealthDataService.getRecordById("record-id")).thenReturn(record);
    DynamoUpload2 upload = new DynamoUpload2();
    upload.setAppId("researcher-app-id");
    upload.setCompletedBy(UploadCompletionClient.S3_WORKER);
    UploadView uploadView = new UploadView.Builder().withUpload(upload).withHealthDataRecord(record).build();
    when(mockUploadService.getUploadView(UPLOAD_ID)).thenReturn(uploadView);
    controller.getUpload("recordId:record-id");
}
Also used : UploadView(org.sagebionetworks.bridge.models.upload.UploadView) HealthDataRecord(org.sagebionetworks.bridge.models.healthdata.HealthDataRecord) DynamoUpload2(org.sagebionetworks.bridge.dynamodb.DynamoUpload2) Test(org.testng.annotations.Test)

Example 3 with UploadView

use of org.sagebionetworks.bridge.models.upload.UploadView in project BridgeServer2 by Sage-Bionetworks.

the class UploadControllerTest method getUploadByIdWorksForDevelopersOwnAccount.

@Test
public void getUploadByIdWorksForDevelopersOwnAccount() {
    doReturn(mockResearcherSession).when(controller).getAuthenticatedSession(DEVELOPER, WORKER);
    when(mockResearcherSession.getAppId()).thenReturn(TEST_APP_ID);
    when(mockResearcherSession.getHealthCode()).thenReturn(HEALTH_CODE);
    when(mockResearcherSession.isInRole(DEVELOPER)).thenReturn(true);
    HealthDataRecord record = HealthDataRecord.create();
    record.setHealthCode(HEALTH_CODE);
    DynamoUpload2 upload = new DynamoUpload2();
    upload.setHealthCode(HEALTH_CODE);
    upload.setAppId("some-other-app");
    upload.setCompletedBy(UploadCompletionClient.S3_WORKER);
    UploadView uploadView = new UploadView.Builder().withUpload(upload).withHealthDataRecord(record).build();
    when(mockUploadService.getUploadView(UPLOAD_ID)).thenReturn(uploadView);
    UploadView view = controller.getUpload(UPLOAD_ID);
    assertNotNull(view);
}
Also used : UploadView(org.sagebionetworks.bridge.models.upload.UploadView) HealthDataRecord(org.sagebionetworks.bridge.models.healthdata.HealthDataRecord) DynamoUpload2(org.sagebionetworks.bridge.dynamodb.DynamoUpload2) Test(org.testng.annotations.Test)

Example 4 with UploadView

use of org.sagebionetworks.bridge.models.upload.UploadView in project BridgeServer2 by Sage-Bionetworks.

the class UploadControllerTest method getUploadByRecordId.

@Test
public void getUploadByRecordId() throws Exception {
    doReturn(TEST_USER_ID).when(mockResearcherSession).getId();
    doReturn(TEST_APP_ID).when(mockResearcherSession).getAppId();
    doReturn(true).when(mockResearcherSession).isInRole(EnumSet.of(SUPERADMIN, WORKER));
    doReturn(mockResearcherSession).when(controller).getAuthenticatedSession(DEVELOPER, WORKER);
    HealthDataRecord record = HealthDataRecord.create();
    record.setAppId(TEST_APP_ID);
    record.setUploadId(UPLOAD_ID);
    record.setHealthCode(HEALTH_CODE);
    when(mockHealthDataService.getRecordById("record-id")).thenReturn(record);
    DynamoUpload2 upload = new DynamoUpload2();
    upload.setAppId(TEST_APP_ID);
    upload.setCompletedBy(UploadCompletionClient.S3_WORKER);
    UploadView uploadView = new UploadView.Builder().withUpload(upload).withHealthDataRecord(record).build();
    when(mockUploadService.getUploadView(UPLOAD_ID)).thenReturn(uploadView);
    UploadView result = controller.getUpload("recordId:record-id");
    JsonNode node = BridgeObjectMapper.get().valueToTree(result);
    assertEquals(node.get("completedBy").textValue(), "s3_worker");
    assertEquals(node.get("type").textValue(), "Upload");
    assertEquals(node.get("healthData").get("healthCode").textValue(), HEALTH_CODE);
}
Also used : UploadView(org.sagebionetworks.bridge.models.upload.UploadView) HealthDataRecord(org.sagebionetworks.bridge.models.healthdata.HealthDataRecord) JsonNode(com.fasterxml.jackson.databind.JsonNode) DynamoUpload2(org.sagebionetworks.bridge.dynamodb.DynamoUpload2) Test(org.testng.annotations.Test)

Example 5 with UploadView

use of org.sagebionetworks.bridge.models.upload.UploadView in project BridgeServer2 by Sage-Bionetworks.

the class AppControllerTest method canGetUploadsForApp.

@SuppressWarnings("deprecation")
@Test
public void canGetUploadsForApp() throws Exception {
    doReturn(mockSession).when(controller).getAuthenticatedSession(ADMIN);
    DateTime startTime = DateTime.parse("2010-01-01T00:00:00.000Z");
    DateTime endTime = DateTime.parse("2010-01-02T00:00:00.000Z");
    List<Upload> list = ImmutableList.of();
    ForwardCursorPagedResourceList<Upload> uploads = new ForwardCursorPagedResourceList<>(list, null).withRequestParam("pageSize", API_MAXIMUM_PAGE_SIZE).withRequestParam("startTime", startTime).withRequestParam("endTime", endTime);
    doReturn(uploads).when(mockUploadService).getAppUploads(TEST_APP_ID, startTime, endTime, API_MAXIMUM_PAGE_SIZE, null);
    ForwardCursorPagedResourceList<UploadView> result = controller.getUploads(startTime.toString(), endTime.toString(), API_MAXIMUM_PAGE_SIZE, null);
    verify(mockUploadService).getAppUploads(TEST_APP_ID, startTime, endTime, API_MAXIMUM_PAGE_SIZE, null);
    verify(mockAppService, never()).getApp(TEST_APP_ID);
    // in other words, it's the object we mocked out from the service, we were returned the value.
    assertNull(result.getRequestParams().get("offsetBy"));
    assertNull(result.getTotal());
    assertEquals(result.getRequestParams().get("pageSize"), API_MAXIMUM_PAGE_SIZE);
    assertEquals(result.getRequestParams().get("startTime"), startTime.toString());
    assertEquals(result.getRequestParams().get("endTime"), endTime.toString());
}
Also used : UploadView(org.sagebionetworks.bridge.models.upload.UploadView) Upload(org.sagebionetworks.bridge.models.upload.Upload) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

UploadView (org.sagebionetworks.bridge.models.upload.UploadView)17 Test (org.testng.annotations.Test)14 DynamoUpload2 (org.sagebionetworks.bridge.dynamodb.DynamoUpload2)10 HealthDataRecord (org.sagebionetworks.bridge.models.healthdata.HealthDataRecord)10 DateTime (org.joda.time.DateTime)5 Upload (org.sagebionetworks.bridge.models.upload.Upload)5 ForwardCursorPagedResourceList (org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 UploadRequest (org.sagebionetworks.bridge.models.upload.UploadRequest)2 RequestContext (org.sagebionetworks.bridge.RequestContext)1 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)1 UnauthorizedException (org.sagebionetworks.bridge.exceptions.UnauthorizedException)1 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1