Search in sources :

Example 6 with AuditLogRecord

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

the class ClientTransferActionStrutsTest method testSuccessful_transferToBranch_AuditLog.

@Test
public void testSuccessful_transferToBranch_AuditLog() throws Exception {
    createObjectsForClientTransfer();
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, client, request);
    setRequestPathInfo("/clientTransferAction.do");
    addRequestParameter("method", "transferToBranch");
    addRequestParameter("officeId", office.getOfficeId().toString());
    addRequestParameter("officeName", office.getOfficeName());
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyForward(ActionForwards.update_success.toString());
    verifyNoActionErrors();
    verifyNoActionMessages();
    client = TestObjectFactory.getClient(client.getCustomerId());
    Assert.assertEquals(client.getOffice().getOfficeId(), office.getOfficeId());
    Assert.assertEquals(CustomerStatus.CLIENT_HOLD, client.getStatus());
    office = client.getOffice();
    StaticHibernateUtil.commitTransaction();
    StaticHibernateUtil.getInterceptor().afterTransactionCompletion(new AuditTransactionForTests());
    List<AuditLog> auditLogList = TestObjectFactory.getChangeLog(EntityType.CLIENT, client.getCustomerId());
    Assert.assertEquals(1, auditLogList.size());
    Assert.assertEquals(EntityType.CLIENT.getValue(), auditLogList.get(0).getEntityType());
    Assert.assertEquals(client.getCustomerId(), auditLogList.get(0).getEntityId());
    Assert.assertEquals(3, auditLogList.get(0).getAuditLogRecords().size());
    for (AuditLogRecord auditLogRecord : auditLogList.get(0).getAuditLogRecords()) {
        if (auditLogRecord.getFieldName().equalsIgnoreCase("Loan Officer Assigned")) {
            matchValues(auditLogRecord, "mifos", "-");
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Status")) {
            matchValues(auditLogRecord, "Active", "On Hold");
        } else if (auditLogRecord.getFieldName().equalsIgnoreCase("Branch Office Name")) {
            matchValues(auditLogRecord, "TestBranchOffice", "customer_office");
        }
    }
}
Also used : AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) AuditTransactionForTests(org.mifos.framework.hibernate.helper.AuditTransactionForTests) AuditLog(org.mifos.framework.components.audit.business.AuditLog) Test(org.junit.Test)

Example 7 with AuditLogRecord

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

the class AuditBusinessServiceIntegrationTest method testGetAuditLogRecords.

@Test
public void testGetAuditLogRecords() 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("ColumnName_1", "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());
    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 8 with AuditLogRecord

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

the class PersonActionStrutsTest method testLoadChangeLog.

@SuppressWarnings("unchecked")
@Test
public void testLoadChangeLog() throws Exception {
    addActionAndMethod(Methods.get.toString());
    addRequestParameter("globalPersonnelNum", "1");
    actionPerform();
    flowKey = request.getAttribute(Constants.CURRENTFLOWKEY).toString();
    // personnel = (PersonnelBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    // Changed the PersonnelBO to PersonnelInformationDto as the former is no longer stored in session using
    // business key
    PersonnelInformationDto personnel = (PersonnelInformationDto) SessionUtils.getAttribute("personnelInformationDto", request);
    AuditLog auditLog = new AuditLog(personnel.getPersonnelId().intValue(), EntityType.PERSONNEL.getValue(), "Mifos", new java.sql.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);
    setRequestPathInfo("/PersonAction.do");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    addRequestParameter("method", "loadChangeLog");
    addRequestParameter("entityType", "Personnel");
    addRequestParameter("entityId", personnel.getPersonnelId().toString());
    actionPerform();
    Assert.assertEquals(1, ((List) request.getSession().getAttribute(AuditConstants.AUDITLOGRECORDS)).size());
    verifyForward("viewPersonnelChangeLog");
    personnel = null;
}
Also used : PersonnelInformationDto(org.mifos.dto.screen.PersonnelInformationDto) AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) AuditLog(org.mifos.framework.components.audit.business.AuditLog) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with AuditLogRecord

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

the class AuditBusinessService method getAuditLogRecords.

public List<AuditLogView> getAuditLogRecords(Short entityType, Integer entityId) throws ServiceException {
    try {
        LegacyAuditDao auditPersistence = ApplicationContextProvider.getBean(LegacyAuditDao.class);
        PersonnelBusinessService personnelService = new PersonnelBusinessService();
        List<AuditLog> auditLogRecords = auditPersistence.getAuditLogRecords(entityType, entityId);
        List<AuditLogView> auditLogViewList = new ArrayList<AuditLogView>();
        for (AuditLog auditLog : auditLogRecords) {
            for (AuditLogRecord auditLogRecord : auditLog.getAuditLogRecords()) {
                AuditLogView auditLogView = new AuditLogView();
                auditLogView.setDate(auditLog.getUpdatedDate().toString());
                Short userId = auditLog.getUpdatedBy();
                PersonnelBO personnel = personnelService.getPersonnel(userId);
                auditLogView.setUser(personnel.getUserName());
                auditLogView.setField(auditLogRecord.getFieldName());
                String encryptedPasswordAuditFieldName = AuditConfiguration.getColumnNameForPropertyName(AuditConstants.PERSONNEL, AuditConstants.Audit_PASSWORD);
                if ((null != encryptedPasswordAuditFieldName) && (auditLogRecord.getFieldName().equals(encryptedPasswordAuditFieldName.trim()))) {
                    auditLogView.setOldValue(AuditConstants.HIDDEN_PASSWORD);
                    auditLogView.setNewValue(AuditConstants.HIDDEN_PASSWORD);
                } else {
                    auditLogView.setOldValue(auditLogRecord.getOldValue());
                    auditLogView.setNewValue(auditLogRecord.getNewValue());
                }
                auditLogViewList.add(auditLogView);
            }
        }
        return auditLogViewList;
    } catch (PersistenceException e) {
        throw new ServiceException(e);
    }
}
Also used : PersonnelBusinessService(org.mifos.customers.personnel.business.service.PersonnelBusinessService) ArrayList(java.util.ArrayList) AuditLogView(org.mifos.framework.components.audit.util.helpers.AuditLogView) AuditLog(org.mifos.framework.components.audit.business.AuditLog) LegacyAuditDao(org.mifos.framework.components.audit.persistence.LegacyAuditDao) AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) ServiceException(org.mifos.framework.exceptions.ServiceException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

Example 10 with AuditLogRecord

use of org.mifos.framework.components.audit.business.AuditLogRecord 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)

Aggregations

AuditLogRecord (org.mifos.framework.components.audit.business.AuditLogRecord)18 AuditLog (org.mifos.framework.components.audit.business.AuditLog)17 Test (org.junit.Test)13 HashSet (java.util.HashSet)8 Date (java.sql.Date)7 AuditTransactionForTests (org.mifos.framework.hibernate.helper.AuditTransactionForTests)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 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)2 FeeBO (org.mifos.accounts.fees.business.FeeBO)2 PersonnelBusinessService (org.mifos.customers.personnel.business.service.PersonnelBusinessService)2 LegacyAuditDao (org.mifos.framework.components.audit.persistence.LegacyAuditDao)2 ServiceException (org.mifos.framework.exceptions.ServiceException)2 DateTimeService (org.mifos.framework.util.DateTimeService)2 Date (java.util.Date)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1 Ignore (org.junit.Ignore)1