use of org.folio.rest.jaxrs.model.NatureOfContentTerm in project mod-inventory-storage by folio-org.
the class NatureOfContentTermAPI method getNatureOfContentTerms.
@Validate
@Override
public void getNatureOfContentTerms(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
/**
* http://host:port/nature-of-content-terms
*/
vertxContext.runOnContext(v -> {
try {
String tenantId = TenantTool.tenantId(okapiHeaders);
CQLWrapper cql = getCQL(query, limit, offset);
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(REFERENCE_TABLE, NatureOfContentTerm.class, new String[] { "*" }, cql, true, true, reply -> {
if (reply.succeeded()) {
NatureOfContentTerms records = new NatureOfContentTerms();
List<NatureOfContentTerm> record = reply.result().getResults();
records.setNatureOfContentTerms(record);
records.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetNatureOfContentTermsResponse.respond200WithApplicationJson(records)));
} else {
log.error(reply.cause().getMessage(), reply.cause());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetNatureOfContentTermsResponse.respond400WithTextPlain(reply.cause().getMessage())));
}
});
} catch (Exception e) {
log.error(e.getMessage(), e);
String message = messages.getMessage(lang, MessageConsts.InternalServerError);
if (e.getCause() instanceof CQLParseException) {
message = " CQL parse error " + e.getLocalizedMessage();
}
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetNatureOfContentTermsResponse.respond500WithTextPlain(message)));
}
});
}
use of org.folio.rest.jaxrs.model.NatureOfContentTerm in project mod-inventory-storage by folio-org.
the class InstanceStorageTest method createNatureOfContentTerm.
private NatureOfContentTerm createNatureOfContentTerm(final String name) throws InterruptedException, ExecutionException, TimeoutException {
NatureOfContentTerm natureOfContentTerm = new NatureOfContentTerm().withId(UUID.randomUUID().toString()).withName(name).withSource("test");
CompletableFuture<Response> createNatureOfContent = new CompletableFuture<>();
client.post(natureOfContentTermsUrl(""), natureOfContentTerm, TENANT_ID, json(createNatureOfContent));
Response response = createNatureOfContent.get(5, SECONDS);
assertThat(response.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
natureOfContentIdsToRemoveAfterTest.add(natureOfContentTerm.getId());
return response.getJson().mapTo(NatureOfContentTerm.class);
}
use of org.folio.rest.jaxrs.model.NatureOfContentTerm in project mod-inventory-storage by folio-org.
the class InstanceStorageTest method canCreateAnInstance.
@Test
public void canCreateAnInstance() throws InterruptedException, ExecutionException, TimeoutException {
UUID id = UUID.randomUUID();
NatureOfContentTerm journalContentType = createNatureOfContentTerm("journal_test");
NatureOfContentTerm bookContentType = createNatureOfContentTerm("book_test");
String[] natureOfContentIds = Stream.of(journalContentType, bookContentType).map(NatureOfContentTerm::getId).toArray(String[]::new);
var publication = new Publication().withDateOfPublication("2000-2001");
String adminNote = "Administrative note";
JsonObject instanceToCreate = smallAngryPlanet(id);
instanceToCreate.put("natureOfContentTermIds", Arrays.asList(natureOfContentIds));
instanceToCreate.put("publication", new JsonArray().add(JsonObject.mapFrom(publication)));
instanceToCreate.put("administrativeNotes", new JsonArray().add(adminNote));
CompletableFuture<Response> createCompleted = new CompletableFuture<>();
client.post(instancesStorageUrl(""), instanceToCreate, TENANT_ID, json(createCompleted));
Response response = createCompleted.get(5, SECONDS);
assertThat(response.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
JsonObject instance = response.getJson();
assertThat(instance.getString("id"), is(id.toString()));
assertThat(instance.getString("title"), is("Long Way to a Small Angry Planet"));
assertThat(instance.getBoolean("previouslyHeld"), is(false));
assertThat(instance.getJsonArray("administrativeNotes").contains(adminNote), is(true));
JsonArray identifiers = instance.getJsonArray("identifiers");
assertThat(identifiers.size(), is(1));
assertThat(identifiers, hasItem(identifierMatches(UUID_ISBN.toString(), "9781473619777")));
assertThat(instance.getJsonArray("natureOfContentTermIds"), containsInAnyOrder(natureOfContentIds));
assertThat(instance.getBoolean(DISCOVERY_SUPPRESS), is(false));
Response getResponse = getById(id);
assertThat(getResponse.getStatusCode(), is(HTTP_OK));
JsonObject instanceFromGet = getResponse.getJson();
assertThat(instanceFromGet.getString("title"), is("Long Way to a Small Angry Planet"));
JsonArray identifiersFromGet = instanceFromGet.getJsonArray("identifiers");
assertThat(identifiersFromGet.size(), is(1));
assertThat(identifiersFromGet, hasItem(identifierMatches(UUID_ISBN.toString(), "9781473619777")));
List<String> tags = instanceFromGet.getJsonObject("tags").getJsonArray("tagList").getList();
assertThat(tags.size(), is(1));
assertThat(tags, hasItem(TAG_VALUE));
assertThat(instanceFromGet.getJsonArray("natureOfContentTermIds"), containsInAnyOrder(natureOfContentIds));
assertThat(instanceFromGet.getString(STATUS_UPDATED_DATE_PROPERTY), hasIsoFormat());
assertThat(instanceFromGet.getBoolean(DISCOVERY_SUPPRESS), is(false));
assertCreateEventForInstance(instanceFromGet);
var storedPublicationPeriod = instance.getJsonObject("publicationPeriod").mapTo(PublicationPeriod.class);
assertThat(storedPublicationPeriod.getStart(), is(2000));
assertThat(storedPublicationPeriod.getEnd(), is(2001));
}
Aggregations