Пример #1
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $config = Config::getInstance();
     $this->config = $config->getTransactionLogConfig();
     $this->transaction_db = $config->getTransactionLogDatabase();
     $this->transaction_collection = $this->transaction_db->selectCollection($this->config['collection']);
 }
Пример #2
0
 public function testToNQuads()
 {
     $g = new \Tripod\Mongo\MongoGraph();
     $g->add_literal_triple("http://example.com/1", $g->qname_to_uri("dct:title"), "some literal title");
     $g->add_resource_triple("http://example.com/1", $g->qname_to_uri("dct:source"), "http://www.google.com");
     $expected = "<http://example.com/1> <http://purl.org/dc/terms/title> \"some literal title\" <http://talisaspire.com/> .\n<http://example.com/1> <http://purl.org/dc/terms/source> <http://www.google.com> <http://talisaspire.com/> .\n";
     $this->assertEquals($expected, $g->to_nquads(\Tripod\Mongo\Config::getInstance()->getDefaultContextAlias()));
 }
 protected function setUp()
 {
     parent::setUp();
     $this->tripod = new \Tripod\Mongo\Driver("CBD_testing", "tripod_php_testing", array("async" => array(OP_VIEWS => true, OP_TABLES => true, OP_SEARCH => false)));
     foreach (\Tripod\Mongo\Config::getInstance()->getCollectionsForSearch($this->tripod->getStoreName()) as $collection) {
         $collection->drop();
     }
     $this->loadResourceDataViaTripod();
     $this->loadBaseSearchDataViaTripod();
 }
Пример #4
0
 /**
  * Since this is a singleton class, use this method to create a new config instance.
  * @uses Config::setConfig() Configuration must be set prior to calling this method. To generate a completely new object, set a new config
  * @codeCoverageIgnore
  * @static
  * @throws \Tripod\Exceptions\ConfigException
  * @internal param string $specName
  * @return Config
  */
 public static function getInstance()
 {
     if (!isset(self::$config)) {
         throw new \Tripod\Exceptions\ConfigException("Call Config::setConfig() first");
     }
     if (!isset(self::$instance)) {
         self::$instance = new Config();
         self::$instance->loadConfig(self::$config);
     }
     return self::$instance;
 }
Пример #5
0
 /**
  * Note: Current version of this test tried to create 1000 objects within 6000ms which is reasonable at this time.
  *       Any change to this class if make it a more a big number it should be validated and tested to ensure performance impact.
  *
  * Create some instances of Config to see what amount of time is taken in creating instance and processing in constructor.
  */
 public function testCreateMongoTripodConfigObject()
 {
     $testStartTime = microtime();
     //Let's try to create 1000 objects to see how much time they take.
     for ($i = 0; $i < self::BENCHMARK_OBJECT_CREATE_ITERATIONS; $i++) {
         \Tripod\Mongo\Config::setConfig($this->config);
         $instance = \Tripod\Mongo\Config::getInstance();
     }
     $testEndTime = microtime();
     $this->assertLessThan(self::BENCHMARK_OBJECT_CREATE_TIME, $this->getTimeDifference($testStartTime, $testEndTime), "It should always take less than " . self::BENCHMARK_OBJECT_CREATE_TIME . "ms to create " . self::BENCHMARK_OBJECT_CREATE_ITERATIONS . " objects of Config class");
 }
Пример #6
0
 /**
  * @param \Tripod\Mongo\ImpactedSubject[] $subjects
  * @param string|null $queueName
  * @param array $otherData
  */
 public function createJob(array $subjects, $queueName = null, $otherData = array())
 {
     if (!$queueName) {
         $queueName = \Tripod\Mongo\Config::getApplyQueueName();
     } elseif (strpos($queueName, \Tripod\Mongo\Config::getApplyQueueName()) === false) {
         $queueName = \Tripod\Mongo\Config::getApplyQueueName() . '::' . $queueName;
     }
     $data = array(self::SUBJECTS_KEY => array_map(function (\Tripod\Mongo\ImpactedSubject $subject) {
         return $subject->toArray();
     }, $subjects), self::TRIPOD_CONFIG_KEY => \Tripod\Mongo\Config::getConfig());
     $this->submitJob($queueName, get_class($this), array_merge($otherData, $data));
 }
Пример #7
0
 public function testGetMongoDateWithParam()
 {
     $config = \Tripod\Mongo\Config::getInstance();
     $updatedAt = (new \Tripod\Mongo\DateUtil())->getMongoDate();
     $_id = array('r' => 'http://talisaspire.com/resources/testEtag' . microtime(false), 'c' => 'http://talisaspire.com/');
     $doc = array('_id' => $_id, 'dct:title' => array('l' => 'etag'), '_version' => 0, '_cts' => $updatedAt, '_uts' => $updatedAt);
     $config->getCollectionForCBD('tripod_php_testing', 'CBD_testing')->insertOne($doc, array("w" => 1));
     $time = floor(microtime(true) * 1000);
     $date = \Tripod\Mongo\DateUtil::getMongoDate($time);
     $this->assertInstanceOf('\\MongoDB\\BSON\\UTCDateTime', $date);
     $this->assertEquals(13, strlen($date->__toString()));
     $this->assertEquals($time, $date->__toString());
 }
Пример #8
0
 protected function setUp()
 {
     parent::setup();
     // Stub ouf 'addToElastic' search to prevent writes into Elastic Search happening by default.
     /** @var \Tripod\Mongo\Driver|PHPUnit_Framework_MockObject_MockObject $tripod */
     $this->tripod = $this->getMock('\\Tripod\\Mongo\\Driver', array('addToSearchIndexQueue'), array('CBD_testing', 'tripod_php_testing'));
     $this->tripod->expects($this->any())->method('addToSearchIndexQueue');
     $this->getTripodCollection($this->tripod)->drop();
     // Lock collection no longer available from Driver, so drop it manually
     \Tripod\Mongo\Config::getInstance()->getCollectionForLocks($this->tripod->getStoreName())->drop();
     $this->loadResourceDataViaTripod();
     $this->tripodTransactionLog = new \Tripod\Mongo\TransactionLog();
     $this->tripodTransactionLog->purgeAllTransactions();
     $this->tripod->setTransactionLog($this->tripodTransactionLog);
 }
Пример #9
0
/**
 * @param string|null $id
 * @param string|null $viewId
 * @param string $storeName
 * @param \Tripod\ITripodStat|null $stat
 * @param string $queue
 */
