Search in sources :

Example 1 with ValidatedAddress

use of gov.ca.cwds.rest.api.domain.ValidatedAddress in project API by ca-cwds.

the class SmartyStreet method usStreetSingleAddress.

/**
   * @param street incoming street address
   * @param city incoming city name
   * @param state incoming state
   * @param zipCode incoming zip code
   * @return returns a validated address back
   */
public ValidatedAddress[] usStreetSingleAddress(String street, String city, String state, Integer zipCode) {
    ArrayList<Candidate> results = (ArrayList<Candidate>) getSmartyStreetsCandidates(street, city, state, zipCode);
    ArrayList<ValidatedAddress> returnValidatedAddresses = new ArrayList<>();
    if (results.isEmpty()) {
        delPoint = false;
        longitude = null;
        latitude = null;
        ValidatedAddress address = new ValidatedAddress(streetAddress, cityName, stateName, zip, longitude, latitude, delPoint);
        returnValidatedAddresses.add(address);
        return returnValidatedAddresses.toArray(new ValidatedAddress[0]);
    }
    for (int i = 0; i < results.size(); i++) {
        Candidate candidate = results.get(i);
        if (("Y").equals(candidate.getAnalysis().getDpvMatchCode()) || ("S").equals(candidate.getAnalysis().getDpvMatchCode()) || ("D").equals(candidate.getAnalysis().getDpvMatchCode())) {
            delPoint = true;
        } else {
            delPoint = false;
        }
        longitude = candidate.getMetadata().getLongitude();
        latitude = candidate.getMetadata().getLatitude();
        streetAddress = candidate.getDeliveryLine1();
        cityName = candidate.getComponents().getCityName();
        stateName = candidate.getComponents().getState();
        zip = Integer.parseInt(candidate.getComponents().getZipCode());
        ValidatedAddress address = new ValidatedAddress(streetAddress, cityName, stateName, zip, longitude, latitude, delPoint);
        returnValidatedAddresses.add(address);
    }
    return returnValidatedAddresses.toArray(new ValidatedAddress[returnValidatedAddresses.size()]);
}
Also used : Candidate(com.smartystreets.api.us_street.Candidate) ArrayList(java.util.ArrayList) ValidatedAddress(gov.ca.cwds.rest.api.domain.ValidatedAddress)

Example 2 with ValidatedAddress

use of gov.ca.cwds.rest.api.domain.ValidatedAddress in project API by ca-cwds.

the class SmartyStreetTest method successfulWithEmptyCandidate.

@Test
public void successfulWithEmptyCandidate() throws Exception {
    ArrayList<Candidate> empty = new ArrayList<Candidate>();
    String a = "a";
    String b = "b";
    String c = "c";
    Integer z = 0;
    Mockito.doReturn(empty).when(spySmartyStreet).getSmartyStreetsCandidates(a, b, c, z);
    ValidatedAddress[] actual = spySmartyStreet.usStreetSingleAddress(a, b, c, z);
    ValidatedAddress[] expected = new ValidatedAddress[1];
    expected[0] = new ValidatedAddress(null, null, null, null, null, null, false);
    assertThat(actual[0], is(equalTo(expected[0])));
}
Also used : Candidate(com.smartystreets.api.us_street.Candidate) ArrayList(java.util.ArrayList) ValidatedAddress(gov.ca.cwds.rest.api.domain.ValidatedAddress) Test(org.junit.Test)

Example 3 with ValidatedAddress

use of gov.ca.cwds.rest.api.domain.ValidatedAddress in project API by ca-cwds.

the class SmartyStreetTest method successfulWithDpvY.

/*
   * Successful Tests
   */
