This module provides a Japan postal code data and API for them. This fetches the csv file from Japan post office website and insert it into the local database table. After fetching the data, developers can make a postal code related feature such as address autofill without depending on any external service.

The project page is currently in:
https://www.drupal.org/sandbox/gh640/2501521

Git clone command:
`git clone --branch 7.x-1.x http://git.drupal.org/sandbox/gh640/2501521.git japan_postal_code`

## Features

- Fetching Japan postal code data from Japan post office website through an admin page `admin/config/services/japan-postal-code`.
- Providing 2 APIs with Japan postal code for developers after fetching the postal code data. One is an function called `japan_postal_code_get_address_by_postal_code()`. This is for backend developers. Second one is a page with path `japan-postal-code/address/%`. This is mainly for front-end developers.

## Current release state

The module is tested in my local environment repeatedly and started to be used in several other environments.

## Similar modules

- [Addressfield - Japanese Postal Code](https://www.drupal.org/project/addressfield_jp) - This module uses an external service "ajaxzip3" and provides an end-user functionality with [Address Field](https://www.drupal.org/project/addressfield) module.

## Installation and test

Installation
------------

1. Enable this module.
2. Go to the admin page `admin/config/services/japan-postal-code` and click the button in the page to fetch Japan postal code data from Japan post office website. This process takes a long time because it has large amount of data (over 100,000). Actually the file size is not so large but inserting them into the database table takes a long time.
3. Then, you can start to use the Japan postal code data with API. For detail on the API, please see below.
4. If you want, you can test this by using the below test code easily.

<form id="myform" action="">
  <input type="text" name="postalcode" id="myform-postalcode" placeholder="postal code">
  <button type="button" id="myform-autocomplete">autocomplete</button>
  <input type="text" name="address" id="myform-address" placeholder="address">
</form>

<script>
$ = jQuery;
$('#myform-autocomplete').click(function(){
  var postalcode = $('#myform-postalcode').val();
  $.getJSON('/japan-postal-code/address/' + postalcode, null, fillInAddress);
  return false;
});

function fillInAddress(data) {
  if (data.status) {
    var d = data.data;
    var address = d.prefecture + d.city + d.address_under_city + d.name;
    $('#myform-address').val(address);
  }
}
</script>

I checked the basic documentation to contribute a new module but I don't have enough experience. If this document lacks necessary information, please tell me. Thank you in advance.

Comments

hgoto’s picture

PA robot’s picture

Multiple Applications
It appears that there have been multiple project applications opened under your username:

Project 1: https://www.drupal.org/node/2501525

Project 2: https://www.drupal.org/node/2241231

As successful completion of the project application process results in the applicant being granted the 'Create Full Projects' permission, there is no need to take multiple applications through the process. Once the first application has been successfully approved, then the applicant can promote other projects without review. Because of this, posting multiple applications is not necessary, and results in additional workload for reviewers ... which in turn results in longer wait times for everyone in the queue. With this in mind, your secondary applications have been marked as 'closed(duplicate)', with only one application left open (chosen at random).

If you prefer that we proceed through this review process with a different application than the one which was left open, then feel free to close the 'open' application as a duplicate, and re-open one of the project applications which had been closed.

I'm a robot and this is an automated message from Project Applications Scraper.

PA robot’s picture

Status: Needs review » Needs work

There are some errors reported by automated review tools, did you already check them? See http://pareview.sh/pareview/httpgitdrupalorgsandboxgh6402501521git

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

hgoto’s picture

Status: Needs work » Needs review

I fixed the errors reported by PA Robot. It seems fine and I'd like someone to review this. Thank you in advance.

everright’s picture

StatusFileSize
new3.22 KB

Hi hgoto,

I have take pareview and manual review for your module.

There were no pareview issues, but found bugs, please review the patch, fix it and test again.

Please update git repository "gh640@git.drupal.org:sandbox/gh640/2501521.git" to "http://git.drupal.org/sandbox/gh640/2501521.git" in description, and the path `admin/config/services/japan-postal-code/%` of features tips may be `japan-postal-code/address/%`.

Bugs

1. Incorrect use db_transaction
2. Address table always empty when click "Clear and update postal code table", I think it should not execute if fail to get postal_codes_normal or postal_codes_special.

Suggestions

1. Add configure to japan_postal_code.info, so user can see the configuration link in module list page.
configure = admin/config/services/japan-postal-code

I will think about integrate your module, then let "addressfield_jp" to support another choice for address lookup with your module.

hgoto’s picture

Issue summary: View changes
hgoto’s picture

Hi everright.

Thank you for your kind and careful review.

I applied your patch and tested it. All the points you pointed are fixed. Also I changed the parts of document you pointed.

> I will think about integrate your module, then let "addressfield_jp" to support another choice for address lookup with your module.

Great. Thank you for that in advance. If it is achieved, a lot of users in Japan will be helped.

azeiteiro’s picture

Automated Review

Fix errors in automated review

Manual Review

* Implements hook_help()
It is recommended to get the basic understanding of the module to new users.
rajeshwari10’s picture

Hi,
Automated Review
Used Coder Module - 1 normal warnings
Manual Review
Individual user account
Yes
No duplication
Yes
Master Branch
Yes
3rd party assets/code
No,Not applicable
README.txt
Yes
Issues

  1. In admin/config/services/japan-postal-code There is no button to fetch Japan postal code data from Japan post office website
  2. When give permissions of Japan Postal Code to authenticated user error occurs: HTTP error -1 occurred when trying to fetch http://www.post.japanpost.jp/zipcode/dl/kogaki/zip/ken_all.zip.
  3. Japan postal code database table update failed.
rajeshwari10’s picture

Status: Needs review » Needs work
hgoto’s picture

@azeiteiro,

Thank you for your kind review and advice. I fixed the errors automated review and added an implementation of hook_help().

@raje1021,

Thank you for your check. I revised the code a little.

> In admin/config/services/japan-postal-code There is no button to fetch Japan postal code data from Japan post office website

The page was confusing and I changed the button text to "Fetch and update the postal code data". Probably it got better.

> When give permissions of Japan Postal Code to authenticated user error occurs: HTTP error -1 occurred when trying to fetch http://www.post.japanpost.jp/zipcode/dl/kogaki/zip/ken_all.zip.
> Japan postal code database table update failed.

I tested the functionality several times again but it successfully completed and I couldn't get any HTTP error... Could you please tell me the detail of the error?

Additionally I added a Drush command to this module `drush japan-postal-code-update`. This command runs same process as the admin page form (It fetches and update the Japan postal code data).

I hope someone kindly review this again. Thank you in advance.

hgoto’s picture

Status: Needs work » Needs review
nbouhid’s picture

Status: Needs review » Needs work

Automated Review

Best practice issues identified by pareview.sh.

FILE: /var/www/drupal-7-pareview/pareview_temp/japan_postal_code.test
---------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------
41 | ERROR | [x] Array closing indentation error, expected 4 spaces but
| | found 6
---------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------

Manual Review

Individual user account
Yes: Follows.
No duplication
Yes.
Master Branch
Yes: Follows the guidelines for master branch.
Licensing
Yes: Follows the licensing requirements.
3rd party assets/code
Yes: Follows the guidelines for 3rd party assets/code.
README.txt/README.md
Yes: Follows the guidelines for in-project documentation.
Code long/complex enough for review
Yes: Follows the guidelines for project length and complexity.
Secure code
Yes: Meets the security requirements
Coding style & Drupal API usage

japan_postal_code.drush.inc

  1. (*) The help hook is copied from another module.
    /**
     * Implements hook_drush_help().
     */
    function japan_postal_code_drush_help($section) {
      switch ($section) {
        case 'drush:delete-all':
          return dt("Delete all nodes, nodes of a specific content type or users.");
      }
    }
    
  2. There is a typo on the documentation of japan_postal_code_drush_update(). It says "upate".
    /**
     * Drush callback to fetch and upate the Japan postal code.
     *
     * @see japan_postal_code_config_form_submit()
     */
    

japan_postal_code.module

  1. I couldn't understand why is this: Is it needed?
      // Strip the unnecessary part of the address data.
      if ($address_under_city === '以下に掲載がない場合') {
        return '';
      }
    

README.txt

  1. There is a typo on the "related" word. it says "releated".

The starred items (*) are fairly big issues and warrant going back to Needs Work. Items marked with a plus sign (+) are important and should be addressed before a stable project release. The rest of the comments in the code walkthrough are recommendations.

Seems that is almost ready for being published. Only one major issue found.

If added, please don't remove the security tag, we keep that for statistics and to show examples of security problems.

This review uses the Project Application Review Template.

hgoto’s picture

StatusFileSize
new3.26 KB

@nbouhid, thank you for your kind and careful review. I fixed all the points.

First, I fixed the following point.

FILE: /var/www/drupal-7-pareview/pareview_temp/japan_postal_code.test
---------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------
41 | ERROR | [x] Array closing indentation error, expected 4 spaces but
| | found 6
---------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------
The help hook is copied from another module.

This hook implemetation is not necessary for this module and I removed it.

There is a typo on the documentation of japan_postal_code_drush_update(). It says "upate".

I fixed it.

I couldn't understand why is this: Is it needed?

I'm sorry, it didn't have enough explanation. This is necessary because this string "以下に掲載がない場合" is contained in the address column in the original address data (CSV) but actually it's not an address but a description sentence. So we need to ignore the sentence when importing it. I added a comment in the code to explain that.

    // Strip the unnecessary part of the address data.
    // The sentence means "all other addresses not listed bellow" in Japanese.
    $description_without_actual_address = '以下に掲載がない場合';
    if ($address_under_city === $description_without_actual_address) {
      return '';
    }

The attached file is the newest diff file which contains all the change I added after nbouhid's feedback. I hope someone would kindly review it again. Thank you in advance.

hgoto’s picture

Status: Needs work » Needs review
nbouhid’s picture

Status: Needs review » Reviewed & tested by the community

@hgoto I found another small issue on this docblock

/**
 * Load all the rows of Japan postal code csv and extract necessary columns.
 *
 * @param string $filepath
 *   The file path of the csv file containing Japan postal code data.
 * @param string $type
 *   Postal code type among 2: 'normal' or 'special'.
 *
 * @return array
 *    Address data extracted from the csv.
 *
 * @see _japan_postal_code_fetch_and_load_postal_code_csv()
 */

The return description has an extra space so it isn't aligned with the other sentences above.

It looks good and ready to be published to me though.

hgoto’s picture

StatusFileSize
new470 bytes

@nbouhid, thanks a lot for checking and telling the issue. I fixed the point.

mlncn’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for your contribution! Congratulations, you are now a vetted Git user. You can promote this to a full project.

When you create new projects (typically as a sandbox to start) you can then promote them to a full project.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

hgoto’s picture

mlncn, thank you for your review and kind comment. I'm so excited to hear that. I'll check the pages and proceed.

Again, thanks a lot, everright, azeiteiro, rajeshwari10, nbouhid for sparing your time to review and help.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.