use of org.folio.rest.jaxrs.model.Item in project mod-inventory-storage by folio-org.
the class LocationAPI method locationInUse.
Future<Boolean> locationInUse(String locationId, String tenantId, Context vertxContext) {
Future<Boolean> future = Future.future();
// Get all items where the temporary future or permanent future is this location id
String query = "permanentLocation == " + locationId + " OR temporarylocation == " + locationId;
try {
CQLWrapper cql = getCQL(query, 10, 0, ItemStorageAPI.ITEM_TABLE);
String[] fieldList = { "*" };
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(ItemStorageAPI.ITEM_TABLE, Item.class, fieldList, cql, true, false, getReply -> {
if (getReply.failed()) {
future.fail(getReply.cause());
} else {
List<Item> itemList = (List<Item>) getReply.result().getResults();
if (itemList.isEmpty()) {
future.complete(false);
} else {
future.complete(true);
}
}
});
} catch (Exception e) {
future.fail(e);
}
return future;
}
use of org.folio.rest.jaxrs.model.Item in project mod-inventory-storage by folio-org.
the class MaterialTypeAPI method deleteMaterialTypesByMaterialtypeId.
@Validate
@Override
public void deleteMaterialTypesByMaterialtypeId(String materialtypeId, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
vertxContext.runOnContext(v -> {
String tenantId = TenantTool.calculateTenantId(okapiHeaders.get(RestVerticle.OKAPI_HEADER_TENANT));
try {
Item item = new Item();
item.setMaterialTypeId(materialtypeId);
/**
* check if any item is using this material type *
*/
try {
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(ItemStorageAPI.ITEM_TABLE, item, new String[] { idFieldName }, true, false, 0, 1, replyHandler -> {
if (replyHandler.succeeded()) {
List<Item> mtypeList = (List<Item>) replyHandler.result().getResults();
if (mtypeList.size() > 0) {
String message = "Can not delete material type, " + materialtypeId + ". " + mtypeList.size() + " items associated with it";
log.error(message);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(DeleteMaterialTypesByMaterialtypeIdResponse.withPlainBadRequest(message)));
return;
} else {
log.info("Attemping delete of unused material type, " + materialtypeId);
}
try {
PostgresClient.getInstance(vertxContext.owner(), tenantId).delete(MATERIAL_TYPE_TABLE, materialtypeId, reply -> {
try {
if (reply.succeeded()) {
if (reply.result().getUpdated() == 1) {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(DeleteMaterialTypesByMaterialtypeIdResponse.withNoContent()));
} else {
log.error(messages.getMessage(lang, MessageConsts.DeletedCountError, 1, reply.result().getUpdated()));
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(DeleteMaterialTypesByMaterialtypeIdResponse.withPlainNotFound(messages.getMessage(lang, MessageConsts.DeletedCountError, 1, reply.result().getUpdated()))));
}
} else {
log.error(reply.cause().getMessage(), reply.cause());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(DeleteMaterialTypesByMaterialtypeIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(DeleteMaterialTypesByMaterialtypeIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
});
} catch (Exception e) {
log.error(e.getMessage(), e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(DeleteMaterialTypesByMaterialtypeIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
} else {
log.error(replyHandler.cause().getMessage(), replyHandler.cause());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(DeleteMaterialTypesByMaterialtypeIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
});
} catch (Exception e) {
log.error(e.getMessage(), e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(DeleteMaterialTypesByMaterialtypeIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(DeleteMaterialTypesByMaterialtypeIdResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
});
}
Aggregations