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