Search in sources :

Example 11 with AuditLog

use of org.mifos.framework.components.audit.business.AuditLog in project head by mifos.

the class AuditLogServiceImpl method addAuditLogRegistry.

@Override
public void addAuditLogRegistry(QuestionGroupDetail questionGroupDetail, QuestionGroupDetail oldQuestionGroupDetail, int creatorId, int entityId, String source, String event) {
    PersonnelBusinessService pbs = new PersonnelBusinessService();
    String modifierName;
    if (oldQuestionGroupDetail != null && event.toLowerCase().equals(CREATE)) {
        String questionGroupName;
        String sectionName;
        String fieldName;
        String fieldValue;
        try {
            modifierName = pbs.getPersonnel((short) creatorId).getDisplayName();
        } catch (ServiceException e) {
            modifierName = "";
        }
        questionGroupName = questionGroupDetail.getTitle();
        AuditLog auditLog = new AuditLog(entityId, EntityType.getEntityValue(source.toUpperCase()), modifierName, new DateTimeService().getCurrentJavaSqlDate(), (short) creatorId);
        Set<AuditLogRecord> auditLogRecords = new HashSet<AuditLogRecord>();
        for (int sectionPosition = 0; sectionPosition < questionGroupDetail.getSectionDetails().size(); sectionPosition++) {
            SectionDetail sectionDetail = questionGroupDetail.getSectionDetails().get(sectionPosition);
            sectionName = sectionDetail.getName();
            for (int questionPosition = 0; questionPosition < sectionDetail.getQuestions().size(); questionPosition++) {
                SectionQuestionDetail sectionQuestionDetail = sectionDetail.getQuestions().get(questionPosition);
                fieldName = sectionQuestionDetail.getText();
                fieldValue = sectionQuestionDetail.getAnswer();
                String oldFieldValue = null;
                for (SectionDetail oldSectionDetail : oldQuestionGroupDetail.getSectionDetails()) {
                    if (oldSectionDetail.getName().equals(sectionName)) {
                        for (SectionQuestionDetail oldSectionQuestionDetail : oldSectionDetail.getQuestions()) {
                            if (oldSectionQuestionDetail.getText().equals(fieldName)) {
                                oldFieldValue = oldSectionQuestionDetail.getAnswer();
                                break;
                            }
                        }
                        break;
                    }
                }
                if (!fieldValue.equals("")) {
                    if (oldFieldValue != null && !oldFieldValue.equals("")) {
                        if (!oldFieldValue.equals(fieldValue)) {
                            auditLogRecords.add(new AuditLogRecord(trimField(questionGroupName + "/" + sectionName + "/" + fieldName, 100), trimField(oldFieldValue, 200), trimField(fieldValue, 200), auditLog));
                        }
                    } else {
                        auditLogRecords.add(new AuditLogRecord(trimField(questionGroupName + "/" + sectionName + "/" + fieldName, 100), "-", trimField(fieldValue, 200), auditLog));
                    }
                }
            }
        }
        if (!auditLogRecords.isEmpty()) {
            auditLog.addAuditLogRecords(auditLogRecords);
            legacyAuditDao.save(auditLog);
        }
    }
}
Also used : AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) PersonnelBusinessService(org.mifos.customers.personnel.business.service.PersonnelBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) DateTimeService(org.mifos.framework.util.DateTimeService) AuditLog(org.mifos.framework.components.audit.business.AuditLog) HashSet(java.util.HashSet)

Example 12 with AuditLog

use of org.mifos.framework.components.audit.business.AuditLog in project head by mifos.

the class AuditBusinessServiceIntegrationTest method testGetAuditLogRecordsPasswordChange.

