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