@Test
public void successfulWithDpvY() throws Exception {
    ArrayList<Candidate> dpvY = new ArrayList<Candidate>();
    Candidate mockcandidate1 = mock(Candidate.class);
    Analysis mockanalysis1 = mock(Analysis.class);
    Components mockancomponents1 = mock(Components.class);
    Metadata mockanmetadata1 = mock(Metadata.class);
    Mockito.when(mockcandidate1.getDeliveryLine1()).thenReturn("106 Big Valley Rd");
    Mockito.when(mockcandidate1.getComponents()).thenReturn(mockancomponents1);
    Mockito.when(mockancomponents1.getCityName()).thenReturn("Folsom");
    Mockito.when(mockancomponents1.getState()).thenReturn("CA");
    Mockito.when(mockancomponents1.getZipCode()).thenReturn("95630");
    Mockito.when(mockcandidate1.getMetadata()).thenReturn(mockanmetadata1);
    Mockito.when(mockanmetadata1.getLongitude()).thenReturn(-121.13233);
    Mockito.when(mockanmetadata1.getLatitude()).thenReturn(38.64028);
    Mockito.when(mockcandidate1.getAnalysis()).thenReturn(mockanalysis1);
    Mockito.when(mockanalysis1.getDpvMatchCode()).thenReturn("Y");
    dpvY.add(mockcandidate1);
    String a = "106 Big Valley Rd";
    String b = "folsom";
    String c = "ca";
    Integer z = 0;
    Mockito.doReturn(dpvY).when(spySmartyStreet).getSmartyStreetsCandidates(a, b, c, z);
    ValidatedAddress[] actual = spySmartyStreet.usStreetSingleAddress(a, b, c, z);
    ValidatedAddress[] expected = new ValidatedAddress[1];
    expected[0] = new ValidatedAddress("106 Big Valley Rd", "Folsom", "CA", 95630, -121.13233, 38.64028, true);
    assertThat(actual[0], is(equalTo(expected[0])));
}
Also used : Candidate(com.smartystreets.api.us_street.Candidate) Components(com.smartystreets.api.us_street.Components) Analysis(com.smartystreets.api.us_street.Analysis) ArrayList(java.util.ArrayList) Metadata(com.smartystreets.api.us_street.Metadata) ValidatedAddress(gov.ca.cwds.rest.api.domain.ValidatedAddress) Test(org.junit.Test)

Example 4 with ValidatedAddress

use of gov.ca.cwds.rest.api.domain.ValidatedAddress in project API by ca-cwds.

the class SmartyStreetTest method successfulWithMultipleCandidates.

