Search in sources :

Example 1 with AuditInterceptor

use of org.mifos.framework.components.audit.util.helpers.AuditInterceptor in project head by mifos.

the class GenericDaoHibernate method update.

@Override
public final void update(final Object entity) {
    try {
        Session session = getSession();
        session.update(entity);
        AuditInterceptor interceptor = (AuditInterceptor) StaticHibernateUtil.getInterceptor();
        if (interceptor.isAuditLogRequired()) {
            interceptor.createChangeValueMap(entity);
        }
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : AuditInterceptor(org.mifos.framework.components.audit.util.helpers.AuditInterceptor) MifosRuntimeException(org.mifos.core.MifosRuntimeException) Session(org.hibernate.Session) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with AuditInterceptor

use of org.mifos.framework.components.audit.util.helpers.AuditInterceptor in project head by mifos.

the class LegacyGenericDao method save.

public Object save(final Object object) throws PersistenceException {
    try {
        getSession().saveOrUpdate(object);
        AuditInterceptor interceptor = (AuditInterceptor) StaticHibernateUtil.getInterceptor();
        if (interceptor.isAuditLogRequired()) {
            interceptor.createChangeValueMap(object);
        }
    } catch (HibernateException e) {
        throw new PersistenceException(e);
    }
    return object;
}
Also used : AuditInterceptor(org.mifos.framework.components.audit.util.helpers.AuditInterceptor) HibernateException(org.hibernate.HibernateException) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

Example 3 with AuditInterceptor

use of org.mifos.framework.components.audit.util.helpers.AuditInterceptor in project head by mifos.

the class LoanOfferingBOIntegrationTest method testUpdateLoanOfferingForLogging.

@Test
public void testUpdateLoanOfferingForLogging() throws ProductDefinitionException, FeeException {
    createIntitalObjects();
    Date startDate = offSetCurrentDate(0);
    Date endDate = offSetCurrentDate(2);
    periodicFee = TestObjectFactory.createPeriodicAmountFee("Loan Periodic", FeeCategory.LOAN, "100", RecurrenceType.MONTHLY, (short) 1);
    oneTimeFee = TestObjectFactory.createOneTimeAmountFee("Loan One time", FeeCategory.LOAN, "100", FeePayment.UPFRONT);
    List<FeeBO> fees = new ArrayList<FeeBO>();
    fees.add(periodicFee);
    fees.add(oneTimeFee);
    product = createLoanOfferingBO("Loan Product", "LOAP");
    ((AuditInterceptor) StaticHibernateUtil.getInterceptor()).createInitialValueMap(product);
    product.update((short) 1, "Loan Product", "LOAN", productCategory, prdApplicableMaster, startDate, endDate, "Loan Product updated", PrdStatus.LOAN_ACTIVE, null, interestTypes, (short) 0, 12.0, 2.0, 12.0, false, true, true, null, fees, null, (short) 2, RecurrenceType.MONTHLY, populateLoanPrdActionForm("1", "1", new Double("3000"), new Double("1000"), new Double("1000"), "12", "1", "2"), waiverInterest, null);
    StaticHibernateUtil.flushAndClearSession();
    StaticHibernateUtil.getInterceptor().afterTransactionCompletion(new AuditTransactionForTests());
    product = (LoanOfferingBO) TestObjectFactory.getObject(LoanOfferingBO.class, product.getPrdOfferingId());
    List<AuditLog> auditLogList = TestObjectFactory.getChangeLog(EntityType.LOANPRODUCT, new Integer(product.getPrdOfferingId().toString()));
    Assert.assertEquals(1, auditLogList.size());
    Assert.assertEquals(EntityType.LOANPRODUCT.getValue(), auditLogList.get(0).getEntityType());
    Assert.assertEquals(15, auditLogList.get(0).getAuditLogRecords().size());
    for (AuditLogRecord auditLogRecord : auditLogList.get(0).getAuditLogRecords()) {
        if (auditLogRecord.getFieldName().equalsIgnoreCase("Min Loan Amount")) {
            Assert.assertEquals("300.0", auditLogRecord.getOldValue());
            Assert.assertEquals("1000.0", auditLogRecord.getNewValue());
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Description")) {
            Assert.assertEquals("-", auditLogRecord.getOldValue());
            Assert.assertEquals("Loan Product updated", auditLogRecord.getNewValue());
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Applicable For")) {
            Assert.assertEquals("Groups", auditLogRecord.getOldValue());
            Assert.assertEquals("Clients", auditLogRecord.getNewValue());
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Frequency Of Installments")) {
            Assert.assertEquals("Week(s)", auditLogRecord.getOldValue());
            Assert.assertEquals("Month(s)", auditLogRecord.getNewValue());
        }
    }
}
Also used : AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) AuditInterceptor(org.mifos.framework.components.audit.util.helpers.AuditInterceptor) ArrayList(java.util.ArrayList) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) AuditTransactionForTests(org.mifos.framework.hibernate.helper.AuditTransactionForTests) Date(java.sql.Date) AuditLog(org.mifos.framework.components.audit.business.AuditLog) Test(org.junit.Test)

