Search in sources :

Example 21 with ReportData

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

the class ReportDataValidatorTest method keyIsValidated.

@Test
public void keyIsValidated() {
    ReportDataKey key = new ReportDataKey.Builder().withReportType(ReportType.STUDY).withAppId(TEST_APP_ID).build();
    ReportData data = ReportData.create();
    data.setReportDataKey(key);
    data.setData(TestUtils.getClientData());
    data.setLocalDate(LocalDate.parse("2017-09-06"));
    TestUtils.assertValidatorMessage(validator, data, "identifier", "cannot be missing or blank");
}
Also used : ReportDataKey(org.sagebionetworks.bridge.models.reports.ReportDataKey) ReportData(org.sagebionetworks.bridge.models.reports.ReportData) Test(org.testng.annotations.Test)

Example 22 with ReportData

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

the class ReportDataValidatorTest method mustHaveOneDate.

@Test
public void mustHaveOneDate() {
    ReportData data = ReportData.create();
    data.setData(TestUtils.getClientData());
    try {
        Validate.entityThrowingException(validator, data);
    } catch (InvalidEntityException e) {
        assertTrue(e.getMessage().contains("ReportData must include a localDate or dateTime"));
    }
}
Also used : ReportData(org.sagebionetworks.bridge.models.reports.ReportData) InvalidEntityException(org.sagebionetworks.bridge.exceptions.InvalidEntityException) Test(org.testng.annotations.Test)

Example 23 with ReportData

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

the class ReportDataValidatorTest method existingIndexNoStudyChangeOK.

@Test
public void existingIndexNoStudyChangeOK() {
    ReportIndex index = ReportIndex.create();
    index.setStudyIds(TestConstants.USER_STUDY_IDS);
    ReportDataKey key = new ReportDataKey.Builder().withReportType(ReportType.STUDY).withIdentifier("foo").withAppId(TEST_APP_ID).build();
    ReportData data = ReportData.create();
    data.setReportDataKey(key);
    data.setData(TestUtils.getClientData());
    data.setLocalDate(LocalDate.parse("2017-09-06"));
    data.setStudyIds(TestConstants.USER_STUDY_IDS);
    validator = new ReportDataValidator(index);
    Validate.entityThrowingException(validator, data);
}
Also used : ReportIndex(org.sagebionetworks.bridge.models.reports.ReportIndex) ReportDataKey(org.sagebionetworks.bridge.models.reports.ReportDataKey) ReportData(org.sagebionetworks.bridge.models.reports.ReportData) Test(org.testng.annotations.Test)

Example 24 with ReportData

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

the class ReportDataValidatorTest method keyIsRequired.

@Test
public void keyIsRequired() {
    ReportData data = ReportData.create();
    data.setData(TestUtils.getClientData());
    TestUtils.assertValidatorMessage(validator, data, "key", "is required");
}
Also used : ReportData(org.sagebionetworks.bridge.models.reports.ReportData) Test(org.testng.annotations.Test)

Example 25 with ReportData

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

the class DynamoReportDataDao method getReportDataV4.

/**
 * Query for report records within a range of DateTime values, using the indicated page size and offset key.
 * The report's date field will be returned using the timezone provided in the startTime/endTime parameters,
 * but all searches are done against the values in UTC time so they remain accurate when a user switches
 * time zones.
 */
@Override
public ForwardCursorPagedResourceList<ReportData> getReportDataV4(final ReportDataKey key, final DateTime startTime, final DateTime endTime, final String offsetKey, final int pageSize) {
    checkNotNull(key);
    checkNotNull(startTime);
    checkNotNull(endTime);
    int pageSizeWithIndicatorRecord = pageSize + 1;
    DynamoReportData hashKey = new DynamoReportData();
    hashKey.setKey(key.getKeyString());
    AttributeValue start = new AttributeValue().withS(startTime.withZone(DateTimeZone.UTC).toString());
    AttributeValue end = new AttributeValue().withS(endTime.withZone(DateTimeZone.UTC).toString());
    // The offsetKey should be in UTC
    if (offsetKey != null) {
        start = new AttributeValue().withS(offsetKey);
    }
    Condition dateCondition = new Condition().withComparisonOperator(BETWEEN).withAttributeValueList(start, end);
    DynamoDBQueryExpression<DynamoReportData> query = new DynamoDBQueryExpression<DynamoReportData>().withHashKeyValues(hashKey).withRangeKeyCondition("date", dateCondition).withLimit(pageSizeWithIndicatorRecord);
    QueryResultPage<DynamoReportData> page = mapper.queryPage(DynamoReportData.class, query);
    List<ReportData> list = Lists.newArrayListWithCapacity(pageSizeWithIndicatorRecord);
    for (int i = 0, len = page.getResults().size(); i < len; i++) {
        ReportData oneReport = page.getResults().get(i);
        DateTime dateTime = oneReport.getDateTime();
        if (dateTime != null) {
            oneReport.setDateTime(dateTime.withZone(startTime.getZone()));
        }
        list.add(i, oneReport);
    }
    String nextPageOffsetKey = null;
    if (list.size() == pageSizeWithIndicatorRecord) {
        nextPageOffsetKey = Iterables.getLast(list).getDate();
    }
    int limit = Math.min(list.size(), pageSize);
    return new ForwardCursorPagedResourceList<ReportData>(list.subList(0, limit), nextPageOffsetKey, true).withRequestParam(PAGE_SIZE, pageSize).withRequestParam(OFFSET_KEY, offsetKey).withRequestParam(START_TIME, startTime).withRequestParam(END_TIME, endTime);
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) ForwardCursorPagedResourceList(org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) ReportData(org.sagebionetworks.bridge.models.reports.ReportData) DateTime(org.joda.time.DateTime)

Aggregations

ReportData (org.sagebionetworks.bridge.models.reports.ReportData)53 Test (org.testng.annotations.Test)36 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)14 ReportDataKey (org.sagebionetworks.bridge.models.reports.ReportDataKey)13 Account (org.sagebionetworks.bridge.models.accounts.Account)11 DateRangeResourceList (org.sagebionetworks.bridge.models.DateRangeResourceList)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)8 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)8 HealthDataSubmission (org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission)7 ReportIndex (org.sagebionetworks.bridge.models.reports.ReportIndex)7 PostMapping (org.springframework.web.bind.annotation.PostMapping)7 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)7 SignIn (org.sagebionetworks.bridge.models.accounts.SignIn)6 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)5 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 Condition (com.amazonaws.services.dynamodbv2.model.Condition)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 LocalDate (org.joda.time.LocalDate)3 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)3