Search in sources :

Example 1 with HibernateAssessment

use of org.sagebionetworks.bridge.models.assessments.HibernateAssessment in project BridgeServer2 by Sage-Bionetworks.

the class HibernateAssessmentConfigDao method updateAssessmentConfig.

@Override
public AssessmentConfig updateAssessmentConfig(String appId, Assessment assessment, String guid, AssessmentConfig config) {
    HibernateAssessment hibAssessment = HibernateAssessment.create(appId, assessment);
    HibernateAssessmentConfig hibConfig = HibernateAssessmentConfig.create(guid, config);
    HibernateAssessmentConfig retValue = hibernateHelper.executeWithExceptionHandling(hibConfig, (session) -> {
        session.merge(hibAssessment);
        session.merge(hibConfig);
        // the merge method does not do this like the save method.
        return session.get(HibernateAssessmentConfig.class, hibConfig.getGuid());
    });
    return AssessmentConfig.create(retValue);
}
Also used : HibernateAssessmentConfig(org.sagebionetworks.bridge.models.assessments.config.HibernateAssessmentConfig) HibernateAssessment(org.sagebionetworks.bridge.models.assessments.HibernateAssessment)

Example 2 with HibernateAssessment

use of org.sagebionetworks.bridge.models.assessments.HibernateAssessment in project BridgeServer2 by Sage-Bionetworks.

the class HibernateAssessmentDaoTest method publishAssessment.

@Test
public void publishAssessment() throws Exception {
    Assessment original = new Assessment();
    Assessment assessmentToPublish = AssessmentTest.createAssessment();
    AssessmentConfig originConfig = new AssessmentConfig();
    when(mockSession.merge(any())).thenReturn(new HibernateAssessment());
    Assessment retValue = dao.publishAssessment(TEST_APP_ID, original, assessmentToPublish, originConfig);
    assertNotNull(retValue);
    verify(mockHelper).executeWithExceptionHandling(any(HibernateAssessment.class), any());
    verify(mockSession).saveOrUpdate(any(HibernateAssessmentConfig.class));
    verify(mockSession).saveOrUpdate(any(HibernateAssessment.class));
}
Also used : AssessmentConfig(org.sagebionetworks.bridge.models.assessments.config.AssessmentConfig) HibernateAssessmentConfig(org.sagebionetworks.bridge.models.assessments.config.HibernateAssessmentConfig) HibernateAssessmentConfig(org.sagebionetworks.bridge.models.assessments.config.HibernateAssessmentConfig) HibernateAssessment(org.sagebionetworks.bridge.models.assessments.HibernateAssessment) Assessment(org.sagebionetworks.bridge.models.assessments.Assessment) HibernateAssessment(org.sagebionetworks.bridge.models.assessments.HibernateAssessment) Test(org.testng.annotations.Test) AssessmentTest(org.sagebionetworks.bridge.models.assessments.AssessmentTest)

Example 3 with HibernateAssessment

use of org.sagebionetworks.bridge.models.assessments.HibernateAssessment in project BridgeServer2 by Sage-Bionetworks.

the class TagEventListenerTest method onSaveOrUpdateNotTag.

@Test
public void onSaveOrUpdateNotTag() throws HibernateException {
    SaveOrUpdateEvent event = new SaveOrUpdateEvent(new HibernateAssessment(), null);
    listener.onSaveOrUpdate(event);
    verify(cacheProvider, never()).removeObject(CacheKey.tagList());
}
Also used : SaveOrUpdateEvent(org.hibernate.event.spi.SaveOrUpdateEvent) HibernateAssessment(org.sagebionetworks.bridge.models.assessments.HibernateAssessment) Test(org.testng.annotations.Test)

Example 4 with HibernateAssessment

use of org.sagebionetworks.bridge.models.assessments.HibernateAssessment in project BridgeServer2 by Sage-Bionetworks.

the class TagEventListenerTest method onPersistNotTag.

@Test
public void onPersistNotTag() throws HibernateException {
    PersistEvent event = new PersistEvent(new HibernateAssessment(), null);
    listener.onPersist(event);
    verify(cacheProvider, never()).removeObject(CacheKey.tagList());
}
Also used : PersistEvent(org.hibernate.event.spi.PersistEvent) HibernateAssessment(org.sagebionetworks.bridge.models.assessments.HibernateAssessment) Test(org.testng.annotations.Test)

Example 5 with HibernateAssessment

use of org.sagebionetworks.bridge.models.assessments.HibernateAssessment in project BridgeServer2 by Sage-Bionetworks.

the class MySQLHibernatePersistenceExceptionConverterTest method sqlIntegrityConstraintViolation_AssessmentRefAssessmentConstraint.

@Test
public void sqlIntegrityConstraintViolation_AssessmentRefAssessmentConstraint() {
    PersistenceException pe = buildIntegrityConstraintViolation("AssessmentRef-Assessment-Cosntraint", "a foreign key constraint fails ... AssessmentRef-Assessment-Constraint`");
    HibernateAssessment assessment = new HibernateAssessment();
    BridgeServiceException converted = (BridgeServiceException) converter.convert(pe, assessment);
    assertEquals(converted.getMessage(), "This assessment cannot be deleted or updated because it is referenced by a scheduling session.");
    assertEquals(converted.getStatusCode(), HttpStatus.SC_CONFLICT);
    assertEquals(converted.getClass().getSimpleName(), "ConstraintViolationException");
}
Also used : PersistenceException(javax.persistence.PersistenceException) BridgeServiceException(org.sagebionetworks.bridge.exceptions.BridgeServiceException) HibernateAssessment(org.sagebionetworks.bridge.models.assessments.HibernateAssessment) Test(org.testng.annotations.Test)

Aggregations

HibernateAssessment (org.sagebionetworks.bridge.models.assessments.HibernateAssessment)16 Test (org.testng.annotations.Test)10 HibernateAssessmentConfig (org.sagebionetworks.bridge.models.assessments.config.HibernateAssessmentConfig)6 DeleteEvent (org.hibernate.event.spi.DeleteEvent)2 MergeEvent (org.hibernate.event.spi.MergeEvent)2 PersistEvent (org.hibernate.event.spi.PersistEvent)2 Assessment (org.sagebionetworks.bridge.models.assessments.Assessment)2 AssessmentConfig (org.sagebionetworks.bridge.models.assessments.config.AssessmentConfig)2 PersistenceException (javax.persistence.PersistenceException)1 SaveOrUpdateEvent (org.hibernate.event.spi.SaveOrUpdateEvent)1 BridgeServiceException (org.sagebionetworks.bridge.exceptions.BridgeServiceException)1 AssessmentTest (org.sagebionetworks.bridge.models.assessments.AssessmentTest)1