Search in sources :

Example 1 with NotCheckedException

use of com.axibase.tsd.api.util.NotCheckedException in project atsd-api-test by axibase.

the class ReplacementTableMethod method replacementTableExist.

public static boolean replacementTableExist(String replacementTable) throws NotCheckedException {
    replacementTable = replacementTable.replace(" ", "_").toLowerCase();
    final Response response = ReplacementTableMethod.getReplacementTablesResponse();
    if (response.getStatus() != OK.getStatusCode()) {
        throw new NotCheckedException("Fail to execute replacement table query");
    }
    InputStream bodyStream = (InputStream) response.getEntity();
    String body;
    try {
        body = IOUtils.toString(bodyStream, "UTF-8");
    } catch (IOException ignored) {
        throw new IllegalStateException("Error in decoding stream to string");
    }
    Document doc = Jsoup.parse(body);
    Element table = doc.select("table").get(0);
    Elements trs = table.select("tr");
    for (Element tr : trs) {
        Elements tds = tr.select("td");
        for (Element td : tds) {
            if (td.text().contains(replacementTable)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) NotCheckedException(com.axibase.tsd.api.util.NotCheckedException) Element(org.jsoup.nodes.Element) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Example 2 with NotCheckedException

use of com.axibase.tsd.api.util.NotCheckedException in project atsd-api-test by axibase.

the class PropertyMethod method propertyTypeExist.

public static boolean propertyTypeExist(String propertyType) {
    final PropertyQuery q = new PropertyQuery();
    q.setEntity("*");
    q.setType(propertyType);
    q.setStartDate(MIN_STORABLE_DATE);
    q.setEndDate(MAX_STORABLE_DATE);
    q.setLimit(1);
    final Response response = queryProperty(q);
    if (response.getStatus() != OK.getStatusCode()) {
        throw new NotCheckedException("Fail to execute property query");
    }
    String given = response.readEntity(String.class);
    if ("[]".equals(given)) {
        return false;
    } else
        return true;
}
Also used : Response(javax.ws.rs.core.Response) PropertyQuery(com.axibase.tsd.api.model.property.PropertyQuery) NotCheckedException(com.axibase.tsd.api.util.NotCheckedException)

Aggregations

NotCheckedException (com.axibase.tsd.api.util.NotCheckedException)2 Response (javax.ws.rs.core.Response)2 PropertyQuery (com.axibase.tsd.api.model.property.PropertyQuery)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Document (org.jsoup.nodes.Document)1 Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1