MIFOSX-329: bring in contribution from gsoc student yanna.

This commit is contained in:
wuyanna
2013-05-07 12:45:33 +01:00
committed by Keith Woodlock
parent 7b7b2cf1da
commit 1114a3b5ca
2 changed files with 48 additions and 3 deletions
@@ -33,7 +33,7 @@ public final class AuditData {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final String processingResult; private final String processingResult;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final String commandAsJson; private String commandAsJson;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final String officeName; private final String officeName;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@@ -75,4 +75,12 @@ public final class AuditData {
this.loanAccountNo = loanAccountNo; this.loanAccountNo = loanAccountNo;
this.savingsAccountNo = savingsAccountNo; this.savingsAccountNo = savingsAccountNo;
} }
public void setCommandAsJson(String commandAsJson) {
this.commandAsJson = commandAsJson;
}
public String getCommandAsJson() {
return this.commandAsJson;
}
} }
@@ -8,7 +8,9 @@ package org.mifosplatform.commands.service;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@@ -29,6 +31,8 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.google.gson.Gson;
@Service @Service
public class AuditReadPlatformServiceImpl implements AuditReadPlatformService { public class AuditReadPlatformServiceImpl implements AuditReadPlatformService {
@@ -162,7 +166,8 @@ public class AuditReadPlatformServiceImpl implements AuditReadPlatformService {
return this.jdbcTemplate.query(sql, rm, new Object[] {}); return this.jdbcTemplate.query(sql, rm, new Object[] {});
} }
@Override @SuppressWarnings("unchecked")
@Override
public AuditData retrieveAuditEntry(final Long auditId) { public AuditData retrieveAuditEntry(final Long auditId) {
AppUser currentUser = context.authenticatedUser(); AppUser currentUser = context.authenticatedUser();
@@ -170,10 +175,41 @@ public class AuditReadPlatformServiceImpl implements AuditReadPlatformService {
final AuditMapper rm = new AuditMapper(); final AuditMapper rm = new AuditMapper();
String sql = "select " + rm.schema(true, hierarchy); String sql = "select " + rm.schema(true, hierarchy);
sql += " where aud.id = " + auditId; sql += " where aud.id = " + auditId;
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] {}); AuditData auditResult = this.jdbcTemplate.queryForObject(sql, rm, new Object[] {});
String commandAsJson = auditResult.getCommandAsJson();
Map<String,Object> commandAsJsonMap = new HashMap<String,Object>();
commandAsJsonMap = new Gson().fromJson(commandAsJson, commandAsJsonMap.getClass());
if (commandAsJsonMap.containsKey("officeId")) {
Object officeIdObj = commandAsJsonMap.get("officeId");
if (officeIdObj instanceof Double) {
Integer officeId = ((Double) officeIdObj).intValue();
sql = " SELECT name FROM m_office WHERE id = " + officeId;
String officeName = this.jdbcTemplate.queryForObject(sql, String.class);
String regex = "\"officeId\":\\s\\d+";
commandAsJson = commandAsJson.replaceAll(regex, "\"officeName\": \""+officeName+"\"");
}
}
if (commandAsJsonMap.containsKey("clientId")) {
Object clientIdObj = commandAsJsonMap.get("clientId");
if (clientIdObj instanceof Double) {
Integer officeId = ((Double) clientIdObj).intValue();
sql = " SELECT display_name FROM m_client WHERE id = " + officeId;
String clientName = this.jdbcTemplate.queryForObject(sql, String.class);
String regex = "\"clientId\":\\s\\d+";
commandAsJson = commandAsJson.replaceAll(regex, "\"clientName\": \""+clientName+"\"");
}
}
auditResult.setCommandAsJson(commandAsJson);
return auditResult;
} }
@Override @Override
@@ -262,4 +298,5 @@ public class AuditReadPlatformServiceImpl implements AuditReadPlatformService {
+ " order by enum_id"; + " order by enum_id";
} }
} }
} }