[proposal] Access to XWQL & QueryManager for scripts

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[proposal] Access to XWQL & QueryManager for scripts

Artem Melentyev-3
Hi devs!

As you know XWQL was introduced in 1.6, but without some easy access
from scripts. Currently it is accessible via
$xwiki.xWiki.store.queryManager.createQuery(stmt, "xwql") and only with
programming rights.

We need some easy ways to access to XWQL similar as
$xwiki.searchDocuments, countDocuments and search. This will allow to
users much more test XWQL and send us feedback.

I planed to implement this by 1.7RC1 or 1.7. This is just an interface
for xwiki scripts and doesn't affect to important parts of platform.


Name of this service?

1. $xwiki.queryManager ($xwiki.query is occupied by old QueryPlugin)
  Later this will be obsoleted by 2.
or
2. $services.query
  $services was proposed in our velocity bridge proposal[1]. We may
implement only $service now as just simple services holder, without
uberspectors.
  $services will be reimplemented later, but "$service.query" name will
be saved.
[1] http://markmail.org/message/nnybto3mluvp2rov

I'm for 1 because velocity bridge isn't exist yet and its design may be
changed.

Technically it will be just some proxy for QueryManager and Query with
access right checking.


Functionality?

1. Just the same as QueryManager
  so: .createQuery("stmt", "lang").execute()
or
2. The same as QueryManager + .xwql("stmt") method which will call
.createQuery("stmt", "xwql")
  .xwql("stmt") is much more laconically than createQuery. Later it may
be transparently replaced by 3.
or
3. QueryManager + dynamic methods like .language("stmt")
  impossible without velocity bridge uberspectors.

I'm for 2.


Access rights?
One way:

1. short-form xwql queries like
  "where <whereexpr>" and "from <fromexp> where <whereexpr>"
  return only document names, so
  will be available for everyone.
  this is analogue for $xwiki.searchDocuments()

2. full-form xwql ("select <selectlist> from <etc>" )
  will require programming rights.
  this is analogue for $xwiki.search()

3. all other languages (currently only HQL) in QueryManager will require
programming rights.

4. Query.setWiki will require programming rights.
  So we need to wrap Query with some SecureQuery.


How should be analogue for "$xwiki.countDocuments"?
Ways:
0. No analogue. just query.execute().size()
   JCRSQL2 has no aggregate functions at all.
   We could make lazy query result list to fix negatives.
1. just accept all queries like "select count(*) ..."
   ("*" is not supported in count() according jpql)
2. implement some simple syntax extension in xwql:
  "count [from ...] where ..."
   no parser change, just replace the statement prefix

I'm 0 for now.

WDYT?

--
   Artem Melentyev

_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

[Rendering]Useravatar macro for Wiki 2.0

Dan Miron
Hi folks,

I could use some hints regarding this issue:
My macro looks something like this:

public class UseravatarMacro extends
AbstractMacro<UseravatarMacroParameters>
{
    /**
     * The description of the macro.
     */
    private static final String DESCRIPTION = "Allows displaying the
avatar for a specific user.";

    /**
     * Injected by the Component Manager.
     */
    private DocumentAccessBridge documentAccessBridge;
 
    //....................................................................
 
    public List<Block> execute(UseravatarMacroParameters parameters,
String content, MacroTransformationContext context)
        throws MacroExecutionException
    {
        String atachment = null;
        String userName = parameters.getUsername();
        Block resultedBlock = null;
       
        try {
            atachment = documentAccessBridge.getProperty(userName,
"XWiki.XWikiUsers", "avatar");
            Image image = new Image(userName, atachment);
            resultedBlock = new ImageBlock(image, false);
        }
        catch {
           
//....................................................................
        }      
        return Collections.singletonList(resultedBlock);
       
       
    }

    //....................................................................

}

Now, the problem is that, if the user doesn't have an avatar, I need to
display the default one (noavatar.png) from the current skin. In
velocity, it was something like this:  $xwiki.getSkinFile("noavatar.png").

Any ideas on how to get the current XWikiContext in my macro in order to
be able to access the skin?

Tnx.

_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: [Rendering]Useravatar macro for Wiki 2.0

vmassol
Administrator
Hi Dan,

