use of org.folio.rest.jaxrs.model.IdentifierType in project mod-inventory-storage by folio-org.
the class IdentifierTypeAPI method getIdentifierTypes.
@Validate
@Override
public void getIdentifierTypes(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
/**
* http://host:port/identifier-types
*/
vertxContext.runOnContext(v -> {
try {
String tenantId = TenantTool.tenantId(okapiHeaders);
CQLWrapper cql = getCQL(query, limit, offset);
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(IDENTIFIER_TYPE_TABLE, IdentifierType.class, new String[] { "*" }, cql, true, true, reply -> {
try {
if (reply.succeeded()) {
IdentifierTypes identifierTypes = new IdentifierTypes();
@SuppressWarnings("unchecked") List<IdentifierType> identifierType = (List<IdentifierType>) reply.result().getResults();
identifierTypes.setIdentifierTypes(identifierType);
identifierTypes.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetIdentifierTypesResponse.withJsonOK(identifierTypes)));
} else {
log.error(reply.cause().getMessage(), reply.cause());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetIdentifierTypesResponse.withPlainBadRequest(reply.cause().getMessage())));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetIdentifierTypesResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
});
} 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(GetIdentifierTypesResponse.withPlainInternalServerError(message)));
}
});
}
use of org.folio.rest.jaxrs.model.IdentifierType in project mod-inventory-storage by folio-org.
the class IdentifierTypeAPI method getIdentifierTypesByIdentifierTypeId.
@Validate
@Override
public void getIdentifierTypesByIdentifierTypeId(String identifierTypeId, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
vertxContext.runOnContext(v -> {
try {
String tenantId = TenantTool.tenantId(okapiHeaders);
Criterion c = new Criterion(new Criteria().addField(idFieldName).setJSONB(false).setOperation("=").setValue("'" + identifierTypeId + "'"));
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(IDENTIFIER_TYPE_TABLE, IdentifierType.class, c, true, reply -> {
try {
if (reply.failed()) {
String msg = PgExceptionUtil.badRequestMessage(reply.cause());
if (msg == null) {
internalServerErrorDuringGetById(reply.cause(), lang, asyncResultHandler);
return;
}
log.info(msg);
asyncResultHandler.handle(Future.succeededFuture(GetIdentifierTypesByIdentifierTypeIdResponse.withPlainNotFound(msg)));
return;
}
@SuppressWarnings("unchecked") List<IdentifierType> identifierType = (List<IdentifierType>) reply.result().getResults();
if (identifierType.isEmpty()) {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetIdentifierTypesByIdentifierTypeIdResponse.withPlainNotFound(identifierTypeId)));
} else {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetIdentifierTypesByIdentifierTypeIdResponse.withJsonOK(identifierType.get(0))));
}
} catch (Exception e) {
internalServerErrorDuringGetById(e, lang, asyncResultHandler);
}
});
} catch (Exception e) {
internalServerErrorDuringGetById(e, lang, asyncResultHandler);
}
});
}
Aggregations