Search in sources :

Example 1 with HridManager

use of org.folio.rest.support.HridManager in project mod-inventory-storage by folio-org.

the class HridSettingsStorageTest method canGetNextInstanceHridWithoutLeadingZeroes.

@Test
public void canGetNextInstanceHridWithoutLeadingZeroes(TestContext testContext) {
    log.info("Starting canGetNextInstanceHrid()");
    final Vertx vertx = StorageTestSuite.getVertx();
    final PostgresClient postgresClient = PostgresClient.getInstance(vertx, TENANT_ID);
    final HridManager hridManager = new HridManager(vertx.getOrCreateContext(), postgresClient);
    hridManager.updateHridSettings(initialHridSettingsWithoutLeadingZeroes).onComplete(testContext.asyncAssertSuccess(hridSettingsResult -> hridManager.getNextInstanceHrid().compose(hrid -> validateHrid(hrid, "in1", testContext)).onComplete(testContext.asyncAssertSuccess(v -> log.info("Finished canGetNextInstanceHridWithoutLeadingZeroes()")))));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Response(org.folio.rest.support.Response) TENANT_ID(org.folio.rest.api.StorageTestSuite.TENANT_ID) CoreMatchers.not(org.hamcrest.CoreMatchers.not) RunWith(org.junit.runner.RunWith) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HridSettings(org.folio.rest.jaxrs.model.HridSettings) InterfaceUrls(org.folio.rest.support.http.InterfaceUrls) Before(org.junit.Before) HridSetting(org.folio.rest.jaxrs.model.HridSetting) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) ResponseHandler.text(org.folio.rest.support.ResponseHandler.text) Future(io.vertx.core.Future) PostgresClient(org.folio.rest.persist.PostgresClient) HridManager(org.folio.rest.support.HridManager) ExecutionException(java.util.concurrent.ExecutionException) ResponseHandler.empty(org.folio.rest.support.ResponseHandler.empty) Logger(org.apache.logging.log4j.Logger) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) Row(io.vertx.sqlclient.Row) ResponseHandler.json(org.folio.rest.support.ResponseHandler.json) LogManager(org.apache.logging.log4j.LogManager) SECONDS(java.util.concurrent.TimeUnit.SECONDS) HridManager(org.folio.rest.support.HridManager) PostgresClient(org.folio.rest.persist.PostgresClient) Vertx(io.vertx.core.Vertx) Test(org.junit.Test)

Example 2 with HridManager

use of org.folio.rest.support.HridManager in project mod-inventory-storage by folio-org.

the class HridSettingsStorageTest method canGetNextItemHridMultipleTimes.

@Test
public void canGetNextItemHridMultipleTimes(TestContext testContext) {
    log.info("Starting canGetNextItemHridMultipleTimes()");
    final Vertx vertx = StorageTestSuite.getVertx();
    final PostgresClient postgresClient = PostgresClient.getInstance(vertx, TENANT_ID);
    final HridManager hridManager = new HridManager(vertx.getOrCreateContext(), postgresClient);
    hridManager.getNextItemHrid().compose(hrid -> validateHrid(hrid, "it00000000001", testContext)).compose(v -> hridManager.getNextItemHrid()).compose(hrid -> validateHrid(hrid, "it00000000002", testContext)).compose(v -> hridManager.getNextItemHrid()).compose(hrid -> validateHrid(hrid, "it00000000003", testContext)).compose(v -> hridManager.getNextItemHrid()).compose(hrid -> validateHrid(hrid, "it00000000004", testContext)).compose(v -> hridManager.getNextItemHrid()).compose(hrid -> validateHrid(hrid, "it00000000005", testContext)).onComplete(testContext.asyncAssertSuccess(v -> log.info("Finished canGetNextItemHridMultipleTimes()")));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Response(org.folio.rest.support.Response) TENANT_ID(org.folio.rest.api.StorageTestSuite.TENANT_ID) CoreMatchers.not(org.hamcrest.CoreMatchers.not) RunWith(org.junit.runner.RunWith) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HridSettings(org.folio.rest.jaxrs.model.HridSettings) InterfaceUrls(org.folio.rest.support.http.InterfaceUrls) Before(org.junit.Before) HridSetting(org.folio.rest.jaxrs.model.HridSetting) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) ResponseHandler.text(org.folio.rest.support.ResponseHandler.text) Future(io.vertx.core.Future) PostgresClient(org.folio.rest.persist.PostgresClient) HridManager(org.folio.rest.support.HridManager) ExecutionException(java.util.concurrent.ExecutionException) ResponseHandler.empty(org.folio.rest.support.ResponseHandler.empty) Logger(org.apache.logging.log4j.Logger) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) Row(io.vertx.sqlclient.Row) ResponseHandler.json(org.folio.rest.support.ResponseHandler.json) LogManager(org.apache.logging.log4j.LogManager) SECONDS(java.util.concurrent.TimeUnit.SECONDS) HridManager(org.folio.rest.support.HridManager) PostgresClient(org.folio.rest.persist.PostgresClient) Vertx(io.vertx.core.Vertx) Test(org.junit.Test)

