Merge remote-tracking branch 'goutham/MIFOSX-286' into develop

This commit is contained in:
Keith Woodlock
2013-05-19 23:21:30 +01:00
9 changed files with 160 additions and 67 deletions
@@ -0,0 +1 @@
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('organistion', 'DELETE_ACCOUNTINGRULE', 'ACCOUNTINGRULE', 'DELETE', 0),('organistion', 'CREATE_ACCOUNTINGRULE', 'ACCOUNTINGRULE', 'CREATE', 0),('organistion', 'UPDATE_ACCOUNTINGRULE', 'ACCOUNTINGRULE', 'UPDATE', 0);
@@ -5,7 +5,6 @@
*/
package org.mifosplatform.accounting.rule.api;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
@@ -75,6 +74,21 @@ public class AccountingRuleApiResource {
this.officeReadPlatformService = officeReadPlatformService;
this.accountReadPlatformService = accountReadPlatformService;
}
@GET
@Path("template")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveTemplate(@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(resourceNameForPermission);
AccountingRuleData accountingRuleData = this.accountingRuleReadPlatformService.retrieveNewAccountingRuleDetails();
accountingRuleData = handleTemplate(accountingRuleData);
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.apiJsonSerializerService.serialize(settings, accountingRuleData, RESPONSE_DATA_PARAMETERS);
}
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@@ -98,11 +112,9 @@ public class AccountingRuleApiResource {
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
final AccountingRuleData accountingRuleData = this.accountingRuleReadPlatformService.retrieveAccountingRuleById(accountingRuleId);
AccountingRuleData accountingRuleData = this.accountingRuleReadPlatformService.retrieveAccountingRuleById(accountingRuleId);
if (settings.isTemplate()) {
accountingRuleData.setAllowedOffices(new ArrayList<OfficeData>(this.officeReadPlatformService.retrieveAllOfficesForDropdown()));
accountingRuleData.setAllowedAccounts(new ArrayList<GLAccountData>(this.accountReadPlatformService
.retrieveAllEnabledDetailGLAccounts()));
accountingRuleData = handleTemplate(accountingRuleData);
}
return this.apiJsonSerializerService.serialize(settings, accountingRuleData, RESPONSE_DATA_PARAMETERS);
@@ -145,4 +157,13 @@ public class AccountingRuleApiResource {
return this.apiJsonSerializerService.serialize(result);
}
private AccountingRuleData handleTemplate(AccountingRuleData accountingRuleData) {
List<GLAccountData> allowedAccounts = this.accountReadPlatformService.retrieveAllEnabledDetailGLAccounts();
List<OfficeData> allowedOffices = (List<OfficeData>) this.officeReadPlatformService.retrieveAllOfficesForDropdown();
if (accountingRuleData == null) {
return new AccountingRuleData(allowedAccounts, allowedOffices);
}
return new AccountingRuleData(accountingRuleData, allowedAccounts, allowedOffices);
}
}
@@ -19,58 +19,89 @@ import org.mifosplatform.organisation.office.data.OfficeData;
*/
public class AccountingRuleData {
@SuppressWarnings("unused")
private final Long id;
@SuppressWarnings("unused")
private final Long officeId;
@SuppressWarnings("unused")
private final String officeName;
@SuppressWarnings("unused")
private final Long accountToDebitId;
@SuppressWarnings("unused")
private final Long accountToCreditId;
@SuppressWarnings("unused")
private final String name;
@SuppressWarnings("unused")
private final String description;
@SuppressWarnings("unused")
private final boolean systemDefined;
private final Long id;
private final Long officeId;
private final String officeName;
private final Long accountToDebitId;
private final Long accountToCreditId;
private final String name;
private final String description;
private final boolean systemDefined;
private final String debitAccountName;
private final String creditAccountName;
private final String debitAccountGLCode;
private final String creditAccountGLCode;
// template
@SuppressWarnings("unused")
private List<OfficeData> allowedOffices = new ArrayList<OfficeData>();
@SuppressWarnings("unused")
private List<GLAccountData> allowedAccounts = new ArrayList<GLAccountData>();
// template
@SuppressWarnings("unused")
private List<OfficeData> allowedOffices = new ArrayList<OfficeData>();
@SuppressWarnings("unused")
private List<GLAccountData> allowedAccounts = new ArrayList<GLAccountData>();
public AccountingRuleData(Long id, Long accountToDebitId, Long accountToCreditId) {
this(id, null, null, accountToDebitId, accountToCreditId, null, null, true, null, null);
}
public AccountingRuleData(final Long id, final Long accountToDebitId, final Long accountToCreditId) {
this(id, null, null, accountToDebitId, accountToCreditId, null, null, true, null, null, null, null, null, null);
}
public AccountingRuleData(Long id, Long officeId, String officeName, Long accountToDebitId, Long accountToCreditId, String name,
String description, boolean systemDefined) {
this(id, officeId, officeName, accountToDebitId, accountToCreditId, name, description, systemDefined, null, null);
}
public AccountingRuleData(final Long id, final Long officeId, final String officeName, final Long accountToDebitId,
final Long accountToCreditId, final String name, final String description, final boolean systemDefined,
final String debitAccountName, final String creditAccountName, final String debitAccountGLCode,
final String creditAccountGLCode) {
this(id, officeId, officeName, accountToDebitId, accountToCreditId, name, description, systemDefined, debitAccountName,
creditAccountName, debitAccountGLCode, creditAccountGLCode, null, null);
}
public AccountingRuleData(Long id, Long officeId, String officeName, Long accountToDebitId, Long accountToCreditId, String name,
String description, boolean systemDefined, List<OfficeData> allowedOffices, List<GLAccountData> allowedAccounts) {
this.id = id;
this.officeId = officeId;
this.officeName = officeName;
this.accountToDebitId = accountToDebitId;
this.accountToCreditId = accountToCreditId;
this.name = name;
this.description = description;
this.systemDefined = systemDefined;
this.allowedOffices = allowedOffices;
this.allowedAccounts = allowedAccounts;
}
public AccountingRuleData(final Long id, final Long officeId, final String officeName, final Long accountToDebitId,
final Long accountToCreditId, final String name, final String description, final boolean systemDefined,
final String debitAccountName, final String creditAccountName, final String debitAccountGLCode,
final String creditAccountGLCode, final List<OfficeData> allowedOffices, final List<GLAccountData> allowedAccounts) {
this.id = id;
this.officeId = officeId;
this.officeName = officeName;
this.accountToDebitId = accountToDebitId;
this.accountToCreditId = accountToCreditId;
this.name = name;
this.description = description;
this.systemDefined = systemDefined;
this.allowedOffices = allowedOffices;
this.allowedAccounts = allowedAccounts;
this.debitAccountName = debitAccountName;
this.creditAccountName = creditAccountName;
this.debitAccountGLCode = debitAccountGLCode;
this.creditAccountGLCode = creditAccountGLCode;
}
public void setAllowedOffices(List<OfficeData> allowedOffices) {
this.allowedOffices = allowedOffices;
}
public void setAllowedAccounts(List<GLAccountData> allowedAccounts) {
this.allowedAccounts = allowedAccounts;
}
public AccountingRuleData(final AccountingRuleData accountingRuleData,
final List<GLAccountData> allowedAccounts, final List<OfficeData> allowedOffices) {
this.id = accountingRuleData.id;
this.officeId = accountingRuleData.officeId;
this.officeName = accountingRuleData.officeName;
this.accountToDebitId = accountingRuleData.accountToDebitId;
this.accountToCreditId = accountingRuleData.accountToCreditId;
this.name = accountingRuleData.name;
this.description = accountingRuleData.description;
this.systemDefined = accountingRuleData.systemDefined;
this.allowedOffices = allowedOffices;
this.allowedAccounts = allowedAccounts;
this.debitAccountName = accountingRuleData.debitAccountName;
this.creditAccountName = accountingRuleData.creditAccountName;
this.debitAccountGLCode = accountingRuleData.debitAccountGLCode;
this.creditAccountGLCode = accountingRuleData.creditAccountGLCode;
}
public AccountingRuleData(final List<GLAccountData> allowedAccounts, final List<OfficeData> allowedOffices) {
this.id = null;
this.officeId = null;
this.officeName = null;
this.accountToDebitId = null;
this.accountToCreditId = null;
this.name = null;
this.description = null;
this.systemDefined = false;
this.allowedOffices = allowedOffices;
this.allowedAccounts = allowedAccounts;
this.debitAccountName = null;
this.creditAccountName = null;
this.debitAccountGLCode = null;
this.creditAccountGLCode = null;
}
}
@@ -10,7 +10,6 @@ import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.mifosplatform.accounting.closure.api.GLClosureJsonInputParams;
import org.mifosplatform.accounting.rule.api.AccountingRuleJsonInputParams;
import org.mifosplatform.accounting.rule.command.AccountingRuleCommand;
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
@@ -43,7 +42,7 @@ public final class AccountingRuleCommandFromApiJsonDeserializer extends Abstract
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
final Set<String> supportedParameters = GLClosureJsonInputParams.getAllValues();
final Set<String> supportedParameters = AccountingRuleJsonInputParams.getAllValues();
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
final JsonElement element = this.fromApiJsonHelper.parse(json);
@@ -15,4 +15,6 @@ public interface AccountingRuleReadPlatformService {
AccountingRuleData retrieveAccountingRuleById(long accountingRuleId);
AccountingRuleData retrieveNewAccountingRuleDetails();
}
@@ -35,10 +35,17 @@ public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleRead
public AccountingRuleMapper() {
final StringBuilder sqlBuilder = new StringBuilder(400);
sqlBuilder.append("select rule.id as id,rule.name as name, rule.office_id as officeId,office.name as officeName,")
sqlBuilder.append(" rule.id as id,rule.name as name, rule.office_id as officeId,office.name as officeName,")
.append(" rule.debit_account_id as debitAccountId,rule.credit_account_id as creditAccountId,")
.append(" rule.description as description, rule.system_defined as systemDefined ").append("from ")
.append(" acc_accounting_rule rule left join m_office office on rule.office_id=office.id");
.append(" rule.description as description, rule.system_defined as systemDefined, ")
.append("debitAccount.glName as debitAccountName, debitAccount.glCode as debitAccountGLCode,")
.append("creditAccount.glName as creditAccountName, creditAccount.glCode as creditAccountGLCode ")
.append("from (Select gl.id as id,gl.name as glName, gl.gl_code as glCode from acc_gl_account gl,acc_accounting_rule rule ")
.append("where gl.id=rule.debit_account_id ) as debitAccount,")
.append("(Select gl.id as id,gl.name as glName, gl.gl_code as glCode from acc_gl_account gl,acc_accounting_rule rule ")
.append("where gl.id=rule.credit_account_id ) as creditAccount,")
.append("acc_accounting_rule rule left join m_office office on rule.office_id=office.id ")
.append("where debitAccount.id=rule.debit_account_id and creditAccount.id = rule.credit_account_id");
this.schemaSql = sqlBuilder.toString();
}
@@ -57,17 +64,27 @@ public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleRead
final Long accountToDebitId = rs.getLong("debitAccountId");
final Long accountToCreditId = rs.getLong("creditAccountId");
final boolean systemDefined = rs.getBoolean("systemDefined");
final String debitAccountName = rs.getString("debitAccountName");
final String creditAccountName = rs.getString("creditAccountName");
final String debitAccountGLCode = rs.getString("debitAccountGLCode");
final String creditAccountGLCode = rs.getString("creditAccountGLCode");
return new AccountingRuleData(id, officeId, officeName, accountToDebitId, accountToCreditId, name, description, systemDefined);
return new AccountingRuleData(id, officeId, officeName, accountToDebitId, accountToCreditId, name, description, systemDefined,
debitAccountName, creditAccountName, debitAccountGLCode, creditAccountGLCode);
}
}
@Override
public List<AccountingRuleData> retrieveAllAccountingRules(Long officeId) {
final AccountingRuleMapper rm = new AccountingRuleMapper();
String sql = "select " + rm.schema() + " where system_defined=0 and office.id = ?";
sql = sql + " order by rule.id asc";
return this.jdbcTemplate.query(sql, rm, new Object[] { officeId });
if(officeId != null) {
String sql = "select " + rm.schema() + " where system_defined=0 and office.id = ?";
sql = sql + " order by rule.id asc";
return this.jdbcTemplate.query(sql, rm, new Object[] { officeId });
}
String sql = "select " + rm.schema() + " and system_defined=0 ";
sql = sql + " order by rule.id asc";
return this.jdbcTemplate.query(sql, rm, new Object[] {});
}
@Override
@@ -75,7 +92,7 @@ public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleRead
try {
final AccountingRuleMapper rm = new AccountingRuleMapper();
final String sql = "select " + rm.schema() + " and glClosure.id = ?";
final String sql = "select " + rm.schema() + " and rule.id = ?";
final AccountingRuleData accountingRuleData = this.jdbcTemplate.queryForObject(sql, rm, new Object[] { accountingRuleId });
return accountingRuleData;
@@ -84,4 +101,10 @@ public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleRead
}
}
@Override
public AccountingRuleData retrieveNewAccountingRuleDetails() {
// Modify if any default values required
return null;
}
}
@@ -123,17 +123,17 @@ public class AccountingRuleWritePlatformServiceJpaRepositoryImpl implements Acco
final AccountingRule accountingRule = this.accountingRuleRepositoryWrapper.findOneWithNotFoundDetection(accountingRuleId);
final Map<String, Object> changesOnly = accountingRule.update(command);
if (changesOnly.containsKey(AccountingRuleJsonInputParams.ACCOUNT_TO_DEBIT.getValue())) {
if (accountToDebitId != null && changesOnly.containsKey(AccountingRuleJsonInputParams.ACCOUNT_TO_DEBIT.getValue())) {
final GLAccount accountToDebit = accountRepositoryWrapper.findOneWithNotFoundDetection(accountToDebitId);
accountingRule.setAccountToDebit(accountToDebit);
}
if (changesOnly.containsKey(AccountingRuleJsonInputParams.ACCOUNT_TO_CREDIT.getValue())) {
if (accountToCreditId != null && changesOnly.containsKey(AccountingRuleJsonInputParams.ACCOUNT_TO_CREDIT.getValue())) {
final GLAccount accountToCredit = accountRepositoryWrapper.findOneWithNotFoundDetection(accountToCreditId);
accountingRule.setAccountToCredit(accountToCredit);
}
if (changesOnly.containsKey(AccountingRuleJsonInputParams.OFFICE_ID.getValue())) {
if (officeId != null && changesOnly.containsKey(AccountingRuleJsonInputParams.OFFICE_ID.getValue())) {
final Office userOffice = this.officeRepository.findOne(officeId);
if (userOffice == null) { throw new OfficeNotFoundException(officeId); }
accountingRule.setOffice(userOffice);
@@ -512,4 +512,8 @@ public class CommandWrapper {
public boolean isDisassociateClients() {
return this.actionName.equalsIgnoreCase("DISASSOCIATECLIENTS");
}
public boolean isAccountingRuleResource() {
return this.entityName.equalsIgnoreCase("ACCOUNTINGRULE");
}
}
@@ -443,7 +443,19 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
throw new UnsupportedCommandException(wrapper.commandName());
}
} else {
} else if (wrapper.isAccountingRuleResource()) {
if (wrapper.isCreate()) {
handler = applicationContext.getBean("createAccountingRuleCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateAccountingRuleCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteAccountingRuleCommandHandler", NewCommandSourceHandler.class);
} else {
throw new UnsupportedCommandException(wrapper.commandName());
}
}else {
throw new UnsupportedCommandException(wrapper.commandName());
}