function generateViews($id, $viewId, $storeName, $stat, $queue)
{
    $viewSpec = \Tripod\Mongo\Config::getInstance()->getViewSpecification($storeName, $viewId);
    if (array_key_exists("from", $viewSpec)) {
        \Tripod\Mongo\Config::getInstance()->setMongoCursorTimeout(-1);
        print "Generating {$viewId}";
        $tripod = new \Tripod\Mongo\Driver($viewSpec['from'], $storeName, array('stat' => $stat));
        $views = $tripod->getTripodViews();
        if ($id) {
            print " for {$id}....\n";
            $views->generateView($viewId, $id, null, $queue);
        } else {
            print " for all views....\n";
            $views->generateView($viewId, null, null, $queue);
        }
    }
}
Пример #10
0
/**
 * @param string|null $id
 * @param string|null $tableId
 * @param string|null $storeName
 * @param \Tripod\ITripodStat|null $stat
 * @param string|null $queue
 */
function generateTables($id, $tableId, $storeName, $stat = null, $queue = null)
{
    $tableSpec = \Tripod\Mongo\Config::getInstance()->getTableSpecification($storeName, $tableId);
    if (array_key_exists("from", $tableSpec)) {
        \Tripod\Mongo\Config::getInstance()->setMongoCursorTimeout(-1);
        print "Generating {$tableId}";
        $tripod = new \Tripod\Mongo\Driver($tableSpec['from'], $storeName, array('stat' => $stat));
        $tTables = $tripod->getTripodTables();
        if ($id) {
            print " for {$id}....\n";
            $tTables->generateTableRows($tableId, $id);
        } else {
            print " for all tables....\n";
            $tTables->generateTableRows($tableId, null, null, $queue);
        }
    }
}
Пример #11
0
/**
 * @param string|null $id
 * @param string|null $specId
 * @param string|null $storeName
 * @param \Tripod\iTripodStat|null $stat
 * @param string|null $queue
 */