Example 3 with HridManager

use of org.folio.rest.support.HridManager in project mod-inventory-storage by folio-org.

the class HridSettingsStorageTest method canGetNextHoldingHridWithoutLeadingZeroes.

@Test
public void canGetNextHoldingHridWithoutLeadingZeroes(TestContext testContext) {
    log.info("Starting canGetNextHoldingHridWithoutLeadingZeroes()");
    final Vertx vertx = StorageTestSuite.getVertx();
    final PostgresClient postgresClient = PostgresClient.getInstance(vertx, TENANT_ID);
    final HridManager hridManager = new HridManager(vertx.getOrCreateContext(), postgresClient);
    hridManager.updateHridSettings(initialHridSettingsWithoutLeadingZeroes).onComplete(testContext.asyncAssertSuccess(hridSettingsResult -> hridManager.getNextHoldingsHrid().compose(hrid -> validateHrid(hrid, "ho1", testContext)).onComplete(testContext.asyncAssertSuccess(v -> log.info("Finished canGetNextHoldingHridWithoutLeadingZeroes()")))));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Response(org.folio.rest.support.Response) TENANT_ID(org.folio.rest.api.StorageTestSuite.TENANT_ID) CoreMatchers.not(org.hamcrest.CoreMatchers.not) RunWith(org.junit.runner.RunWith) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HridSettings(org.folio.rest.jaxrs.model.HridSettings) InterfaceUrls(org.folio.rest.support.http.InterfaceUrls) Before(org.junit.Before) HridSetting(org.folio.rest.jaxrs.model.HridSetting) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) ResponseHandler.text(org.folio.rest.support.ResponseHandler.text) Future(io.vertx.core.Future) PostgresClient(org.folio.rest.persist.PostgresClient) HridManager(org.folio.rest.support.HridManager) ExecutionException(java.util.concurrent.ExecutionException) ResponseHandler.empty(org.folio.rest.support.ResponseHandler.empty) Logger(org.apache.logging.log4j.Logger) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) Row(io.vertx.sqlclient.Row) ResponseHandler.json(org.folio.rest.support.ResponseHandler.json) LogManager(org.apache.logging.log4j.LogManager) SECONDS(java.util.concurrent.TimeUnit.SECONDS) HridManager(org.folio.rest.support.HridManager) PostgresClient(org.folio.rest.persist.PostgresClient) Vertx(io.vertx.core.Vertx) Test(org.junit.Test)

Example 4 with HridManager

use of org.folio.rest.support.HridManager in project mod-inventory-storage by folio-org.

the class InstanceStorageBatchAPI method saveInstance.

/**
 * Saves Instance into the db
 *
 * @param instance       Instance to save
 * @param postgresClient Postgres Client
 * @return future containing saved Instance or error
 */
