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);
}
}
}
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);
}
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());
}
}
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());
}
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;
}
Aggregations