use of org.folio.rest.persist.Criteria.Criteria in project mod-inventory-storage by folio-org.
the class LocationUnitAPI method deleteLocationUnitsInstitutionsById.
@Override
public void deleteLocationUnitsInstitutionsById(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.DeleteLocationUnitsInstitutionsByIdResponse.withPlainInternalServerError(message)));
return;
}
instInUse(id, tenantId, vertxContext).setHandler(res -> {
if (res.failed()) {
String message = logAndSaveError(res.cause());
LocationUnitsResource.DeleteLocationUnitsInstitutionsByIdResponse.withPlainInternalServerError(message);
} else {
if (res.result()) {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsInstitutionsByIdResponse.withPlainBadRequest("Cannot delete institution, as it is in use")));
} else {
try {
PostgresClient.getInstance(vertxContext.owner(), tenantId).delete(INSTITUTION_TABLE, criterion, deleteReply -> {
if (deleteReply.failed()) {
logAndSaveError(deleteReply.cause());
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsInstitutionsByIdResponse.withPlainNotFound("Institution not found")));
} else {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsInstitutionsByIdResponse.withNoContent()));
}
});
} catch (Exception e) {
String message = logAndSaveError(e);
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsInstitutionsByIdResponse.withPlainInternalServerError(message)));
}
}
}
});
}
use of org.folio.rest.persist.Criteria.Criteria in project mod-inventory-storage by folio-org.
the class LocationUnitAPI method deleteLocationUnitsCampusesById.
@Override
public void deleteLocationUnitsCampusesById(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(CAMP_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.DeleteLocationUnitsCampusesByIdResponse.withPlainInternalServerError(message)));
return;
}
campInUse(id, tenantId, vertxContext).setHandler(res -> {
if (res.failed()) {
String message = logAndSaveError(res.cause());
LocationUnitsResource.DeleteLocationUnitsCampusesByIdResponse.withPlainInternalServerError(message);
} else {
if (res.result()) {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsCampusesByIdResponse.withPlainBadRequest("Cannot delete campus, as it is in use")));
} else {
PostgresClient.getInstance(vertxContext.owner(), tenantId).delete(CAMPUS_TABLE, criterion, deleteReply -> {
if (deleteReply.failed()) {
logAndSaveError(deleteReply.cause());
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsCampusesByIdResponse.withPlainNotFound("Campus not found")));
} else {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsCampusesByIdResponse.withNoContent()));
}
});
}
}
});
}
use of org.folio.rest.persist.Criteria.Criteria in project mod-inventory-storage by folio-org.
the class LocationUnitAPI method getLocationUnitsLibrariesById.
@Override
public void getLocationUnitsLibrariesById(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.GetLocationUnitsLibrariesByIdResponse.withPlainInternalServerError(message)));
return;
}
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(LIBRARY_TABLE, Loclib.class, criterion, true, false, getReply -> {
if (getReply.failed()) {
String message = logAndSaveError(getReply.cause());
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsLibrariesByIdResponse.withPlainInternalServerError(message)));
} else {
List<Loclib> items = (List<Loclib>) getReply.result().getResults();
if (items.isEmpty()) {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsLibrariesByIdResponse.withPlainNotFound(messages.getMessage(lang, MessageConsts.ObjectDoesNotExist))));
} else if (items.size() > 1) {
String message = "Multiple locations found with the same id";
logger.error(message);
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsLibrariesByIdResponse.withPlainInternalServerError(message)));
} else {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsLibrariesByIdResponse.withJsonOK(items.get(0))));
}
}
});
}
use of org.folio.rest.persist.Criteria.Criteria in project mod-inventory-storage by folio-org.
the class LocationUnitAPI method putLocationUnitsCampusesById.
@Override
public void putLocationUnitsCampusesById(String id, String lang, Loccamp entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
if (!id.equals(entity.getId())) {
String message = "Illegal operation: id cannot be changed";
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.PutLocationUnitsCampusesByIdResponse.withPlainBadRequest(message)));
return;
}
String tenantId = getTenant(okapiHeaders);
Criterion criterion;
try {
Criteria criteria = new Criteria(CAMP_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.PutLocationUnitsCampusesByIdResponse.withPlainInternalServerError(message)));
return;
}
PostgresClient.getInstance(vertxContext.owner(), tenantId).update(CAMPUS_TABLE, entity, criterion, false, updateReply -> {
if (updateReply.failed()) {
String message = logAndSaveError(updateReply.cause());
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.PutLocationUnitsCampusesByIdResponse.withPlainInternalServerError(message)));
} else {
if (updateReply.result().getUpdated() == 0) {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.PutLocationUnitsCampusesByIdResponse.withPlainNotFound("Campus not found")));
} else {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.PutLocationUnitsCampusesByIdResponse.withNoContent()));
}
}
});
}
use of org.folio.rest.persist.Criteria.Criteria in project mod-inventory-storage by folio-org.
the class LocationUnitAPI method getLocationUnitsCampusesById.
@Override
public void getLocationUnitsCampusesById(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(CAMP_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.GetLocationUnitsCampusesByIdResponse.withPlainInternalServerError(message)));
return;
}
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(CAMPUS_TABLE, Loccamp.class, criterion, true, false, getReply -> {
if (getReply.failed()) {
String message = logAndSaveError(getReply.cause());
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsCampusesByIdResponse.withPlainInternalServerError(message)));
} else {
List<Loccamp> items = (List<Loccamp>) getReply.result().getResults();
if (items.isEmpty()) {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsCampusesByIdResponse.withPlainNotFound(messages.getMessage(lang, MessageConsts.ObjectDoesNotExist))));
} else if (items.size() > 1) {
String message = "Multiple campuses found with the same id";
logger.error(message);
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsCampusesByIdResponse.withPlainInternalServerError(message)));
} else {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsCampusesByIdResponse.withJsonOK(items.get(0))));
}
}
});
}
Aggregations