Skip to content

Commit

Permalink
Item9750: don't try to re-alias long form registered META:TYPES
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/MongoDBPlugin@10598 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Jan 25, 2011
1 parent bb6a838 commit 44b7d51
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 31 deletions.
56 changes: 25 additions & 31 deletions lib/Foswiki/Plugins/MongoDBPlugin/HoistMongoDB.pm
Expand Up @@ -126,7 +126,6 @@ sub _hoist {
or defined( $node->{inWhere} )
)
{
print STDERR "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]";
$node->{params}[0]->{inWhere} = $node->{inWhere}
if ( defined( $node->{params}[0] ) and (ref($node->{params}[0]) ne ''));
$node->{params}[1]->{inWhere} = ( $node->{inWhere} || $node )
Expand Down Expand Up @@ -416,15 +415,10 @@ hoist ~ into a mongoDB ixHash query
=cut

package Foswiki::Query::OP_dot;
our %aliases = (
use Foswiki::Meta;

# attachments => 'META:FILEATTACHMENT',
# fields => 'META:FIELD',
# form => 'META:FORM',
# info => 'META:TOPICINFO',
# moved => 'META:TOPICMOVED',
# parent => 'META:TOPICPARENT',
# preferences => 'META:PREFERENCE',
#mongo specific aliases
our %aliases = (
name => '_topic',
web => '_web',
text => '_text'
Expand Down Expand Up @@ -454,28 +448,21 @@ sub hoistMongoDB {
#return;
}

#TODO: both the net 2 should only work form registered META - including what params are allowed. (except we don't do that for FIELDS :(
if ( ref( $node->{op} ) ) {

#an actual OP_dot
my $lhs = $node->{params}[0];
my $rhs = $node->{params}[1];

# ASSERT( !ref( $lhs->{op} ) ) if DEBUG;
# ASSERT( !ref( $rhs->{op} ) ) if DEBUG;
# ASSERT( $lhs->{op} eq Foswiki::Infix::Node::NAME ) if DEBUG;
# ASSERT( $rhs->{op} eq Foswiki::Infix::Node::NAME )
# if DEBUG;

$lhs = $lhs->{params}[0];
$rhs = $rhs->{params}[0];
my $lhs = $node->{params}[0]->{params}[0];
my $rhs = $node->{params}[1]->{params}[0];

my $mappedName = mapAlias($lhs);

print STDERR "-------------------------------- hoist OP_dot("
. ref( $node->{op} ) . ", "
. Data::Dumper::Dumper($node)
. ")\n INTO "
. $mappedName . '.'
. $rhs . "\n";
#print STDERR "-------------------------------- hoist OP_dot("
# . ref( $node->{op} ) . ", "
# . Data::Dumper::Dumper($node)
# . ")\n INTO "
# . $mappedName . '.'
# . $rhs . "\n";

if ( $mappedName ne $lhs ) {
return $mappedName . '.' . $rhs;
Expand All @@ -489,14 +476,21 @@ sub hoistMongoDB {
elsif ( $node->{op} == Foswiki::Infix::Node::NAME ) {

#if we're in a where, this is a bit transmissive
print STDERR "============================= hoist OP_dot("
. $node->{op} . ", "
. $node->{params}[0] . ', '
. (defined($node->{inWhere})?'inwhere':'notinwhere'). ")\n";
#print STDERR "============================= hoist OP_dot("
# . $node->{op} . ", "
# . $node->{params}[0] . ', '
# . (defined($node->{inWhere})?'inwhere':'notinwhere'). ")\n";

#if we're in a 'where' eg preferences[name = 'Summary'] then don't aliases
return $node->{params}[0] if (defined($node->{inWhere}));

#if its a registered META, just return it.
if ($node->{params}[0] =~ /META:(.*)/) {
return $1 if (defined($Foswiki::Meta::VALIDATE{$1}));
}



my $mappedName = mapAlias($node->{params}[0]);
if ($mappedName ne $node->{params}[0]) {
$mappedName =~ s/^META://;
Expand Down
96 changes: 96 additions & 0 deletions test/unit/HoistMongoDBsTests.pm
Expand Up @@ -322,6 +322,29 @@ sub test_hoistANDAND {
);
}

sub test_hoistSimpleFieldDOT {
my $this = shift;
my $s = "FIELD.number.bana = 12";
my $queryParser = new Foswiki::Query::Parser();
my $query = $queryParser->parse($s);
my $mongoDBQuery =
Foswiki::Plugins::MongoDBPlugin::HoistMongoDB::hoist($query);

#TODO: there's and assumption that the bit before the . is the form-name
$this->do_Assert( $query, $mongoDBQuery, { 'FIELD.bana.value' => '12' } );
}
sub test_hoistMETAFieldDOT {
my $this = shift;
my $s = "META:FIELD.number.bana = 12";
my $queryParser = new Foswiki::Query::Parser();
my $query = $queryParser->parse($s);
my $mongoDBQuery =
Foswiki::Plugins::MongoDBPlugin::HoistMongoDB::hoist($query);

#TODO: there's and assumption that the bit before the . is the form-name
$this->do_Assert( $query, $mongoDBQuery, { 'FIELD.bana.value' => '12' } );
}

sub test_hoistSimpleDOT {
my $this = shift;
my $s = "number.bana = 12";
Expand All @@ -333,6 +356,17 @@ sub test_hoistSimpleDOT {
#TODO: there's and assumption that the bit before the . is the form-name
$this->do_Assert( $query, $mongoDBQuery, { 'FIELD.bana.value' => '12' } );
}
sub test_hoistSimpleField {
my $this = shift;
my $s = "number = 12";
my $queryParser = new Foswiki::Query::Parser();
my $query = $queryParser->parse($s);
my $mongoDBQuery =
Foswiki::Plugins::MongoDBPlugin::HoistMongoDB::hoist($query);

#TODO: there's and assumption that the bit before the . is the form-name
$this->do_Assert( $query, $mongoDBQuery, { 'FIELD.number.value' => '12' } );
}

sub test_hoistGT {
my $this = shift;
Expand Down Expand Up @@ -554,6 +588,68 @@ sub test_hoistOP_Where {
{ 'PREFERENCE.__RAW_ARRAY' => { '$elemMatch' => {'name' => 'SVEN' }}}
);
}
#
sub test_hoistOP_Where1 {
my $this = shift;
my $s = "fields[value='FrequentlyAskedQuestion'";
my $queryParser = new Foswiki::Query::Parser();
my $query = $queryParser->parse($s);
my $mongoDBQuery =
Foswiki::Plugins::MongoDBPlugin::HoistMongoDB::hoist($query);

# db.current.find({ 'PREFERENCE.__RAW_ARRAY' : { '$elemMatch' : {'name' : 'SVEN' }}})

$this->do_Assert( $query, $mongoDBQuery,
{
'FIELD.__RAW_ARRAY' => {
'$elemMatch' => {
'value' => 'FrequentlyAskedQuestion'
}
}
}
);
}
sub test_hoistOP_Where2 {
my $this = shift;
my $s = "META:FIELD[value='FrequentlyAskedQuestion'";
my $queryParser = new Foswiki::Query::Parser();
my $query = $queryParser->parse($s);
my $mongoDBQuery =
Foswiki::Plugins::MongoDBPlugin::HoistMongoDB::hoist($query);

# db.current.find({ 'PREFERENCE.__RAW_ARRAY' : { '$elemMatch' : {'name' : 'SVEN' }}})

$this->do_Assert( $query, $mongoDBQuery,
{
'FIELD.__RAW_ARRAY' => {
'$elemMatch' => {
'value' => 'FrequentlyAskedQuestion'
}
}
}
);
}
sub test_hoistOP_Where3 {
my $this = shift;
my $s = "META:FIELD[name='TopicClassification' AND value='FrequentlyAskedQuestion'";
my $queryParser = new Foswiki::Query::Parser();
my $query = $queryParser->parse($s);
my $mongoDBQuery =
Foswiki::Plugins::MongoDBPlugin::HoistMongoDB::hoist($query);

# db.current.find({ 'PREFERENCE.__RAW_ARRAY' : { '$elemMatch' : {'name' : 'SVEN' }}})

$this->do_Assert( $query, $mongoDBQuery,
{
'FIELD.__RAW_ARRAY' => {
'$elemMatch' => {
'value' => 'FrequentlyAskedQuestion',
'name' => 'TopicClassification'
}
}
}
);
}
#i think this is meaninless, but i'm not sure.
sub test_hoistOP_preferencesDotName {
my $this = shift;
Expand Down

0 comments on commit 44b7d51

Please sign in to comment.