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();
}
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");
}
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);
}
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);
}
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());
}
Aggregations