function generateSearchDocuments($id, $specId, $storeName, $stat = null, $queue = null)
{
    $spec = \Tripod\Mongo\Config::getInstance()->getSearchDocumentSpecification($storeName, $specId);
    if (array_key_exists("from", $spec)) {
        \Tripod\Mongo\Config::getInstance()->setMongoCursorTimeout(-1);
        print "Generating {$specId}";
        $tripod = new \Tripod\Mongo\Driver($spec['from'], $storeName, array('stat' => $stat));
        $search = $tripod->getSearchIndexer();
        if ($id) {
            print " for {$id}....\n";
            $search->generateSearchDocuments($specId, $id, null, $queue);
        } else {
            print " for all tables....\n";
            $search->generateSearchDocuments($specId, null, null, $queue);
        }
    }
}
 public function testSerializerWithMultipleSubjects()
 {
     $g = new MongoGraph();
     $docs = json_decode(file_get_contents(dirname(__FILE__) . '/data/resources.json'), true);
     foreach ($docs as $d) {
         $g->add_tripod_array($d);
     }
     $expected = "<http://life.ac.uk/resources/BFBC6A06-A8B0-DED8-53AA-8E80DB44CC53> <http://purl.org/dc/terms/title> \"Title of resource 2\" <http://talisaspire.com/> .\n<http://life.ac.uk/resources/836E7CAD-63D2-63A0-B1CB-AA6A7E54A5C9> <http://purl.org/dc/terms/title> \"Title of resource 1\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://purl.org/dc/terms/isVersionOf> <http://talisaspire.com/works/4d101f63c10a6> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://purl.org/dc/terms/source> <http://life.ac.uk/resources/BFBC6A06-A8B0-DED8-53AA-8E80DB44CC53> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://purl.org/dc/terms/source> <http://life.ac.uk/resources/836E7CAD-63D2-63A0-B1CB-AA6A7E54A5C9> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://purl.org/dc/terms/subject> <http://talisaspire.com/disciplines/physics> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://purl.org/ontology/bibo/isbn13> \"9780393929690\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/schema#bookmarkReferences> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/bookmarks> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/schema#foo> \"wibble\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/schema#jacsUri> <http://jacs3.dataincubator.org/f300> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/schema#jacsUri> <http://jacs3.dataincubator.org/f340> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/schema#listReferences> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/lists> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/schema#openLibraryUri> <http://openlibrary.org/books/OL10157958M> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/schema#preferredMetadata> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/metadata> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#author> \"Ohanian\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#discipline> \"physics\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#isbn> \"9780393929690\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"Engineering: general\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"PHYSICS\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"Science\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#title> \"Physics 3rd Edition\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#title> \"Physics for Engineers and Scientists\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#topic> \"engineering: general\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#topic> \"physics\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#topic> \"science\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#usedAt> \"0071\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ontology/bibo/Book> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#Resource> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://www.w3.org/2002/07/owl#sameAs> <http://talisaspire.com/isbn/9780393929690> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://purl.org/dc/terms/isVersionOf> <http://talisaspire.com/works/4d101f63c10a6> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://purl.org/dc/terms/source> <http://life.ac.uk/resources/836E7CAD-63D2-63A0-B1CB-AA6A7E54A5C9> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://purl.org/dc/terms/source> <http://life.ac.uk/resources/BFBC6A06-A8B0-DED8-53AA-8E80DB44CC53> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://purl.org/dc/terms/subject> <http://talisaspire.com/disciplines/physics> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://purl.org/ontology/bibo/isbn13> \"9780393929691\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/schema#bookmarkReferences> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/bookmarks> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/schema#foo> \"wibble\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/schema#jacsUri> <http://jacs3.dataincubator.org/f300> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/schema#jacsUri> <http://jacs3.dataincubator.org/f340> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/schema#listReferences> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/lists> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/schema#openLibraryUri> <http://openlibrary.org/books/OL10157958M> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/schema#preferredMetadata> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/metadata> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#author> \"Ohanian\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#discipline> \"physics\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#isbn> \"9780393929690\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"Engineering: general\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"PHYSICS\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"Science\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#title> \"Physics 3rd Edition\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#title> \"Physics for Engineers and Scientists\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#topic> \"engineering: general\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#topic> \"physics\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#topic> \"science\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#usedAt> \"0071\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ontology/bibo/Book> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#Resource> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://www.w3.org/2002/07/owl#sameAs> <http://talisaspire.com/isbn/9780393929690> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://purl.org/dc/terms/isVersionOf> <http://talisaspire.com/works/4d101f63c10a6> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://purl.org/dc/terms/source> <http://life.ac.uk/resources/836E7CAD-63D2-63A0-B1CB-AA6A7E54A5C9> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://purl.org/dc/terms/source> <http://life.ac.uk/resources/BFBC6A06-A8B0-DED8-53AA-8E80DB44CC53> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://purl.org/dc/terms/subject> <http://talisaspire.com/disciplines/physics> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://purl.org/ontology/bibo/isbn13> \"1234567890123\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/schema#bookmarkReferences> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/bookmarks> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/schema#foo> \"wibble\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/schema#jacsUri> <http://jacs3.dataincubator.org/f300> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/schema#jacsUri> <http://jacs3.dataincubator.org/f340> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/schema#listReferences> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/lists> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/schema#openLibraryUri> <http://openlibrary.org/books/OL10157958M> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/schema#preferredMetadata> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/metadata> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#author> \"Ohanian\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#discipline> \"physics\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#isbn> \"1234567890\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"Engineering: general\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"PHYSICS\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"Science\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#title> \"Mahommah Gardo Baquaqua. Biography of Mahommah G. Baquaqua, a Native of Zoogoo, in the Interior of Africa. (A Convert to Christianity,) With a Description of That Part of the World; Including the Manners and Customs of the Inhabitants, Their Religious Notions, Form of Government, Laws, Appearance of the Country, Buildings, Agriculture, Manufactures, Shepherds and Herdsmen, Domestic Animals, Marriage Ceremonials, Funeral Services, Styles of Dress, Trade and Commerce, Modes of Warfare, System of Slavery, &amp;c., &amp;c. Mahommah&#039;s Early Life, His Education, His Capture and Slavery in Western Africa and Brazil, His Escape to the United States, from Thence to Hayti, (the City of Port Au Prince,) His Reception by the Baptist Missionary There, The Rev. W. L. Judd; His Conversion to Christianity, Baptism, and Return to This Country, His Views, Objects and Aim. Written and Revised from His Own Words, by Samuel Moore, Esq., Late Publisher of the &quot;North of England Shipping Gazette,&quot; Author of Several Popular Works, and Editor of Sundry Reform Papers.\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#topic> \"engineering: general\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#topic> \"physics\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#topic> \"science\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#usedAt> \"0071\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ontology/bibo/Book> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#ResourceForTruncating> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://www.w3.org/2002/07/owl#sameAs> <http://talisaspire.com/isbn/9780393929690> <http://talisaspire.com/> .\n<http://jacs3.dataincubator.org/f300> <http://purl.org/dc/terms/title> \"First title\" <http://talisaspire.com/> .\n<http://jacs3.dataincubator.org/f300> <http://purl.org/dc/terms/title> \"Second title\" <http://talisaspire.com/> .\n<http://jacs3.dataincubator.org/f340> <http://purl.org/dc/terms/title> \"First title\" <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6> <http://purl.org/dc/terms/subject> <http://talisaspire.com/disciplines/physics> <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6> <http://purl.org/ontology/bibo/isbn13> \"9780393929691\" <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6> <http://purl.org/ontology/bibo/isbn13> \"9780393929691-2\" <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6> <http://talisaspire.com/searchTerms/schema#discipline> \"physics\" <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6> <http://talisaspire.com/schema#seeAlso> <http://talisaspire.com/works/4d101f63c10a6-2> <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ontology/bibo/Book> <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#Work> <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6-2> <http://purl.org/dc/terms/subject> <http://talisaspire.com/disciplines/physics> <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6-2> <http://purl.org/ontology/bibo/isbn13> \"9780393929691\" <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6-2> <http://talisaspire.com/searchTerms/schema#discipline> \"physics\" <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6-2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ontology/bibo/Book> <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6-2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#Work> <http://talisaspire.com/> .\n<http://talisaspire.com/works/lockedDoc> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ontology/bibo/Book> <http://talisaspire.com/> .\n<http://talisaspire.com/works/lockedDoc> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#Work> <http://talisaspire.com/> .\n<http://basedata.com/b/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#Work> <http://talisaspire.com/> .\n<http://basedata.com/b/1> <http://talisaspire.com/schema#seeAlso> <http://talisaspire.com/works/4d101f63c10a6-2> <http://talisaspire.com/> .\n<http://basedata.com/b/2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#Work> <http://talisaspire.com/> .\n<http://basedata.com/b/2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#Work2> <http://talisaspire.com/> .\n<http://basedata.com/b/2> <http://talisaspire.com/schema#seeAlso> <http://basedata.com/b/1> <http://talisaspire.com/> .\n<tenantUsers:s2123> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/sioc/spec/User> <http://talisaspire.com/> .\n<tenantUsers:s2123> <http://xmlns.com/foaf/0.1/firstName> \"Harry\" <http://talisaspire.com/> .\n<tenantUsers:s2123> <http://xmlns.com/foaf/0.1/surname> \"Potter\" <http://talisaspire.com/> .\n<tenantUsers:s2123> <http://lists.talis.com/schema/temp#last_login> \"2014-03-25T15:07:12+00:00\" <http://talisaspire.com/> .\n<tenantUsers:s2123> <http://lists.talis.com/schema/temp#last_login_invalid> \"invalid\" <http://talisaspire.com/> .\n<http://basedata.com/b/foo1234> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ontology/bibo/Document> <http://talisaspire.com/> .\n<http://basedata.com/b/foo1234> <http://purl.org/dc/terms/creator> <http://schemas.talis.com/2005/user/schema#10101> <http://talisaspire.com/> .\n<http://basedata.com/b/foo1234> <http://purl.org/dc/terms/title> \"A document title\" <http://talisaspire.com/> .\n<http://basedata.com/b/foo1234> <http://purl.org/dc/terms/isVersionOf> <http://talisaspire.com/works/4d101f63c10a6> <http://talisaspire.com/> .\n<http://schemas.talis.com/2005/user/schema#10101> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://talisaspire.com/> .\n<http://schemas.talis.com/2005/user/schema#10101> <http://xmlns.com/foaf/0.1/name> \"A. Person\" <http://talisaspire.com/> .\n<http://schemas.talis.com/2005/user/schema#10101> <http://xmlns.com/foaf/0.1/knows> <http://schemas.talis.com/2005/user/schema#10102> <http://talisaspire.com/> .\n<http://schemas.talis.com/2005/user/schema#10102> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://talisaspire.com/> .\n<http://schemas.talis.com/2005/user/schema#10102> <http://xmlns.com/foaf/0.1/name> \"Anne O'ther\" <http://talisaspire.com/> .\n<http://basedata.com/b/bar1234> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ontology/bibo/Document> <http://talisaspire.com/> .\n<http://basedata.com/b/bar1234> <http://purl.org/dc/terms/creator> <http://schemas.talis.com/2005/user/schema#10103> <http://talisaspire.com/> .\n<http://basedata.com/b/bar1234> <http://purl.org/dc/terms/contributor> <http://schemas.talis.com/2005/user/schema#10101> <http://talisaspire.com/> .\n<http://basedata.com/b/bar1234> <http://purl.org/dc/terms/contributor> <http://schemas.talis.com/2005/user/schema#10102> <http://talisaspire.com/> .\n<http://basedata.com/b/bar1234> <http://purl.org/dc/terms/title> \"Another document title\" <http://talisaspire.com/> .\n<http://basedata.com/b/docWithEmptySeq123> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://basedata.com/b/DocWithSequence> <http://talisaspire.com/> .\n<http://basedata.com/b/docWithEmptySeq123> <http://basedata.com/b/hasSequence> <http://basedata.com/b/sequence123> <http://talisaspire.com/> .\n<http://basedata.com/b/docWithEmptySeq123> <http://purl.org/dc/terms/creator> <http://schemas.talis.com/2005/user/schema#xyz> <http://talisaspire.com/> .\n<http://basedata.com/b/docWithEmptySeq123> <http://purl.org/dc/terms/title> \"Doc with sequence\" <http://talisaspire.com/> .";
     $serializer = new NQuadSerializer();
     $actual = $serializer->getSerializedIndex($g->_index, \Tripod\Mongo\Config::getInstance()->getDefaultContextAlias());
     // This test initially asserted that $expected was equal to $actual
     //   $this->assertEquals($expected, $actual);
     // However, each time test data was added - it would also need to be added to expected above.
     // Rather than increasing the size of $expected further when adding new test data
     // this test now asserts that each line in $expected has been serialised correctly, without failing
     // due to new test data.
     foreach (preg_split("/((\r?\n)|(\r\n?))/", $expected) as $expectedLine) {
         $this->assertTrue(strpos($actual, rtrim($expectedLine)) !== false, "Failed checking for line: " . rtrim($expectedLine));
     }
 }
