class DBService implements RolesProvider {

    List<RoleMember> applyMembershipChanges(Role updatedRole, Role originalRole, Role role, String auditRef) {

        Map<String, RoleMember> incomingMemberMap =
                role.getRoleMembers().stream().collect(Collectors.toMap(RoleMember::getMemberName, item -> item));

        List<RoleMember> noActionMembers = new ArrayList<>(originalRole.getRoleMembers().size());

        // updatedMembers size is driven by input

        List<RoleMember> updatedMembers = new ArrayList<>(incomingMemberMap.size());
        updatedRole.setRoleMembers(updatedMembers);
        RoleMember updatedMember;

        // if original role is auditEnabled then all the extensions should be sent for approval again.

        boolean approvalStatus = originalRole.getAuditEnabled() != Boolean.TRUE;
        RoleMember tempMemberFromMap;

        for (RoleMember originalMember : originalRole.getRoleMembers()) {

            // we are only going to update the changed members

            if (incomingMemberMap.containsKey(originalMember.getMemberName())) {

                updatedMember = new RoleMember();
                updatedMember.setMemberName(originalMember.getMemberName());

                tempMemberFromMap = incomingMemberMap.get(updatedMember.getMemberName());

                // member's approval status is determined by auditEnabled flag set on original role

                updatedMember.setApproved(approvalStatus);

                // member's active status is determined by action taken in UI

                updatedMember.setActive(tempMemberFromMap.getActive());

                // member's new expiration is set by role / domain level expiration setting

                updatedMember.setExpiration(tempMemberFromMap.getExpiration());

                updatedMember.setAuditRef(auditRef);
                updatedMembers.add(updatedMember);
            } else {
                noActionMembers.add(originalMember);
            }
        }
        return noActionMembers;
    }

    public  DBService(ObjectStore store, AuditLogger auditLogger, ZMSConfig zmsConfig, AuditReferenceValidator auditReferenceValidator);

}