Example 4 with AuditInterceptor

use of org.mifos.framework.components.audit.util.helpers.AuditInterceptor in project head by mifos.

the class LegacyGenericDao method createOrUpdate.

/**
     * @deprecated - move away from using this as starts transaction but doesn't not commit..
     */
@Deprecated
public Object createOrUpdate(final Object object) throws PersistenceException {
    try {
        StaticHibernateUtil.startTransaction();
        getSession().saveOrUpdate(object);
        AuditInterceptor interceptor = (AuditInterceptor) StaticHibernateUtil.getInterceptor();
        if (interceptor.isAuditLogRequired()) {
            interceptor.createChangeValueMap(object);
        }
    } catch (HibernateException e) {
        throw new PersistenceException(e);
    }
    return object;
}
Also used : AuditInterceptor(org.mifos.framework.components.audit.util.helpers.AuditInterceptor) HibernateException(org.hibernate.HibernateException) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

Example 5 with AuditInterceptor

use of org.mifos.framework.components.audit.util.helpers.AuditInterceptor in project head by mifos.

the class GenericDaoHibernate method createOrUpdate.

@Override
public final void createOrUpdate(final Object entity) {
    try {
        Session session = getSession();
        session.saveOrUpdate(entity);
        AuditInterceptor interceptor = (AuditInterceptor) StaticHibernateUtil.getInterceptor();
        if (interceptor.isAuditLogRequired()) {
            interceptor.createChangeValueMap(entity);
        }
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : AuditInterceptor(org.mifos.framework.components.audit.util.helpers.AuditInterceptor) MifosRuntimeException(org.mifos.core.MifosRuntimeException) Session(org.hibernate.Session) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

AuditInterceptor (org.mifos.framework.components.audit.util.helpers.AuditInterceptor)8 Test (org.junit.Test)4 AuditLog (org.mifos.framework.components.audit.business.AuditLog)4 AuditLogRecord (org.mifos.framework.components.audit.business.AuditLogRecord)4 AuditTransactionForTests (org.mifos.framework.hibernate.helper.AuditTransactionForTests)4 Date (java.sql.Date)3 ArrayList (java.util.ArrayList)2 HibernateException (org.hibernate.HibernateException)2 Session (org.hibernate.Session)2 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)2 FeeBO (org.mifos.accounts.fees.business.FeeBO)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 PersistenceException (org.mifos.framework.exceptions.PersistenceException)2 Date (java.util.Date)1 LoanBO (org.mifos.accounts.loan.business.LoanBO)1 MeetingBO (org.mifos.application.meeting.business.MeetingBO)1 Money (org.mifos.framework.util.helpers.Money)1