Exemplo n.º 1
0
 /**
  * Constructor of role
  * Private function to prevent outside instantiation of roles. Use Role::getRoleById($roleId) or Role::getRoleByName($roleName)
  * 
  * @param array $roleDef
  */
 private function __construct($roleDef)
 {
     $this->id = $roleDef['id'];
     $this->label = $roleDef['name'];
     $this->maintains = $roleDef['maintains'];
     foreach ($roleDef['interfaces'] as $ifcId) {
         $this->interfaces[] = InterfaceObject::getInterface($ifcId);
     }
 }
Exemplo n.º 2
0
 /**
  * Function to delete an atom from Concept collection
  * @param array $options
  * @throws Exception when delete is not allowed/possible
  * @return void
  */
 public function delete($options = array())
 {
     $this->logger->debug("delete() called on {$this->path}");
     // CRUD check
     if (!$this->parentIfc->crudD) {
         throw new Exception("Delete not allowed for '{$this->path}'", 405);
     }
     if (!$this->parentIfc->tgtConcept->isObject) {
         throw new Exception("Cannot delete non-object '{$this->__toString()}' in '{$this->path}'. Use PATCH remove operation instead", 405);
     }
     if ($this->parentIfc->isRef()) {
         throw new Exception("Cannot delete on reference interface in '{$this->path}'. See #498", 501);
     }
     // Handle options
     if (isset($options['requestType'])) {
         $this->database->setRequestType($options['requestType']);
     }
     // Perform delete
     $this->deleteAtom();
     // Close transaction
     $this->database->closeTransaction($this->concept . ' deleted');
     return;
 }
Exemplo n.º 3
0
            $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);
    }
    $arr = array();
    foreach (InterfaceObject::getAllInterfaces() as $key => $ifc) {
        $arr = array_merge($arr, $ifc->getInterfaceFlattened());
    }
    $content = array_map(function (InterfaceObject $ifc) {
        return array('path' => $ifc->path, 'label' => $ifc->label, 'crudC' => $ifc->crudC, 'crudR' => $ifc->crudR, 'crudU' => $ifc->crudU, 'crudD' => $ifc->crudD, 'src' => $ifc->srcConcept->name, 'tgt' => $ifc->tgtConcept->name, 'view' => $ifc->view->label, 'relation' => $ifc->relation->signature, 'flipped' => $ifc->relationIsFlipped, 'ref' => $ifc->refInterfaceId, 'root' => $ifc->isRoot(), 'public' => $ifc->isPublic(), 'roles' => implode(',', $ifc->ifcRoleNames));
    }, $arr);
    // Output
    $output = new OutputCSV();
    $output->addColumns(array_keys($content[0]));
    foreach ($content as $row) {
        $output->addRow($row);
    }
    $output->render('ifc-report.csv');
    // print json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
