/**
  * 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']));
 }
Exemple #2
0
 }
 $database = Database::singleton();
 include_once Config::get('absolutePath') . Config::get('logPath') . "{$file}";
 // check if all concepts and relations are defined
 foreach ((array) $allAtoms as $cpt => $atoms) {
     if (!empty($atoms)) {
         Concept::getConcept($cpt);
     }
 }
 foreach ((array) $allLinks as $rel => $links) {
     if (!empty($links)) {
         Relation::getRelation($rel);
     }
 }
 foreach ((array) $allAtoms as $cpt => $atoms) {
     $concept = Concept::getConcept($cpt);
     foreach ($atoms as $atomId) {
         $atom = new Atom($atomId, $concept);
         $atom->addAtom();
     }
 }
 foreach ((array) $allLinks as $rel => $links) {
     if (!empty($links)) {
         $relation = Relation::getRelation($rel);
     }
     foreach ($links as $link) {
         if (is_null($link['src']) || is_null($link['tgt'])) {
             continue;
         }
         // skip
         $relation->addLink(new Atom($link['src'], $relation->srcConcept), new Atom($link['tgt'], $relation->tgtConcept));
    $result = array('patches' => $app->request->getBody(), 'content' => $content, 'notifications' => Notifications::getAll(), 'invariantRulesHold' => $session->database->getInvariantRulesHold(), 'requestType' => $session->database->getRequestType(), 'sessionRefreshAdvice' => $session->getSessionRefreshAdvice());
    print json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
$app->post('/resources/:resourceType/:resourceId/:ifcPath+', function ($resourceType, $resourceId, $ifcPath) use($app) {
    $session = Session::singleton();
    $roleIds = $app->request->params('roleIds');
    $session->activateRoles($roleIds);
    $options = $app->request->params();
    $ifcPath = implode('/', $ifcPath);
    $atom = new Atom($resourceId, Concept::getConcept($resourceType));
    $atomOrIfc = $atom->walkIfcPath($ifcPath);
    // Perform create
    $content = $atomOrIfc->create($app->request->getBody(), $options);
    // Return result
    $result = array('content' => $content, 'notifications' => Notifications::getAll(), 'invariantRulesHold' => $session->database->getInvariantRulesHold(), 'requestType' => $session->database->getRequestType(), 'sessionRefreshAdvice' => $session->getSessionRefreshAdvice());
    print json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
$app->delete('/resources/:resourceType/:resourceId/:ifcPath+', function ($resourceType, $resourceId, $ifcPath) use($app) {
    $session = Session::singleton();
    $roleIds = $app->request->params('roleIds');
    $session->activateRoles($roleIds);
    $options = $app->request->params();
    $ifcPath = implode('/', $ifcPath);
    $atom = new Atom($resourceId, Concept::getConcept($resourceType));
    $atomOrIfc = $atom->walkIfcPath($ifcPath);
    // Perform delete
    $atomOrIfc->delete($options);
    // Return result
    $result = array('notifications' => Notifications::getAll(), 'invariantRulesHold' => $session->database->getInvariantRulesHold(), 'requestType' => $session->database->getRequestType(), 'sessionRefreshAdvice' => $session->getSessionRefreshAdvice());
    print json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
Exemple #4
0
 /**
  * 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);
     }
 }
 /**
  * InterfaceObject constructor
  * @param array $ifcDef Interface object definition as provided by Ampersand generator
  * @param string $pathEntry
  * @param boolean $rootIfc Specifies if this interface object is a toplevel interface (true) or subinterface (false)
  */
 public function __construct($ifcDef, $pathEntry = null, $rootIfc = false)
 {
     $this->database = Database::singleton();
     $this->logger = Logger::getLogger('FW');
     $this->isRoot = $rootIfc;
     // Set attributes from $ifcDef
     $this->id = $ifcDef['id'];
     $this->label = $ifcDef['label'];
     $this->view = is_null($ifcDef['viewId']) ? null : View::getView($ifcDef['viewId']);
     $this->path = is_null($pathEntry) ? $this->id : "{$pathEntry}/{$this->id}";
     // Information about the (editable) relation if applicable
     $this->relation = is_null($ifcDef['relation']) ? null : Relation::getRelation($ifcDef['relation']);
     $this->relationIsFlipped = $ifcDef['relationIsFlipped'];
     // Interface expression information
     $this->srcConcept = Concept::getConcept($ifcDef['expr']['srcConceptId']);
     $this->tgtConcept = Concept::getConcept($ifcDef['expr']['tgtConceptId']);
     $this->isUni = $ifcDef['expr']['isUni'];
     $this->isTot = $ifcDef['expr']['isTot'];
     $this->isIdent = $ifcDef['expr']['isIdent'];
     $this->query = $ifcDef['expr']['query'];
     // CRUD rights
     $this->crudC = $ifcDef['crud']['create'];
     $this->crudR = $ifcDef['crud']['read'];
     $this->crudU = $ifcDef['crud']['update'];
     $this->crudD = $ifcDef['crud']['delete'];
     if ($this->crudU && $this->tgtConcept->isObject) {
         $this->editableConcepts[] = $this->tgtConcept;
     }
     // Interface expression must equal (editable) relation when crudU is specified
     if ($this->crudU && is_null($this->relation)) {
         $this->logger->warning("Update rights (crUd) specified while interface expression is not an editable relation for (sub)interface: {$this->path}");
     }
     // Check for unsupported patchReplace functionality due to missing 'old value'. Related with issue #318
     if (!is_null($this->relation) && $this->crudU && !$this->tgtConcept->isObject && $this->isUni) {
         // Only applies to editable relations
         // Only applies to crudU, because issue is with patchReplace, not with add/remove
         // Only applies to scalar, because objects don't use patchReplace, but Remove and Add
         // Only if interface expression (not! the relation) is univalent, because else a add/remove option is used in the UI
         if (!$this->relationIsFlipped && $this->relation->getMysqlTable()->tableOf == 'tgt' || $this->relationIsFlipped && $this->relation->getMysqlTable()->tableOf == 'src') {
             $this->logger->warning("Unsupported edit functionality due to combination of factors for (sub)interface: '{$this->path}' - {$this->relation->__toString()}" . ($this->relationIsFlipped ? '~' : '') . " administrated in table of '{$this->relation->getMysqlTable()->tableOf}'");
         }
     }
     // Subinterfacing
     if (!is_null($ifcDef['subinterfaces'])) {
         // Subinterfacing is not supported/possible for tgt concepts with a scalar representation type (i.e. non-objects)
         if (!$this->tgtConcept->isObject) {
             throw new Exception("Subinterfacing is not supported for concepts with a scalar representation type (i.e. non-objects). (Sub)Interface '{$this->path}' with target {$this->tgtConcept->__toString()} (type:{$this->tgtConcept->type}) has subinterfaces specified", 501);
         }
         // Reference to top level interface
         $this->refInterfaceId = $ifcDef['subinterfaces']['refSubInterfaceId'];
         $this->isLinkTo = $ifcDef['subinterfaces']['refIsLinTo'];
         // Inline subinterface definitions
         foreach ((array) $ifcDef['subinterfaces']['ifcObjects'] as $subIfcDef) {
             $ifc = new InterfaceObject($subIfcDef, $this->path);
             $this->subInterfaces[$ifc->id] = $ifc;
             $this->editableConcepts = array_merge($this->editableConcepts, $ifc->editableConcepts);
         }
     }
 }
 /**
  * Returns largest generalization concept (can be itself)
  * @return Concept
  */
 public function getLargestConcept()
 {
     return Concept::getConcept($this->largestConceptId);
 }