use of org.folio.rest.persist.Criteria.Criteria in project mod-inventory-storage by folio-org.
the class LoanTypeAPI method getLoanTypesByLoantypeId.
@Validate
@Override
public void getLoanTypesByLoantypeId(String loantypeId, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
vertxContext.runOnContext(v -> {
try {
Criterion c = new Criterion(new Criteria().addField(idFieldName).setJSONB(false).setOperation("=").setValue("'" + loantypeId + "'"));
getPostgresClient(vertxContext, okapiHeaders).get(LOAN_TYPE_TABLE, Loantype.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(GetLoanTypesByLoantypeIdResponse.withPlainNotFound(msg)));
return;
}
@SuppressWarnings("unchecked") List<Loantype> userGroup = (List<Loantype>) reply.result().getResults();
if (userGroup.isEmpty()) {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetLoanTypesByLoantypeIdResponse.withPlainNotFound(loantypeId)));
} else {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetLoanTypesByLoantypeIdResponse.withJsonOK(userGroup.get(0))));
}
} catch (Exception e) {
internalServerErrorDuringGetById(e, lang, asyncResultHandler);
}
});
} catch (Exception e) {
internalServerErrorDuringGetById(e, lang, asyncResultHandler);
}
});
}
use of org.folio.rest.persist.Criteria.Criteria in project mod-inventory-storage by folio-org.
the class ClassificationTypeAPI method getClassificationTypesByClassificationTypeId.
@Validate
@Override
public void getClassificationTypesByClassificationTypeId(String instanceTypeId, 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("'" + instanceTypeId + "'"));
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(CLASSIFICATION_TYPE_TABLE, ClassificationType.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(GetClassificationTypesByClassificationTypeIdResponse.withPlainNotFound(msg)));
return;
}
@SuppressWarnings("unchecked") List<ClassificationType> instanceType = (List<ClassificationType>) reply.result().getResults();
if (instanceType.isEmpty()) {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetClassificationTypesByClassificationTypeIdResponse.withPlainNotFound(instanceTypeId)));
} else {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetClassificationTypesByClassificationTypeIdResponse.withJsonOK(instanceType.get(0))));
}
} catch (Exception e) {
internalServerErrorDuringGetById(e, lang, asyncResultHandler);
}
});
} catch (Exception e) {
internalServerErrorDuringGetById(e, lang, asyncResultHandler);
}
});
}
use of org.folio.rest.persist.Criteria.Criteria 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.persist.Criteria.Criteria in project mod-inventory-storage by folio-org.
the class LocationUnitAPI method putLocationUnitsInstitutionsById.
@Override
public void putLocationUnitsInstitutionsById(String id, String lang, Locinst entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
if (!id.equals(entity.getId())) {
String message = "Illegal operation: id cannot be changed";
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.PutLocationUnitsInstitutionsByIdResponse.withPlainBadRequest(message)));
return;
}
String tenantId = getTenant(okapiHeaders);
Criterion criterion;
try {
Criteria criteria = new Criteria(INST_SCHEMA_PATH);
criteria.addField(ID_FIELD_NAME);
criteria.setOperation("=");
criteria.setValue(id);
criterion = new Criterion(criteria);
} catch (Exception e) {
String message = logAndSaveError(e);
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.PutLocationUnitsInstitutionsByIdResponse.withPlainInternalServerError(message)));
return;
}
PostgresClient.getInstance(vertxContext.owner(), tenantId).update(INSTITUTION_TABLE, entity, criterion, false, updateReply -> {
if (updateReply.failed()) {
String message = logAndSaveError(updateReply.cause());
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.PutLocationUnitsInstitutionsByIdResponse.withPlainInternalServerError(message)));
} else {
if (updateReply.result().getUpdated() == 0) {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.PutLocationUnitsInstitutionsByIdResponse.withPlainNotFound("Institution not found")));
} else {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.PutLocationUnitsInstitutionsByIdResponse.withNoContent()));
}
}
});
}
use of org.folio.rest.persist.Criteria.Criteria in project mod-inventory-storage by folio-org.
the class LocationUnitAPI method deleteLocationUnitsLibrariesById.
@Override
public void deleteLocationUnitsLibrariesById(String id, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
String tenantId = getTenant(okapiHeaders);
Criterion criterion;
try {
Criteria criteria = new Criteria(LIB_SCHEMA_PATH);
criteria.addField(ID_FIELD_NAME);
criteria.setOperation("=");
criteria.setValue(id);
criterion = new Criterion(criteria);
} catch (Exception e) {
String message = logAndSaveError(e);
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsLibrariesByIdResponse.withPlainInternalServerError(message)));
return;
}
libInUse(id, tenantId, vertxContext).setHandler(res -> {
if (res.failed()) {
String message = logAndSaveError(res.cause());
LocationUnitsResource.DeleteLocationUnitsLibrariesByIdResponse.withPlainInternalServerError(message);
} else {
if (res.result()) {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsLibrariesByIdResponse.withPlainBadRequest("Cannot delete library, as it is in use")));
} else {
PostgresClient.getInstance(vertxContext.owner(), tenantId).delete(LIBRARY_TABLE, criterion, deleteReply -> {
if (deleteReply.failed()) {
logAndSaveError(deleteReply.cause());
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsLibrariesByIdResponse.withPlainNotFound("Library not found")));
} else {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsLibrariesByIdResponse.withNoContent()));
}
});
}
}
});
}
Aggregations