@Test
public void testGetAuditLogRecordsPasswordChange() throws Exception {
    AuditLog auditLog = new AuditLog(1, (short) 2, "Mifos", new Date(System.currentTimeMillis()), (short) 3);
    Set<AuditLogRecord> auditLogRecords = new HashSet<AuditLogRecord>();
    AuditLogRecord auditLogRecord = new AuditLogRecord("Password", "test_1", "new_test_1", auditLog);
    auditLogRecords.add(auditLogRecord);
    auditLog.addAuditLogRecords(auditLogRecords);
    legacyAuditDao.save(auditLog);
    AuditBusinessService auditBusinessService = new AuditBusinessService();
    List<AuditLogView> auditLogViewList = auditBusinessService.getAuditLogRecords((short) 2, 1);
    Assert.assertEquals(1, auditLogViewList.size());
    AuditLogView auditLogView = auditLogViewList.get(0);
    Assert.assertEquals(AuditConstants.HIDDEN_PASSWORD, auditLogView.getOldValue());
    Assert.assertEquals(AuditConstants.HIDDEN_PASSWORD, auditLogView.getNewValue());
    auditLog = getAuditLog(1, (short) 2);
}
Also used : AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) AuditLogView(org.mifos.framework.components.audit.util.helpers.AuditLogView) AuditLog(org.mifos.framework.components.audit.business.AuditLog) Date(java.sql.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with AuditLog

use of org.mifos.framework.components.audit.business.AuditLog in project head by mifos.

the class AuditPersistenceIntegrationTest method testSave.

@Test
public void testSave() {
    AuditLog auditLog = new AuditLog(Integer.valueOf("1"), Short.valueOf("2"), "Mifos", new Date(System.currentTimeMillis()), Short.valueOf("3"));
    Set<AuditLogRecord> auditLogRecords = new HashSet<AuditLogRecord>();
    AuditLogRecord auditLogRecord = new AuditLogRecord("ColumnName_1", "test_1", "new_test_1", auditLog);
    auditLogRecords.add(auditLogRecord);
    auditLog.addAuditLogRecords(auditLogRecords);
    legacyAuditDao.save(auditLog);
    auditLog = getAuditLog(Integer.valueOf("1"), Short.valueOf("2"));
    Assert.assertEquals(Integer.valueOf("1"), auditLog.getEntityId());
    Assert.assertEquals(Short.valueOf("2"), auditLog.getEntityType());
    Assert.assertEquals("Mifos", auditLog.getModifierName());
    Assert.assertEquals("Mifos", auditLog.getModifierName());
    Assert.assertEquals(1, auditLog.getAuditLogRecords().size());
    for (AuditLogRecord logRecord : auditLog.getAuditLogRecords()) {
        Assert.assertEquals("ColumnName_1", logRecord.getFieldName());
        Assert.assertEquals("test_1", logRecord.getOldValue());
        Assert.assertEquals("new_test_1", logRecord.getNewValue());
    }
}
Also used : AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) AuditLog(org.mifos.framework.components.audit.business.AuditLog) Date(java.sql.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with AuditLog

use of org.mifos.framework.components.audit.business.AuditLog in project head by mifos.

the class AuditPersistenceIntegrationTest method testGetAuditLogRecords.

@Test
public void testGetAuditLogRecords() throws Exception {
    AuditLog auditLog = new AuditLog(Integer.valueOf("1"), Short.valueOf("2"), "Mifos", new Date(System.currentTimeMillis()), Short.valueOf("3"));
    Set<AuditLogRecord> auditLogRecords = new HashSet<AuditLogRecord>();
    AuditLogRecord auditLogRecord = new AuditLogRecord("ColumnName_1", "test_1", "new_test_1", auditLog);
    auditLogRecords.add(auditLogRecord);
    auditLog.addAuditLogRecords(auditLogRecords);
    legacyAuditDao.save(auditLog);
    auditLog = getAuditLog(Integer.valueOf("1"), Short.valueOf("2"));
    List<AuditLog> auditLogList = legacyAuditDao.getAuditLogRecords(Short.valueOf("2"), Integer.valueOf("1"));
    Assert.assertEquals(1, auditLogList.size());
}
Also used : AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) AuditLog(org.mifos.framework.components.audit.business.AuditLog) Date(java.sql.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with AuditLog

use of org.mifos.framework.components.audit.business.AuditLog in project head by mifos.

the class AuditInterceptorIntegrationTest method testUpdateLoanForLogging.

/*
     * Note: since this loan is active the disbursement date will not be updated
     */
@Test
public void testUpdateLoanForLogging() throws Exception {
    Date newDate = incrementCurrentDate(14);
    accountBO = getLoanAccount();
    accountBO.setUserContext(TestUtils.makeUser());
    ((AuditInterceptor) StaticHibernateUtil.getInterceptor()).createInitialValueMap(accountBO);
    LoanBO loanBO = ((LoanBO) accountBO);
    ((LoanBO) accountBO).updateLoan(true, loanBO.getLoanAmount(), loanBO.getInterestRate(), loanBO.getNoOfInstallments(), newDate, (short) 2, TestObjectFactory.SAMPLE_BUSINESS_ACTIVITY_2, "Added note", null, null, false, null, null);
    StaticHibernateUtil.flushSession();
    group = TestObjectFactory.getCustomer(group.getCustomerId());
    accountBO = (AccountBO) StaticHibernateUtil.getSessionTL().get(AccountBO.class, accountBO.getAccountId());
    StaticHibernateUtil.getInterceptor().afterTransactionCompletion(new AuditTransactionForTests());
    List<AuditLog> auditLogList = TestObjectFactory.getChangeLog(EntityType.LOAN, accountBO.getAccountId());
    Assert.assertEquals(1, auditLogList.size());
    Assert.assertEquals(EntityType.LOAN.getValue(), auditLogList.get(0).getEntityType());
    Assert.assertEquals(3, auditLogList.get(0).getAuditLogRecords().size());
    for (AuditLogRecord auditLogRecord : auditLogList.get(0).getAuditLogRecords()) {
        if (auditLogRecord.getFieldName().equalsIgnoreCase("Collateral Notes")) {
            Assert.assertEquals("-", auditLogRecord.getOldValue());
            Assert.assertEquals("Added note", auditLogRecord.getNewValue());
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Service Charge deducted At Disbursement")) {
            Assert.assertEquals("1", auditLogRecord.getOldValue());
            Assert.assertEquals("0", auditLogRecord.getNewValue());
        }
    }
    accountBO = null;
    group = null;
    center = null;
}
Also used : AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) AuditInterceptor(org.mifos.framework.components.audit.util.helpers.AuditInterceptor) LoanBO(org.mifos.accounts.loan.business.LoanBO) AuditTransactionForTests(org.mifos.framework.hibernate.helper.AuditTransactionForTests) Date(java.util.Date) AuditLog(org.mifos.framework.components.audit.business.AuditLog) Test(org.junit.Test)

