ps-bridge-helpers-common
Version:
PS Connectors Common
48 lines • 2.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProvisionHelper = void 0;
const bentleyjs_core_1 = require("@bentley/bentleyjs-core");
const Logger_1 = require("./utils/Logger");
class ProvisionHelper {
static IsIModelProvisioned(imodel) {
if (!imodel) {
Logger_1.Logger.logInfo(this.LOG_CATEGORY, "Invalid iModel");
throw new Error("Invalid iModel");
}
const funcSchema = this.LocateSchema(imodel, "ProcessFunctional");
const phySchema = this.LocateSchema(imodel, "ProcessPhysical");
if (funcSchema && phySchema) {
Logger_1.Logger.logInfo(this.LOG_CATEGORY, "Imodel is provisioned");
return true;
}
else
return false;
}
static SchemaClassExists(imodel, classFullName) {
if (!imodel || !classFullName) {
Logger_1.Logger.logInfo(this.LOG_CATEGORY, "Invalid arguments. Please provide a valid imodel and/or a valid class name (Example-> SomeSchema:SomeClass)");
throw new Error("Invalid arguments. Please provide a valid imodel and/or a valid class name (Example-> SomeSchema:SomeClass)");
}
return imodel.containsClass(classFullName);
}
static LocateSchema(dbFind, schemaName) {
this.queryResult = false;
const query = `SELECT Name FROM meta.ECSchemaDef where Name='${schemaName}'`;
dbFind.withPreparedStatement(query, (stmt) => {
if (bentleyjs_core_1.DbResult.BE_SQLITE_ROW === stmt.step()) {
const row = stmt.getRow();
if (row.name == schemaName) {
Logger_1.Logger.logInfo(this.LOG_CATEGORY, `${schemaName} schema found`);
this.queryResult = true;
}
}
});
if (!this.queryResult) {
Logger_1.Logger.logInfo(this.LOG_CATEGORY, `${schemaName} Schema does not exist`);
}
return this.queryResult;
}
}
exports.ProvisionHelper = ProvisionHelper;
ProvisionHelper.LOG_CATEGORY = "PSConnectorsCommon(Provision Helper):";
//# sourceMappingURL=ProvisionHelper.js.map