use of org.folio.rest.annotations.Validate in project mod-inventory-storage by folio-org.
the class ClassificationTypeAPI method postClassificationTypes.
@Validate
@Override
public void postClassificationTypes(String lang, ClassificationType 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(CLASSIFICATION_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(PostClassificationTypesResponse.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(PostClassificationTypesResponse.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 ClassificationTypeAPI method deleteClassificationTypesByClassificationTypeId.
@Validate
@Override
public void deleteClassificationTypesByClassificationTypeId(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);
PostgresClient postgres = PostgresClient.getInstance(vertxContext.owner(), tenantId);
postgres.delete(CLASSIFICATION_TYPE_TABLE, instanceTypeId, 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(DeleteClassificationTypesByClassificationTypeIdResponse.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(DeleteClassificationTypesByClassificationTypeIdResponse.withPlainNotFound(msg)));
return;
}
asyncResultHandler.handle(Future.succeededFuture(DeleteClassificationTypesByClassificationTypeIdResponse.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 ContributorNameTypeAPI method postContributorNameTypes.
@Validate
@Override
public void postContributorNameTypes(String lang, ContributorNameType 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(CONTRIBUTOR_NAME_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(PostContributorNameTypesResponse.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(PostContributorNameTypesResponse.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 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)));
}
});
}
use of org.folio.rest.annotations.Validate in project mod-inventory-storage by folio-org.
the class ContributorTypeAPI method postContributorTypes.
@Validate
@Override
public void postContributorTypes(String lang, ContributorType 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(CONTRIBUTOR_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(PostContributorTypesResponse.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(PostContributorTypesResponse.withPlainBadRequest(msg)));
}
} catch (Exception e) {
internalServerErrorDuringPost(e, lang, asyncResultHandler);
}
});
} catch (Exception e) {
internalServerErrorDuringPost(e, lang, asyncResultHandler);
}
});
}
Aggregations