com.pepaproch.gtswsdlclient.impl.AddrCheckQueryBuilderImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.pepaproch.gtswsdlclient.impl.AddrCheckQueryBuilderImpl.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pepaproch.gtswsdlclient.impl;

import com.pepaproch.gtswsdl.QueryBuilder;
import com.pepaproch.gtswsdlclient.model.gts.AddressQuery;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

/**
 *
 * @author pepa
 */
public class AddrCheckQueryBuilderImpl implements QueryBuilder<AddressQuery> {

    private final String url;

    public AddrCheckQueryBuilderImpl(String url) {
        this.url = url;

    }

    @Override
    public UriComponents buildQuery(AddressQuery addresQuery) {
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
        if (addresQuery.getCity() != null && !addresQuery.getCity().isEmpty()) {
            builder.queryParam("city", addresQuery.getCity());
        }
        if (addresQuery.getHouseNumberReg() != null) {
            builder.queryParam("houseNumberReg", addresQuery.getHouseNumberReg());
        }
        if (addresQuery.getHouseNumberOr() != null) {
            builder.queryParam("houseNumberOr", addresQuery.getHouseNumberOr());
        }
        if (addresQuery.getStreet() != null && !addresQuery.getStreet().isEmpty()) {
            builder.queryParam("street", addresQuery.getStreet());
        }
        if (addresQuery.getZipCode() != null) {
            builder.queryParam("zipCode", addresQuery.getZipCode());
        }

        return builder.build();
    }

}