Skip to content

Commit

Permalink
Merge pull request #151 from techfromsage/TA-1767-join-on-id-in-view
Browse files Browse the repository at this point in the history
TA-1767 Adding support for joining on _id in a view
  • Loading branch information
pogotc authored Nov 4, 2024
2 parents 66b935c + 81fd6c9 commit 0db75e5
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/mongo/delegates/Views.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,9 @@ protected function doJoins($source, $joins, &$dest, $from, $contextAlias, $build
{
// single value for join
$joinUris[] = array(_ID_RESOURCE=>$source[$predicate][VALUE_URI],_ID_CONTEXT=>$contextAlias);
}
else
{
} else if($predicate == '_id') {
$joinUris[] = array(_ID_RESOURCE => $source[$predicate][_ID_RESOURCE], _ID_CONTEXT => $contextAlias);
} else {
// multiple values for join
$joinsPushed = 0;
foreach ($source[$predicate] as $v)
Expand Down
2 changes: 1 addition & 1 deletion test/unit/mongo/ConfigGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testCreateFromConfig()
$this->assertInstanceOf(Tripod\Mongo\Config::class, $instance);
$this->assertInstanceOf(Tripod\ITripodConfigSerializer::class, $instance);
$this->assertEquals(
['CBD_testing', 'CBD_testing_2'],
['CBD_testing', 'CBD_test_related_content', 'CBD_testing_2'],
$instance->getPods('tripod_php_testing')
);
}
Expand Down
7 changes: 6 additions & 1 deletion test/unit/mongo/MongoTripodConfigUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,12 @@ public function testGetViewSpecification()
'rdf:type',
],
],
],
'_id' => [
'from' => 'CBD_test_related_content',
'include' => ['dct:title']

]
]
];

$vspec = Tripod\Config::getInstance()->getViewSpecification('tripod_php_testing', 'v_resource_full');
Expand Down
24 changes: 19 additions & 5 deletions test/unit/mongo/MongoTripodTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,43 @@ protected function loadResourceData()

protected function loadDatesDataViaTripod()
{
$this->loadDataViaTripod('/data/dates.json');
$this->loadDataViaTripod($this->tripod, '/data/dates.json');
}

protected function loadResourceDataViaTripod()
{
$this->loadDataViaTripod('/data/resources.json');
$this->loadDataViaTripod($this->tripod,'/data/resources.json');
}

protected function loadBaseSearchDataViaTripod()
{
$this->loadDataViaTripod('/data/searchData.json');
$this->loadDataViaTripod($this->tripod,'/data/searchData.json');
}

protected function loadRelatedContentIntoTripod()
{
$relatedContentTripod = new Tripod\Mongo\Driver(
'CBD_test_related_content',
'tripod_php_testing',
[
'defaultContext' => 'http://talisaspire.com/',
'async' => [OP_VIEWS => true], // don't generate views syncronously when saving automatically - let unit tests deal with this)
],
);

$this->loadDataViaTripod($relatedContentTripod,'/data/relatedContent.json');
}

/**
* @param string $filename
*/
private function loadDataViaTripod($filename)
private function loadDataViaTripod(Tripod\Mongo\Driver $tripod, $filename)
{
$docs = json_decode(file_get_contents(dirname(__FILE__) . $filename), true);
foreach ($docs as $d) {
$g = new Tripod\Mongo\MongoGraph();
$g->add_tripod_array($d);
$this->tripod->saveChanges(new Tripod\ExtendedGraph(), $g, $d['_id'][_ID_CONTEXT]);
$tripod->saveChanges(new Tripod\ExtendedGraph(), $g, $d['_id'][_ID_CONTEXT]);
}
}

Expand Down
7 changes: 7 additions & 0 deletions test/unit/mongo/MongoTripodViewsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ protected function setUp(): void

// load base data
$this->loadResourceDataViaTripod();

$this->loadRelatedContentIntoTripod();
}

/**
Expand All @@ -78,6 +80,10 @@ public function testGenerateView()
[VALUE_URI => 'acorn:Work'],
],
],
[
'_id' => ['r' => 'http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA', 'c' => 'http://talisaspire.com/'],
'dct:title' => ['l' => 'Title of the related resource content joined by id']
],
[
'_id' => ['r' => 'http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA', 'c' => 'http://talisaspire.com/'],
'rdf:type' => [
Expand Down Expand Up @@ -105,6 +111,7 @@ public function testGenerateView()
$this->assertEquals($expectedView['_id'], $actualView['_id']);
$this->assertEquals($expectedView['value'], $actualView['value']);
$this->assertInstanceOf(MongoDB\BSON\UTCDateTime::class, $actualView['_cts']);

}

/**
Expand Down
11 changes: 11 additions & 0 deletions test/unit/mongo/data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
}
}
},
"CBD_test_related_content": {
"cardinality": {
"dct:created": 1
}
},
"CBD_testing_2": {
"data_source" : "rs2",
"cardinality": {
Expand Down Expand Up @@ -75,6 +80,12 @@
"joins": {
"dct:isVersionOf": {
"include": ["dct:subject", "rdf:type"]
},
"_id": {
"from": "CBD_test_related_content",
"include": [
"dct:title"
]
}
}
},
Expand Down
18 changes: 18 additions & 0 deletions test/unit/mongo/data/relatedContent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"_id": {
"r":"http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA",
"c":"http://talisaspire.com/"
},
"_version": 0,
"rdf:type":[
{
"u":"http://talisaspire.com/schema#ResourceContent"
}
],
"dct:title":
{
"l":"Title of the related resource content joined by id"
}
}
]

0 comments on commit 0db75e5

Please sign in to comment.