Exemplo n.º 4
0
    throw new Exception("Not implemented yet", 501);
});
$app->patch('/resources/:resourceType/:resourceId(/:ifcPath+)', function ($resourceType, $resourceId, $ifcPath = array()) use($app) {
    $session = Session::singleton();
    $roleIds = $app->request->params('roleIds');
    $topLevelIfcId = $app->request->params('topLevelIfc');
    $options = $app->request->params();
    $session->activateRoles($roleIds);
    if (empty($ifcPath) && empty($topLevelIfcId)) {
        throw new Exception("Parameter 'topLevelIfc' is required to return data when no interface path is specified", 400);
    }
    $ifcPath = implode('/', $ifcPath);
    $atom = new Atom($resourceId, Concept::getConcept($resourceType));
    $atom->topLevelIfcId = $topLevelIfcId;
    // Create atom if not exists and crudC is allowed
    if (!$atom->atomExists() && InterfaceObject::getInterface($topLevelIfcId)->crudC) {
        $atom->addAtom();
    }
    $atomOrIfc = $atom->walkIfcPath($ifcPath);
    // Perform patch(es)
    $content = $atomOrIfc->patch($app->request->getBody(), $options);
    // Return result
    $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);
Exemplo n.º 5
0
 /**
  * 
  * @param PHPExcel_Worksheet $worksheet
  * @param InterfaceObject $ifc
  * @return void
  */
 private function ParseWorksheetWithIfc($worksheet, $ifc)
 {
     /* Use interface name as worksheet name. Format for content is as follows:
        #1 <srcConcept> | <ifc label x> | <ifc label y> | <etc>
        #2 <srcAtomA>   | <tgtAtom1>    | <tgtAtom2>    | <etc>
        #3 <srcAtomB>   | <tgtAtom3>    | <tgtAtom4>    | <etc>
        */
     $highestrow = $worksheet->getHighestRow();
     $highestcolumn = $worksheet->getHighestColumn();
     $highestcolumnnr = PHPExcel_Cell::columnIndexFromString($highestcolumn);
     $leftConcept = Concept::getConceptByLabel((string) $worksheet->getCell('A1'));
     if ($leftConcept != $ifc->tgtConcept) {
         throw new Exception("Target concept of interface '{$ifc->path}' does not match concept specified in cell {$worksheet->getTitle()}:A1", 500);
     }
     // Parse other columns of first row
     $header = array();
     for ($columnnr = 1; $columnnr < $highestcolumnnr; $columnnr++) {
         $columnletter = PHPExcel_Cell::stringFromColumnIndex($columnnr);
         $cell = $worksheet->getCell($columnletter . '1');
         $cellvalue = (string) $cell->getCalculatedValue();
         if ($cellvalue == '') {
             $header[$columnletter] = null;
         } else {
             $subIfc = $ifc->getSubinterfaceByLabel($cellvalue);
             if (!$subIfc->crudU || !$subIfc->relation) {
                 throw new Exception("Update not allowed/possible for {$subIfc->label} as specified in cell {$columnletter}1", 403);
             }
             $header[$columnletter] = $subIfc;
         }
     }
     for ($row = 2; $row <= $highestrow; $row++) {
         $firstCol = (string) $worksheet->getCell('A' . $row)->getCalculatedValue();
         if ($firstCol == '') {
             continue;
         } elseif ($firstCol == '_NEW') {
             if (!$ifc->crudC) {
                 throw new Exception("Trying to create new atom in cell A{$row}. This is not allowed.", 403);
             }
             $leftAtom = $leftConcept->createNewAtom()->addAtom();
         } else {
             $leftAtom = new Atom($firstCol, $leftConcept);
             if (!$leftAtom->atomExists() && !$ifc->crudC) {
                 throw new Exception("Trying to create new {$leftConcept} in cell A{$row}. This is not allowed.", 403);
             }
             $leftAtom->addAtom();
         }
         for ($columnnr = 1; $columnnr < $highestcolumnnr; $columnnr++) {
             $columnletter = PHPExcel_Cell::stringFromColumnIndex($columnnr);
             if (is_null($header[$columnletter])) {
                 continue;
             }
             // skip this column.
             $cell = $worksheet->getCell($columnletter . $row);
             $cellvalue = (string) $cell->getCalculatedValue();
             if ($cellvalue == '') {
                 continue;
             }
             // skip if not value provided
             // overwrite $cellvalue in case of datetime
             // the @ is a php indicator for a unix timestamp (http://php.net/manual/en/datetime.formats.compound.php), later used for typeConversion
             if (PHPExcel_Shared_Date::isDateTime($cell) && !empty($cellvalue)) {
                 $cellvalue = '@' . (string) PHPExcel_Shared_Date::ExcelToPHP($cellvalue);
             }
             $rightAtom = new Atom($cellvalue, $header[$columnletter]->tgtConcept);
             if (!$rightAtom->atomExists() && !$header[$columnletter]->crudC) {
                 throw new Exception("Trying to create new {$header[$columnletter]->tgtConcept} in cell {$columnletter}{$row}. This is not allowed.", 403);
             }
             $header[$columnletter]->relation()->addLink($leftAtom, $rightAtom, $header[$columnletter]->relationIsFlipped, 'ExcelImport');
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Returns all toplevel interface objects that are public (i.e. not assigned to a role)
  * @return InterfaceObject[]
  */
 public static function getPublicInterfaces()
 {
     return array_values(array_filter(InterfaceObject::getAllInterfaces(), function ($ifc) {
         return $ifc->isPublic();
     }));
 }
Exemplo n.º 7
0
 /**
  * 
  * @return InterfaceObject[]
  */
 public function getInterfaces()
 {
     $interfaces = array();
     foreach ($this->interfaceIds as $ifcId) {
         $ifc = InterfaceObject::getInterface($ifcId);
         $interfaces[$ifc->id] = $ifc;
     }
     return $interfaces;
 }
Exemplo n.º 8
0
<?php

use Ampersand\Config;
use Ampersand\Interfacing\InterfaceObject;
global $app;
$app->get('/interfaces', function () use($app) {
    if (Config::get('productionEnv')) {
        throw new Exception("List of all interfaces is not allowed in production environment", 403);
    }
    $content = InterfaceObject::getAllInterfaces();
    // Return all interfaces
    print json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
$app->get('/interfaces/public', function () use($app) {
    if (Config::get('productionEnv')) {
        throw new Exception("List of public interfaces is not allowed in production environment", 403);
    }
    $content = InterfaceObject::getPublicInterfaces();
    // Return all public interfaces
    print json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
Exemplo n.º 9
0
 public static function getNavBarIfcs($menu)
 {
     $session = Session::singleton();
     $navBarIfcs = array();
     // Add public interfaces
     $interfaces = InterfaceObject::getPublicInterfaces();
     // Add interfaces for active roles
     foreach ($session->getActiveRoles() as $role) {
         $interfaces = array_merge($interfaces, $role->interfaces());
     }
     // Filter duplicate interfaces
     $interfaces = array_unique($interfaces);
     // Filter interfaces for requested part of navbar
     $interfaces = array_filter($interfaces, function ($ifc) use($menu) {
         switch ($menu) {
             case 'top':
                 if (($ifc->srcConcept->name == 'SESSION' || $ifc->srcConcept->name == 'ONE') && $ifc->crudR) {
                     return true;
                 } else {
                     return false;
                 }
             case 'new':
                 // crudC, otherwise the atom cannot be created
                 // isIdent (interface expr = I[Concept]), because otherwise a src atom is necesarry, which we don't have wiht +-menu
                 if ($ifc->crudC && $ifc->isIdent) {
                     return true;
                 } else {
                     return false;
                 }
             default:
                 throw new Exception("Cannot get navbar interfaces. Unknown menu: '{$menu}'", 500);
         }
     });
     // Create return object
     $result = array_map(function ($ifc) {
         return array('id' => $ifc->id, 'label' => $ifc->label, 'link' => '/' . $ifc->id);
     }, $interfaces);
     return array_values($result);
     // reindex array
 }
Exemplo n.º 10
0
 /**
  * Get session variables (from 'SessionVars' interface)
  * @return mixed|false session variables (if interface 'SessionVars' is defined in &-script) or false otherwise
  */
 public function getSessionVars()
 {
     if (InterfaceObject::interfaceExists('SessionVars')) {
         try {
             $this->logger->debug("Getting interface 'SessionVars' for {$this->sessionAtom->__toString()}");
             return $this->sessionAtom->ifc('SessionVars')->read(['metaData' => false, 'navIfc' => false]);
         } catch (Exception $e) {
             $this->logger->warning("Error while getting SessionVars interface: " . $e->getMessage());
             return false;
         }
     } else {
         return false;
     }
 }