Example #1
0
 public function testWrapperInstantiation()
 {
     $this->markTestNeedsTestConfig();
     $this->_manager->addWrapperPath($this->_resourcesPath);
     $registry = Erfurt_Wrapper_Registry::getInstance();
     $ldw = $registry->getWrapperInstance('linkeddata');
     $this->assertInstanceOf('Erfurt_Wrapper_LinkeddataWrapper', $ldw);
     $rdfaw = $registry->getWrapperInstance('rdfa');
     $this->assertInstanceOf('Erfurt_Wrapper_RdfaWrapper', $rdfaw);
     $ew = $registry->getWrapperInstance('enabled');
     $this->assertInstanceOf('EnabledWrapper', $ew);
 }
Example #2
0
 /**
  * Returns the instance of the Erfurt wrapper registry.
  *
  * @param Erfurt_Wrapper_Registry
  */
 public function getWrapperRegistry()
 {
     require_once 'Erfurt/Wrapper/Registry.php';
     return Erfurt_Wrapper_Registry::getInstance();
 }
Example #3
0
 public function addWrapperExternally($wrapperName, $wrapperPath, $privateConfig)
 {
     //        if($privateConfig instanceof Zend_Config){
     //            $privateConfig = $privateConfig->toArray();
     //        }
     $wrapperSpec = array('class_name' => ucfirst($wrapperName) . 'Wrapper', 'include_path' => $wrapperPath, 'config' => $privateConfig, 'instance' => null);
     // Finally register the wrapper.
     $registry = Erfurt_Wrapper_Registry::getInstance();
     $registry->register($wrapperName, $wrapperSpec);
 }
