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);
}
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;
}
}
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;
}
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;
}
Aggregations