On Nov 24, 2008, at 12:43 PM, Dan Miron wrote:

> Hi folks,
>
> I could use some hints regarding this issue:
> My macro looks something like this:
>
> public class UseravatarMacro extends
> AbstractMacro<UseravatarMacroParameters>
> {
>    /**
>     * The description of the macro.
>     */
>    private static final String DESCRIPTION = "Allows displaying the
> avatar for a specific user.";
>
>    /**
>     * Injected by the Component Manager.
>     */
>    private DocumentAccessBridge documentAccessBridge;
>
>    //....................................................................
>
>    public List<Block> execute(UseravatarMacroParameters parameters,
> String content, MacroTransformationContext context)
>        throws MacroExecutionException
>    {
>        String atachment = null;
>        String userName = parameters.getUsername();
>        Block resultedBlock = null;
>
>        try {
>            atachment = documentAccessBridge.getProperty(userName,
> "XWiki.XWikiUsers", "avatar");
>            Image image = new Image(userName, atachment);
>            resultedBlock = new ImageBlock(image, false);
>        }
>        catch {
>
> //....................................................................
>        }
>        return Collections.singletonList(resultedBlock);
>
>
>    }
>
>    //....................................................................
>
> }
>
> Now, the problem is that, if the user doesn't have an avatar, I need  
> to
> display the default one (noavatar.png) from the current skin. In
> velocity, it was something like this:  
> $xwiki.getSkinFile("noavatar.png").

You need to add some skin API in the component bridge (in a new class  
IMO).

Thanks
-Vincent

>
>
> Any ideas on how to get the current XWikiContext in my macro in  
> order to
> be able to access the skin?
>
> Tnx.
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: [Rendering]Useravatar macro for Wiki 2.0

