本文整理匯總了Java中org.folio.rest.tools.utils.TenantTool類的典型用法代碼示例。如果您正苦於以下問題:Java TenantTool類的具體用法?Java TenantTool怎麽用?Java TenantTool使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TenantTool類屬於org.folio.rest.tools.utils包,在下文中一共展示了TenantTool類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: postAdminGetPassword
import org.folio.rest.tools.utils.TenantTool; //導入依賴的package包/類
@Validate
@Override
public void postAdminGetPassword(String key, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
String tenantId = TenantTool.calculateTenantId( okapiHeaders.get(ClientGenerator.OKAPI_HEADER_TENANT) );
if(tenantId == null){
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(
PostAdminGetPasswordResponse.withPlainBadRequest("Tenant id is null")));
}
else{
try {
String password = AES.encryptPasswordAsBase64(tenantId, AES.getSecretKeyObject(key));
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PostAdminGetPasswordResponse.withPlainOK(password)));
} catch (Exception e) {
log.error(e.getMessage(), e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(
PostAdminGetPasswordResponse.withPlainInternalServerError(e.getMessage())));
}
}
}
示例2: deleteLoanStorageLoans
import org.folio.rest.tools.utils.TenantTool; //導入依賴的package包/類
@Override
public void deleteLoanStorageLoans(
String lang,
Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler,
Context vertxContext) throws Exception {
String tenantId = okapiHeaders.get(TENANT_HEADER);
vertxContext.runOnContext(v -> {
try {
PostgresClient postgresClient = PostgresClient.getInstance(
vertxContext.owner(), TenantTool.calculateTenantId(tenantId));
postgresClient.mutate(String.format("TRUNCATE TABLE %s_%s.loan",
tenantId, "mod_circulation_storage"),
reply -> {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(
LoanStorageResource.DeleteLoanStorageLoansResponse
.noContent().build()));
});
}
catch(Exception e) {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(
LoanStorageResource.DeleteLoanStorageLoansResponse
.withPlainInternalServerError(e.getMessage())));
}
});
}
示例3: deleteLoanPolicyStorageLoanPolicies
import org.folio.rest.tools.utils.TenantTool; //導入依賴的package包/類
@Override
@Validate
public void deleteLoanPolicyStorageLoanPolicies(
String lang, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler,
Context vertxContext) throws Exception {
String tenantId = okapiHeaders.get(TENANT_HEADER);
vertxContext.runOnContext(v -> {
try {
PostgresClient postgresClient = PostgresClient.getInstance(
vertxContext.owner(), TenantTool.calculateTenantId(tenantId));
postgresClient.mutate(String.format("TRUNCATE TABLE %s_%s.%s",
tenantId, "mod_circulation_storage", LOAN_POLICY_TABLE),
reply -> {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(
LoanPolicyStorageResource.DeleteLoanPolicyStorageLoanPoliciesResponse
.noContent().build()));
});
}
catch(Exception e) {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(
LoanPolicyStorageResource.DeleteLoanPolicyStorageLoanPoliciesResponse
.withPlainInternalServerError(e.getMessage())));
}
});
}
示例4: deleteRequestStorageRequests
import org.folio.rest.tools.utils.TenantTool; //導入依賴的package包/類
@Override
public void deleteRequestStorageRequests(
String lang,
Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler,
Context vertxContext) throws Exception {
String tenantId = okapiHeaders.get(TENANT_HEADER);
vertxContext.runOnContext(v -> {
try {
PostgresClient postgresClient = PostgresClient.getInstance(
vertxContext.owner(), TenantTool.calculateTenantId(tenantId));
postgresClient.mutate(String.format("TRUNCATE TABLE %s_%s.%s",
tenantId, "mod_circulation_storage", REQUEST_TABLE),
reply -> {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(
DeleteRequestStorageRequestsResponse.withNoContent()));
});
}
catch(Exception e) {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(
DeleteRequestStorageRequestsResponse
.withPlainInternalServerError(e.getMessage())));
}
});
}
示例5: deleteInstanceStorageInstances
import org.folio.rest.tools.utils.TenantTool; //導入依賴的package包/類
@Override
public void deleteInstanceStorageInstances(
@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);
if (blankTenantId(tenantId)) {
badRequestResult(asyncResultHandler, BLANK_TENANT_MESSAGE);
return;
}
vertxContext.runOnContext(v -> {
try {
PostgresClient postgresClient = PostgresClient.getInstance(
vertxContext.owner(), TenantTool.calculateTenantId(tenantId));
postgresClient.mutate(String.format("TRUNCATE TABLE %s_%s.instance",
tenantId, "inventory_storage"),
reply -> {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(
InstanceStorageResource.DeleteInstanceStorageInstancesResponse
.noContent().build()));
});
}
catch(Exception e) {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(
InstanceStorageResource.DeleteInstanceStorageInstancesResponse
.withPlainInternalServerError(e.getMessage())));
}
});
}
示例6: getTenant
import org.folio.rest.tools.utils.TenantTool; //導入依賴的package包/類
@Validate
@Override
public void getTenant(Map<String, String> headers, Handler<AsyncResult<Response>> handlers,
Context context) throws Exception {
context.runOnContext(v -> {
try {
String tenantId = TenantTool.calculateTenantId( headers.get(ClientGenerator.OKAPI_HEADER_TENANT) );
log.info("sending... postTenant for " + tenantId);
tenantExists(context, tenantId, res -> {
boolean exists = false;
if(res.succeeded()){
exists = res.result();
handlers.handle(io.vertx.core.Future.succeededFuture(GetTenantResponse.withPlainOK(String.valueOf(
exists))));
}
else{
log.error(res.cause().getMessage(), res.cause());
handlers.handle(io.vertx.core.Future.succeededFuture(GetTenantResponse
.withPlainInternalServerError(res.cause().getMessage())));
}
});
} catch (Exception e) {
log.error(e.getMessage(), e);
handlers.handle(io.vertx.core.Future.succeededFuture(GetTenantResponse
.withPlainInternalServerError(e.getMessage())));
}
});
}
示例7: postAdminImportSQL
import org.folio.rest.tools.utils.TenantTool; //導入依賴的package包/類
@Validate
@Override
public void postAdminImportSQL(InputStream entity, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
//TODO BUG, if database is down, this wont get caught and will return an OK
//THE sql file must be tenant specific, meaning, to insert into a table the file should
//have any table name prefixed with the schema - schema.table_name
String tenantId = TenantTool.calculateTenantId( okapiHeaders.get(ClientGenerator.OKAPI_HEADER_TENANT) );
if(tenantId == null){
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PostAdminImportSQLResponse.withPlainBadRequest("tenant not set")));
}
String sqlFile = IOUtils.toString(entity, "UTF8");
PostgresClient.getInstance(vertxContext.owner(), tenantId).runSQLFile(sqlFile, false, reply -> {
if(reply.succeeded()){
if(!reply.result().isEmpty()){
//some statements failed, transaction aborted
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(
PostAdminImportSQLResponse.withPlainBadRequest("import failed... see logs for details")));
}
else{
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PostAdminImportSQLResponse.withOK("")));
}
}
else{
asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply.cause().getMessage()));
}
});
}
示例8: deleteFixedDueDateScheduleStorageFixedDueDateSchedules
import org.folio.rest.tools.utils.TenantTool; //導入依賴的package包/類
@Override
@Validate
public void deleteFixedDueDateScheduleStorageFixedDueDateSchedules(
String lang,
Map<String,
String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler,
Context vertxContext
) throws Exception {
String tenantId = okapiHeaders.get(TENANT_HEADER);
vertxContext.runOnContext(v -> {
try {
PostgresClient postgresClient = PostgresClient.getInstance(vertxContext.owner(),
TenantTool.calculateTenantId(tenantId));
postgresClient.mutate(
String.format("DELETE FROM %s_%s.%s", tenantId,
PomReader.INSTANCE.getModuleName(), FIXED_SCHEDULE_TABLE), reply -> {
if(reply.succeeded()){
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(
FixedDueDateScheduleStorageResource
.DeleteFixedDueDateScheduleStorageFixedDueDateSchedulesResponse
.noContent().build()));
}
else{
log.error(reply.cause());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(
FixedDueDateScheduleStorageResource.DeleteFixedDueDateScheduleStorageFixedDueDateSchedulesResponse
.withPlainInternalServerError(reply.cause().getMessage())));
}
});
} catch (Exception e) {
log.error(e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(
FixedDueDateScheduleStorageResource.DeleteFixedDueDateScheduleStorageFixedDueDateSchedulesResponse
.withPlainInternalServerError(e.getMessage())));
}
});
}
示例9: deleteItemStorageItems
import org.folio.rest.tools.utils.TenantTool; //導入依賴的package包/類
@Validate
@Override
public void deleteItemStorageItems(
@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);
if (blankTenantId(tenantId)) {
badRequestResult(asyncResultHandler, BLANK_TENANT_MESSAGE);
return;
}
try {
vertxContext.runOnContext(v -> {
PostgresClient postgresClient = PostgresClient.getInstance(
vertxContext.owner(), TenantTool.calculateTenantId(tenantId));
postgresClient.mutate(String.format("TRUNCATE TABLE %s_%s.item",
tenantId, "inventory_storage"),
reply -> {
if (reply.succeeded()) {
asyncResultHandler.handle(Future.succeededFuture(
ItemStorageResource.DeleteItemStorageItemsResponse.noContent()
.build()));
} else {
asyncResultHandler.handle(Future.succeededFuture(
ItemStorageResource.DeleteItemStorageItemsResponse.
withPlainInternalServerError(reply.cause().getMessage())));
}
});
});
}
catch(Exception e) {
asyncResultHandler.handle(Future.succeededFuture(
ItemStorageResource.DeleteItemStorageItemsResponse.
withPlainInternalServerError(e.getMessage())));
}
}
示例10: postAdminPostgresMaintenance
import org.folio.rest.tools.utils.TenantTool; //導入依賴的package包/類
@Validate
@Override
public void postAdminPostgresMaintenance(String table, Command command, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
String tenantId = TenantTool.calculateTenantId( okapiHeaders.get(ClientGenerator.OKAPI_HEADER_TENANT) );
String module = PomReader.INSTANCE.getModuleName();
String querySuffix = tenantId+"_"+module+"."+table+";";
String query = null;
if(Command.ANALYZE == command){
query = "analyze " + querySuffix;
}
else if(Command.VACUUM == command){
query = "vacuum " + querySuffix;
}
else if(Command.VACUUM_ANALYZE == command){
query = "vacuum analyze " + querySuffix;
}
else if(Command.VACUUM_VERBOSE == command){
query = "vacuum verbose " + querySuffix;
}
try{
PostgresClient.getInstance(vertxContext.owner()).select(query, reply -> {
if(reply.succeeded()){
OutStream stream = new OutStream();
stream.setData(reply.result().getRows());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PostAdminPostgresMaintenanceResponse.
withJsonCreated(stream)));
}
else{
log.error(reply.cause().getMessage(), reply.cause());
asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply.cause().getMessage()));
}
});
} catch (Exception e) {
log.error(e.getMessage());
asyncResultHandler.handle(io.vertx.core.Future.failedFuture(e.getMessage()));
}
}