cancel
Showing results for 
Search instead for 
Did you mean: 

searchservice

_jan
Champ on-the-rise
Champ on-the-rise
Hi,
How to get search service for using in Java ActionExecuterAbstractBase ? Is it possible ? I am trying to update other document after new is created.
Thanks
10 REPLIES 10

jpotts
World-Class Innovator
World-Class Innovator
<a href="https://github.com/jpotts/alfresco-developer-series/blob/master/actions/actions-tutorial-repo/src/ma...">Here</a> is an example of an action executer that uses the node service and the file folder service. Those services are injected as dependencies into the action class.

The thing that does the injection is the module's <a href="https://github.com/jpotts/alfresco-developer-series/blob/master/actions/actions-tutorial-repo/src/ma...">Spring configuration</a>.

You can handle the search service (and any other service that you might need) by following this same pattern.

If you need more help with actions, this code goes with a <a href="http://ecmarchitect.com/alfresco-developer-series-tutorials/actions/tutorial/tutorial.html">tutorial</a> on UI actions.

Jeff

_jan
Champ on-the-rise
Champ on-the-rise
Hi, thanks a lot for reply
I saw that tutorial and I try to do that by same way, but I stucked on how to get Node of root, for example Data Dictionary.
Because there is method
.searchSimple(NodeRef contextNodeRef, String name)
but i don't have that NodeRef of parent and don't know how to get it.
I found that i can create new Noderef by
NodeRef folder = new NodeRef("workspace://SpacesStore/some_id_of_folder");

But is there some constant value for root node from which I can go down to child folder, something like default root node ?

kaynezhang
World-Class Innovator
World-Class Innovator
You can use node service to get root node of a store,like following.

NodeRef rootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);

You should also inject NodeService spring bean into you class.

_jan
Champ on-the-rise
Champ on-the-rise
Yeah, that was exactly what I was looking for. Thanks.
I have another question. Is possible to use
scriptService
in
ActionExecuterAbstractBase
Action ? when I try to put

<property name="scriptService ">
    <ref bean="ScriptService "/>
</property>

my alfresco cannot start. Is neccesary to add something else to my code for scriptService ?
I am trying to make rule which will call javascript from /Script folder.

kaynezhang
World-Class Innovator
World-Class Innovator
You want to execute a script in your action,why not extend ScriptActionExecuter instead of ActionExecuterAbstractBase,ScriptActionExecuter has an ServiceRegistry property from which you can get scriptservice using
ServiceRegistry.getScriptService()


Or you can inject ServiceRegistry into your custom action class ,from ServiceRegistry you can get NodeService,ScriptService and so on.

_jan
Champ on-the-rise
Champ on-the-rise
And is that a good aproach to call some JS script which is located in "Data Directory/Scripts" from Java Action? I am begginer at Alfresco, so I am trying to find right way. I want to prepare everything with .amp file and than only install that to alfresco. I will bootstrap some JS script to that directory. Or is better way to execute JS script like action ? 

kaynezhang
World-Class Innovator
World-Class Innovator
I do not think it is a good approach to mix java code and JavaScript code in your action(although you can).
Why not implement your action just using java code?

_jan
Champ on-the-rise
Champ on-the-rise
Beacuse it looked for me easier to write javascript code than Java code.

I am not able to get that ServiceRegistry property even when I change extend to ScriptActionExecuter and include org.alfresco.repo.action.executer.ScriptActionExecuter. Is there some other step which I forgot to do ?

kaynezhang
World-Class Innovator
World-Class Innovator
If your class extend ScriptActionExecuter  ,you can configure "script" bean as your bean's parent in spring configuration file then you can get ServiceRegistry property,like following


   <bean id="yourwebscript" class="com.yourcompany.***.****" parent="script">

        <property name="yourproperty">
            <ref bean="yourproperty" />
        </property>
…..
    </bean>