Merge pull request #394 from mifoscontributer/MIFOSX-480
Allow assign parent office staff to group
This commit is contained in:
@@ -162,4 +162,8 @@ public class Staff extends AbstractPersistable<Long> {
|
|||||||
public String displayName() {
|
public String displayName() {
|
||||||
return this.displayName;
|
return this.displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Office office() {
|
||||||
|
return this.office;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
-2
@@ -20,7 +20,5 @@ public interface StaffRepository extends JpaRepository<Staff, Long>,
|
|||||||
*/
|
*/
|
||||||
@Query(FIND_BY_OFFICE_QUERY)
|
@Query(FIND_BY_OFFICE_QUERY)
|
||||||
public Staff findByOffice(@Param("id") Long id, @Param("officeId") Long officeId);
|
public Staff findByOffice(@Param("id") Long id, @Param("officeId") Long officeId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+10
@@ -36,4 +36,14 @@ public class StaffRepositoryWrapper {
|
|||||||
if (staff == null) { throw new StaffNotFoundException(staffId); }
|
if (staff == null) { throw new StaffNotFoundException(staffId); }
|
||||||
return staff;
|
return staff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Staff findByOfficeHierarchyWithNotFoundDetection(final Long staffId, final String hierarchy) {
|
||||||
|
final Staff staff = this.repository.findOne(staffId);
|
||||||
|
if (staff == null) { throw new StaffNotFoundException(staffId); }
|
||||||
|
final String staffhierarchy = staff.office().getHierarchy();
|
||||||
|
if (!hierarchy.startsWith(staffhierarchy)) {
|
||||||
|
throw new StaffNotFoundException(staffId);
|
||||||
|
}
|
||||||
|
return staff;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -107,7 +107,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
Staff staff = null;
|
Staff staff = null;
|
||||||
final Long staffId = command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName);
|
final Long staffId = command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName);
|
||||||
if (staffId != null) {
|
if (staffId != null) {
|
||||||
staff = this.staffRepository.findByOfficeWithNotFoundDetection(staffId, officeId);
|
staff = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(staffId, groupOffice.getHierarchy());
|
||||||
}
|
}
|
||||||
|
|
||||||
final Set<Client> clientMembers = assembleSetOfClients(officeId, command);
|
final Set<Client> clientMembers = assembleSetOfClients(officeId, command);
|
||||||
@@ -228,7 +228,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
|
|
||||||
Staff newStaff = null;
|
Staff newStaff = null;
|
||||||
if (newValue != null) {
|
if (newValue != null) {
|
||||||
newStaff = this.staffRepository.findByOfficeWithNotFoundDetection(newValue, officeId);
|
newStaff = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(newValue, groupHierarchy);
|
||||||
}
|
}
|
||||||
groupForUpdate.updateStaff(newStaff);
|
groupForUpdate.updateStaff(newStaff);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user