vmassol
Administrator
In reply to this post by Dan Miron
BTW please create a new email thread next time :)
(what you did here was reuse an existing mail and remove the subject  
and content but that's not a new mail, it keeps the mail headers)

Thanks
-Vincent

On Nov 24, 2008, at 12:43 PM, Dan Miron wrote:

> Hi folks,
>
> I could use some hints regarding this issue:
> My macro looks something like this:
>
> public class UseravatarMacro extends
> AbstractMacro<UseravatarMacroParameters>
> {
>    /**
>     * The description of the macro.
>     */
>    private static final String DESCRIPTION = "Allows displaying the
> avatar for a specific user.";
>
>    /**
>     * Injected by the Component Manager.
>     */
>    private DocumentAccessBridge documentAccessBridge;
>
>    //....................................................................
>
>    public List<Block> execute(UseravatarMacroParameters parameters,
> String content, MacroTransformationContext context)
>        throws MacroExecutionException
>    {
>        String atachment = null;
>        String userName = parameters.getUsername();
>        Block resultedBlock = null;
>
>        try {
>            atachment = documentAccessBridge.getProperty(userName,
> "XWiki.XWikiUsers", "avatar");
>            Image image = new Image(userName, atachment);
>            resultedBlock = new ImageBlock(image, false);
>        }
>        catch {
>
> //....................................................................
>        }
>        return Collections.singletonList(resultedBlock);
>
>
>    }
>
>    //....................................................................
>
> }
>
> Now, the problem is that, if the user doesn't have an avatar, I need  
> to
> display the default one (noavatar.png) from the current skin. In
> velocity, it was something like this:  
> $xwiki.getSkinFile("noavatar.png").
>
> Any ideas on how to get the current XWikiContext in my macro in  
> order to
> be able to access the skin?
>
> Tnx.

_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: [Rendering]Useravatar macro for Wiki 2.0

Marius Dumitru Florea
Vincent Massol wrote:

> BTW please create a new email thread next time :)
> (what you did here was reuse an existing mail and remove the subject  
> and content but that's not a new mail, it keeps the mail headers)
>
> Thanks
> -Vincent
>
> On Nov 24, 2008, at 12:43 PM, Dan Miron wrote:
>
>> Hi folks,
>>
>> I could use some hints regarding this issue:
>> My macro looks something like this:
>>
>> public class UseravatarMacro extends

You should also use camel case for the class name.

>> AbstractMacro<UseravatarMacroParameters>
>> {
>>    /**
>>     * The description of the macro.
>>     */
>>    private static final String DESCRIPTION = "Allows displaying the
>> avatar for a specific user.";
>>
>>    /**
>>     * Injected by the Component Manager.
>>     */
>>    private DocumentAccessBridge documentAccessBridge;
>>
>>    //....................................................................
>>
>>    public List<Block> execute(UseravatarMacroParameters parameters,
>> String content, MacroTransformationContext context)
>>        throws MacroExecutionException
>>    {
>>        String atachment = null;
>>        String userName = parameters.getUsername();
>>        Block resultedBlock = null;
>>
>>        try {
>>            atachment = documentAccessBridge.getProperty(userName,
>> "XWiki.XWikiUsers", "avatar");
>>            Image image = new Image(userName, atachment);
>>            resultedBlock = new ImageBlock(image, false);
>>        }
>>        catch {
>>
>> //....................................................................
>>        }
>>        return Collections.singletonList(resultedBlock);
>>
>>
>>    }
>>
>>    //....................................................................
>>
>> }
>>
>> Now, the problem is that, if the user doesn't have an avatar, I need  
>> to
>> display the default one (noavatar.png) from the current skin. In
>> velocity, it was something like this:  
>> $xwiki.getSkinFile("noavatar.png").
>>
>> Any ideas on how to get the current XWikiContext in my macro in  
>> order to
>> be able to access the skin?
>>
>> Tnx.
>
> _______________________________________________
> devs mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: [Rendering]Useravatar macro for Wiki 2.0

Florin Ciubotaru
Marius Dumitru Florea wrote:

> Vincent Massol wrote:
>  
>> BTW please create a new email thread next time :)
>> (what you did here was reuse an existing mail and remove the subject  
>> and content but that's not a new mail, it keeps the mail headers)
>>
>> Thanks
>> -Vincent
>>
>> On Nov 24, 2008, at 12:43 PM, Dan Miron wrote:
>>
>>    
>>> Hi folks,
>>>
>>> I could use some hints regarding this issue:
>>> My macro looks something like this:
>>>
>>> public class UseravatarMacro extends
>>>      
>
> You should also use camel case for the class name.
>  
Disambiguation:
Dan is an ex-C# programmer. He may recognize camel case as in
lowerCamelCase only. Of course Marius is talking about
UpperCamelCase(usually known as PascalCase).

>  
>>> AbstractMacro<UseravatarMacroParameters>
>>> {
>>>    /**
>>>     * The description of the macro.
>>>     */
>>>    private static final String DESCRIPTION = "Allows displaying the
>>> avatar for a specific user.";
>>>
>>>    /**
>>>     * Injected by the Component Manager.
>>>     */
>>>    private DocumentAccessBridge documentAccessBridge;
>>>
>>>    //....................................................................
>>>
>>>    public List<Block> execute(UseravatarMacroParameters parameters,
>>> String content, MacroTransformationContext context)
>>>        throws MacroExecutionException
>>>    {
>>>        String atachment = null;
>>>        String userName = parameters.getUsername();
>>>        Block resultedBlock = null;
>>>
>>>        try {
>>>            atachment = documentAccessBridge.getProperty(userName,
>>> "XWiki.XWikiUsers", "avatar");
>>>            Image image = new Image(userName, atachment);
>>>            resultedBlock = new ImageBlock(image, false);
>>>        }
>>>        catch {
>>>
>>> //....................................................................
>>>        }
>>>        return Collections.singletonList(resultedBlock);
>>>
>>>
>>>    }
>>>
>>>    //....................................................................
>>>
>>> }
>>>
>>> Now, the problem is that, if the user doesn't have an avatar, I need  
>>> to
>>> display the default one (noavatar.png) from the current skin. In
>>> velocity, it was something like this:  
>>> $xwiki.getSkinFile("noavatar.png").
>>>
>>> Any ideas on how to get the current XWikiContext in my macro in  
>>> order to
>>> be able to access the skin?
>>>
>>> Tnx.
>>>      
>> _______________________________________________
>> devs mailing list
>> [hidden email]
>> http://lists.xwiki.org/mailman/listinfo/devs
>>    
> _______________________________________________
> devs mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/devs
>  

_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs