use of org.sagebionetworks.bridge.models.appconfig.AppConfigElement in project BridgeServer2 by Sage-Bionetworks.
the class DynamoAppConfigElementDao method getMostRecentElements.
@Override
public List<AppConfigElement> getMostRecentElements(String appId, boolean includeDeleted) {
DynamoAppConfigElement key = new DynamoAppConfigElement();
key.setAppId(appId);
DynamoDBQueryExpression<DynamoAppConfigElement> query = new DynamoDBQueryExpression<DynamoAppConfigElement>().withIndexName(STUDY_ID_INDEX_NAME).withHashKeyValues(key).withConsistentRead(false).withScanIndexForward(false);
List<DynamoAppConfigElement> elementIndices = mapper.query(DynamoAppConfigElement.class, query);
Map<String, AppConfigElement> versionMap = Maps.newHashMap();
Map<String, List<Object>> resultMap = mapper.batchLoad(elementIndices);
for (List<Object> resultList : resultMap.values()) {
for (Object oneResult : resultList) {
if (!(oneResult instanceof DynamoAppConfigElement)) {
// This should never happen, but just in case.
throw new BridgeServiceException("DynamoDB returned objects of type " + oneResult.getClass().getName() + " instead of DynamoAppConfigElement");
}
DynamoAppConfigElement oneElement = (DynamoAppConfigElement) oneResult;
if (!includeDeleted && oneElement.isDeleted()) {
continue;
}
AppConfigElement existingElement = versionMap.get(oneElement.getId());
Long existingRevision = (existingElement == null) ? null : existingElement.getRevision();
if (existingRevision == null || oneElement.getRevision() > existingRevision) {
versionMap.put(oneElement.getId(), oneElement);
}
}
}
List<AppConfigElement> elements = Lists.newArrayList(versionMap.values());
Collections.sort(elements, Comparator.comparing(AppConfigElement::getId));
return elements;
}
use of org.sagebionetworks.bridge.models.appconfig.AppConfigElement in project BridgeServer2 by Sage-Bionetworks.
the class DynamoAppConfigElementDaoTest method getMostRecentElement.
@Test
public void getMostRecentElement() {
DynamoAppConfigElement element = new DynamoAppConfigElement();
when(mockMapper.query(eq(DynamoAppConfigElement.class), any())).thenReturn(mockResults);
when(mockResults.get(0)).thenReturn(element);
AppConfigElement returned = dao.getMostRecentElement(TEST_APP_ID, "id");
assertEquals(returned, element);
verify(mockMapper).query(eq(DynamoAppConfigElement.class), queryCaptor.capture());
DynamoDBQueryExpression<DynamoAppConfigElement> query = queryCaptor.getValue();
assertEquals(query.getHashKeyValues().getKey(), TEST_APP_ID + ":id");
assertFalse(query.isScanIndexForward());
assertEquals(query.getLimit(), new Integer(1));
Condition deleteCondition = query.getQueryFilter().get("deleted");
assertEquals(deleteCondition.getComparisonOperator(), "EQ");
assertFalse(deleteCondition.getAttributeValueList().get(0).getBOOL());
}
use of org.sagebionetworks.bridge.models.appconfig.AppConfigElement in project BridgeServer2 by Sage-Bionetworks.
the class DynamoAppConfigElementDaoTest method saveElementRevisionThrowsConditionalCheckFailedException.
// As will happen if version attribute isn't returned or is wrong
@Test(expectedExceptions = ConcurrentModificationException.class)
public void saveElementRevisionThrowsConditionalCheckFailedException() {
doThrow(new ConditionalCheckFailedException("")).when(mockMapper).save(any());
AppConfigElement element = TestUtils.getAppConfigElement();
dao.saveElementRevision(element);
}
use of org.sagebionetworks.bridge.models.appconfig.AppConfigElement in project BridgeServer2 by Sage-Bionetworks.
the class DynamoAppConfigElementDaoTest method getElementRevisionsExcludesDeleted.
@Test
public void getElementRevisionsExcludesDeleted() {
when(mockMapper.query(eq(DynamoAppConfigElement.class), any())).thenReturn(mockResults);
when(mockResults.stream()).thenReturn(appConfigElementListId1().stream());
List<AppConfigElement> returned = dao.getElementRevisions(TEST_APP_ID, ID_1, false);
assertEquals(returned, appConfigElementListId1());
verify(mockMapper).query(eq(DynamoAppConfigElement.class), queryCaptor.capture());
DynamoDBQueryExpression<DynamoAppConfigElement> query = queryCaptor.getValue();
assertEquals(query.getHashKeyValues().getKey(), TEST_APP_ID + ":id1");
assertFalse(query.isScanIndexForward());
Condition deleteCondition = query.getQueryFilter().get("deleted");
assertEquals(deleteCondition.getComparisonOperator(), "EQ");
assertFalse(deleteCondition.getAttributeValueList().get(0).getBOOL());
}
use of org.sagebionetworks.bridge.models.appconfig.AppConfigElement in project BridgeServer2 by Sage-Bionetworks.
the class DynamoAppConfigElementDaoTest method saveElementRevision.
@Test
public void saveElementRevision() {
AppConfigElement element = AppConfigElement.create();
element.setVersion(1L);
VersionHolder returned = dao.saveElementRevision(element);
assertEquals(returned.getVersion(), new Long(1));
verify(mockMapper).save(element);
}
Aggregations