feat: implement teller creation limit and soft delete with cashier check bypass
This commit is contained in:
+11
@@ -76,6 +76,9 @@ public class Teller extends AbstractPersistableCustom<Long> {
|
||||
@Column(name = "state", nullable = false)
|
||||
private Integer status;
|
||||
|
||||
@Column(name = "is_deleted", nullable = false)
|
||||
private boolean deleted = false;
|
||||
|
||||
@OneToMany(mappedBy = "teller", fetch = FetchType.LAZY)
|
||||
private Set<Cashier> cashiers;
|
||||
|
||||
@@ -161,4 +164,12 @@ public class Teller extends AbstractPersistableCustom<Long> {
|
||||
this.office.getId();
|
||||
this.cashiers.size();
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
this.deleted = true;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return this.deleted;
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -31,4 +31,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
public interface TellerRepository extends JpaRepository<Teller, Long>, JpaSpecificationExecutor<Teller> {
|
||||
|
||||
Collection<Teller> findTellerByOfficeId(Long officeId);
|
||||
|
||||
long countByDeletedFalse();
|
||||
}
|
||||
|
||||
+7
@@ -36,6 +36,9 @@ public class TellerRepositoryWrapper {
|
||||
@Transactional(readOnly = true)
|
||||
public Teller findOneWithNotFoundDetection(final Long id) {
|
||||
final Teller teller = this.repository.findById(id).orElseThrow(() -> new TellerNotFoundException(id));
|
||||
if (teller.isDeleted()) {
|
||||
throw new TellerNotFoundException(id);
|
||||
}
|
||||
teller.initializeLazyCollections();
|
||||
return teller;
|
||||
}
|
||||
@@ -51,4 +54,8 @@ public class TellerRepositoryWrapper {
|
||||
public void delete(final Teller teller) {
|
||||
this.repository.delete(teller);
|
||||
}
|
||||
|
||||
public boolean existsAny() {
|
||||
return this.repository.countByDeletedFalse() > 0;
|
||||
}
|
||||
}
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.organisation.teller.exception;
|
||||
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException;
|
||||
|
||||
public class TellerAlreadyExistsException extends AbstractPlatformDomainRuleException {
|
||||
|
||||
private static final String ERROR_MESSAGE_CODE = "error.msg.teller.already.exists";
|
||||
private static final String DEFAULT_ERROR_MESSAGE = "Cannot create teller as a teller is already present.";
|
||||
|
||||
public TellerAlreadyExistsException() {
|
||||
super(ERROR_MESSAGE_CODE, DEFAULT_ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -120,7 +120,7 @@ public class TellerManagementReadPlatformServiceImpl implements TellerManagement
|
||||
|
||||
try {
|
||||
final TellerMapper tm = new TellerMapper();
|
||||
final String sql = "select " + tm.schema() + " where t.id = ?";
|
||||
final String sql = "select " + tm.schema() + " where t.id = ? and t.is_deleted = false";
|
||||
|
||||
return this.jdbcTemplate.queryForObject(sql, tm, new Object[] { tellerId }); // NOSONAR
|
||||
} catch (final EmptyResultDataAccessException e) {
|
||||
@@ -198,7 +198,7 @@ public class TellerManagementReadPlatformServiceImpl implements TellerManagement
|
||||
hierarchySearchString = hierarchy + "%";
|
||||
}
|
||||
final TellerMapper tm = new TellerMapper();
|
||||
final String sql = "select " + tm.schema() + "where o.hierarchy like ? order by o.hierarchy";
|
||||
final String sql = "select " + tm.schema() + "where o.hierarchy like ? and t.is_deleted = false order by o.hierarchy";
|
||||
|
||||
return this.jdbcTemplate.query(sql, tm, new Object[] { hierarchySearchString }); // NOSONAR
|
||||
}
|
||||
|
||||
+7
-12
@@ -46,6 +46,7 @@ import org.apache.fineract.organisation.teller.domain.Teller;
|
||||
import org.apache.fineract.organisation.teller.domain.TellerRepositoryWrapper;
|
||||
import org.apache.fineract.organisation.teller.exception.CashierExistForTellerException;
|
||||
import org.apache.fineract.organisation.teller.exception.CashierNotFoundException;
|
||||
import org.apache.fineract.organisation.teller.exception.TellerAlreadyExistsException;
|
||||
import org.apache.fineract.organisation.teller.serialization.TellerCommandFromApiJsonDeserializer;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
@@ -71,6 +72,10 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
|
||||
try {
|
||||
this.context.authenticatedUser();
|
||||
|
||||
if (this.tellerRepositoryWrapper.existsAny()) {
|
||||
throw new TellerAlreadyExistsException();
|
||||
}
|
||||
|
||||
final Long officeId = command.longValueOfParameterNamed("officeId");
|
||||
|
||||
this.fromApiJsonDeserializer.validateForCreateAndUpdateTeller(command.json());
|
||||
@@ -152,22 +157,12 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer
|
||||
@Override
|
||||
@Transactional
|
||||
public CommandProcessingResult deleteTeller(Long tellerId) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
Teller teller = tellerRepositoryWrapper.findOneWithNotFoundDetection(tellerId);
|
||||
Set<Cashier> isTellerIdPresentInCashier = teller.getCashiers();
|
||||
|
||||
for (final Cashier tellerIdInCashier : isTellerIdPresentInCashier) {
|
||||
if (tellerIdInCashier.getTeller().getId().toString().equalsIgnoreCase(tellerId.toString())) {
|
||||
throw new CashierExistForTellerException(tellerId);
|
||||
}
|
||||
|
||||
}
|
||||
tellerRepositoryWrapper.delete(teller);
|
||||
teller.delete();
|
||||
tellerRepositoryWrapper.saveAndFlush(teller);
|
||||
return new CommandProcessingResultBuilder() //
|
||||
.withEntityId(teller.getId()) //
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -365,4 +365,5 @@
|
||||
<include file="parts/0335_create_bank_transfer_log.xml" relativeToChangelogFile="true"/>
|
||||
<include file="parts/0336_add_request_type_to_clerk_disbursement.xml" relativeToChangelogFile="true"/>
|
||||
<include file="parts/0337_create_election_module.xml" relativeToChangelogFile="true"/>
|
||||
<include file="parts/0338_add_soft_delete_to_tellers.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
-->
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
|
||||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">
|
||||
|
||||
<changeSet id="0338_add_soft_delete_to_tellers" author="fineract">
|
||||
<preConditions onFail="MARK_RAN">
|
||||
<and>
|
||||
<tableExists tableName="m_tellers"/>
|
||||
<not><columnExists tableName="m_tellers" columnName="is_deleted"/></not>
|
||||
</and>
|
||||
</preConditions>
|
||||
<addColumn tableName="m_tellers">
|
||||
<column name="is_deleted" type="boolean" defaultValueBoolean="false">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
Reference in New Issue
Block a user