Пример #13
0
 /**
  * @return Database
  */
 protected function getDatabase()
 {
     if (!isset($this->db)) {
         $this->db = $this->config->getDatabase($this->storeName, $this->config->getDataSourceForPod($this->storeName, $this->podName), $this->readPreference);
     }
     return $this->db;
 }
Пример #14
0
require_once dirname(__FILE__) . '/common.inc.php';
$options = getopt("c:h", array("config:", "help"));
function showUsage()
{
    $help = <<<END
validateConfig.php

Usage:

php validateConfig.php -c/--config path/to/tripod-config.json [options]

Options:
    -h --help               This help
    -c --config             path to Config configuration (required)
END;
    echo $help;
}
if (empty($options) || isset($options['h']) || isset($options['help']) || !isset($options['c']) && !isset($options['config'])) {
    showUsage();
    exit;
}
$configLocation = isset($options['c']) ? $options['c'] : $options['config'];
require_once dirname(dirname(dirname(__FILE__))) . '/src/tripod.inc.php';
\Tripod\Mongo\Config::setValidationLevel(\Tripod\Mongo\Config::VALIDATE_MAX);
\Tripod\Mongo\Config::setConfig(json_decode(file_get_contents($configLocation), true));
try {
    \Tripod\Mongo\Config::getInstance();
    echo "\nConfig OK\n";
} catch (\Tripod\Exceptions\ConfigException $e) {
    echo "\nError: " . $e->getMessage() . "\n";
}
 /**
  * Saving a change to an entity that appears in the impact index for view/table_rows/search docs of 3 other entities should result in
  * 4 items being placed on the queue, with the operations for each relevant to the configured operations based on the specifications
  * todo: new test in composite for one subject that impacts another
  */
 public function testSingleJobSubmittedToQueueForChangeToSeveralSubjects()
 {
     $tripod = $this->getMockBuilder('\\Tripod\\Mongo\\Driver')->setMethods(array('getDataUpdater', 'getComposite'))->setConstructorArgs(array('CBD_testing', 'tripod_php_testing', array('defaultContext' => 'http://talisaspire.com/', OP_ASYNC => array(OP_VIEWS => true, OP_TABLES => true, OP_SEARCH => true))))->getMock();
     $tripodUpdates = $this->getMockBuilder('\\Tripod\\Mongo\\Updates')->setMethods(array('processSyncOperations', 'getDiscoverImpactedSubjects'))->setConstructorArgs(array($tripod, array('defaultContext' => 'http://talisaspire.com/', OP_ASYNC => array(OP_VIEWS => true, OP_TABLES => true, OP_SEARCH => true))))->getMock();
     $discoverImpactedSubjects = $this->getMockBuilder('\\Tripod\\Mongo\\Jobs\\DiscoverImpactedSubjects')->setMethods(array('createJob'))->getMock();
     $tripod->expects($this->once())->method('getDataUpdater')->will($this->returnValue($tripodUpdates));
     $subjectsAndPredicatesOfChange = array("http://talisaspire.com/resources/doc1" => array('dct:date'), "http://talisaspire.com/resources/doc2" => array('dct:date'), "http://talisaspire.com/resources/doc3" => array('dct:date'));
     $tripod->expects($this->never())->method('getComposite');
     $data = array("changes" => $subjectsAndPredicatesOfChange, "operations" => array(OP_VIEWS, OP_TABLES, OP_SEARCH), "tripodConfig" => \Tripod\Mongo\Config::getConfig(), "storeName" => 'tripod_php_testing', "podName" => 'CBD_testing', "contextAlias" => 'http://talisaspire.com/', "statsConfig" => array());
     $tripodUpdates->expects($this->once())->method('getDiscoverImpactedSubjects')->will($this->returnValue($discoverImpactedSubjects));
     $discoverImpactedSubjects->expects($this->once())->method('createJob')->with($data, \Tripod\Mongo\Config::getDiscoverQueueName());
     $g1 = $tripod->describeResources(array("http://talisaspire.com/resources/doc1", "http://talisaspire.com/resources/doc2", "http://talisaspire.com/resources/doc3"));
     $g2 = $tripod->describeResources(array("http://talisaspire.com/resources/doc1", "http://talisaspire.com/resources/doc2", "http://talisaspire.com/resources/doc3"));
     $g2->add_literal_triple("http://talisaspire.com/resources/doc1", $g2->qname_to_uri("dct:date"), "01-01-1970");
     $g2->add_literal_triple("http://talisaspire.com/resources/doc2", $g2->qname_to_uri("dct:date"), "01-01-1970");
     $g2->add_literal_triple("http://talisaspire.com/resources/doc3", $g2->qname_to_uri("dct:date"), "01-01-1970");
     $tripod->saveChanges($g1, $g2);
 }
