/** * Relation constructor * Private function to prevent outside instantiation of Relations. Use Relation::getRelation($relationSignature) * * @param array $relationDef */ public function __construct($relationDef) { $this->db = Database::singleton(); $this->logger = Logger::getLogger('FW'); $this->name = $relationDef['name']; $this->srcConcept = Concept::getConcept($relationDef['srcConceptId']); $this->tgtConcept = Concept::getConcept($relationDef['tgtConceptId']); $this->signature = $relationDef['signature']; $this->isUni = $relationDef['uni']; $this->isTot = $relationDef['tot']; $this->isInj = $relationDef['inj']; $this->isSur = $relationDef['sur']; $this->isProp = $relationDef['prop']; foreach ((array) $relationDef['affectedConjuncts'] as $conjId) { $conj = Conjunct::getConjunct($conjId); $this->affectedConjuncts[] = $conj; if ($conj->isSigConj()) { $this->affectedSigConjuncts[] = $conj; } if ($conj->isInvConj()) { $this->affectedInvConjuncts[] = $conj; } // if (!$conj->isSigConj() && !$conj->isInvConj()) $this->logger->warning("Affected conjunct '{$conj->id}' (specified for relation '{$this->__toString()}') is not part of an invariant or signal rule"); } // Specify mysql table information $this->mysqlTable = new RelationTable($relationDef['mysqlTable']['name'], $relationDef['mysqlTable']['tableOf']); $srcCol = $relationDef['mysqlTable']['srcCol']; $tgtCol = $relationDef['mysqlTable']['tgtCol']; $this->mysqlTable->addSrcCol(new DatabaseTableCol($srcCol['name'], $srcCol['null'], $srcCol['unique'])); $this->mysqlTable->addTgtCol(new DatabaseTableCol($tgtCol['name'], $tgtCol['null'], $tgtCol['unique'])); }
} foreach ($conjunct->sigRuleNames as $ruleName) { $relArr['affectedConjuncts'][$conjunct->id]['sigRules'][] = $ruleName; } } $relArr['srcOrTgtTable'] = $relation->getMysqlTable()->tableOf; $content[] = $relArr; } print json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); }); $app->get('/admin/report/conjuncts', function () use($app) { if (Config::get('productionEnv')) { throw new Exception("Reports are not allowed in production environment", 403); } $content = array(); foreach (Conjunct::getAllConjuncts() as $conj) { if ($conj->isInvConj()) { $content['invConjuncts'][] = $conj->__toString(); } if ($conj->isSigConj()) { $content['sigConjuncts'][] = $conj->__toString(); } if (!$conj->isInvConj() && !$conj->isSigConj()) { $content['unused'][] = $conj->__toString(); } } print json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); }); $app->get('/admin/report/interfaces', function () use($app) { if (Config::get('productionEnv')) { throw new Exception("Reports are not allowed in production environment", 403);
/** * Concept constructor * Private function to prevent outside instantiation of concepts. Use Concept::getConcept($conceptName) * * @param array $conceptDef */ private function __construct($conceptDef) { $this->database = Database::singleton(); $this->logger = Logger::getLogger('FW'); $this->def = $conceptDef; $this->name = $conceptDef['id']; $this->label = $conceptDef['label']; $this->type = $conceptDef['type']; $this->isObject = $this->type == "OBJECT" ? true : false; $this->affectedConjunctIds = (array) $conceptDef['affectedConjuncts']; foreach ($this->affectedConjunctIds as $conjId) { $conj = Conjunct::getConjunct($conjId); if ($conj->isSigConj()) { $this->affectedSigConjuncts[] = $conj; } if ($conj->isInvConj()) { $this->affectedInvConjuncts[] = $conj; } // if (!$conj->isSigConj() && !$conj->isInvConj()) $this->logger->warning("Affected conjunct '{$conj->id}' (specified for concept '[{$this->name}]') is not part of an invariant or signal rule"); } $this->specializations = (array) $conceptDef['specializations']; $this->generalizations = (array) $conceptDef['generalizations']; $this->interfaceIds = (array) $conceptDef['interfaces']; $this->largestConceptId = $conceptDef['largestConcept']; if (!is_null($conceptDef['defaultViewId'])) { $this->defaultView = View::getView($conceptDef['defaultViewId']); } $this->mysqlConceptTable = new DatabaseTable($conceptDef['conceptTable']['name']); foreach ($conceptDef['conceptTable']['cols'] as $colName) { $this->mysqlConceptTable->addCol(new DatabaseTableCol($colName)); } }
/** * Rule constructor * Private function to prevent outside instantiation. Use Rule::getRule($ruleName) * * @param array $ruleDef * @param boolean $type */ private function __construct($ruleDef, $type = null) { $this->logger = Logger::getLogger('FW'); $this->id = $ruleDef['name']; $this->origin = $ruleDef['origin']; $this->ruleAdl = $ruleDef['ruleAdl']; $this->srcConcept = Concept::getConcept($ruleDef['srcConceptId']); $this->tgtConcept = Concept::getConcept($ruleDef['tgtConceptId']); $this->meaning = $ruleDef['meaning']; $this->message = $ruleDef['message']; // Conjuncts foreach ($ruleDef['conjunctIds'] as $conjId) { $this->conjuncts[] = Conjunct::getConjunct($conjId); } $this->violationSegments = (array) $ruleDef['pairView']; switch ($type) { case 'sig': $this->isSignal = true; break; case 'inv': $this->isInvariant = true; break; case null: break; default: throw new Exception("Unknown/unsupported rule type. Allowed types are signal or invariant", 500); } }
/** * Function to reinstall database structure and load default population * @param boolean $loadDefaultPop specifies whether or not to install the default population * @return void */ public function reinstallDB($installDefaultPop = true) { $queries = file_get_contents(Config::get('pathToGeneratedFiles') . 'mysql-installer.json'); $queries = json_decode($queries, true); $this->logger->info("Start database reinstall"); $this->logger->info("Execute database structure queries"); foreach ($queries['allDBstructQueries'] as $query) { $this->Exe($query); set_time_limit((int) ini_get('max_execution_time')); // reset time limit counter to handle large amounts of create table / index queries. } if ($installDefaultPop) { $this->logger->info("Install default population"); if (Config::get('checkDefaultPopulation', 'transactions')) { $this->startTransaction(); } foreach ($queries['allDefPopQueries'] as $query) { $this->Exe($query); set_time_limit((int) ini_get('max_execution_time')); // reset time limit counter to handle large amounts of default population queries. } } else { $this->logger->info("Skip default population"); } // Ininiate new session Session::reInit(); Hooks::callHooks('postDatabaseReinstallDB', get_defined_vars()); $this->logger->info("Database reinstalled"); // Initial conjunct evaluation Conjunct::evaluateConjuncts(null, true); // Evaluate, cache and store all conjuncts, not only those that are affected (done by closeTransaction() function) $this->closeTransaction('Database successfully reinstalled', true); }