use of org.folio.rest.persist.Criteria.Criteria in project mod-inventory-storage by folio-org.
the class LocationUnitAPI method putLocationUnitsLibrariesById.
@Override
public void putLocationUnitsLibrariesById(String id, String lang, Loclib 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.PutLocationUnitsLibrariesByIdResponse.withPlainBadRequest(message)));
return;
}
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.PutLocationUnitsLibrariesByIdResponse.withPlainInternalServerError(message)));
return;
}
PostgresClient.getInstance(vertxContext.owner(), tenantId).update(LIBRARY_TABLE, entity, criterion, false, updateReply -> {
if (updateReply.failed()) {
String message = logAndSaveError(updateReply.cause());
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.PutLocationUnitsLibrariesByIdResponse.withPlainInternalServerError(message)));
} else {
if (updateReply.result().getUpdated() == 0) {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.PutLocationUnitsLibrariesByIdResponse.withPlainNotFound("Library not found")));
} else {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.PutLocationUnitsLibrariesByIdResponse.withNoContent()));
}
}
});
}
use of org.folio.rest.persist.Criteria.Criteria in project mod-inventory-storage by folio-org.
the class LocationUnitAPI method getLocationUnitsInstitutionsById.
@Override
public void getLocationUnitsInstitutionsById(String id, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
Criterion criterion;
String tenantId = getTenant(okapiHeaders);
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.GetLocationUnitsInstitutionsByIdResponse.withPlainInternalServerError(message)));
return;
}
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(INSTITUTION_TABLE, Locinst.class, criterion, true, false, getReply -> {
if (getReply.failed()) {
String message = logAndSaveError(getReply.cause());
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsInstitutionsByIdResponse.withPlainInternalServerError(message)));
} else {
List<Locinst> instlist = (List<Locinst>) getReply.result().getResults();
if (instlist.isEmpty()) {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsInstitutionsByIdResponse.withPlainNotFound(messages.getMessage(lang, MessageConsts.ObjectDoesNotExist))));
// We can safely ignore the case that we have more than one with
// the same id, RMB has a primary key on ID, will not allow it
} else {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsInstitutionsByIdResponse.withJsonOK(instlist.get(0))));
}
}
});
}
use of org.folio.rest.persist.Criteria.Criteria in project mod-inventory-storage by folio-org.
the class HoldingsStorageAPI method deleteHoldingsStorageHoldingsByHoldingsRecordId.
@Override
public void deleteHoldingsStorageHoldingsByHoldingsRecordId(@NotNull String holdingsRecordId, @DefaultValue("en") @Pattern(regexp = "[a-zA-Z]{2}") String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
String tenantId = okapiHeaders.get(TENANT_HEADER);
try {
PostgresClient postgresClient = PostgresClient.getInstance(vertxContext.owner(), TenantTool.calculateTenantId(tenantId));
Criteria a = new Criteria();
a.addField("'id'");
a.setOperation("=");
a.setValue(holdingsRecordId);
Criterion criterion = new Criterion(a);
vertxContext.runOnContext(v -> {
try {
postgresClient.delete(HOLDINGS_RECORD_TABLE, criterion, reply -> {
if (reply.succeeded()) {
asyncResultHandler.handle(Future.succeededFuture(DeleteHoldingsStorageHoldingsByHoldingsRecordIdResponse.withNoContent()));
} else {
asyncResultHandler.handle(Future.succeededFuture(DeleteHoldingsStorageHoldingsByHoldingsRecordIdResponse.withPlainInternalServerError(reply.cause().getMessage())));
}
});
} catch (Exception e) {
asyncResultHandler.handle(Future.succeededFuture(DeleteHoldingsStorageHoldingsByHoldingsRecordIdResponse.withPlainInternalServerError(e.getMessage())));
}
});
} catch (Exception e) {
asyncResultHandler.handle(Future.succeededFuture(DeleteHoldingsStorageHoldingsByHoldingsRecordIdResponse.withPlainInternalServerError(e.getMessage())));
}
}
use of org.folio.rest.persist.Criteria.Criteria 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);
}
});
}
use of org.folio.rest.persist.Criteria.Criteria in project mod-inventory-storage by folio-org.
the class InstanceFormatAPI method getInstanceFormatsByInstanceFormatId.
@Validate
@Override
public void getInstanceFormatsByInstanceFormatId(String instanceFormatId, 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("'" + instanceFormatId + "'"));
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(INSTANCE_FORMAT_TABLE, InstanceFormat.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(GetInstanceFormatsByInstanceFormatIdResponse.withPlainNotFound(msg)));
return;
}
@SuppressWarnings("unchecked") List<InstanceFormat> instanceFormat = (List<InstanceFormat>) reply.result().getResults();
if (instanceFormat.isEmpty()) {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetInstanceFormatsByInstanceFormatIdResponse.withPlainNotFound(instanceFormatId)));
} else {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetInstanceFormatsByInstanceFormatIdResponse.withJsonOK(instanceFormat.get(0))));
}
} catch (Exception e) {
internalServerErrorDuringGetById(e, lang, asyncResultHandler);
}
});
} catch (Exception e) {
internalServerErrorDuringGetById(e, lang, asyncResultHandler);
}
});
}
Aggregations