use of org.folio.rest.jaxrs.model.ContributorNameType in project mod-inventory-storage by folio-org.
the class ContributorNameTypeAPI method getContributorNameTypesByContributorNameTypeId.
@Validate
@Override
public void getContributorNameTypesByContributorNameTypeId(String ContributorNameTypeId, 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("'" + ContributorNameTypeId + "'"));
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(CONTRIBUTOR_NAME_TYPE_TABLE, ContributorNameType.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(GetContributorNameTypesByContributorNameTypeIdResponse.withPlainNotFound(msg)));
return;
}
@SuppressWarnings("unchecked") List<ContributorNameType> ContributorNameType = (List<ContributorNameType>) reply.result().getResults();
if (ContributorNameType.isEmpty()) {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetContributorNameTypesByContributorNameTypeIdResponse.withPlainNotFound(ContributorNameTypeId)));
} else {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetContributorNameTypesByContributorNameTypeIdResponse.withJsonOK(ContributorNameType.get(0))));
}
} catch (Exception e) {
internalServerErrorDuringGetById(e, lang, asyncResultHandler);
}
});
} catch (Exception e) {
internalServerErrorDuringGetById(e, lang, asyncResultHandler);
}
});
}
use of org.folio.rest.jaxrs.model.ContributorNameType in project mod-inventory-storage by folio-org.
the class ContributorNameTypeAPI method getContributorNameTypes.
@Validate
@Override
public void getContributorNameTypes(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
/**
* http://host:port/contributor-name-types
*/
vertxContext.runOnContext(v -> {
try {
String tenantId = TenantTool.tenantId(okapiHeaders);
CQLWrapper cql = getCQL(query, limit, offset);
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(CONTRIBUTOR_NAME_TYPE_TABLE, ContributorNameType.class, new String[] { "*" }, cql, true, true, reply -> {
try {
if (reply.succeeded()) {
ContributorNameTypes ContributorNameTypes = new ContributorNameTypes();
@SuppressWarnings("unchecked") List<ContributorNameType> ContributorNameType = (List<ContributorNameType>) reply.result().getResults();
ContributorNameTypes.setContributorNameTypes(ContributorNameType);
ContributorNameTypes.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetContributorNameTypesResponse.withJsonOK(ContributorNameTypes)));
} else {
log.error(reply.cause().getMessage(), reply.cause());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetContributorNameTypesResponse.withPlainBadRequest(reply.cause().getMessage())));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetContributorNameTypesResponse.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(GetContributorNameTypesResponse.withPlainInternalServerError(message)));
}
});
}
Aggregations