use of org.folio.rest.annotations.Validate 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.annotations.Validate in project mod-inventory-storage by folio-org.
the class InstanceFormatAPI method deleteInstanceFormatsByInstanceFormatId.
@Validate
@Override
public void deleteInstanceFormatsByInstanceFormatId(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);
PostgresClient postgres = PostgresClient.getInstance(vertxContext.owner(), tenantId);
postgres.delete(INSTANCE_FORMAT_TABLE, instanceFormatId, reply -> {
try {
if (reply.failed()) {
String msg = PgExceptionUtil.badRequestMessage(reply.cause());
if (msg == null) {
internalServerErrorDuringDelete(reply.cause(), lang, asyncResultHandler);
return;
}
log.info(msg);
asyncResultHandler.handle(Future.succeededFuture(DeleteInstanceFormatsByInstanceFormatIdResponse.withPlainBadRequest(msg)));
return;
}
int updated = reply.result().getUpdated();
if (updated != 1) {
String msg = messages.getMessage(lang, MessageConsts.DeletedCountError, 1, updated);
log.error(msg);
asyncResultHandler.handle(Future.succeededFuture(DeleteInstanceFormatsByInstanceFormatIdResponse.withPlainNotFound(msg)));
return;
}
asyncResultHandler.handle(Future.succeededFuture(DeleteInstanceFormatsByInstanceFormatIdResponse.withNoContent()));
} catch (Exception e) {
internalServerErrorDuringDelete(e, lang, asyncResultHandler);
}
});
} catch (Exception e) {
internalServerErrorDuringDelete(e, lang, asyncResultHandler);
}
});
}
use of org.folio.rest.annotations.Validate in project mod-inventory-storage by folio-org.
the class InstanceFormatAPI method getInstanceFormats.
@Validate
@Override
public void getInstanceFormats(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
/**
* http://host:port/instance-formats
*/
vertxContext.runOnContext(v -> {
try {
String tenantId = TenantTool.tenantId(okapiHeaders);
CQLWrapper cql = getCQL(query, limit, offset);
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(INSTANCE_FORMAT_TABLE, InstanceFormat.class, new String[] { "*" }, cql, true, true, reply -> {
try {
if (reply.succeeded()) {
InstanceFormats instanceFormats = new InstanceFormats();
@SuppressWarnings("unchecked") List<InstanceFormat> instanceFormat = (List<InstanceFormat>) reply.result().getResults();
instanceFormats.setInstanceFormats(instanceFormat);
instanceFormats.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetInstanceFormatsResponse.withJsonOK(instanceFormats)));
} else {
log.error(reply.cause().getMessage(), reply.cause());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetInstanceFormatsResponse.withPlainBadRequest(reply.cause().getMessage())));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetInstanceFormatsResponse.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(GetInstanceFormatsResponse.withPlainInternalServerError(message)));
}
});
}
use of org.folio.rest.annotations.Validate in project mod-inventory-storage by folio-org.
the class InstanceTypeAPI method postInstanceTypes.
@Validate
@Override
public void postInstanceTypes(String lang, InstanceType entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
vertxContext.runOnContext(v -> {
try {
String id = entity.getId();
if (id == null) {
id = UUID.randomUUID().toString();
entity.setId(id);
}
String tenantId = TenantTool.tenantId(okapiHeaders);
PostgresClient.getInstance(vertxContext.owner(), tenantId).save(INSTANCE_TYPE_TABLE, id, entity, reply -> {
try {
if (reply.succeeded()) {
Object ret = reply.result();
entity.setId((String) ret);
OutStream stream = new OutStream();
stream.setData(entity);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PostInstanceTypesResponse.withJsonCreated(LOCATION_PREFIX + ret, stream)));
} else {
String msg = PgExceptionUtil.badRequestMessage(reply.cause());
if (msg == null) {
internalServerErrorDuringPost(reply.cause(), lang, asyncResultHandler);
return;
}
log.info(msg);
asyncResultHandler.handle(Future.succeededFuture(PostInstanceTypesResponse.withPlainBadRequest(msg)));
}
} catch (Exception e) {
internalServerErrorDuringPost(e, lang, asyncResultHandler);
}
});
} catch (Exception e) {
internalServerErrorDuringPost(e, lang, asyncResultHandler);
}
});
}
use of org.folio.rest.annotations.Validate in project mod-inventory-storage by folio-org.
the class ItemStorageAPI method deleteItemStorageItemsByItemId.
@Validate
@Override
public void deleteItemStorageItemsByItemId(@PathParam("itemId") @NotNull String itemId, @QueryParam("lang") @DefaultValue("en") @Pattern(regexp = "[a-zA-Z]{2}") String lang, java.util.Map<String, String> okapiHeaders, io.vertx.core.Handler<io.vertx.core.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(itemId);
Criterion criterion = new Criterion(a);
vertxContext.runOnContext(v -> {
try {
postgresClient.delete("item", criterion, reply -> {
if (reply.succeeded()) {
asyncResultHandler.handle(Future.succeededFuture(DeleteItemStorageItemsByItemIdResponse.withNoContent()));
} else {
asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.DeleteItemStorageItemsByItemIdResponse.withPlainInternalServerError("Error")));
}
});
} catch (Exception e) {
asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.DeleteItemStorageItemsByItemIdResponse.withPlainInternalServerError("Error")));
}
});
} catch (Exception e) {
asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.DeleteItemStorageItemsByItemIdResponse.withPlainInternalServerError("Error")));
}
}
Aggregations