Search in sources :

Example 1 with ReportIndex

use of org.sagebionetworks.bridge.models.reports.ReportIndex in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantReportControllerTest method getParticipantReportIndex.

@Test
public void getParticipantReportIndex() throws Exception {
    ReportIndex index = ReportIndex.create();
    index.setIdentifier(REPORT_ID);
    index.setPublic(true);
    index.setStudyIds(USER_STUDY_IDS);
    when(mockReportService.getReportIndex(any())).thenReturn(index);
    ReportIndex result = controller.getParticipantReportIndex(REPORT_ID);
    assertEquals(result.getIdentifier(), REPORT_ID);
    assertEquals(result.getStudyIds(), USER_STUDY_IDS);
    verify(mockReportService).getReportIndex(reportDataKeyCaptor.capture());
    ReportDataKey key = reportDataKeyCaptor.getValue();
    assertEquals(key.getAppId(), TEST_APP_ID);
    assertEquals(key.getIdentifier(), REPORT_ID);
    assertEquals(key.getReportType(), PARTICIPANT);
}
Also used : ReportIndex(org.sagebionetworks.bridge.models.reports.ReportIndex) ReportDataKey(org.sagebionetworks.bridge.models.reports.ReportDataKey) Test(org.testng.annotations.Test)

Example 2 with ReportIndex

use of org.sagebionetworks.bridge.models.reports.ReportIndex in project BridgeServer2 by Sage-Bionetworks.

the class ReportService method getParticipantReportV4.

/**
 * Return set of participant report records based on the provided datetime range. Study memberships are enforced.
 */
public ForwardCursorPagedResourceList<ReportData> getParticipantReportV4(final String appId, final String userId, final String identifier, final String healthCode, final DateTime startTime, final DateTime endTime, final String offsetKey, final int pageSize) {
    if (pageSize < API_MINIMUM_PAGE_SIZE || pageSize > API_MAXIMUM_PAGE_SIZE) {
        throw new BadRequestException(BridgeConstants.PAGE_SIZE_ERROR);
    }
    RangeTuple<DateTime> finalTimes = validateDateTimeRange(startTime, endTime);
    ReportDataKey key = new ReportDataKey.Builder().withHealthCode(healthCode).withReportType(ReportType.PARTICIPANT).withIdentifier(identifier).withAppId(appId).build();
    Validate.entityThrowingException(ReportDataKeyValidator.INSTANCE, key);
    ReportIndex index = reportIndexDao.getIndex(key);
    checkParticipantReportAccess(userId, index);
    return reportDataDao.getReportDataV4(key, finalTimes.getStart(), finalTimes.getEnd(), offsetKey, pageSize);
}
Also used : ReportIndex(org.sagebionetworks.bridge.models.reports.ReportIndex) ReportDataKey(org.sagebionetworks.bridge.models.reports.ReportDataKey) BadRequestException(org.sagebionetworks.bridge.exceptions.BadRequestException) DateTime(org.joda.time.DateTime)

Example 3 with ReportIndex

use of org.sagebionetworks.bridge.models.reports.ReportIndex in project BridgeServer2 by Sage-Bionetworks.

the class ReportService method getStudyReportV4.

/**
 * Return set of study report records based on the provided datetime range. Study memberships are enforced.
 */
public ForwardCursorPagedResourceList<ReportData> getStudyReportV4(final String appId, final String identifier, final DateTime startTime, final DateTime endTime, final String offsetKey, final int pageSize) {
    if (pageSize < API_MINIMUM_PAGE_SIZE || pageSize > API_MAXIMUM_PAGE_SIZE) {
        throw new BadRequestException(BridgeConstants.PAGE_SIZE_ERROR);
    }
    RangeTuple<DateTime> finalTimes = validateDateTimeRange(startTime, endTime);
    ReportDataKey key = new ReportDataKey.Builder().withReportType(ReportType.STUDY).withIdentifier(identifier).withAppId(appId).build();
    Validate.entityThrowingException(ReportDataKeyValidator.INSTANCE, key);
    ReportIndex index = reportIndexDao.getIndex(key);
    checkStudyReportAccess(index);
    return reportDataDao.getReportDataV4(key, finalTimes.getStart(), finalTimes.getEnd(), offsetKey, pageSize);
}
Also used : ReportIndex(org.sagebionetworks.bridge.models.reports.ReportIndex) ReportDataKey(org.sagebionetworks.bridge.models.reports.ReportDataKey) BadRequestException(org.sagebionetworks.bridge.exceptions.BadRequestException) DateTime(org.joda.time.DateTime)

Example 4 with ReportIndex

use of org.sagebionetworks.bridge.models.reports.ReportIndex in project BridgeServer2 by Sage-Bionetworks.

the class ReportService method deleteStudyReport.

/**
 * Delete all records for a study report. Study memberships will be enforced.
 */
public void deleteStudyReport(String appId, String identifier) {
    ReportDataKey key = new ReportDataKey.Builder().withReportType(ReportType.STUDY).withIdentifier(identifier).withAppId(appId).build();
    Validate.entityThrowingException(ReportDataKeyValidator.INSTANCE, key);
    ReportIndex index = reportIndexDao.getIndex(key);
    checkStudyReportAccess(index);
    reportDataDao.deleteReportData(key);
    reportIndexDao.removeIndex(key);
}
Also used : ReportIndex(org.sagebionetworks.bridge.models.reports.ReportIndex) ReportDataKey(org.sagebionetworks.bridge.models.reports.ReportDataKey)

Example 5 with ReportIndex

use of org.sagebionetworks.bridge.models.reports.ReportIndex in project BridgeServer2 by Sage-Bionetworks.

the class ReportService method getReportIndex.

/**
 * Get a report index.
 */
public ReportIndex getReportIndex(ReportDataKey key) {
    checkNotNull(key);
    ReportIndex index = reportIndexDao.getIndex(key);
    checkStudyReportAccess(index);
    return index;
}
Also used : ReportIndex(org.sagebionetworks.bridge.models.reports.ReportIndex)

Aggregations

ReportIndex (org.sagebionetworks.bridge.models.reports.ReportIndex)67 Test (org.testng.annotations.Test)39 ReportDataKey (org.sagebionetworks.bridge.models.reports.ReportDataKey)37 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)10 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)10 ReportData (org.sagebionetworks.bridge.models.reports.ReportData)8 ReportTypeResourceList (org.sagebionetworks.bridge.models.ReportTypeResourceList)6 DateTime (org.joda.time.DateTime)5 RequestContext (org.sagebionetworks.bridge.RequestContext)5 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)5 Account (org.sagebionetworks.bridge.models.accounts.Account)5 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)4 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 DynamoDBSaveExpression (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBSaveExpression)3 LocalDate (org.joda.time.LocalDate)3 ForwardCursorPagedResourceList (org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList)3 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 ConditionalCheckFailedException (com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)2