Skip to content

基本契約情報登録実装編#

1.1. 処理概要#

画面の入力内容をもとに基本契約情報の登録を行います。
本処理を行うには、API認証よりAPIを呼び出すためのアクセストークンが必要となります。

1.1.1. 呼出API#

以下、基本契約情報登録で呼び出すAPIとなります。

No API 処理内容 使用用途
1 POST /v2/api/basiccontract 基本契約を編集する 基本契約登録画面で登録ボタン押下時に基本契約情報を作成

1.1.2. 処理フロー#

基本契約情報登録を行うまでの処理は以下のフローとなります。

1.1.3. 実装例#

以下API呼び出しの実装例となります。
※本マニュアルに記載している実装例は、分かりやすさを優先し簡易的に記載しております。提供しているソースと異なりますので詳細については提供ソースをご確認ください。

BasicContractRegistController.java

/**
 * 登録処理
 * @param model モデル
 * @param form 基本契約登録フォーム
 * @param result バリデーション結果
 * @return 基本契約登録
 */
@RequestMapping(value = "/BasicContractRegist/regist", method = RequestMethod.POST)
public String regist(
        Model model,
        @Valid BasicContractRegistForm form,
        BindingResult result) {

    form.setMessage("");
    form.setErrorInformation("");
    model.addAttribute("basicContractRegistForm", form);
    basicContractRegistFormSession.setBasicContractRegistForm(form);

    if (result.hasErrors()) {
        return ControllerConstants.BASIC_CONTRACT_REGIST_JSP;
    }

    Web_IFBasicContractEdition_I web_IFBasicContractEdition_I = new Web_IFBasicContractEdition_I();
    Web_IFBasicContractEdition_O web_IFBasicContractEdition_O = new Web_IFBasicContractEdition_O();

    web_IFBasicContractEdition_I.entry_id = CommonConstants.登録者ID;
    web_IFBasicContractEdition_I.administration_number = "1";
    web_IFBasicContractEdition_I.bill_to_name = SampleUtil.emptyToNull(form.getBillToName());
    web_IFBasicContractEdition_I.bill_to_version_info = "1";
    web_IFBasicContractEdition_I.customer_id = SampleUtil.emptyToNull(form.getCustomerId());
    web_IFBasicContractEdition_I.group_id = SampleUtil.emptyToNull(form.getGroupNameCode());
    web_IFBasicContractEdition_I.classification_of_contract = SampleUtil.emptyToNull(form.getClassificationOfContractCode());
    web_IFBasicContractEdition_I.apply_start_date = SampleUtil.emptyToNull(DateUtil.nowDate());
    web_IFBasicContractEdition_I.zip_code = SampleUtil.emptyToNull(form.getZipCode());
    web_IFBasicContractEdition_I.address1 = SampleUtil.emptyToNull(form.getPrefectures());
    web_IFBasicContractEdition_I.address2 = SampleUtil.emptyToNull(form.getCity());
    web_IFBasicContractEdition_I.address3 = SampleUtil.emptyToNull(form.getAddress1());
    web_IFBasicContractEdition_I.address4 = SampleUtil.emptyToNull(form.getAddress2());
    web_IFBasicContractEdition_I.phone_number1 = SampleUtil.emptyToNull(form.getPhoneNumber1());
    web_IFBasicContractEdition_I.phone_number2 = SampleUtil.emptyToNull(form.getPhoneNumber2());
    web_IFBasicContractEdition_I.email_address1 = SampleUtil.emptyToNull(form.getEmailAddress1());
    web_IFBasicContractEdition_I.email_address2 = SampleUtil.emptyToNull(form.getEmailAddress2());
    web_IFBasicContractEdition_I.free_item2 = SampleUtil.emptyToNull(form.getMedia());

    JsonObject free_json = new JsonObject();
    free_json.addProperty("address",  form.getAddress());
    free_json.addProperty("comment", form.getComment());
    web_IFBasicContractEdition_I.free_item = free_json;

    try {
        web_IFBasicContractEdition_O = basicContractService.basicContractEdition(web_IFBasicContractEdition_I);

        if (ControllerConstants.API_RESULT_NG.equals(web_IFBasicContractEdition_O.result_information.result)) {
            form.setErrorInformation(web_IFBasicContractEdition_O.result_information.detailed_result);
            return ControllerConstants.BASIC_CONTRACT_REGIST_JSP;
        }

    } catch (ApiException e) {
        model.addAttribute("errorCode", e.getErrorCode().getValue());
        return ControllerConstants.SYSTEM_ERROR_JSP;

    } catch (Exception e) {
        return ControllerConstants.SYSTEM_ERROR_JSP;
    }

    form.setBasicContractId(web_IFBasicContractEdition_O.basic_contract_id);
    form.setBasicContractId(web_IFBasicContractEdition_O.bill_to_id);

    // メッセージ表示
    form.setMessage(getMsg(MessageConstants.MSGI00011, 
            getMsg(MessageConstants.LBL000002), 
            web_IFBasicContractEdition_O.basic_contract_id, 
            getMsg(MessageConstants.LBL000003), 
            web_IFBasicContractEdition_O.bill_to_id));

    return ControllerConstants.BASIC_CONTRACT_REGIST_JSP;
}

BasicContractService.java

/**
 * 基本契約_編集 API
 * 
 * @param web_IFBasicContractEdition_I IF基本契約_編集_入力
 * @return IF基本契約_編集_出力
 */
public Web_IFBasicContractEdition_O basicContractEdition(Web_IFBasicContractEdition_I web_IFBasicContractEdition_I) {

    // 通信設定
    String strURI = ClientUtil.makeURI(UriInfo.BasicContractEdition, null, null);
    HttpPost postMethod = ClientUtil.makeHttpPost(strURI, web_IFBasicContractEdition_I);

    return CommonHttpClient.httpPost(postMethod, Web_IFBasicContractEdition_O.class);

}

共通HTTPリクエストクラス[CommonHttpClient.java]の実装例についてはこちらをご参照ください。

Top