private Future<Instance> saveInstance(Instance instance, PostgresClient postgresClient) {
    final Future<String> hridFuture;
    if (isBlank(instance.getHrid())) {
        final HridManager hridManager = new HridManager(Vertx.currentContext(), postgresClient);
        hridFuture = hridManager.getNextInstanceHrid();
    } else {
        hridFuture = succeededFuture(instance.getHrid());
    }
    return hridFuture.compose(hrid -> {
        instance.setHrid(hrid);
        return Future.<String>future(promise -> postgresClient.save(INSTANCE_TABLE, instance.getId(), instance, promise));
    }).map(id -> {
        instance.setId(id);
        return instance;
    }).onFailure(error -> log.error("Failed to generate an instance HRID", error));
}
Also used : Future.succeededFuture(io.vertx.core.Future.succeededFuture) Instance(org.folio.rest.jaxrs.model.Instance) Function(java.util.function.Function) Context(io.vertx.core.Context) ArrayList(java.util.ArrayList) PostInstanceStorageBatchInstancesResponse.respond500WithApplicationJson(org.folio.rest.jaxrs.resource.InstanceStorageBatchInstances.PostInstanceStorageBatchInstancesResponse.respond500WithApplicationJson) MetadataUtil(org.folio.rest.tools.utils.MetadataUtil) CompositeFuture(io.vertx.core.CompositeFuture) Lists(com.google.common.collect.Lists) StatusUpdatedDateGenerator.generateStatusUpdatedDate(org.folio.rest.support.StatusUpdatedDateGenerator.generateStatusUpdatedDate) Instances(org.folio.rest.jaxrs.model.Instances) Map(java.util.Map) InstanceDomainEventPublisher(org.folio.services.domainevent.InstanceDomainEventPublisher) PostInstanceStorageBatchInstancesResponse.respond500WithTextPlain(org.folio.rest.jaxrs.resource.InstanceStorageBatchInstances.PostInstanceStorageBatchInstancesResponse.respond500WithTextPlain) AsyncResult(io.vertx.core.AsyncResult) PostInstanceStorageBatchInstancesResponse.respond201WithApplicationJson(org.folio.rest.jaxrs.resource.InstanceStorageBatchInstances.PostInstanceStorageBatchInstancesResponse.respond201WithApplicationJson) MODULE_SPECIFIC_ARGS(org.folio.rest.RestVerticle.MODULE_SPECIFIC_ARGS) Vertx(io.vertx.core.Vertx) Collectors(java.util.stream.Collectors) Validate(org.folio.rest.annotations.Validate) Future(io.vertx.core.Future) PostgresClient(org.folio.rest.persist.PostgresClient) HridManager(org.folio.rest.support.HridManager) InstanceStorageBatchInstances(org.folio.rest.jaxrs.resource.InstanceStorageBatchInstances) List(java.util.List) PgUtil(org.folio.rest.persist.PgUtil) Logger(org.apache.logging.log4j.Logger) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) Response(javax.ws.rs.core.Response) InstancesBatchResponse(org.folio.rest.jaxrs.model.InstancesBatchResponse) Handler(io.vertx.core.Handler) LogManager(org.apache.logging.log4j.LogManager) HridManager(org.folio.rest.support.HridManager)

Example 5 with HridManager

use of org.folio.rest.support.HridManager in project mod-inventory-storage by folio-org.

the class HridSettingsStorageTest method setUp.

@Before
public void setUp(TestContext testContext) {
    log.info("Initializing values");
    final Async async = testContext.async();
    vertx = StorageTestSuite.getVertx();
    postgresClient = PostgresClient.getInstance(vertx, TENANT_ID);
    hridManager = new HridManager(vertx.getOrCreateContext(), postgresClient);
    hridManager.updateHridSettings(initialHridSettings).onComplete(hridSettings -> {
        // We need to do this in cases where tests do not update the start number. In this
        // case, calling updateHridSettings will not update the sequences since the start number
        // has not changed. Since tests are executed in a non-deterministic order, we need to
        // ensure that the sequences are reset to 1 on start and that the next HRID value will be
        // use 1 as the number component.
        Promise<Row> instancePromise = Promise.promise();
        Promise<Row> holdingPromise = Promise.promise();
        Promise<Row> itemPromise = Promise.promise();
        postgresClient.selectSingle("select setval('hrid_instances_seq',1,FALSE)", instancePromise);
        instancePromise.future().map(v -> {
            postgresClient.selectSingle("select setval('hrid_holdings_seq',1,FALSE)", holdingPromise);
            return null;
        });
        holdingPromise.future().map(v -> {
            postgresClient.selectSingle("select setval('hrid_items_seq',1,FALSE)", itemPromise);
            return null;
        });
        itemPromise.future().map(v -> {
            log.info("Initializing values complete");
            async.complete();
            return null;
        });
    });
}
Also used : Async(io.vertx.ext.unit.Async) HridManager(org.folio.rest.support.HridManager) Row(io.vertx.sqlclient.Row) Before(org.junit.Before)

Aggregations

HridManager (org.folio.rest.support.HridManager)10 Future (io.vertx.core.Future)9 LogManager (org.apache.logging.log4j.LogManager)9 Logger (org.apache.logging.log4j.Logger)9 PostgresClient (org.folio.rest.persist.PostgresClient)9 HridSettings (org.folio.rest.jaxrs.model.HridSettings)8 Vertx (io.vertx.core.Vertx)7 Async (io.vertx.ext.unit.Async)7 Row (io.vertx.sqlclient.Row)7 Before (org.junit.Before)7 Promise (io.vertx.core.Promise)6 TestContext (io.vertx.ext.unit.TestContext)6 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)6 UUID (java.util.UUID)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 ExecutionException (java.util.concurrent.ExecutionException)6 SECONDS (java.util.concurrent.TimeUnit.SECONDS)6 TimeoutException (java.util.concurrent.TimeoutException)6 TENANT_ID (org.folio.rest.api.StorageTestSuite.TENANT_ID)6 HridSetting (org.folio.rest.jaxrs.model.HridSetting)6