Example #4
0
 public function testGetInstance()
 {
     $instance = Erfurt_Wrapper_Registry::getInstance();
     $this->assertTrue($instance instanceof Erfurt_Wrapper_Registry);
 }
 /**
  * Event handler method, which is called on menu creation. Adds some
  * datagathering relevant menu entries.
  *
  * @param Erfurt_Event $event
  *
  * @return bool
  */
 public function onCreateMenu($event)
 {
     $menu = $event->menu;
     $resource = $event->resource;
     $model = $event->model;
     $owApp = OntoWiki::getInstance();
     // We only add entries to the menu, if all params are given and the
     // model is editable.
     if (null === $resource || null === $model || !$model->isEditable() || !$owApp->erfurt->getAc()->isModelAllowed('edit', $owApp->selectedModel)) {
         return;
     }
     $owApp = OntoWiki::getInstance();
     $translate = $owApp->translate;
     $wrapperRegistry = Erfurt_Wrapper_Registry::getInstance();
     $activeWrapperList = $wrapperRegistry->listActiveWrapper();
     if ((bool) $this->_privateConfig->sync->enabled) {
         $syncConfigList = $this->_listSyncConfigs();
     } else {
         $syncConfigList = array();
     }
     $uri = (string) $resource;
     $modelUri = (string) $model;
     $menuArray = array();
     // Check all active wrapper extensions, whether URI is handled. Also
     // check, whether a sync config exists.
     foreach ($activeWrapperList as $wrapperName) {
         $hash = $this->_getHash($uri, $wrapperName, $modelUri);
         $r = new Erfurt_Rdf_Resource($uri);
         $r->setLocator($this->_getProxyUri($uri));
         $wrapperInstance = $wrapperRegistry->getWrapperInstance($wrapperName);
         if ($wrapperInstance->isHandled($r, $modelUri)) {
             $menuArray[$wrapperName] = array('instance' => $wrapperInstance);
             if (isset($syncConfigList[$hash])) {
                 $menuArray[$wrapperName]['sync'] = true;
             }
         }
     }
     // Only add a separator, if at least one active wrapper exists.
     if (count($menuArray) > 0) {
         $menu->appendEntry(OntoWiki_Menu::SEPARATOR);
     }
     foreach ($menuArray as $wrapperName => $wrapperArray) {
         $wrapperInstance = $wrapperArray['instance'];
         if (isset($wrapperArray['sync']) && $wrapperArray['sync'] === true) {
             $message = $translate->_('Sync Data with %1$s');
             $menu->appendEntry(sprintf($message, $wrapperInstance->getName()), array('about' => $uri, 'class' => 'sync_data_button wrapper_' . $wrapperName));
         } else {
             $message = $translate->_('Import Data with %1$s');
             $menu->appendEntry(sprintf($message, $wrapperInstance->getName()), array('about' => $uri, 'class' => 'fetch_data_button wrapper_' . $wrapperName));
         }
         // Configure for sync entry.
         if ((bool) $this->_privateConfig->sync->enabled) {
             $configUrl = $owApp->config->urlBase . 'datagathering/config?uri=' . urlencode($uri) . '&wrapper=' . urlencode($wrapperName);
             if ($event->isModel) {
                 $configUrl .= '&m=' . urlencode($uri);
             }
             $message = $translate->_('Configure Sync with %1$s');
             $menu->appendEntry(sprintf($message, $wrapperInstance->getName()), $configUrl);
         }
     }
     return true;
 }
 public static function import($graphUri, $uri, $locator, $all = true, $presets = array(), $exceptedProperties = array(), $wrapperName = 'linkeddata', $fetchMode = 'none', $action = 'add', $versioning = true, $filterCallback = null)
 {
     // Check whether user is allowed to write the model.
     $erfurt = Erfurt_App::getInstance();
     $store = $erfurt->getStore();
     $storeGraph = $store->getModel($graphUri);
     if (!$storeGraph || !$storeGraph->isEditable()) {
         return self::IMPORT_NOT_EDITABLE;
     }
     $r = new Erfurt_Rdf_Resource($uri);
     $r->setLocator($locator);
     // Try to instanciate the requested wrapper
     $wrapper = null;
     try {
         $wrapper = Erfurt_Wrapper_Registry::getInstance()->getWrapperInstance($wrapperName);
     } catch (Erfurt_Wrapper_Exception $e) {
         return self::IMPORT_WRAPPER_INSTANCIATION_ERR;
     }
     if (null == $wrapper) {
         return self::IMPORT_WRAPPER_NOT_AVAILABLE;
     }
     $wrapperResult = null;
     try {
         $wrapperResult = $wrapper->run($r, $graphUri, $all);
     } catch (Erfurt_Wrapper_Exception $e) {
         return self::IMPORT_WRAPPER_ERR;
     }
     if ($wrapperResult === false) {
         return self::IMPORT_WRAPPER_RESULT_NOT_AVAILABLE;
     } else {
         if (is_array($wrapperResult)) {
             if (isset($wrapperResult['status_codes'])) {
                 if (in_array(Erfurt_Wrapper::RESULT_HAS_ADD, $wrapperResult['status_codes'])) {
                     $newStatements = $wrapperResult['add'];
                     //default filter
                     $newStatements = self::filterStatements($newStatements, $uri, $all, $presets, $exceptedProperties, $fetchMode);
                     //custom filter
                     if ($filterCallback != null && is_array($filterCallback)) {
                         try {
                             $newStatements = call_user_func($filterCallback, $newStatements);
                         } catch (Exception $e) {
                             return self::IMPORT_CUSTOMFILTER_EXCEPTION;
                         }
                     }
                     $stmtBeforeCount = $store->countWhereMatches($graphUri, '{ ?s ?p ?o }', '*');
                     if ($versioning) {
                         // Prepare versioning...
                         $versioning = $erfurt->getVersioning();
                         $actionSpec = array('type' => self::VERSIONING_IMPORT_ACTION_TYPE, 'modeluri' => $graphUri, 'resourceuri' => $uri);
                         // Start action
                         $versioning->startAction($actionSpec);
                     }
                     if ($action == 'add') {
                         try {
                             $store->addMultipleStatements($graphUri, $newStatements);
                         } catch (Exception $e) {
                             $versioning->abortAction();
                             if (defined('_EFDEBUG')) {
                                 throw $e;
                             }
                             return self::IMPORT_GENERAL_EXCEPTION;
                         }
                     } else {
                         if ($action == 'update') {
                             $queryoptions = array('use_ac' => false, 'result_format' => Erfurt_Store::RESULTFORMAT_EXTENDED, 'use_additional_imports' => false);
                             $oldStatements = $store->sparqlQuery('SELECT * FROM <' . $graphUri . '> WHERE { ?s ?p ?o }', $queryoptions);
                             //transform resultset to rdf/php statements
                             $modelOld = new Erfurt_Rdf_MemoryModel();
                             $modelOld->addStatementsFromSPOQuery($oldStatements);
                             $modelNew = new Erfurt_Rdf_MemoryModel($newStatements);
                             $storeGraph->updateWithMutualDifference($modelOld->getStatements(), $modelNew->getStatements());
                         }
                     }
                     if ($versioning) {
                         $versioning->endAction();
                     }
                     $stmtAfterCount = $store->countWhereMatches($graphUri, '{ ?s ?p ?o }', '*');
                     $stmtAddCount = $stmtAfterCount - $stmtBeforeCount;
                     if ($stmtAddCount > 0) {
                         // TODO test ns
                         // If we added some statements, we check for additional namespaces and add them.
                         if (in_array(Erfurt_Wrapper::RESULT_HAS_NS, $wrapperResult['status_codes'])) {
                             $namespaces = $wrapperResult['ns'];
                             $erfurtNamespaces = $erfurt->getNamespaces();
                             foreach ($namespaces as $ns => $prefix) {
                                 try {
                                     $erfurtNamespaces->addNamespacePrefix($graphUri, $prefix, $ns, false);
                                 } catch (Exception $e) {
                                     // Ignore...
                                 }
                             }
                         }
                         return self::IMPORT_OK;
                     } else {
                         if (count($newStatements) > 0) {
                             return self::IMPORT_NO_NEW_DATA;
                         } else {
                             return self::IMPORT_NO_DATA;
                         }
                     }
                 } else {
                     return self::IMPORT_NO_DATA;
                 }
             } else {
                 return self::IMPORT_WRAPPER_ERR;
             }
         } else {
             return self::IMPORT_WRAPPER_ERR;
         }
     }
 }
Example #7
0
 private function _getWrapper($wrapperName)
 {
     if ($this->_wrapperRegistry === null) {
         Erfurt_Wrapper_Registry::reset();
         $this->_wrapperRegistry = Erfurt_Wrapper_Registry::getInstance();
     }
     $wrapper = $this->_wrapperRegistry->getWrapperInstance($wrapperName);
     if ($this->_httpAdapter !== null) {
         $wrapper->setHttpAdapter($this->_httpAdapter);
     }
     return $wrapper;
 }