Aggregations

AuditLog (org.mifos.framework.components.audit.business.AuditLog)19 AuditLogRecord (org.mifos.framework.components.audit.business.AuditLogRecord)17 Test (org.junit.Test)15 AuditTransactionForTests (org.mifos.framework.hibernate.helper.AuditTransactionForTests)9 Date (java.sql.Date)7 HashSet (java.util.HashSet)7 ArrayList (java.util.ArrayList)4 AuditInterceptor (org.mifos.framework.components.audit.util.helpers.AuditInterceptor)4 AuditLogView (org.mifos.framework.components.audit.util.helpers.AuditLogView)3 Date (java.util.Date)2 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)2 FeeBO (org.mifos.accounts.fees.business.FeeBO)2 CustomerNoteEntity (org.mifos.customers.business.CustomerNoteEntity)2 CenterBO (org.mifos.customers.center.business.CenterBO)2 ClientBO (org.mifos.customers.client.business.ClientBO)2 GroupBO (org.mifos.customers.group.business.GroupBO)2 PersonnelBusinessService (org.mifos.customers.personnel.business.service.PersonnelBusinessService)2 CustomerStatusFlag (org.mifos.customers.util.helpers.CustomerStatusFlag)2 CenterBuilder (org.mifos.domain.builders.CenterBuilder)2 ClientBuilder (org.mifos.domain.builders.ClientBuilder)2