MIFOSX-365: formatting and add license to files without it.
This commit is contained in:
+9
-3
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -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 {
|
||||||
|
|||||||
+11
-6
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
@@ -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;
|
||||||
|
|||||||
+5
@@ -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;
|
||||||
|
|||||||
+5
@@ -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;
|
||||||
|
|||||||
+5
@@ -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;
|
||||||
|
|||||||
+5
@@ -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;
|
||||||
|
|||||||
+5
@@ -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;
|
||||||
|
|||||||
+5
-5
@@ -28,13 +28,13 @@ public class UpdateDatatableCommandHandler implements NewCommandSourceHandler {
|
|||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult processCommand(final JsonCommand command) {
|
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||||
|
|
||||||
final String datatableName = command.getUrl().replaceAll("/datatables/", "");
|
final String datatableName = command.getUrl().replaceAll("/datatables/", "");
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+245
-266
@@ -56,12 +56,18 @@ import com.google.gson.reflect.TypeToken;
|
|||||||
@Service
|
@Service
|
||||||
public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataService {
|
public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataService {
|
||||||
|
|
||||||
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); }
|
||||||
@@ -234,7 +238,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
|
|
||||||
final String deleteRegisteredDatatableSql = "delete from x_registered_table where registered_table_name = '" + datatable + "'";
|
final String deleteRegisteredDatatableSql = "delete from x_registered_table where registered_table_name = '" + datatable + "'";
|
||||||
|
|
||||||
String[] sqlArray = {deleteRolePermissionsSql, deletePermissionsSql, deleteRegisteredDatatableSql};
|
String[] sqlArray = { deleteRolePermissionsSql, deletePermissionsSql, deleteRegisteredDatatableSql };
|
||||||
this.jdbcTemplate.batchUpdate(sqlArray);
|
this.jdbcTemplate.batchUpdate(sqlArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,256 +287,237 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
|
|
||||||
private Boolean datatableExists(final String datatable) {
|
private Boolean datatableExists(final String datatable) {
|
||||||
|
|
||||||
String sql = "SELECT COUNT(*) FROM `x_registered_table` WHERE `registered_table_name`='" + datatable + "'";
|
String sql = "SELECT COUNT(*) FROM `x_registered_table` WHERE `registered_table_name`='" + datatable + "'";
|
||||||
Integer rowCount = this.jdbcTemplate.queryForInt(sql);
|
Integer rowCount = this.jdbcTemplate.queryForInt(sql);
|
||||||
|
|
||||||
return (rowCount > 0);
|
return (rowCount > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
|
||||||
String name = (column.has("name")) ? column.get("name").getAsString() : null;
|
String name = (column.has("name")) ? column.get("name").getAsString() : null;
|
||||||
String type = (column.has("type")) ? column.get("type").getAsString() : null;
|
String type = (column.has("type")) ? column.get("type").getAsString() : null;
|
||||||
Integer length = (column.has("length")) ? column.get("length").getAsInt() : null;
|
Integer length = (column.has("length")) ? column.get("length").getAsInt() : null;
|
||||||
Boolean mandatory = (column.has("mandatory")) ? column.get("mandatory").getAsBoolean() : false;
|
Boolean mandatory = (column.has("mandatory")) ? column.get("mandatory").getAsBoolean() : false;
|
||||||
|
|
||||||
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")) {
|
sqlBuilder = sqlBuilder.append("(19,6)");
|
||||||
sqlBuilder = sqlBuilder.append("(19,6)");
|
}
|
||||||
}
|
}
|
||||||
}
|
if (mandatory != null) {
|
||||||
if (mandatory != null) {
|
if (mandatory) {
|
||||||
if (mandatory) {
|
sqlBuilder = sqlBuilder.append(" NOT NULL");
|
||||||
sqlBuilder = sqlBuilder.append(" NOT NULL");
|
} else {
|
||||||
} else {
|
sqlBuilder = sqlBuilder.append(" DEFAULT NULL");
|
||||||
sqlBuilder = sqlBuilder.append(" DEFAULT NULL");
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
sqlBuilder = sqlBuilder.append(", ");
|
sqlBuilder = sqlBuilder.append(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult createDatatable(final JsonCommand command) {
|
public CommandProcessingResult createDatatable(final JsonCommand command) {
|
||||||
|
|
||||||
context.authenticatedUser();
|
context.authenticatedUser();
|
||||||
this.fromApiJsonDeserializer.validateForCreate(command.json());
|
this.fromApiJsonDeserializer.validateForCreate(command.json());
|
||||||
|
|
||||||
JsonElement element = this.fromJsonHelper.parse(command.json());
|
JsonElement element = this.fromJsonHelper.parse(command.json());
|
||||||
JsonArray columns = this.fromJsonHelper.extractJsonArrayNamed("columns", element);
|
JsonArray columns = this.fromJsonHelper.extractJsonArrayNamed("columns", element);
|
||||||
String datatableName = this.fromJsonHelper.extractStringNamed("datatableName", element);
|
String datatableName = this.fromJsonHelper.extractStringNamed("datatableName", element);
|
||||||
String apptable = this.fromJsonHelper.extractStringNamed("apptableName", element);
|
String apptable = this.fromJsonHelper.extractStringNamed("apptableName", element);
|
||||||
Boolean multiRow = this.fromJsonHelper.extractBooleanNamed("multiRow", element);
|
Boolean multiRow = this.fromJsonHelper.extractBooleanNamed("multiRow", element);
|
||||||
|
|
||||||
if (multiRow == null) {
|
if (multiRow == null) {
|
||||||
multiRow = false;
|
multiRow = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
validateDatatableName(datatableName);
|
validateDatatableName(datatableName);
|
||||||
validateDatatableName(apptable);
|
validateDatatableName(apptable);
|
||||||
validateDatatableNotExists(datatableName);
|
validateDatatableNotExists(datatableName);
|
||||||
|
|
||||||
String fkColumnName = apptable.substring(2) + "_id";
|
String fkColumnName = apptable.substring(2) + "_id";
|
||||||
String fkName = datatableName.toLowerCase().replaceAll("\\s", "_");
|
String fkName = datatableName.toLowerCase().replaceAll("\\s", "_");
|
||||||
StringBuilder sqlBuilder = new StringBuilder();
|
StringBuilder sqlBuilder = new StringBuilder();
|
||||||
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.append("`" + fkColumnName + "` BIGINT(20) NOT NULL, ");
|
||||||
sqlBuilder = sqlBuilder
|
}
|
||||||
.append("`" + fkColumnName + "` BIGINT(20) NOT NULL, ");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (JsonElement column : columns) {
|
for (JsonElement column : columns) {
|
||||||
parseDatatableColumnObjectForCreate(column.getAsJsonObject(), sqlBuilder);
|
parseDatatableColumnObjectForCreate(column.getAsJsonObject(), sqlBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove trailing comma and space
|
// Remove trailing comma and space
|
||||||
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("REFERENCES `" + apptable + "` (`id`)");
|
||||||
.append(", CONSTRAINT `fk_" + fkName + "` ")
|
|
||||||
.append("FOREIGN KEY (`" + fkColumnName + "`) ")
|
|
||||||
.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;");
|
||||||
this.jdbcTemplate.execute(sqlBuilder.toString());
|
this.jdbcTemplate.execute(sqlBuilder.toString());
|
||||||
|
|
||||||
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) {
|
||||||
|
|
||||||
String name = (column.has("name")) ? column.get("name").getAsString() : null;
|
String name = (column.has("name")) ? column.get("name").getAsString() : null;
|
||||||
String newName = (column.has("newName")) ? column.get("newName").getAsString() : name;
|
String newName = (column.has("newName")) ? column.get("newName").getAsString() : name;
|
||||||
String type = (column.has("type")) ? column.get("type").getAsString() : null;
|
String type = (column.has("type")) ? column.get("type").getAsString() : null;
|
||||||
Integer length = (column.has("length")) ? column.get("length").getAsInt() : null;
|
Integer length = (column.has("length")) ? column.get("length").getAsInt() : null;
|
||||||
Boolean mandatory = (column.has("mandatory")) ? column.get("mandatory").getAsBoolean() : false;
|
Boolean mandatory = (column.has("mandatory")) ? column.get("mandatory").getAsBoolean() : false;
|
||||||
String after = (column.has("after")) ? column.get("after").getAsString() : null;
|
String after = (column.has("after")) ? column.get("after").getAsString() : null;
|
||||||
|
|
||||||
String mysqlType = apiTypeToMySQL.get(type);
|
String mysqlType = apiTypeToMySQL.get(type);
|
||||||
sqlBuilder = sqlBuilder.append(", CHANGE `" + name + "` `" + newName + "` " + mysqlType);
|
sqlBuilder = sqlBuilder.append(", CHANGE `" + name + "` `" + newName + "` " + mysqlType);
|
||||||
|
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
if (type.equals("String") && length != null) {
|
if (type.equals("String") && length != null) {
|
||||||
sqlBuilder = sqlBuilder.append("(" + length + ")");
|
sqlBuilder = sqlBuilder.append("(" + length + ")");
|
||||||
} else if (type.equals("Decimal")) {
|
} else if (type.equals("Decimal")) {
|
||||||
sqlBuilder = sqlBuilder.append("(19,6)");
|
sqlBuilder = sqlBuilder.append("(19,6)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mandatory != null) {
|
if (mandatory != null) {
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
sqlBuilder = sqlBuilder.append(" NOT NULL");
|
sqlBuilder = sqlBuilder.append(" NOT NULL");
|
||||||
} else {
|
} else {
|
||||||
sqlBuilder = sqlBuilder.append(" DEFAULT NULL");
|
sqlBuilder = sqlBuilder.append(" DEFAULT NULL");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (after != null) {
|
if (after != null) {
|
||||||
sqlBuilder = sqlBuilder.append(" AFTER `" + after + "`");
|
sqlBuilder = sqlBuilder.append(" AFTER `" + after + "`");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseDatatableColumnForAdd(final JsonObject column, StringBuilder sqlBuilder) {
|
private void parseDatatableColumnForAdd(final JsonObject column, StringBuilder sqlBuilder) {
|
||||||
|
|
||||||
String name = (column.has("name")) ? column.get("name").getAsString() : null;
|
String name = (column.has("name")) ? column.get("name").getAsString() : null;
|
||||||
String type = (column.has("type")) ? column.get("type").getAsString() : null;
|
String type = (column.has("type")) ? column.get("type").getAsString() : null;
|
||||||
Integer length = (column.has("length")) ? column.get("length").getAsInt() : null;
|
Integer length = (column.has("length")) ? column.get("length").getAsInt() : null;
|
||||||
Boolean mandatory = (column.has("mandatory")) ? column.get("mandatory").getAsBoolean() : false;
|
Boolean mandatory = (column.has("mandatory")) ? column.get("mandatory").getAsBoolean() : false;
|
||||||
String after = (column.has("after")) ? column.get("after").getAsString() : null;
|
String after = (column.has("after")) ? column.get("after").getAsString() : null;
|
||||||
|
|
||||||
String mysqlType = apiTypeToMySQL.get(type);
|
String mysqlType = apiTypeToMySQL.get(type);
|
||||||
sqlBuilder = sqlBuilder.append(", ADD `" + name + "` " + mysqlType);
|
sqlBuilder = sqlBuilder.append(", ADD `" + name + "` " + mysqlType);
|
||||||
|
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
if (type.equals("String") && length != null) {
|
if (type.equals("String") && length != null) {
|
||||||
sqlBuilder = sqlBuilder.append("(" + length + ")");
|
sqlBuilder = sqlBuilder.append("(" + length + ")");
|
||||||
} else if (type.equals("Decimal")) {
|
} else if (type.equals("Decimal")) {
|
||||||
sqlBuilder = sqlBuilder.append("(19,6)");
|
sqlBuilder = sqlBuilder.append("(19,6)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mandatory != null) {
|
if (mandatory != null) {
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
sqlBuilder = sqlBuilder.append(" NOT NULL");
|
sqlBuilder = sqlBuilder.append(" NOT NULL");
|
||||||
} else {
|
} else {
|
||||||
sqlBuilder = sqlBuilder.append(" DEFAULT NULL");
|
sqlBuilder = sqlBuilder.append(" DEFAULT NULL");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (after != null) {
|
if (after != null) {
|
||||||
sqlBuilder = sqlBuilder.append(" AFTER `" + after + "`");
|
sqlBuilder = sqlBuilder.append(" AFTER `" + after + "`");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseDatatableColumnForDrop(final JsonObject column, StringBuilder sqlBuilder) {
|
private void parseDatatableColumnForDrop(final JsonObject column, StringBuilder sqlBuilder) {
|
||||||
|
|
||||||
String name = (column.has("name")) ? column.get("name").getAsString() : null;
|
String name = (column.has("name")) ? column.get("name").getAsString() : null;
|
||||||
|
|
||||||
sqlBuilder = sqlBuilder.append(", DROP COLUMN `" + name + "`");
|
sqlBuilder = sqlBuilder.append(", DROP COLUMN `" + name + "`");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public void updateDatatable(final String datatableName, final JsonCommand command) {
|
public void updateDatatable(final String datatableName, final JsonCommand command) {
|
||||||
|
|
||||||
context.authenticatedUser();
|
context.authenticatedUser();
|
||||||
this.fromApiJsonDeserializer.validateForUpdate(command.json());
|
this.fromApiJsonDeserializer.validateForUpdate(command.json());
|
||||||
|
|
||||||
JsonElement element = this.fromJsonHelper.parse(command.json());
|
JsonElement element = this.fromJsonHelper.parse(command.json());
|
||||||
JsonArray changeColumns = this.fromJsonHelper.extractJsonArrayNamed("changeColumns", element);
|
JsonArray changeColumns = this.fromJsonHelper.extractJsonArrayNamed("changeColumns", element);
|
||||||
JsonArray addColumns = this.fromJsonHelper.extractJsonArrayNamed("addColumns", element);
|
JsonArray addColumns = this.fromJsonHelper.extractJsonArrayNamed("addColumns", element);
|
||||||
JsonArray dropColumns = this.fromJsonHelper.extractJsonArrayNamed("dropColumns", element);
|
JsonArray dropColumns = this.fromJsonHelper.extractJsonArrayNamed("dropColumns", element);
|
||||||
|
|
||||||
validateDatatableName(datatableName);
|
validateDatatableName(datatableName);
|
||||||
validateDatatableExists(datatableName);
|
validateDatatableExists(datatableName);
|
||||||
|
|
||||||
StringBuilder sqlBuilder = new StringBuilder("ALTER TABLE `" + datatableName + "`");
|
StringBuilder sqlBuilder = new StringBuilder("ALTER TABLE `" + datatableName + "`");
|
||||||
|
|
||||||
for (JsonElement column : changeColumns) {
|
for (JsonElement column : changeColumns) {
|
||||||
parseDatatableColumnForUpdate(column.getAsJsonObject(), sqlBuilder);
|
parseDatatableColumnForUpdate(column.getAsJsonObject(), sqlBuilder);
|
||||||
}
|
}
|
||||||
for (JsonElement column : addColumns) {
|
for (JsonElement column : addColumns) {
|
||||||
parseDatatableColumnForAdd(column.getAsJsonObject(), sqlBuilder);
|
parseDatatableColumnForAdd(column.getAsJsonObject(), sqlBuilder);
|
||||||
}
|
}
|
||||||
for (JsonElement column : dropColumns) {
|
for (JsonElement column : dropColumns) {
|
||||||
parseDatatableColumnForDrop(column.getAsJsonObject(), sqlBuilder);
|
parseDatatableColumnForDrop(column.getAsJsonObject(), sqlBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the first comma, right after ALTER TABLE `datatable`
|
// Remove the first comma, right after ALTER TABLE `datatable`
|
||||||
sqlBuilder = sqlBuilder.deleteCharAt(sqlBuilder.indexOf(","));
|
sqlBuilder = sqlBuilder.deleteCharAt(sqlBuilder.indexOf(","));
|
||||||
this.jdbcTemplate.execute(sqlBuilder.toString());
|
this.jdbcTemplate.execute(sqlBuilder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public void deleteDatatable(final String datatableName) {
|
public void deleteDatatable(final String datatableName) {
|
||||||
|
|
||||||
context.authenticatedUser();
|
context.authenticatedUser();
|
||||||
|
|
||||||
validateDatatableName(datatableName);
|
validateDatatableName(datatableName);
|
||||||
validateDatatableExists(datatableName);
|
validateDatatableExists(datatableName);
|
||||||
deregisterDatatable(datatableName);
|
deregisterDatatable(datatableName);
|
||||||
|
|
||||||
String sql = "DROP TABLE `" + datatableName + "`";
|
String sql = "DROP TABLE `" + datatableName + "`";
|
||||||
this.jdbcTemplate.execute(sql);
|
this.jdbcTemplate.execute(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult updateDatatableEntryOneToOne(final String dataTableName, final Long appTableId, final JsonCommand command) {
|
public CommandProcessingResult updateDatatableEntryOneToOne(final String dataTableName, final Long appTableId, final JsonCommand command) {
|
||||||
|
|
||||||
return updateDatatableEntry(dataTableName, appTableId, null, command);
|
return updateDatatableEntry(dataTableName, appTableId, null, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -540,10 +525,9 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
public CommandProcessingResult updateDatatableEntryOneToMany(final String dataTableName, final Long appTableId, final Long datatableId,
|
public CommandProcessingResult updateDatatableEntryOneToMany(final String dataTableName, final Long appTableId, final Long datatableId,
|
||||||
final JsonCommand command) {
|
final JsonCommand command) {
|
||||||
|
|
||||||
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) {
|
||||||
|
|
||||||
@@ -560,14 +544,18 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
final Type typeOfMap = new TypeToken<Map<String, String>>() {}.getType();
|
final Type typeOfMap = new TypeToken<Map<String, String>>() {}.getType();
|
||||||
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)) {
|
||||||
@@ -575,21 +563,20 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
changes.put("locale", dataParams.get("locale"));
|
changes.put("locale", dataParams.get("locale"));
|
||||||
changes.put("dateFormat", "yyyy-MM-dd");
|
changes.put("dateFormat", "yyyy-MM-dd");
|
||||||
} else {
|
} else {
|
||||||
logger.info("No Changes");
|
logger.info("No Changes");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CommandProcessingResultBuilder() //
|
return new CommandProcessingResultBuilder() //
|
||||||
.withOfficeId(commandProcessingResult.getOfficeId()) //
|
.withOfficeId(commandProcessingResult.getOfficeId()) //
|
||||||
.withGroupId(commandProcessingResult.getGroupId()) //
|
.withGroupId(commandProcessingResult.getGroupId()) //
|
||||||
.withClientId(commandProcessingResult.getClientId()) //
|
.withClientId(commandProcessingResult.getClientId()) //
|
||||||
.withSavingsId(commandProcessingResult.getSavingsId()) //
|
.withSavingsId(commandProcessingResult.getSavingsId()) //
|
||||||
.withLoanId(commandProcessingResult.getLoanId()) //
|
.withLoanId(commandProcessingResult.getLoanId()) //
|
||||||
.with(changes) //
|
.with(changes) //
|
||||||
.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);
|
||||||
|
|
||||||
@@ -671,7 +656,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
private CommandProcessingResult checkMainResourceExistsWithinScope(final String appTable, final Long appTableId) {
|
private CommandProcessingResult checkMainResourceExistsWithinScope(final String appTable, final Long appTableId) {
|
||||||
|
|
||||||
final String sql = dataScopedSQL(appTable, appTableId);
|
final String sql = dataScopedSQL(appTable, appTableId);
|
||||||
logger.info("data scoped sql: " + sql);
|
logger.info("data scoped sql: " + sql);
|
||||||
final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);
|
final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);
|
||||||
|
|
||||||
if (!rs.next()) { throw new DatatableNotFoundException(appTable, appTableId); }
|
if (!rs.next()) { throw new DatatableNotFoundException(appTable, appTableId); }
|
||||||
@@ -685,86 +670,82 @@ logger.info("data scoped sql: " + sql);
|
|||||||
if (rs.next()) { throw new DatatableSystemErrorException("System Error: More than one row returned from data scoping query"); }
|
if (rs.next()) { throw new DatatableSystemErrorException("System Error: More than one row returned from data scoping query"); }
|
||||||
|
|
||||||
return new CommandProcessingResultBuilder() //
|
return new CommandProcessingResultBuilder() //
|
||||||
.withOfficeId(officeId) //
|
.withOfficeId(officeId) //
|
||||||
.withGroupId(groupId) //
|
.withGroupId(groupId) //
|
||||||
.withClientId(clientId) //
|
.withClientId(clientId) //
|
||||||
.withSavingsId(savingsId) //
|
.withSavingsId(savingsId) //
|
||||||
.withLoanId(LoanId) //
|
.withLoanId(LoanId) //
|
||||||
.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
|
<!--
|
||||||
License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
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/.
|
||||||
|
-->
|
||||||
<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">
|
||||||
|
|||||||
Reference in New Issue
Block a user