use of org.sagebionetworks.bridge.models.assessments.HibernateAssessmentResource in project BridgeServer2 by Sage-Bionetworks.
the class HibernateAssessmentResourceDaoTest method getResource.
@Test
public void getResource() {
AssessmentResourceId id = new AssessmentResourceId(TEST_APP_ID, GUID);
when(mockHelper.getById(HibernateAssessmentResource.class, id)).thenReturn(new HibernateAssessmentResource());
Optional<AssessmentResource> optional = dao.getResource(TEST_APP_ID, GUID);
assertTrue(optional.isPresent());
verify(mockHelper).getById(HibernateAssessmentResource.class, id);
}
use of org.sagebionetworks.bridge.models.assessments.HibernateAssessmentResource in project BridgeServer2 by Sage-Bionetworks.
the class HibernateAssessmentResourceDao method saveResource.
@Override
public AssessmentResource saveResource(String appId, String assessmentId, AssessmentResource resource) {
// If you do not receive back the managed object from the executeWithExceptionHandling() method, and THEN
// convert it to a non-managed object, the version will not be updated. It appears that the update of the
// Java object happens as part of the transaction commit, or something like that.
HibernateAssessmentResource hibernateResource = HibernateAssessmentResource.create(resource, appId, assessmentId);
HibernateAssessmentResource retValue = hibernateHelper.executeWithExceptionHandling(hibernateResource, (session) -> {
session.saveOrUpdate(hibernateResource);
return hibernateResource;
});
return AssessmentResource.create(retValue);
}
use of org.sagebionetworks.bridge.models.assessments.HibernateAssessmentResource in project BridgeServer2 by Sage-Bionetworks.
the class HibernateAssessmentResourceDaoTest method saveResources.
@Test
public void saveResources() {
AssessmentResource ar1 = AssessmentResourceTest.createAssessmentResource();
AssessmentResource ar2 = AssessmentResourceTest.createAssessmentResource();
AssessmentResource ar3 = AssessmentResourceTest.createAssessmentResource();
ar1.setGuid(GUID + "1");
ar2.setGuid(GUID + "2");
ar3.setGuid(GUID + "3");
List<AssessmentResource> resources = ImmutableList.of(ar1, ar2, ar3);
when(mockSession.merge(any())).thenReturn(HibernateAssessmentResource.create(ar1, TEST_APP_ID, ASSESSMENT_ID), HibernateAssessmentResource.create(ar2, TEST_APP_ID, ASSESSMENT_ID), HibernateAssessmentResource.create(ar3, TEST_APP_ID, ASSESSMENT_ID));
dao.saveResources(TEST_APP_ID, ASSESSMENT_ID, resources);
verify(mockSession, times(3)).merge(hibernateResourceCaptor.capture());
List<HibernateAssessmentResource> retValue = hibernateResourceCaptor.getAllValues();
assertEquals(retValue.get(0).getGuid(), GUID + "1");
assertEquals(retValue.get(1).getGuid(), GUID + "2");
assertEquals(retValue.get(2).getGuid(), GUID + "3");
}
use of org.sagebionetworks.bridge.models.assessments.HibernateAssessmentResource in project BridgeServer2 by Sage-Bionetworks.
the class HibernateAssessmentResourceDao method getResource.
@Override
public Optional<AssessmentResource> getResource(String appId, String guid) {
AssessmentResourceId id = new AssessmentResourceId(appId, guid);
HibernateAssessmentResource resource = hibernateHelper.getById(HibernateAssessmentResource.class, id);
return (resource == null) ? Optional.empty() : Optional.of(AssessmentResource.create(resource));
}
Aggregations