Пример #16
0
 /**
  * Add $triples about a given $subject to Mongo. Only $triples with subject matching $subject will be added, others will be ignored.
  * Make them quads with a $context
  * @param string $subject
  * @param array $triples
  * @param string|null $context
  * @return array
  */
 public function bsonizeTriplesAbout($subject, array $triples, $context = null)
 {
     $context = $context == null ? Config::getInstance()->getDefaultContextAlias() : $this->labeller->uri_to_alias($context);
     $graph = new MongoGraph();
     foreach ($triples as $triple) {
         $triple = rtrim($triple);
         $parts = preg_split("/\\s/", $triple);
         $subject = trim($parts[0], '><');
         $predicate = trim($parts[1], '><');
         $object = $this->extract_object($parts);
         if ($this->isUri($object)) {
             $graph->add_resource_triple($subject, $predicate, $object);
         } else {
             $graph->add_literal_triple($subject, $predicate, $object);
         }
     }
     return $graph->to_tripod_array($subject, $context);
 }
 public function testNestConditionalInArithmeticFunction()
 {
     $tableSpec = array("_id" => "t_arithmetic_with_nested_conditional", "type" => array("bibo:Book", "bibo:Document"), "from" => "CBD_testing", "fields" => array(array("fieldName" => "x", "predicates" => array("foo:wibble"))), "computed_fields" => array(array("fieldName" => "foobar", "value" => array("arithmetic" => array(array("conditional" => array("if" => array('$x'), "then" => '$x', "else" => 100)), "*", 3)))));
     $oldConfig = \Tripod\Mongo\Config::getConfig();
     $newConfig = \Tripod\Mongo\Config::getConfig();
     $newConfig['stores']['tripod_php_testing']['table_specifications'][] = $tableSpec;
     \Tripod\Mongo\Config::setConfig($newConfig);
     \Tripod\Mongo\Config::getInstance();
     $this->tripod = new \Tripod\Mongo\Driver('CBD_testing', 'tripod_php_testing');
     $this->loadResourceDataViaTripod();
     $this->tripod->generateTableRows('t_arithmetic_with_nested_conditional');
     $collection = \Tripod\Mongo\Config::getInstance()->getCollectionForTable('tripod_php_testing', 't_arithmetic_with_nested_conditional');
     $tableDoc = $collection->findOne(array('_id.type' => 't_arithmetic_with_nested_conditional'));
     $this->assertEquals(300, $tableDoc['value']['foobar']);
     \Tripod\Mongo\Config::setConfig($oldConfig);
     \Tripod\Mongo\Config::getInstance();
     $collection->drop();
 }
Пример #18
0
 public function testCursorNoExceptionThrownWhenCursorThrowsSomeExceptions()
 {
     $uri1 = "http://uri1";
     $viewType = "someView";
     $context = "http://someContext";
     $returnedGraph = new \Tripod\ExtendedGraph();
     $returnedGraph->add_literal_triple($uri1, 'http://somepred', 'someval');
     $mockDb = $this->getMockBuilder('\\MongoDB\\Database')->disableOriginalConstructor()->setMethods(['selectCollection'])->getMock();
     $mockColl = $this->getMockBuilder('\\MongoDB\\Collection')->disableOriginalConstructor()->setMethods(['findOne'])->getMock();
     $mockViewColl = $this->getMockBuilder('\\MongoDB\\Collection')->disableOriginalConstructor()->setMethods(['find', 'findOne'])->getMock();
     $mockCursor = $this->getMock('\\ArrayIterator', array('rewind'));
     $mockCursor->expects($this->exactly(5))->method('rewind')->will($this->onConsecutiveCalls($this->throwException(new \Exception('Exception thrown when cursoring to Mongo')), $this->throwException(new \Exception('Exception thrown when cursoring to Mongo')), $this->throwException(new \Exception('Exception thrown when cursoring to Mongo')), $this->throwException(new \Exception('Exception thrown when cursoring to Mongo')), $this->returnValue($mockCursor)));
     $mockViewColl->expects($this->once())->method('find')->will($this->returnValue($mockCursor));
     $mockDb->expects($this->any())->method("selectCollection")->will($this->returnValue($mockColl));
     $mockColl->expects($this->once())->method("findOne")->will($this->returnValue(null));
     /** @var PHPUnit_Framework_MockObject_MockObject|TripodTestConfig $mockConfig */
     $mockConfig = $this->getMock('TripodTestConfig', array('getCollectionForCBD', 'getCollectionForView'));
     $mockConfig->expects($this->atLeastOnce())->method('getCollectionForCBD')->with('tripod_php_testing', $this->anything(), $this->anything())->will($this->returnValue($mockColl));
     $mockConfig->expects($this->atLeastOnce())->method('getCollectionForView')->with('tripod_php_testing', $this->anything(), $this->anything())->will($this->returnValue($mockViewColl));
     $mockConfig->loadConfig(\Tripod\Mongo\Config::getConfig());
     /* @var $mockTripodViews|PHPUnit_Framework_MockObject_MockObject Views */
     $mockTripodViews = $this->getMock('\\Tripod\\Mongo\\Composites\\Views', array('generateView', 'getConfigInstance'), array('tripod_php_testing', $mockColl, $context));
     $mockTripodViews->expects($this->never())->method('generateView');
     $mockTripodViews->expects($this->atLeastOnce())->method('getConfigInstance')->will($this->returnValue($mockConfig));
     $mockTripodViews->getViewForResources(array($uri1), $viewType, $context);
 }
