use of org.sagebionetworks.bridge.models.reports.ReportData in project BridgeServer2 by Sage-Bionetworks.
the class ParticipantReportControllerTest method saveParticipantReportData.
@Test
public void saveParticipantReportData() throws Exception {
String json = TestUtils.createJson("{'date':'2015-02-12','data':{'field1':'Last','field2':'Name'}}");
mockRequestBody(mockRequest, json);
when(mockAccountService.getAccount(any())).thenReturn(Optional.of(mockOtherAccount));
StatusMessage result = controller.saveParticipantReport(OTHER_PARTICIPANT_ID, REPORT_ID);
assertEquals(result.getMessage(), "Report data saved.");
verify(mockReportService).saveParticipantReport(eq(TEST_APP_ID), eq(TEST_USER_ID), eq(REPORT_ID), eq(OTHER_PARTICIPANT_HEALTH_CODE), reportDataCaptor.capture());
ReportData reportData = reportDataCaptor.getValue();
assertEquals(reportData.getDate().toString(), LocalDate.parse("2015-02-12").toString());
assertNull(reportData.getKey());
assertEquals(reportData.getData().get("field1").asText(), "Last");
assertEquals(reportData.getData().get("field2").asText(), "Name");
}
use of org.sagebionetworks.bridge.models.reports.ReportData in project BridgeServer2 by Sage-Bionetworks.
the class ParticipantReportControllerTest method createReport.
private ReportData createReport(DateTime date, String fieldValue1, String fieldValue2) {
ObjectNode node = JsonNodeFactory.instance.objectNode();
node.put("field1", fieldValue1);
node.put("field2", fieldValue2);
ReportData report = ReportData.create();
report.setKey("foo:" + TEST_APP_ID);
report.setDateTime(date);
report.setData(node);
return report;
}
use of org.sagebionetworks.bridge.models.reports.ReportData in project BridgeServer2 by Sage-Bionetworks.
the class ParticipantReportController method saveParticipantReportForSelf.
@PostMapping({ "/v4/users/self/reports/{identifier}", "/v3/users/self/reports/{identifier}" })
@ResponseStatus(HttpStatus.CREATED)
public StatusMessage saveParticipantReportForSelf(@PathVariable String identifier) {
UserSession session = getAuthenticatedSession();
ReportData reportData = parseJson(ReportData.class);
// set in service, but just so no future use depends on it
reportData.setKey(null);
reportService.saveParticipantReport(session.getAppId(), session.getId(), identifier, session.getHealthCode(), reportData);
return new StatusMessage("Report data saved.");
}
use of org.sagebionetworks.bridge.models.reports.ReportData in project BridgeServer2 by Sage-Bionetworks.
the class ReportServiceTest method saveStudyReport.
@Test
public void saveStudyReport() {
ReportData someData = createReport(LocalDate.parse("2015-02-10"), "First", "Name");
service.saveStudyReport(TEST_APP_ID, IDENTIFIER, someData);
verify(mockReportDataDao).saveReportData(reportDataCaptor.capture());
ReportData retrieved = reportDataCaptor.getValue();
assertEquals(retrieved, someData);
assertEquals(retrieved.getKey(), STUDY_REPORT_DATA_KEY.getKeyString());
assertEquals(retrieved.getDate(), "2015-02-10");
assertEquals(retrieved.getData().get("field1").asText(), "First");
assertEquals(retrieved.getData().get("field2").asText(), "Name");
verify(mockReportIndexDao).addIndex(new ReportDataKey.Builder().withAppId(TEST_APP_ID).withReportType(ReportType.STUDY).withIdentifier(IDENTIFIER).build(), null);
}
use of org.sagebionetworks.bridge.models.reports.ReportData in project BridgeServer2 by Sage-Bionetworks.
the class ReportServiceTest method saveParticipantReportAuthorizes.
@Test(expectedExceptions = EntityNotFoundException.class)
public void saveParticipantReportAuthorizes() {
setupMismatchedStudies(PARTICIPANT_REPORT_DATA_KEY);
ReportData data = createReport(START_DATE, "value", "value2");
service.saveParticipantReport(TEST_APP_ID, "some-other-user", IDENTIFIER, HEALTH_CODE, data);
}
Aggregations