Search in sources :

Example 1 with NatureOfContentTerm

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)));
        }
    });
}
Also used : NatureOfContentTerm(org.folio.rest.jaxrs.model.NatureOfContentTerm) NatureOfContentTerms(org.folio.rest.jaxrs.model.NatureOfContentTerms) CQLParseException(org.z3950.zing.cql.CQLParseException) CQLWrapper(org.folio.rest.persist.cql.CQLWrapper) CQLParseException(org.z3950.zing.cql.CQLParseException) FieldException(org.folio.cql2pgjson.exception.FieldException) Validate(org.folio.rest.annotations.Validate)

Example 2 with NatureOfContentTerm

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);
}
Also used : NatureOfContentTerm(org.folio.rest.jaxrs.model.NatureOfContentTerm) JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) InstancesBatchResponse(org.folio.rest.jaxrs.model.InstancesBatchResponse) Response(org.folio.rest.support.Response) CompletableFuture(java.util.concurrent.CompletableFuture)

Example 3 with NatureOfContentTerm

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));
}
Also used : NatureOfContentTerm(org.folio.rest.jaxrs.model.NatureOfContentTerm) JsonArray(io.vertx.core.json.JsonArray) JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) InstancesBatchResponse(org.folio.rest.jaxrs.model.InstancesBatchResponse) Response(org.folio.rest.support.Response) CompletableFuture(java.util.concurrent.CompletableFuture) Publication(org.folio.rest.jaxrs.model.Publication) JsonObject(io.vertx.core.json.JsonObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

NatureOfContentTerm (org.folio.rest.jaxrs.model.NatureOfContentTerm)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 InstancesBatchResponse (org.folio.rest.jaxrs.model.InstancesBatchResponse)2 JsonErrorResponse (org.folio.rest.support.JsonErrorResponse)2 Response (org.folio.rest.support.Response)2 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 UUID (java.util.UUID)1 FieldException (org.folio.cql2pgjson.exception.FieldException)1 Validate (org.folio.rest.annotations.Validate)1 NatureOfContentTerms (org.folio.rest.jaxrs.model.NatureOfContentTerms)1 Publication (org.folio.rest.jaxrs.model.Publication)1 CQLWrapper (org.folio.rest.persist.cql.CQLWrapper)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1 CQLParseException (org.z3950.zing.cql.CQLParseException)1