Search in sources :

Example 1 with ApiException

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

the class SmartyStreet method getSmartyStreetsCandidates.

/**
   * @param street incoming street address
   * @param city incoming city name
   * @param state incoming state
   * @param zipCode incoming zip code
   * @return returns a address back
   */
public List<Candidate> getSmartyStreetsCandidates(String street, String city, String state, Integer zipCode) {
    Client client = new ClientBuilder(smartyStreetsDao.getClientId(), smartyStreetsDao.getToken()).build();
    Lookup lookup = createSmartyStreetsLookup(street, city, state, zipCode);
    try {
        client.send(lookup);
    } catch (SmartyException e) {
        LOGGER.error("SmartyStreet error, Unable to validate the address", e);
        throw new ApiException("ERROR calling SmartyStreet - ", e);
    } catch (IOException e) {
        LOGGER.error("SmartyStreet IO error, Unable to validate the address", e);
        throw new ApiException("ERROR calling SmartyStreet - ", e);
    }
    return lookup.getResult();
}
Also used : SmartyException(com.smartystreets.api.exceptions.SmartyException) Lookup(com.smartystreets.api.us_street.Lookup) IOException(java.io.IOException) Client(com.smartystreets.api.us_street.Client) ClientBuilder(com.smartystreets.api.us_street.ClientBuilder) ApiException(gov.ca.cwds.rest.api.ApiException)

Example 2 with ApiException

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

the class PersonService method create.

/**
   * {@inheritDoc}
   * 
   * @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
   */
@Override
@UnitOfWork(value = "ns")
public PostedPerson create(Request request) {
    assert request instanceof Person;
    Person person = (Person) request;
    gov.ca.cwds.data.persistence.ns.Person managedPerson = new gov.ca.cwds.data.persistence.ns.Person(person, null, null);
    managedPerson = personDao.create(managedPerson);
    populatePersonDetails(person, managedPerson);
    managedPerson = personDao.find(managedPerson.getId());
    PostedPerson postedPerson = new PostedPerson(managedPerson);
    try {
        final gov.ca.cwds.rest.api.domain.es.Person esPerson = new gov.ca.cwds.rest.api.domain.es.Person(managedPerson.getId().toString(), managedPerson.getFirstName(), managedPerson.getLastName(), managedPerson.getGender(), DomainChef.cookDate(managedPerson.getDateOfBirth()), managedPerson.getSsn(), managedPerson.getClass().getName(), MAPPER.writeValueAsString(managedPerson));
        final String document = MAPPER.writeValueAsString(esPerson);
        // If the people index is missing, create it.
        elasticsearchDao.createIndexIfNeeded(elasticsearchDao.getDefaultAlias());
    // The ES Dao manages its own connections. No need to manually start or stop.
    // elasticsearchDao.index(elasticsearchDao.getDefaultAlias(),
    // elasticsearchDao.getDefaultDocType(), document, esPerson.getId());
    } catch (Exception e) {
        LOGGER.error("Unable to Index Person in ElasticSearch", e);
        throw new ApiException("Unable to Index Person in ElasticSearch", e);
    }
    return postedPerson;
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) ApiException(gov.ca.cwds.rest.api.ApiException) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson) Person(gov.ca.cwds.rest.api.domain.Person) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson) ApiException(gov.ca.cwds.rest.api.ApiException) UnitOfWork(io.dropwizard.hibernate.UnitOfWork)

Example 3 with ApiException

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

the class Db2XASample method buildDB2DataSource.