@Test
public void successfulWithMultipleCandidates() throws Exception {
    ArrayList<Candidate> multiCandidates = new ArrayList<Candidate>();
    Candidate mockcandidate1 = mock(Candidate.class);
    Analysis mockanalysis1 = mock(Analysis.class);
    Components mockancomponents1 = mock(Components.class);
    Metadata mockanmetadata1 = mock(Metadata.class);
    Mockito.when(mockcandidate1.getDeliveryLine1()).thenReturn("106 Big Valley Rd");
    Mockito.when(mockcandidate1.getComponents()).thenReturn(mockancomponents1);
    Mockito.when(mockancomponents1.getCityName()).thenReturn("Folsom");
    Mockito.when(mockancomponents1.getState()).thenReturn("CA");
    Mockito.when(mockancomponents1.getZipCode()).thenReturn("95630");
    Mockito.when(mockcandidate1.getMetadata()).thenReturn(mockanmetadata1);
    Mockito.when(mockanmetadata1.getLongitude()).thenReturn(-121.13233);
    Mockito.when(mockanmetadata1.getLatitude()).thenReturn(38.64028);
    Mockito.when(mockcandidate1.getAnalysis()).thenReturn(mockanalysis1);
    Mockito.when(mockanalysis1.getDpvMatchCode()).thenReturn("Y");
    multiCandidates.add(mockcandidate1);
    Candidate mockcandidate2 = mock(Candidate.class);
    Analysis mockanalysis2 = mock(Analysis.class);
    Components mockancomponents2 = mock(Components.class);
    Metadata mockanmetadata2 = mock(Metadata.class);
    Mockito.when(mockcandidate2.getDeliveryLine1()).thenReturn("106 Big Valley Ct");
    Mockito.when(mockcandidate2.getComponents()).thenReturn(mockancomponents2);
    Mockito.when(mockancomponents2.getCityName()).thenReturn("Folsom");
    Mockito.when(mockancomponents2.getState()).thenReturn("CA");
    Mockito.when(mockancomponents2.getZipCode()).thenReturn("95630");
    Mockito.when(mockcandidate2.getMetadata()).thenReturn(mockanmetadata2);
    Mockito.when(mockanmetadata2.getLongitude()).thenReturn(-121.13232);
    Mockito.when(mockanmetadata2.getLatitude()).thenReturn(38.68207);
    Mockito.when(mockcandidate2.getAnalysis()).thenReturn(mockanalysis2);
    Mockito.when(mockanalysis2.getDpvMatchCode()).thenReturn("S");
    multiCandidates.add(mockcandidate2);
    String a = "106 Big Valley";
    String b = "folsom";
    String c = "ca";
    Integer z = 0;
    Mockito.doReturn(multiCandidates).when(spySmartyStreet).getSmartyStreetsCandidates(a, b, c, z);
    ValidatedAddress[] actual = spySmartyStreet.usStreetSingleAddress(a, b, c, z);
    ValidatedAddress[] expected = new ValidatedAddress[2];
    expected[0] = new ValidatedAddress("106 Big Valley Rd", "Folsom", "CA", 95630, -121.13233, 38.64028, true);
    expected[1] = new ValidatedAddress("106 Big Valley Ct", "Folsom", "CA", 95630, -121.13232, 38.68207, true);
    assertThat(actual[0], is(equalTo(expected[0])));
    assertThat(actual[1], is(equalTo(expected[1])));
}
Also used : Candidate(com.smartystreets.api.us_street.Candidate) Components(com.smartystreets.api.us_street.Components) Analysis(com.smartystreets.api.us_street.Analysis) ArrayList(java.util.ArrayList) Metadata(com.smartystreets.api.us_street.Metadata) ValidatedAddress(gov.ca.cwds.rest.api.domain.ValidatedAddress) Test(org.junit.Test)

Example 5 with ValidatedAddress

use of gov.ca.cwds.rest.api.domain.ValidatedAddress in project API by ca-cwds.

the class AddressValidationService method fetchValidatedAddresses.

/**
   * Returns all valid addresses, up to the default number set in {@link SmartyStreetsDao}
   * 
   * @param address The address to validate
   * @return array of {@link ValidatedAddress}
   * @throws ServiceException due to SmartyStreets error, I/O error, etc.
   */
public ValidatedAddress[] fetchValidatedAddresses(Address address) throws ServiceException {
    ValidatedAddress[] addresses = null;
    try {
        SmartyStreet smartyStreet = new SmartyStreet(smartyStreetsDao);
        addresses = smartyStreet.usStreetSingleAddress(address.getStreetAddress(), address.getCity(), address.getState(), address.getZip());
    } catch (Exception e) {
        throw new ServiceException("ERROR calling usStreetSingleAddress in SmartyStreet", e);
    }
    return addresses;
}
Also used : SmartyStreet(gov.ca.cwds.rest.validation.SmartyStreet) ValidatedAddress(gov.ca.cwds.rest.api.domain.ValidatedAddress) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

Aggregations

ValidatedAddress (gov.ca.cwds.rest.api.domain.ValidatedAddress)5 Candidate (com.smartystreets.api.us_street.Candidate)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)3 Analysis (com.smartystreets.api.us_street.Analysis)2 Components (com.smartystreets.api.us_street.Components)2 Metadata (com.smartystreets.api.us_street.Metadata)2 SmartyStreet (gov.ca.cwds.rest.validation.SmartyStreet)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1