use of org.sagebionetworks.bridge.exceptions.BridgeServiceException in project BridgeServer2 by Sage-Bionetworks.
the class DynamoSurveyDao method saveSurvey.
private Survey saveSurvey(Survey survey) {
deleteAllElements(survey.getGuid(), survey.getCreatedOn());
List<DynamoSurveyElement> dynamoElements = Lists.newArrayList();
for (int i = 0; i < survey.getElements().size(); i++) {
SurveyElement element = survey.getElements().get(i);
element.setSurveyKeyComponents(survey.getGuid(), survey.getCreatedOn());
element.setOrder(i);
if (element.getGuid() == null) {
element.setGuid(generateGuid());
}
reconcileRules(element);
dynamoElements.add((DynamoSurveyElement) element);
}
List<FailedBatch> failures = surveyElementMapper.batchSave(dynamoElements);
BridgeUtils.ifFailuresThrowException(failures);
try {
surveyMapper.save(survey);
} catch (ConditionalCheckFailedException throwable) {
// At this point, delete the elements you just created... compensating transaction
deleteAllElements(survey.getGuid(), survey.getCreatedOn());
throw new ConcurrentModificationException(survey);
} catch (Throwable t) {
throw new BridgeServiceException(t);
}
return survey;
}
use of org.sagebionetworks.bridge.exceptions.BridgeServiceException in project BridgeServer2 by Sage-Bionetworks.
the class HibernateTemplateRevisionDao method getTemplateRevision.
@Override
public Optional<TemplateRevision> getTemplateRevision(String templateGuid, DateTime createdOn) {
checkNotNull(templateGuid);
checkNotNull(createdOn);
TemplateRevisionId revisionId = new TemplateRevisionId(templateGuid, createdOn);
HibernateTemplateRevision revision = hibernateHelper.getById(HibernateTemplateRevision.class, revisionId);
if (revision == null) {
return Optional.empty();
}
// Load document content
try {
String storagePath = getStoragePath(templateGuid, createdOn);
String documentContent = s3Helper.readS3FileAsString(publicationsBucket, storagePath);
revision.setDocumentContent(documentContent);
} catch (IOException ioe) {
throw new BridgeServiceException("Error loading template revision document", ioe);
}
return Optional.of(revision);
}
use of org.sagebionetworks.bridge.exceptions.BridgeServiceException in project BridgeServer2 by Sage-Bionetworks.
the class ViewCacheTest method nothingWasCachedAndThereIsAnException.
@Test
public void nothingWasCachedAndThereIsAnException() {
ViewCache cache = new ViewCache();
cache.setObjectMapper(BridgeObjectMapper.get());
cache.setCachePeriod(BridgeConstants.BRIDGE_VIEW_EXPIRE_IN_SECONDS);
CacheKey cacheKey = cache.getCacheKey(App.class, app.getIdentifier());
CacheProvider provider = mock(CacheProvider.class);
when(provider.getObject(cacheKey, String.class)).thenReturn(null);
cache.setCacheProvider(provider);
// It doesn't get wrapped or transformed or anything
try {
cache.getView(cacheKey, new Supplier<App>() {
@Override
public App get() {
throw new BridgeServiceException("There has been a problem retrieving the app");
}
});
fail("This should have thrown an exception");
} catch (BridgeServiceException e) {
assertEquals(e.getMessage(), "There has been a problem retrieving the app");
}
}
Aggregations