Пример #19
0
 /**
  * Joins data to $dest from $source according to specification in $joins, or queries DB if data is not available in $source.
  * @param $source
  * @param $joins
  * @param $dest
  * @param $from
  * @param $contextAlias
  * @param bool $buildImpactIndex
  */
 protected function doJoins($source, $joins, &$dest, $from, $contextAlias, $buildImpactIndex = true)
 {
     // expand sequences before doing any joins...
     $this->expandSequence($joins, $source);
     foreach ($joins as $predicate => $ruleset) {
         if ($predicate == 'followSequence') {
             continue;
         }
         if (isset($source[$predicate])) {
             // todo: perhaps we can get better performance by detecting whether or not
             // the uri to join on is already in the impact index, and if so not attempting
             // to join on it. However, we need to think about different combinations of
             // nested joins in different points of the view spec and see if this would
             // complicate things. Needs a unit test or two.
             $joinUris = array();
             if (isset($source[$predicate][VALUE_URI])) {
                 // single value for join
                 $joinUris[] = array(_ID_RESOURCE => $source[$predicate][VALUE_URI], _ID_CONTEXT => $contextAlias);
             } else {
                 // multiple values for join
                 $joinsPushed = 0;
                 foreach ($source[$predicate] as $v) {
                     if (isset($ruleset['maxJoins']) && !$joinsPushed < $ruleset['maxJoins']) {
                         break;
                         // maxJoins reached
                     }
                     $joinUris[] = array(_ID_RESOURCE => $v[VALUE_URI], _ID_CONTEXT => $contextAlias);
                     $joinsPushed++;
                 }
             }
             $recursiveJoins = array();
             $collection = isset($ruleset['from']) ? $this->config->getCollectionForCBD($this->storeName, $ruleset['from']) : $this->config->getCollectionForCBD($this->storeName, $from);
             $cursor = $collection->find(array('_id' => array('$in' => $joinUris)), array('maxTimeMS' => \Tripod\Mongo\Config::getInstance()->getMongoCursorTimeout()));
             $this->addIdToImpactIndex($joinUris, $dest, $buildImpactIndex);
             foreach ($cursor as $linkMatch) {
                 // if there is a condition, check it...
                 if (isset($ruleset['condition'])) {
                     $ruleset['condition']['._id'] = $linkMatch['_id'];
                 }
                 if (!(isset($ruleset['condition']) && $collection->count($ruleset['condition']) == 0)) {
                     // make sure any sequences are expanded before extracting properties
                     if (isset($ruleset['joins'])) {
                         $this->expandSequence($ruleset['joins'], $linkMatch);
                     }
                     if (isset($ruleset['filter'])) {
                         foreach ($ruleset['filter'] as $filterPredicate => $filter) {
                             foreach ($filter as $filterType => $filterMatch) {
                                 if (isset($linkMatch[$filterPredicate])) {
                                     foreach ($linkMatch[$filterPredicate] as $linkMatchType => $linkMatchValues) {
                                         if (is_array($linkMatchValues) == false) {
                                             $linkMatchValues = array($linkMatchType => $linkMatchValues);
                                         }
                                         foreach ($linkMatchValues as $linkMatchType => $linkMatchValue) {
                                             if ($this->matchesFilter($linkMatchType, $linkMatchValue, $filterType, $filterMatch)) {
                                                 $dest[_GRAPHS][] = $this->extractProperties($linkMatch, $ruleset, $from);
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     } else {
                         $dest[_GRAPHS][] = $this->extractProperties($linkMatch, $ruleset, $from);
                     }
                     if (isset($ruleset['joins'])) {
                         // recursive joins must be done after this cursor has completed, otherwise things get messy
                         $recursiveJoins[] = array('data' => $linkMatch, 'ruleset' => $ruleset['joins']);
                     }
                 }
             }
             if (count($recursiveJoins) > 0) {
                 foreach ($recursiveJoins as $r) {
                     $this->doJoins($r['data'], $r['ruleset'], $dest, $from, $contextAlias, $buildImpactIndex);
                 }
             }
         }
     }
     return;
 }
Пример #20
0
<?php

require_once dirname(__FILE__) . '/common.inc.php';
require_once dirname(dirname(dirname(__FILE__))) . '/src/tripod.inc.php';
if ($argc != 2) {
    echo "usage: ./BSONToQuads.php tripodConfig.json < bsondata\n";
    echo "  When exporting bson data from Mongo use:  \n";
    echo "     mongoexport -d <dbname> -c <collectionName> > bsondata.txt \n";
    die;
}
array_shift($argv);
$config = json_decode(file_get_contents($argv[0]), true);
\Tripod\Mongo\Config::setConfig($config);
$tu = new \Tripod\Mongo\TriplesUtil();
while (($line = fgets(STDIN)) !== false) {
    $line = rtrim($line);
    $doc = json_decode($line, true);
    $context = $doc['_id']['c'];
    $graph = new \Tripod\Mongo\MongoGraph();
    $graph->add_tripod_array($doc);
    echo $graph->to_nquads($context);
}
Пример #21
0
}
array_shift($argv);
$config = json_decode(file_get_contents($argv[0]), true);
\Tripod\Mongo\Config::setConfig($config);
$currentSubject = "";
$triples = array();
$docs = array();
$errors = array();
// array of subjects that failed to insert, even after retry...
$tu = new \Tripod\Mongo\TriplesUtil();
while (($line = fgets(STDIN)) !== false) {
    $line = rtrim($line);
    $parts = preg_split("/\\s/", $line);
    $subject = trim($parts[0], '><');
    if (empty($currentSubject)) {
        $currentSubject = $subject;
    }
    if ($currentSubject != $subject) {
        print json_encode($tu->getTArrayAbout($currentSubject, $triples, \Tripod\Mongo\Config::getInstance()->getDefaultContextAlias())) . "\n";
        $currentSubject = $subject;
        // reset current subject to next subject
        $triples = array();
        // reset triples
    }
    $triples[] = $line;
}
// last doc
print json_encode($tu->getTArrayAbout($currentSubject, $triples, \Tripod\Mongo\Config::getInstance()->getDefaultContextAlias())) . "\n";
?>

Пример #22
0
        $loader->loadTriplesAbout($subject, $triples, $storeName, $podName);
    } catch (Exception $e) {
        print "Exception for subject {$subject} failed with message: " . $e->getMessage() . "\n";
        $errors[] = $subject;
    }
}
$timer = new \Tripod\Timer();
$timer->start();
if ($argc != 4) {
    echo "usage: ./loadTriples.php storename podname tripodConfig.json < ntriplesdata\n";
    die;
}
array_shift($argv);
$storeName = $argv[0];
$podName = $argv[1];
\Tripod\Mongo\Config::setConfig(json_decode(file_get_contents($argv[2]), true));
$i = 0;
$currentSubject = "";
$triples = array();
$errors = array();
// array of subjects that failed to insert, even after retry...
$loader = new \Tripod\Mongo\TriplesUtil();
while (($line = fgets(STDIN)) !== false) {
    $i++;
    if ($i % 250000 == 0) {
        print "Memory: " . memory_get_usage() . "\n";
    }
    $line = rtrim($line);
    $parts = preg_split("/\\s/", $line);
    $subject = trim($parts[0], '><');
    if (empty($currentSubject)) {
Пример #23
0
 /**
  * @param \Tripod\Mongo\Driver $tripod
  * @param array $specs
  * @return int
  */
 protected function getCountForSearchSpecs(\Tripod\Mongo\Driver $tripod, $specs = array())
 {
     $count = 0;
     if (empty($specs)) {
         $specs = \Tripod\Mongo\Config::getInstance()->getSearchDocumentSpecifications($tripod->getStoreName(), null, true);
     }
     foreach ($specs as $spec) {
         $count += \Tripod\Mongo\Config::getInstance()->getCollectionForSearchDocument($tripod->getStoreName(), $spec)->count(array('_id.type' => $spec));
     }
     return $count;
 }
Пример #24
0
 public function testRemoveTableSpecDoesNotAffectInvalidation()
 {
     foreach (\Tripod\Mongo\Config::getInstance()->getTableSpecifications($this->tripod->getStoreName()) as $specId => $spec) {
         $this->generateTableRows($specId);
     }
     $context = 'http://talisaspire.com/';
     $uri = "http://talisaspire.com/works/4d101f63c10a6";
     $collection = \Tripod\Mongo\Config::getInstance()->getCollectionForTable('tripod_php_testing', 't_resource');
     $this->assertGreaterThan(0, $collection->count(array('_id.type' => 't_resource', 'value._impactIndex' => array(_ID_RESOURCE => $uri, _ID_CONTEXT => $context))));
     $config = \Tripod\Mongo\Config::getConfig();
     unset($config['stores']['tripod_php_testing']['table_specifications'][0]);
     \Tripod\Mongo\Config::setConfig($config);
     /** @var PHPUnit_Framework_MockObject_MockObject|\Tripod\Mongo\Driver $mockTripod */
     $mockTripod = $this->getMockBuilder('\\Tripod\\Mongo\\Driver')->setMethods(array('getComposite'))->setConstructorArgs(array('CBD_testing', 'tripod_php_testing', array('defaultContext' => $context, OP_ASYNC => array(OP_VIEWS => true, OP_TABLES => false, OP_SEARCH => true))))->getMock();
     $mockTables = $this->getMockBuilder('\\Tripod\\Mongo\\Composites\\Tables')->setMethods(array('update'))->setConstructorArgs(array('tripod_php_testing', \Tripod\Mongo\Config::getInstance()->getCollectionForCBD('tripod_php_testing', 'CBD_testing'), $context))->getMock();
     $labeller = new \Tripod\Mongo\Labeller();
     $mockTripod->expects($this->once())->method('getComposite')->with(OP_TABLES)->will($this->returnValue($mockTables));
     $mockTables->expects($this->never())->method('update');
     $originalGraph = $mockTripod->describeResource($uri);
     $updatedGraph = $originalGraph->get_subject_subgraph($uri);
     $updatedGraph->add_literal_triple($uri, $labeller->qname_to_uri('dct:description'), 'Physics textbook');
     $mockTripod->saveChanges($originalGraph, $updatedGraph);
     // The table row should still be there, even if the tablespec no longer exists
     $this->assertGreaterThan(0, $collection->count(array('_id.type' => 't_resource', 'value._impactIndex' => array(_ID_RESOURCE => $uri, _ID_CONTEXT => $context))));
 }
Пример #25
0
         $tripod = new \Tripod\Mongo\Driver($podName, $storeName, $tripodOptions);
         $oldGraph = $tripod->describeResource(base64_decode($encodedFqUri));
         $tripod->saveChanges($oldGraph, new \Tripod\ExtendedGraph());
     });
     $app->post('/', function ($storeName, $podName) use($app, $tripodOptions) {
         $tripodOptions['statsConfig'] = getStat($app, $tripodOptions);
         $tripod = new \Tripod\Mongo\Driver($podName, $storeName, $tripodOptions);
         $rawGraphData = $app->request()->getBody();
         $graph = new \Tripod\Mongo\MongoGraph();
         $graph->add_rdf($rawGraphData);
         $tripod->saveChanges(new \Tripod\ExtendedGraph(), $graph);
     });
 });
 $app->group('/change', function () use($app, $tripodOptions) {
     $app->post('/', function ($storeName, $podName) use($app, $tripodOptions) {
         \Tripod\Mongo\Config::setConfig(json_decode(file_get_contents('./config/tripod-config-' . $storeName . '.json'), true));
         $app->response()->setStatus(500);
         $tripodOptions['statsConfig'] = getStat($app, $tripodOptions);
         $tripod = new \Tripod\Mongo\Driver($podName, $storeName, $tripodOptions);
         $rawChangeData = $app->request()->post('data');
         if ($rawChangeData) {
             $changeData = json_decode($rawChangeData, true);
             $from = new \Tripod\Mongo\MongoGraph();
             $to = new \Tripod\Mongo\MongoGraph();
             if (isset($changeData['originalCBDs'])) {
                 foreach ($changeData['originalCBDs'] as $change) {
                     if (is_array($change) && isset($change[_ID_KEY])) {
                         $from->add_tripod_array($change);
                     }
                 }
             }
 protected function setArgs()
 {
     $this->args = array('tripodConfig' => \Tripod\Mongo\Config::getConfig(), 'storeName' => 'tripod_php_testing', 'podName' => 'CBD_testing', 'changes' => array('http://example.com/resources/foo' => array('rdf:type', 'dct:title')), 'operations' => array(OP_VIEWS, OP_TABLES, OP_SEARCH), 'contextAlias' => 'http://talisaspire.com/');
 }
Пример #27
0
 /**
  * @param string $tableType
  * @param string|null $resource
  * @param string|null $context
  * @param string|null $queueName Queue for background bulk generation
  * @return null //@todo: this should be a bool
  */
 public function generateTableRows($tableType, $resource = null, $context = null, $queueName = null)
 {
     $t = new \Tripod\Timer();
     $t->start();
     $this->temporaryFields = array();
     $tableSpec = Config::getInstance()->getTableSpecification($this->storeName, $tableType);
     $collection = $this->config->getCollectionForTable($this->storeName, $tableType);
     if ($tableSpec == null) {
         $this->debugLog("Could not find a table specification for {$tableType}");
         return null;
     }
     // ensure that the ID field, view type, and the impactIndex indexes are correctly set up
     $collection->createIndex(array('_id.r' => 1, '_id.c' => 1, '_id.type' => 1), array('background' => 1));
     $collection->createIndex(array('_id.type' => 1), array('background' => 1));
     $collection->createIndex(array('value.' . _IMPACT_INDEX => 1), array('background' => 1));
     // ensure any custom view indexes
     foreach (Config::getInstance()->getTableSpecifications($this->storeName) as $tSpec) {
         if (isset($tSpec['ensureIndexes']) && $tSpec['to_data_source'] == $tableSpec['to_data_source']) {
             foreach ($tSpec['ensureIndexes'] as $ensureIndex) {
                 $this->ensureIndex($collection, $ensureIndex);
             }
         }
     }
     // default the context
     $contextAlias = $this->getContextAlias($context);
     // default collection
     $from = isset($tableSpec["from"]) ? $tableSpec["from"] : $this->podName;
     $types = array();
     if (is_array($tableSpec["type"])) {
         foreach ($tableSpec["type"] as $type) {
             $types[] = array("rdf:type.u" => $this->labeller->qname_to_alias($type));
             $types[] = array("rdf:type.u" => $this->labeller->uri_to_alias($type));
         }
     } else {
         $types[] = array("rdf:type.u" => $this->labeller->qname_to_alias($tableSpec["type"]));
         $types[] = array("rdf:type.u" => $this->labeller->uri_to_alias($tableSpec["type"]));
     }
     $filter = array('$or' => $types);
     if (isset($resource)) {
         $filter["_id"] = array(_ID_RESOURCE => $this->labeller->uri_to_alias($resource), _ID_CONTEXT => $contextAlias);
     }
     $docs = $this->config->getCollectionForCBD($this->storeName, $from)->find($filter, array('maxTimeMS' => 1000000));
     foreach ($docs as $doc) {
         if ($queueName && !$resource) {
             $subject = new ImpactedSubject($doc['_id'], OP_TABLES, $this->storeName, $from, array($tableType));
             $jobOptions = array();
             if ($this->stat || !empty($this->statsConfig)) {
                 $jobOptions['statsConfig'] = $this->getStatsConfig();
             }
             $this->getApplyOperation()->createJob(array($subject), $queueName, $jobOptions);
         } else {
             // set up ID
             $generatedRow = array("_id" => array(_ID_RESOURCE => $doc["_id"][_ID_RESOURCE], _ID_CONTEXT => $doc["_id"][_ID_CONTEXT], _ID_TYPE => $tableSpec['_id']));
             $value = array('_id' => $doc['_id']);
             // everything must go in the value object todo: this is a hang over from map reduce days, engineer out once we have stability on new PHP method for M/R
             $this->addIdToImpactIndex($doc['_id'], $value);
             // need to add the doc to the impact index to be consistent with views/search etc. this is needed for discovering impacted operations
             $this->addFields($doc, $tableSpec, $value);
             if (isset($tableSpec['joins'])) {
                 $this->doJoins($doc, $tableSpec['joins'], $value, $from, $contextAlias);
             }
             if (isset($tableSpec['counts'])) {
                 $this->doCounts($doc, $tableSpec['counts'], $value);
             }
             if (isset($tableSpec['computed_fields'])) {
                 $this->doComputedFields($tableSpec, $value);
             }
             // Remove temp fields from document
             $generatedRow['value'] = array_diff_key($value, array_flip($this->temporaryFields));
             $this->truncatingSave($collection, $generatedRow);
         }
     }
     $t->stop();
     $this->timingLog(MONGO_CREATE_TABLE, array('type' => $tableSpec['type'], 'duration' => $t->result(), 'filter' => $filter, 'from' => $from));
     $this->getStat()->timer(MONGO_CREATE_TABLE . ".{$tableType}", $t->result());
 }
 /**
  * @param array $data
  * @param string|null $queueName
  */
 public function createJob(array $data, $queueName = null)
 {
     if (!$queueName) {
         $queueName = Config::getDiscoverQueueName();
     } elseif (strpos($queueName, \Tripod\Mongo\Config::getDiscoverQueueName()) === false) {
         $queueName = \Tripod\Mongo\Config::getDiscoverQueueName() . '::' . $queueName;
     }
     $this->submitJob($queueName, get_class($this), $data);
 }
Пример #29
0
 /**
  * Sets job arguments
  */
 protected function setArgs()
 {
     $subject = new \Tripod\Mongo\ImpactedSubject(array(_ID_RESOURCE => 'http://example.com/resources/foo', _ID_CONTEXT => 'http://talisaspire.com/'), OP_VIEWS, 'tripod_php_testing', 'CBD_testing');
     $this->args = array('tripodConfig' => \Tripod\Mongo\Config::getConfig(), 'subjects' => array($subject->toArray()), 'statsConfig' => $this->getStatsDConfig());
 }
Пример #30
0
<?php

require_once dirname(__FILE__) . '/common.inc.php';
require_once dirname(dirname(dirname(__FILE__))) . '/src/tripod.inc.php';
if ($argc != 2 && $argc != 3 && $argc != 4) {
    echo "usage: php ensureIndexes.php tripodConfig.json [storeName] [forceReindex (default is false)]\n";
    die;
}
array_shift($argv);
\Tripod\Mongo\Config::setConfig(json_decode(file_get_contents($argv[0]), true));
$storeName = isset($argv[1]) ? $argv[1] : null;
$forceReindex = isset($argv[2]) && $argv[2] == "true" ? true : false;
\Tripod\Mongo\Config::getInstance()->setMongoCursorTimeout(-1);
$ei = new \Tripod\Mongo\IndexUtils();
$t = new \Tripod\Timer();
$t->start();
print "About to start indexing on {$storeName}...\n";
$ei->ensureIndexes($forceReindex, $storeName);
$t->stop();
print "Indexing complete, took {$t->result()} seconds\n";