MIFOSX-365: formatting and add license to files without it.

This commit is contained in:
Keith Woodlock
2013-05-28 21:21:43 +01:00
parent 721a12c2fa
commit e2c4ce9a13
13 changed files with 363 additions and 336 deletions
@@ -1,11 +1,17 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.accounting.glaccount.exception; package org.mifosplatform.accounting.glaccount.exception;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException; import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
public class InvalidParentGLAccountHeadException extends AbstractPlatformDomainRuleException { public class InvalidParentGLAccountHeadException extends AbstractPlatformDomainRuleException {
public InvalidParentGLAccountHeadException(Long glAccountId, Long parentId) { public InvalidParentGLAccountHeadException(final Long glAccountId, final Long parentId) {
super("error.msg.glaccount.id.and.parentid.must.not.same", "parentId:"+parentId+", id"+glAccountId+" should not be same", glAccountId, parentId); super("error.msg.glaccount.id.and.parentid.must.not.same", "parentId:" + parentId + ", id" + glAccountId + " should not be same",
glAccountId, parentId);
} }
} }
@@ -1,3 +1,8 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.accounting.producttoaccountmapping.data; package org.mifosplatform.accounting.producttoaccountmapping.data;
public class PaymentTypeToGLAccountMapper { public class PaymentTypeToGLAccountMapper {
@@ -1,12 +1,17 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.accounting.producttoaccountmapping.service; package org.mifosplatform.accounting.producttoaccountmapping.service;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.mifosplatform.accounting.common.AccountingRuleType;
import org.mifosplatform.accounting.common.AccountingConstants.ACCRUAL_ACCOUNTS_FOR_LOAN; import org.mifosplatform.accounting.common.AccountingConstants.ACCRUAL_ACCOUNTS_FOR_LOAN;
import org.mifosplatform.accounting.common.AccountingConstants.CASH_ACCOUNTS_FOR_LOAN; import org.mifosplatform.accounting.common.AccountingConstants.CASH_ACCOUNTS_FOR_LOAN;
import org.mifosplatform.accounting.common.AccountingConstants.LOAN_PRODUCT_ACCOUNTING_PARAMS; import org.mifosplatform.accounting.common.AccountingConstants.LOAN_PRODUCT_ACCOUNTING_PARAMS;
import org.mifosplatform.accounting.common.AccountingRuleType;
import org.mifosplatform.accounting.glaccount.domain.GLAccountRepository; import org.mifosplatform.accounting.glaccount.domain.GLAccountRepository;
import org.mifosplatform.accounting.glaccount.domain.GLAccountType; import org.mifosplatform.accounting.glaccount.domain.GLAccountType;
import org.mifosplatform.accounting.producttoaccountmapping.domain.PortfolioProductType; import org.mifosplatform.accounting.producttoaccountmapping.domain.PortfolioProductType;
@@ -23,9 +28,9 @@ import com.google.gson.JsonElement;
public class LoanProductToGLAccountMappingHelper extends ProductToGLAccountMappingHelper { public class LoanProductToGLAccountMappingHelper extends ProductToGLAccountMappingHelper {
@Autowired @Autowired
public LoanProductToGLAccountMappingHelper(GLAccountRepository glAccountRepository, public LoanProductToGLAccountMappingHelper(final GLAccountRepository glAccountRepository,
ProductToGLAccountMappingRepository glAccountMappingRepository, FromJsonHelper fromApiJsonHelper, final ProductToGLAccountMappingRepository glAccountMappingRepository, final FromJsonHelper fromApiJsonHelper,
CodeValueRepositoryWrapper codeValueRepositoryWrapper) { final CodeValueRepositoryWrapper codeValueRepositoryWrapper) {
super(glAccountRepository, glAccountMappingRepository, fromApiJsonHelper, codeValueRepositoryWrapper); super(glAccountRepository, glAccountMappingRepository, fromApiJsonHelper, codeValueRepositoryWrapper);
} }
@@ -68,12 +73,12 @@ public class LoanProductToGLAccountMappingHelper extends ProductToGLAccountMappi
/*** Abstractions for payments channel related to loan products ***/ /*** Abstractions for payments channel related to loan products ***/
public void savePaymentChannelToFundSourceMappings(final JsonCommand command, final JsonElement element, final Long productId, public void savePaymentChannelToFundSourceMappings(final JsonCommand command, final JsonElement element, final Long productId,
Map<String, Object> changes) { final Map<String, Object> changes) {
savePaymentChannelToFundSourceMappings(command, element, productId, changes, PortfolioProductType.LOAN); savePaymentChannelToFundSourceMappings(command, element, productId, changes, PortfolioProductType.LOAN);
} }
public void updatePaymentChannelToFundSourceMappings(final JsonCommand command, final JsonElement element, final Long productId, public void updatePaymentChannelToFundSourceMappings(final JsonCommand command, final JsonElement element, final Long productId,
Map<String, Object> changes) { final Map<String, Object> changes) {
updatePaymentChannelToFundSourceMappings(command, element, productId, changes, PortfolioProductType.LOAN); updatePaymentChannelToFundSourceMappings(command, element, productId, changes, PortfolioProductType.LOAN);
} }
@@ -1,3 +1,8 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.accounting.producttoaccountmapping.service; package org.mifosplatform.accounting.producttoaccountmapping.service;
import java.util.HashMap; import java.util.HashMap;
@@ -1,3 +1,8 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.accounting.producttoaccountmapping.service; package org.mifosplatform.accounting.producttoaccountmapping.service;
import java.util.HashMap; import java.util.HashMap;
@@ -1,3 +1,8 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.accounting.rule.data; package org.mifosplatform.accounting.rule.data;
import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.infrastructure.core.data.EnumOptionData;
@@ -1,3 +1,8 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.accounting.rule.domain; package org.mifosplatform.accounting.rule.domain;
import javax.persistence.Column; import javax.persistence.Column;
@@ -1,3 +1,8 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.accounting.rule.service; package org.mifosplatform.accounting.rule.service;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@@ -1,3 +1,8 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.infrastructure.core.serialization; package org.mifosplatform.infrastructure.core.serialization;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@@ -32,9 +32,9 @@ public class UpdateDatatableCommandHandler implements NewCommandSourceHandler {
this.writePlatformService.updateDatatable(datatableName, command); this.writePlatformService.updateDatatable(datatableName, command);
return new CommandProcessingResultBuilder() return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) .withCommandId(command.commandId()) //
.withResourceIdAsString(datatableName) .withResourceIdAsString(datatableName) //
.build(); .build();
} }
} }
@@ -59,9 +59,15 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
private final static String DATATABLE_NAME_REGEX_PATTERN = "^[a-zA-Z][a-zA-Z0-9\\-_\\s]{0,48}[a-zA-Z0-9]$"; private final static String DATATABLE_NAME_REGEX_PATTERN = "^[a-zA-Z][a-zA-Z0-9\\-_\\s]{0,48}[a-zA-Z0-9]$";
private final static Logger logger = LoggerFactory.getLogger(ReadWriteNonCoreDataServiceImpl.class); private final static Logger logger = LoggerFactory.getLogger(ReadWriteNonCoreDataServiceImpl.class);
private final static HashMap<String, String> apiTypeToMySQL = new HashMap<String, String>() {{ private final static HashMap<String, String> apiTypeToMySQL = new HashMap<String, String>() {
put("String", "VARCHAR"); put("Number", "INT"); put("Decimal", "DECIMAL"); put("Date", "DATE");
}}; {
put("String", "VARCHAR");
put("Number", "INT");
put("Decimal", "DECIMAL");
put("Date", "DATE");
}
};
private final JdbcTemplate jdbcTemplate; private final JdbcTemplate jdbcTemplate;
private final DataSource dataSource; private final DataSource dataSource;
@@ -108,8 +114,8 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
while (rs.next()) { while (rs.next()) {
final String appTableName = rs.getString("application_table_name"); final String appTableName = rs.getString("application_table_name");
final String registeredDatatableName = rs.getString("registered_table_name"); final String registeredDatatableName = rs.getString("registered_table_name");
final List<ResultsetColumnHeaderData> columnHeaderData = final List<ResultsetColumnHeaderData> columnHeaderData = this.genericDataService
this.genericDataService.fillResultsetColumnHeaders(registeredDatatableName); .fillResultsetColumnHeaders(registeredDatatableName);
datatables.add(DatatableData.create(appTableName, registeredDatatableName, columnHeaderData)); datatables.add(DatatableData.create(appTableName, registeredDatatableName, columnHeaderData));
} }
@@ -124,8 +130,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
final String sql = "select application_table_name, registered_table_name" + " from x_registered_table " + " where exists" final String sql = "select application_table_name, registered_table_name" + " from x_registered_table " + " where exists"
+ " (select 'f'" + " from m_appuser_role ur " + " join m_role r on r.id = ur.role_id" + " (select 'f'" + " from m_appuser_role ur " + " join m_role r on r.id = ur.role_id"
+ " left join m_role_permission rp on rp.role_id = r.id" + " left join m_permission p on p.id = rp.permission_id" + " left join m_role_permission rp on rp.role_id = r.id" + " left join m_permission p on p.id = rp.permission_id"
+ " where ur.appuser_id = " + context.authenticatedUser().getId() + " where ur.appuser_id = " + context.authenticatedUser().getId() + " and registered_table_name='" + datatable + "'"
+ " and registered_table_name='" + datatable + "'"
+ " and (p.code in ('ALL_FUNCTIONS', 'ALL_FUNCTIONS_READ') or p.code = concat('READ_', registered_table_name))) " + " and (p.code in ('ALL_FUNCTIONS', 'ALL_FUNCTIONS_READ') or p.code = concat('READ_', registered_table_name))) "
+ " order by application_table_name, registered_table_name"; + " order by application_table_name, registered_table_name";
@@ -135,8 +140,8 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
while (rs.next()) { while (rs.next()) {
final String appTableName = rs.getString("application_table_name"); final String appTableName = rs.getString("application_table_name");
final String registeredDatatableName = rs.getString("registered_table_name"); final String registeredDatatableName = rs.getString("registered_table_name");
final List<ResultsetColumnHeaderData> columnHeaderData = final List<ResultsetColumnHeaderData> columnHeaderData = this.genericDataService
this.genericDataService.fillResultsetColumnHeaders(registeredDatatableName); .fillResultsetColumnHeaders(registeredDatatableName);
datatableData = DatatableData.create(appTableName, registeredDatatableName, columnHeaderData); datatableData = DatatableData.create(appTableName, registeredDatatableName, columnHeaderData);
} }
@@ -201,15 +206,14 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
+ ", 'DELETE', '" + ", 'DELETE', '"
+ dataTableName + "', false)"; + dataTableName + "', false)";
try { try {
String[] sqlArray = { registerDatatableSql, permissionsSql }; String[] sqlArray = { registerDatatableSql, permissionsSql };
this.jdbcTemplate.batchUpdate(sqlArray); this.jdbcTemplate.batchUpdate(sqlArray);
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
Throwable realCause = dve.getMostSpecificCause(); Throwable realCause = dve.getMostSpecificCause();
//even if duplicate is only due to permission duplicate, okay to show duplicate datatable error msg // even if duplicate is only due to permission duplicate, okay to
// show duplicate datatable error msg
if (realCause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException( if (realCause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException(
"error.msg.datatable.registered", "Datatable `" + dataTableName "error.msg.datatable.registered", "Datatable `" + dataTableName
+ "` is already registered against an application table.", "dataTableName", dataTableName); } + "` is already registered against an application table.", "dataTableName", dataTableName); }
@@ -291,29 +295,22 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
private void validateDatatableExists(final String name) { private void validateDatatableExists(final String name) {
if (!datatableExists(name)) { if (!datatableExists(name)) { throw new PlatformDataIntegrityException("error.msg.datatables.missing.table.name", "Table '" + name
throw new PlatformDataIntegrityException("error.msg.datatables.missing.table.name", + "' does not exist.", name); }
"Table '" + name + "' does not exist.", name);
}
} }
private void validateDatatableNotExists(final String name) { private void validateDatatableNotExists(final String name) {
if (datatableExists(name)) { if (datatableExists(name)) { throw new PlatformDataIntegrityException("error.msg.datatables.duplicate.table.name", "Table '" + name
throw new PlatformDataIntegrityException("error.msg.datatables.duplicate.table.name", + "' already exists.", name); }
"Table '" + name + "' already exists.", name);
}
} }
private void validateDatatableName(final String name) { private void validateDatatableName(final String name) {
if (name == null || name.isEmpty()) { if (name == null || name.isEmpty()) {
throw new PlatformDataIntegrityException("error.msg.datatables.datatable.null.name", throw new PlatformDataIntegrityException("error.msg.datatables.datatable.null.name", "Data table name must not be blank.");
"Data table name must not be blank."); } else if (!name.matches(DATATABLE_NAME_REGEX_PATTERN)) { throw new PlatformDataIntegrityException(
} else if (!name.matches(DATATABLE_NAME_REGEX_PATTERN)) { "error.msg.datatables.datatable.invalid.name.regex", "Invalid data table name.", name); }
throw new PlatformDataIntegrityException("error.msg.datatables.datatable.invalid.name.regex",
"Invalid data table name.", name);
}
} }
private void parseDatatableColumnObjectForCreate(final JsonObject column, StringBuilder sqlBuilder) { private void parseDatatableColumnObjectForCreate(final JsonObject column, StringBuilder sqlBuilder) {
@@ -326,8 +323,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
String mysqlType = apiTypeToMySQL.get(type); String mysqlType = apiTypeToMySQL.get(type);
sqlBuilder = sqlBuilder.append("`" + name + "` " + mysqlType); sqlBuilder = sqlBuilder.append("`" + name + "` " + mysqlType);
if (type != null) if (type != null) {
{
if (type.equals("String")) { if (type.equals("String")) {
sqlBuilder = sqlBuilder.append("(" + length + ")"); sqlBuilder = sqlBuilder.append("(" + length + ")");
} else if (type.equals("Decimal")) { } else if (type.equals("Decimal")) {
@@ -372,12 +368,10 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
sqlBuilder = sqlBuilder.append("CREATE TABLE `" + datatableName + "` ("); sqlBuilder = sqlBuilder.append("CREATE TABLE `" + datatableName + "` (");
if (multiRow) { if (multiRow) {
sqlBuilder = sqlBuilder sqlBuilder = sqlBuilder.append("`id` BIGINT(20) NOT NULL AUTO_INCREMENT, ").append(
.append("`id` BIGINT(20) NOT NULL AUTO_INCREMENT, ") "`" + fkColumnName + "` BIGINT(20) NOT NULL, ");
.append("`" + fkColumnName + "` BIGINT(20) NOT NULL, ");
} else { } else {
sqlBuilder = sqlBuilder sqlBuilder = sqlBuilder.append("`" + fkColumnName + "` BIGINT(20) NOT NULL, ");
.append("`" + fkColumnName + "` BIGINT(20) NOT NULL, ");
} }
for (JsonElement column : columns) { for (JsonElement column : columns) {
@@ -388,19 +382,13 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
sqlBuilder = sqlBuilder.delete(sqlBuilder.length() - 2, sqlBuilder.length()); sqlBuilder = sqlBuilder.delete(sqlBuilder.length() - 2, sqlBuilder.length());
if (multiRow) { if (multiRow) {
sqlBuilder = sqlBuilder sqlBuilder = sqlBuilder.append(", PRIMARY KEY (`id`)").append(", KEY `fk_" + apptable + "` (`" + fkColumnName + "`)")
.append(", PRIMARY KEY (`id`)") .append(", CONSTRAINT `fk_" + fkName + "` ").append("FOREIGN KEY (`" + fkColumnName + "`) ")
.append(", KEY `fk_" + apptable + "` (`" + fkColumnName + "`)")
.append(", CONSTRAINT `fk_" + fkName + "` ")
.append("FOREIGN KEY (`" + fkColumnName + "`) ")
.append("REFERENCES `" + apptable + "` (`id`)"); .append("REFERENCES `" + apptable + "` (`id`)");
} else { } else {
sqlBuilder = sqlBuilder sqlBuilder = sqlBuilder.append(", PRIMARY KEY (`" + fkColumnName + "`)").append(", CONSTRAINT `fk_" + fkName + "` ")
.append(", PRIMARY KEY (`" + fkColumnName + "`)") .append("FOREIGN KEY (`" + fkColumnName + "`) ").append("REFERENCES `" + apptable + "` (`id`)");
.append(", CONSTRAINT `fk_" + fkName + "` ")
.append("FOREIGN KEY (`" + fkColumnName + "`) ")
.append("REFERENCES `" + apptable + "` (`id`)");
} }
sqlBuilder = sqlBuilder.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;"); sqlBuilder = sqlBuilder.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
@@ -408,10 +396,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
registerDatatable(datatableName, apptable); registerDatatable(datatableName, apptable);
return new CommandProcessingResultBuilder() return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withResourceIdAsString(datatableName).build();
.withCommandId(command.commandId())
.withResourceIdAsString(datatableName)
.build();
} }
private void parseDatatableColumnForUpdate(final JsonObject column, StringBuilder sqlBuilder) { private void parseDatatableColumnForUpdate(final JsonObject column, StringBuilder sqlBuilder) {
@@ -543,7 +528,6 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
return updateDatatableEntry(dataTableName, appTableId, datatableId, command); return updateDatatableEntry(dataTableName, appTableId, datatableId, command);
} }
private CommandProcessingResult updateDatatableEntry(final String dataTableName, final Long appTableId, final Long datatableId, private CommandProcessingResult updateDatatableEntry(final String dataTableName, final Long appTableId, final Long datatableId,
final JsonCommand command) { final JsonCommand command) {
@@ -561,13 +545,17 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
Map<String, String> dataParams = this.fromJsonHelper.extractDataMap(typeOfMap, command.json()); Map<String, String> dataParams = this.fromJsonHelper.extractDataMap(typeOfMap, command.json());
String pkName = "id"; // 1:M datatable String pkName = "id"; // 1:M datatable
if (datatableId == null) { pkName = getFKField(appTable);} //1:1 datatable if (datatableId == null) {
pkName = getFKField(appTable);
} // 1:1 datatable
final Map<String, Object> changes = getAffectedAndChangedColumns(grs, dataParams, pkName); final Map<String, Object> changes = getAffectedAndChangedColumns(grs, dataParams, pkName);
if (!changes.isEmpty()) { if (!changes.isEmpty()) {
Long pkValue = appTableId; Long pkValue = appTableId;
if (datatableId != null) { pkValue = datatableId;} if (datatableId != null) {
pkValue = datatableId;
}
final String sql = getUpdateSql(dataTableName, pkName, pkValue, changes); final String sql = getUpdateSql(dataTableName, pkName, pkValue, changes);
logger.info("Update sql: " + sql); logger.info("Update sql: " + sql);
if (StringUtils.isNotBlank(sql)) { if (StringUtils.isNotBlank(sql)) {
@@ -589,7 +577,6 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
.build(); .build();
} }
@Transactional @Transactional
@Override @Override
public CommandProcessingResult deleteDatatableEntries(final String dataTableName, final Long appTableId) { public CommandProcessingResult deleteDatatableEntries(final String dataTableName, final Long appTableId) {
@@ -597,7 +584,6 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
final String appTable = queryForApplicationTableName(dataTableName); final String appTable = queryForApplicationTableName(dataTableName);
CommandProcessingResult commandProcessingResult = checkMainResourceExistsWithinScope(appTable, appTableId); CommandProcessingResult commandProcessingResult = checkMainResourceExistsWithinScope(appTable, appTableId);
final String deleteOneToOneEntrySql = getDeleteEntriesSql(dataTableName, getFKField(appTable), appTableId); final String deleteOneToOneEntrySql = getDeleteEntriesSql(dataTableName, getFKField(appTable), appTableId);
int rowsDeleted = this.jdbcTemplate.update(deleteOneToOneEntrySql); int rowsDeleted = this.jdbcTemplate.update(deleteOneToOneEntrySql);
@@ -647,9 +633,8 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
return new GenericResultsetData(columnHeaders, result); return new GenericResultsetData(columnHeaders, result);
} }
private GenericResultsetData retrieveDataTableGenericResultSetForUpdate(final String appTable, final String dataTableName,
private GenericResultsetData retrieveDataTableGenericResultSetForUpdate(final String appTable, String dataTableName, final Long appTableId, final Long appTableId, final Long id) {
final Long id) {
final List<ResultsetColumnHeaderData> columnHeaders = this.genericDataService.fillResultsetColumnHeaders(dataTableName); final List<ResultsetColumnHeaderData> columnHeaders = this.genericDataService.fillResultsetColumnHeaders(dataTableName);
@@ -693,78 +678,74 @@ logger.info("data scoped sql: " + sql);
.build(); .build();
} }
private Long getLongSqlRowSet(SqlRowSet rs, String column) { private Long getLongSqlRowSet(final SqlRowSet rs, final String column) {
Long val = rs.getLong(column); Long val = rs.getLong(column);
if (val == 0) val = null; if (val == 0) val = null;
return val; return val;
} }
private String dataScopedSQL(final String appTable, final Long appTableId) { private String dataScopedSQL(final String appTable, final Long appTableId) {
/* /*
* unfortunately have to, one way or another, be able to restrict data * unfortunately have to, one way or another, be able to restrict data
* to the users office hierarchy. Here, a few key tables are done. * to the users office hierarchy. Here, a few key tables are done. But
* But if additional fields are needed on other tables the * if additional fields are needed on other tables the same pattern
* same pattern applies * applies
*/ */
AppUser currentUser = context.authenticatedUser(); AppUser currentUser = context.authenticatedUser();
String scopedSQL = null; String scopedSQL = null;
/* /*
* m_loan and m_savings_account are connected to an m_office thru either an m_client or an m_group * m_loan and m_savings_account are connected to an m_office thru either
* If both it means it relates to an m_client that is in a group (still an m_client account) * an m_client or an m_group If both it means it relates to an m_client
* that is in a group (still an m_client account)
*/ */
if (appTable.equalsIgnoreCase("m_loan")) { if (appTable.equalsIgnoreCase("m_loan")) {
scopedSQL = "select distinctrow x.* from (" + scopedSQL = "select distinctrow x.* from ("
" (select o.id as officeId, l.group_id as groupId, l.client_id as clientId, null as savingsId, l.id as loanId from m_loan l " + + " (select o.id as officeId, l.group_id as groupId, l.client_id as clientId, null as savingsId, l.id as loanId from m_loan l "
" join m_client c on c.id = l.client_id " + + " join m_client c on c.id = l.client_id "
" join m_office o on o.id = c.office_id and o.hierarchy like '" + + " join m_office o on o.id = c.office_id and o.hierarchy like '"
currentUser.getOffice().getHierarchy() + "%'" + + currentUser.getOffice().getHierarchy()
" where l.id = " + appTableId + ")" + + "%'"
" union all " + + " where l.id = "
" (select o.id as officeId, l.group_id as groupId, l.client_id as clientId, null as savingsId, l.id as loanId from m_loan l " + + appTableId
" join m_group g on g.id = l.group_id " + + ")"
" join m_office o on o.id = g.office_id and o.hierarchy like '" + + " union all "
currentUser.getOffice().getHierarchy() + "%'" + + " (select o.id as officeId, l.group_id as groupId, l.client_id as clientId, null as savingsId, l.id as loanId from m_loan l "
" where l.id = " + appTableId + ")" + + " join m_group g on g.id = l.group_id " + " join m_office o on o.id = g.office_id and o.hierarchy like '"
" ) x"; + currentUser.getOffice().getHierarchy() + "%'" + " where l.id = " + appTableId + ")" + " ) x";
} }
if (appTable.equalsIgnoreCase("m_savings_account")) { if (appTable.equalsIgnoreCase("m_savings_account")) {
scopedSQL = "select distinctrow x.* from (" + scopedSQL = "select distinctrow x.* from ("
" (select o.id as officeId, s.group_id as groupId, s.client_id as clientId, s.id as savingsId, null as loanId from m_savings_account s " + + " (select o.id as officeId, s.group_id as groupId, s.client_id as clientId, s.id as savingsId, null as loanId from m_savings_account s "
" join m_client c on c.id = s.client_id " + + " join m_client c on c.id = s.client_id "
" join m_office o on o.id = c.office_id and o.hierarchy like '" + + " join m_office o on o.id = c.office_id and o.hierarchy like '"
currentUser.getOffice().getHierarchy() + "%'" + + currentUser.getOffice().getHierarchy()
" where s.id = " + appTableId+ ")" + + "%'"
" union all " + + " where s.id = "
" (select o.id as officeId, s.group_id as groupId, s.client_id as clientId, s.id as savingsId, null as loanId from m_savings_account s " + + appTableId
" join m_group g on g.id = s.group_id " + + ")"
" join m_office o on o.id = g.office_id and o.hierarchy like '" + + " union all "
currentUser.getOffice().getHierarchy() + "%'" + + " (select o.id as officeId, s.group_id as groupId, s.client_id as clientId, s.id as savingsId, null as loanId from m_savings_account s "
" where s.id = " + appTableId+ ")" + + " join m_group g on g.id = s.group_id " + " join m_office o on o.id = g.office_id and o.hierarchy like '"
" ) x"; + currentUser.getOffice().getHierarchy() + "%'" + " where s.id = " + appTableId + ")" + " ) x";
} }
if (appTable.equalsIgnoreCase("m_client")) { if (appTable.equalsIgnoreCase("m_client")) {
scopedSQL = "select o.id as officeId, null as groupId, c.id as clientId, null as savingsId, null as loanId from m_client c " + scopedSQL = "select o.id as officeId, null as groupId, c.id as clientId, null as savingsId, null as loanId from m_client c "
" join m_office o on o.id = c.office_id and o.hierarchy like '" + + " join m_office o on o.id = c.office_id and o.hierarchy like '" + currentUser.getOffice().getHierarchy() + "%'"
currentUser.getOffice().getHierarchy() + "%'" + + " where c.id = " + appTableId;
" where c.id = " + appTableId;
} }
if (appTable.equalsIgnoreCase("m_group")) { if (appTable.equalsIgnoreCase("m_group")) {
scopedSQL = "select o.id as officeId, g.id as groupId, null as clientId, null as savingsId, null as loanId from m_group g " + scopedSQL = "select o.id as officeId, g.id as groupId, null as clientId, null as savingsId, null as loanId from m_group g "
" join m_office o on o.id = g.office_id and o.hierarchy like '" + + " join m_office o on o.id = g.office_id and o.hierarchy like '" + currentUser.getOffice().getHierarchy() + "%'"
currentUser.getOffice().getHierarchy() + "%'" + + " where g.id = " + appTableId;
" where g.id = " + appTableId;
} }
if (appTable.equalsIgnoreCase("m_office")) { if (appTable.equalsIgnoreCase("m_office")) {
scopedSQL = "select o.id as officeId, null as groupId, null as clientId, null as savingsId, null as loanId from m_office o " + scopedSQL = "select o.id as officeId, null as groupId, null as clientId, null as savingsId, null as loanId from m_office o "
" where o.hierarchy like '" + + " where o.hierarchy like '" + currentUser.getOffice().getHierarchy() + "%'" + " and o.id = " + appTableId;
currentUser.getOffice().getHierarchy() + "%'" +
" and o.id = " + appTableId;
} }
if (scopedSQL == null) { throw new PlatformDataIntegrityException("error.msg.invalid.dataScopeCriteria", if (scopedSQL == null) { throw new PlatformDataIntegrityException("error.msg.invalid.dataScopeCriteria", "Application Table: "
"Application Table: " + appTable + " not catered for in data Scoping"); } + appTable + " not catered for in data Scoping"); }
return scopedSQL; return scopedSQL;
@@ -923,9 +904,7 @@ logger.info("data scoped sql: " + sql);
if (key.equals(grs.getColumnHeaders().get(i).getColumnName())) { if (key.equals(grs.getColumnHeaders().get(i).getColumnName())) {
columnValue = columnValues.get(i); columnValue = columnValues.get(i);
if (notTheSame(columnValue, keyValue, colType)) { if (notTheSame(columnValue, keyValue, colType)) { return true; }
return true;
}
return false; return false;
} }
} }
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public <!--
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this file, License, v. 2.0. If a copy of the MPL was not distributed with this file,
You can obtain one at http://mozilla.org/MPL/2.0/. --> You can obtain one at http://mozilla.org/MPL/2.0/.
-->
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">