Search in sources :

Example 6 with HttpRequest

use of nl.knaw.huygens.concordion.extensions.HttpRequest in project timbuctoo by HuygensING.

the class WwRelationV2_1EndpointFixture method getRelationId.

public String getRelationId() throws JSONException {
    HttpRequest request = new HttpRequest("POST", "/v2.1/gremlin", "g.V().has(\"relationtype_regularName\", \"isCreatedBy\")").withHeader("accept", "text/plain").withHeader("content-type", "text/plain");
    ActualResult response = executeRequestUsingJaxRs(request);
    Pattern pattern = Pattern.compile(".*tim_id: \"([^\n]*)\".*", Pattern.DOTALL);
    Matcher matcher = pattern.matcher(response.getBody());
    matcher.matches();
    return matcher.group(1);
}
Also used : HttpRequest(nl.knaw.huygens.concordion.extensions.HttpRequest) Pattern(java.util.regex.Pattern) ActualResult(nl.knaw.huygens.concordion.extensions.ActualResult) Matcher(java.util.regex.Matcher)

Example 7 with HttpRequest

use of nl.knaw.huygens.concordion.extensions.HttpRequest in project timbuctoo by HuygensING.

the class BaseDomainV2_1EndpointFixture method retrievePid.

public String retrievePid(String path) {
    if (path != null) {
        int attempts = 0;
        HttpRequest getRequest = new HttpRequest("GET", path).withHeader("Accept", "application/json");
        while ((pid == null || pid.equalsIgnoreCase("null")) && attempts < 24) {
            ActualResult response = executeRequestUsingJaxRs(getRequest);
            try {
                JSONObject data = new JSONObject(response.getBody());
                pid = data.getString("^pid");
            } catch (JSONException e) {
            // Expected exception when record is still updating
            }
            attempts++;
            try {
                Thread.sleep(2500);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        return pid;
    } else {
        return null;
    }
}
Also used : HttpRequest(nl.knaw.huygens.concordion.extensions.HttpRequest) ActualResult(nl.knaw.huygens.concordion.extensions.ActualResult) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException)

Example 8 with HttpRequest

use of nl.knaw.huygens.concordion.extensions.HttpRequest in project timbuctoo by HuygensING.

the class WwRelationV2_1EndpointFixture method makeDocumentRecord.

public String makeDocumentRecord() throws JSONException {
    HttpRequest postRequest = new HttpRequest("POST", "/v2.1/domain/wwdocuments", makeDocumentJson()).withHeaders(makeAuthHeaders());
    ActualResult response = executeRequestUsingJaxRs(postRequest);
    documentPath = response.getFirstHeader("Location").orElseThrow(() -> new RuntimeException("Location header not present")).replaceAll("http://[^/]+/", "");
    documentId = documentPath.replaceAll(".*\\/", "");
    retrievePid(documentPath);
    return documentId;
}
Also used : HttpRequest(nl.knaw.huygens.concordion.extensions.HttpRequest) ActualResult(nl.knaw.huygens.concordion.extensions.ActualResult)

Example 9 with HttpRequest

use of nl.knaw.huygens.concordion.extensions.HttpRequest in project timbuctoo by HuygensING.

the class WwRelationV2_1EndpointFixture method makePersonRecord.

public String makePersonRecord() throws JSONException {
    HttpRequest postRequest = new HttpRequest("POST", "/v2.1/domain/wwpersons", makePersonJson()).withHeaders(makeAuthHeaders());
    ActualResult response = executeRequestUsingJaxRs(postRequest);
    personPath = response.getFirstHeader("Location").orElseThrow(() -> new RuntimeException("Location header not present")).replaceAll("http://[^/]+/", "");
    personId = personPath.replaceAll(".*\\/", "");
    retrievePid(personPath);
    return personId;
}
Also used : HttpRequest(nl.knaw.huygens.concordion.extensions.HttpRequest) ActualResult(nl.knaw.huygens.concordion.extensions.ActualResult)

Aggregations

ActualResult (nl.knaw.huygens.concordion.extensions.ActualResult)9 HttpRequest (nl.knaw.huygens.concordion.extensions.HttpRequest)9 WebTarget (javax.ws.rs.client.WebTarget)2 JsonDiffer (nl.knaw.huygens.contractdiff.jsondiff.JsonDiffer)2 JsonDiffer.jsonDiffer (nl.knaw.huygens.contractdiff.jsondiff.JsonDiffer.jsonDiffer)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 XmlEscapers.xmlContentEscaper (com.google.common.xml.XmlEscapers.xmlContentEscaper)1 DropwizardAppRule (io.dropwizard.testing.junit.DropwizardAppRule)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ClientBuilder (javax.ws.rs.client.ClientBuilder)1 Entity (javax.ws.rs.client.Entity)1 Invocation (javax.ws.rs.client.Invocation)1 Response (javax.ws.rs.core.Response)1 ExpectedResult (nl.knaw.huygens.concordion.extensions.ExpectedResult)1 HttpCommandExtension (nl.knaw.huygens.concordion.extensions.HttpCommandExtension)1 ReplaceEmbeddedStylesheetExtension (nl.knaw.huygens.concordion.extensions.ReplaceEmbeddedStylesheetExtension)1