Search in sources :

Example 6 with ApiException

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

the class IndexQueryResource method searchIndex.

/**
   * Endpoint for Intake Person Query Search.
   * 
   * @param index {@link IndexQueryRequest}
   * @param req JSON {@link IndexQueryRequest}
   * @return web service response
   */
@POST
@Path("/{index}/_search")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Unable to process JSON"), @ApiResponse(code = 401, message = "Not Authorized"), @ApiResponse(code = 406, message = "Accept Header not supported") })
@ApiOperation(value = "Query ElasticSearch Persons on given search terms", code = HttpStatus.SC_OK, response = JSONObject.class)
@Consumes(value = MediaType.APPLICATION_JSON)
public Response searchIndex(@PathParam("index") @ApiParam(required = true, name = "index", value = "The index of the search") String index, @Valid @ApiParam(hidden = false, required = true) Object req) {
    Response ret;
    try {
        IndexQueryRequest personQueryRequest = new IndexQueryRequest(index, req);
        IndexQueryResponse personQueryResponse = (IndexQueryResponse) resourceDelegate.handle(personQueryRequest).getEntity();
        if (personQueryResponse != null) {
            ret = Response.status(Response.Status.OK).entity(personQueryResponse.getPersons()).build();
        } else {
            ret = null;
        }
    } catch (Exception e) {
        LOGGER.error("Intake Person Query ERROR: {}", e.getMessage(), e);
        throw new ApiException("Intake Person Query ERROR. " + e.getMessage(), e);
    }
    return ret;
}
Also used : IndexQueryResponse(gov.ca.cwds.rest.api.domain.es.IndexQueryResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) IndexQueryResponse(gov.ca.cwds.rest.api.domain.es.IndexQueryResponse) IndexQueryRequest(gov.ca.cwds.rest.api.domain.es.IndexQueryRequest) ApiException(gov.ca.cwds.rest.api.ApiException) ApiException(gov.ca.cwds.rest.api.ApiException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 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