-
Notifications
You must be signed in to change notification settings - Fork 2.6k
commit for FINERACT-46 (Throw an exception if staff to be deactivated is attached to an entity with status enum id not equal to 600) #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,10 +27,36 @@ public interface StaffRepository extends JpaRepository<Staff, Long>, JpaSpecific | |
|
|
||
| public final static String FIND_BY_OFFICE_QUERY = "select s from Staff s where s.id = :id AND s.office.id = :officeId"; | ||
|
|
||
| public final static String IS_ANY_ACTIVE_ENTITY_ASSOCIATED_WITH_STAFF_QUERY = "select " + | ||
| "case when (sum(total) > 0) then true else false end " + | ||
| "from (" + | ||
| "(select count(mg.id) as total " + | ||
| "from m_staff ms " + | ||
| "join m_group mg on mg.staff_id = ms.id " + | ||
| "where ms.id = :staffId " + | ||
| "and mg.status_enum in (100,300)) " + | ||
| "union all " + | ||
| "(select count(ml.id) as total " + | ||
| "from m_loan ml " + | ||
| "join m_staff ms on ml.loan_officer_id = ms.id " + | ||
| "where ms.id = :staffId " + | ||
| "and ml.loan_status_id in (100,200,300,700)) " + | ||
| "union all " + | ||
| "(select count(msa.id) as total " + | ||
| "from m_savings_account msa " + | ||
| "join m_staff ms on msa.field_officer_id = ms.id " + | ||
| "where ms.id = :staffId and " + | ||
| "msa.status_enum in (100,300))) as t1 "; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Client and share accounts not checked. |
||
| /** | ||
| * Find staff by officeid. | ||
| */ | ||
| @Query(FIND_BY_OFFICE_QUERY) | ||
| public Staff findByOffice(@Param("id") Long id, @Param("officeId") Long officeId); | ||
|
|
||
| } | ||
| /** | ||
| * Query finds if a staff is attached to active, pending group or loans or savings | ||
| */ | ||
| @Query(value=IS_ANY_ACTIVE_ENTITY_ASSOCIATED_WITH_STAFF_QUERY, nativeQuery = true) | ||
| public boolean isAnyActiveEntityAssociatedWithStaff(@Param("staffId") Long staffId); | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
...a/org/apache/fineract/organisation/staff/exception/StaffCannotBeDeactivatedException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * 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.staff.exception; | ||
|
|
||
| import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException; | ||
|
|
||
| public class StaffCannotBeDeactivatedException extends AbstractPlatformDomainRuleException { | ||
| private static final long serialVersionUID = -4991377873402585935L; | ||
|
|
||
| public StaffCannotBeDeactivatedException(final Long id) { | ||
| super("error.mgs.staff.cannot.be.deactivated", "Staff with identifier " + id + " cannot be deactivated."); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
| import org.apache.fineract.organisation.office.exception.OfficeNotFoundException; | ||
| import org.apache.fineract.organisation.staff.domain.Staff; | ||
| import org.apache.fineract.organisation.staff.domain.StaffRepository; | ||
| import org.apache.fineract.organisation.staff.exception.StaffCannotBeDeactivatedException; | ||
| import org.apache.fineract.organisation.staff.exception.StaffNotFoundException; | ||
| import org.apache.fineract.organisation.staff.serialization.StaffCommandFromApiJsonDeserializer; | ||
| import org.slf4j.Logger; | ||
|
|
@@ -91,6 +92,17 @@ public CommandProcessingResult updateStaff(final Long staffId, final JsonCommand | |
|
|
||
| final Staff staffForUpdate = this.staffRepository.findOne(staffId); | ||
| if (staffForUpdate == null) { throw new StaffNotFoundException(staffId); } | ||
|
|
||
| final boolean isActive = command.booleanPrimitiveValueOfParameterNamed("isActive"); | ||
|
|
||
| if(staffForUpdate.isActive() && !isActive) { | ||
| final boolean isAnyActiveEntityAssociatedWithStaff = this.staffRepository. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use StaffReadPlatformService instead of repository |
||
| isAnyActiveEntityAssociatedWithStaff(staffId); | ||
|
|
||
| if (isAnyActiveEntityAssociatedWithStaff) { | ||
| throw new StaffCannotBeDeactivatedException(staffId); | ||
| } | ||
| } | ||
|
|
||
| final Map<String, Object> changesOnly = staffForUpdate.update(command); | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding a native query in StaffRepository, add new method in StaffReadPlatformService and use JDBC template to run this query