Merge pull request #1283 from karan173/MIFOSX-1847-datatable-delete-fix
MIFOSX-1847. Deleting non empty Datatables now causes an exception
This commit is contained in:
+10
@@ -31,6 +31,7 @@ import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||
import org.mifosplatform.infrastructure.core.exception.GeneralPlatformDomainRuleException;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformServiceUnavailableException;
|
||||
@@ -966,6 +967,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
||||
this.context.authenticatedUser();
|
||||
if (!isRegisteredDataTable(datatableName)) { throw new DatatableNotFoundException(datatableName); }
|
||||
validateDatatableName(datatableName);
|
||||
assertDataTableEmpty(datatableName);
|
||||
deregisterDatatable(datatableName);
|
||||
String[] sqlArray = null;
|
||||
if (this.configurationDomainService.isConstraintApproachEnabledForDatatables()) {
|
||||
@@ -991,6 +993,14 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
||||
}
|
||||
}
|
||||
|
||||
private void assertDataTableEmpty(final String datatableName) {
|
||||
final String sql = "select count(*) from `" + datatableName + "`";
|
||||
final int rowCount = this.jdbcTemplate.queryForObject(sql, Integer.class);
|
||||
if (rowCount != 0) {
|
||||
throw new GeneralPlatformDomainRuleException("error.msg.non.empty.datatable.cannot.be.deleted", "Non-empty datatable cannot be deleted.");
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult updateDatatableEntryOneToOne(final String dataTableName, final Long appTableId, final JsonCommand command) {
|
||||
|
||||
Reference in New Issue
Block a user