private static DB2XADataSource buildDB2DataSource(String user, String password, String serverName, int port, String databaseName) {
    DB2XADataSource ds = new DB2XADataSource();
    ds.setUser(user);
    ds.setPassword(password);
    ds.setServerName(serverName);
    ds.setPortNumber(port);
    ds.setDatabaseName(databaseName);
    ds.setDriverType(4);
    try {
        ds.getProperties().setProperty(DB2XADataSource.propertyKey_serverName, serverName);
        ds.getProperties().setProperty(DB2XADataSource.propertyKey_portNumber, String.valueOf(port));
        ds.getProperties().setProperty(DB2XADataSource.propertyKey_databaseName, databaseName);
        ds.getProperties().setProperty(DB2XADataSource.propertyKey_driverType, "4");
    } catch (SQLException e) {
        e.printStackTrace();
        throw new ApiException("datasource property error", e);
    }
    return ds;
}
Also used : SQLException(java.sql.SQLException) DB2XADataSource(com.ibm.db2.jcc.DB2XADataSource) ApiException(gov.ca.cwds.rest.api.ApiException)

Example 4 with ApiException

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

the class XASample method buildDB2DataSource.

private static DB2XADataSource buildDB2DataSource(String user, String password, String serverName, int port, String databaseName) {
    DB2XADataSource ds = new DB2XADataSource();
    ds.setUser(user);
    ds.setPassword(password);
    ds.setServerName(serverName);
    ds.setPortNumber(port);
    ds.setDatabaseName(databaseName);
    ds.setDriverType(4);
    try {
        ds.getProperties().setProperty(DB2XADataSource.propertyKey_serverName, serverName);
        ds.getProperties().setProperty(DB2XADataSource.propertyKey_portNumber, String.valueOf(port));
        ds.getProperties().setProperty(DB2XADataSource.propertyKey_databaseName, databaseName);
        ds.getProperties().setProperty(DB2XADataSource.propertyKey_driverType, "4");
    } catch (SQLException e) {
        e.printStackTrace();
        throw new ApiException("datasource property error", e);
    }
    return ds;
}
Also used : SQLException(java.sql.SQLException) DB2XADataSource(com.ibm.db2.jcc.DB2XADataSource) ApiException(gov.ca.cwds.rest.api.ApiException)

Example 5 with ApiException

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

the class XASample method buildPGDataSource.

private static PGXADataSource buildPGDataSource(String user, String password, String serverName, int port, String databaseName) {
    PGXADataSource ds = new PGXADataSource();
    ds.setUser(user);
    ds.setPassword(password);
    ds.setServerName(serverName);
    ds.setPortNumber(port);
    ds.setDatabaseName(databaseName);
    try {
        ds.setProperty("user", user);
        ds.setProperty("password", password);
        ds.setProperty(PGProperty.PG_DBNAME, databaseName);
        ds.setProperty(PGProperty.PG_HOST, serverName);
        ds.setProperty(PGProperty.PG_PORT, String.valueOf(port));
    } catch (SQLException e) {
        e.printStackTrace();
        throw new ApiException("datasource property error", e);
    }
    System.out.println("pgxa data source");
    return ds;
}
Also used : SQLException(java.sql.SQLException) PGXADataSource(org.postgresql.xa.PGXADataSource) ApiException(gov.ca.cwds.rest.api.ApiException)

Aggregations

ApiException (gov.ca.cwds.rest.api.ApiException)7 SQLException (java.sql.SQLException)3 DB2XADataSource (com.ibm.db2.jcc.DB2XADataSource)2 Provides (com.google.inject.Provides)1 SmartyException (com.smartystreets.api.exceptions.SmartyException)1 Client (com.smartystreets.api.us_street.Client)1 ClientBuilder (com.smartystreets.api.us_street.ClientBuilder)1 Lookup (com.smartystreets.api.us_street.Lookup)1 ElasticsearchConfiguration (gov.ca.cwds.rest.ElasticsearchConfiguration)1 Person (gov.ca.cwds.rest.api.domain.Person)1 PostedPerson (gov.ca.cwds.rest.api.domain.PostedPerson)1 IndexQueryRequest (gov.ca.cwds.rest.api.domain.es.IndexQueryRequest)1 IndexQueryResponse (gov.ca.cwds.rest.api.domain.es.IndexQueryResponse)1 UnitOfWork (io.dropwizard.hibernate.UnitOfWork)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1