use of org.sagebionetworks.bridge.exceptions.BridgeServiceException in project BridgeServer2 by Sage-Bionetworks.
the class BridgeUtils method ifFailuresThrowException.
/**
* All batch methods in Dynamo return a list of failures rather than
* throwing an exception. We should have an exception specifically for
* these so the caller gets a list of items back, but for now, convert
* to a generic exception;
* @param failures
*/
public static void ifFailuresThrowException(List<FailedBatch> failures) {
if (!failures.isEmpty()) {
List<String> messages = Lists.newArrayList();
for (FailedBatch failure : failures) {
String message = failure.getException().getMessage();
messages.add(message);
String ids = Joiner.on("; ").join(failure.getUnprocessedItems().keySet());
messages.add(ids);
}
throw new BridgeServiceException(Joiner.on(", ").join(messages));
}
}
use of org.sagebionetworks.bridge.exceptions.BridgeServiceException 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.exceptions.BridgeServiceException in project BridgeServer2 by Sage-Bionetworks.
the class CacheProvider method removeSetOfCacheKeys.
public void removeSetOfCacheKeys(CacheKey cacheKeyOfSet) {
checkNotNull(cacheKeyOfSet);
try {
Set<String> members = jedisOps.smembers(cacheKeyOfSet.toString());
if (members != null && !members.isEmpty()) {
try (JedisTransaction transaction = jedisOps.getTransaction()) {
for (String oneMember : members) {
transaction.del(oneMember);
}
transaction.del(cacheKeyOfSet.toString());
transaction.exec();
}
}
} catch (Throwable e) {
promptToStartRedisIfLocal(e);
throw new BridgeServiceException(e);
}
}
use of org.sagebionetworks.bridge.exceptions.BridgeServiceException in project BridgeServer2 by Sage-Bionetworks.
the class CacheProvider method getObject.
public <T> T getObject(CacheKey cacheKey, TypeReference<T> typeRef) {
checkNotNull(cacheKey);
checkNotNull(typeRef);
try {
String ser = jedisOps.get(cacheKey.toString());
if (ser != null) {
JsonNode node = adjustJsonWithStudyIdentifier(ser);
return BridgeObjectMapper.get().readValue(node.toString(), typeRef);
}
} catch (Throwable e) {
promptToStartRedisIfLocal(e);
throw new BridgeServiceException(e);
}
return null;
}
use of org.sagebionetworks.bridge.exceptions.BridgeServiceException in project BridgeServer2 by Sage-Bionetworks.
the class CacheProvider method getObject.
/**
* Get the object, resetting its expiration period.
*/
public <T> T getObject(CacheKey cacheKey, Class<T> clazz, int expireInSeconds) {
checkNotNull(cacheKey);
checkNotNull(clazz);
try {
String ser = jedisOps.get(cacheKey.toString());
if (ser != null) {
jedisOps.expire(cacheKey.toString(), expireInSeconds);
return BridgeObjectMapper.get().readValue(ser, clazz);
}
} catch (Throwable e) {
promptToStartRedisIfLocal(e);
throw new BridgeServiceException(e);
}
return null;
}
Aggregations