cancel
Showing results for 
Search instead for 
Did you mean: 

Get all users (but with Java not Javascript)

kaffi
Confirmed Champ
Confirmed Champ
Hey Guys

I have seen that it is totally easy to get all user data with JavaScript, but my customer wants to have it written in JAVA therefore and I am very new to the Alfresco API. I have written the following code:
   protected Map<String, Object> executeImpl(WebScriptRequest req,
         Status status, Cache cache) {

      
      model = new HashMap<String, Object>();
      requestedUser = req.getParameter("name");
      authorityService = this.getAuthorityService();

      if(!requestedUser.trim().isEmpty()||requestedUser!=null &&personService.personExists(requestedUser)){

         NodeRef singleUser = personService.getPerson(requestedUser);
         log.debug(singleUser);
         model.put("user", nodeService.getProperties(singleUser));
         
      }else{
         userList = personService.getPeople("*",true,new ArrayList<QName>() ,new ArrayList<Pair<QName,Boolean>>(),new PagingRequest(personService.countPeople()));
         
      }
      
      return model;
   }
   

I am not sure how to bind it to the model and how I can I get access it in my json view? Or is there an easier way?

Regards
Kaffi
1 REPLY 1

jpotts
World-Class Innovator
World-Class Innovator
It looks like you've written a Java-based web script that will add data to your model, so that's all taken care of.

It sounds like you've done this once using a JavaScript based web script, so your Freemarker-based view should remain unchanged.

If you haven't already, all you need to do now is wire in the web script via Spring and you should be able to invoke it just like you would if the controller had been written in JavaScript.

As shown in the <a href="http://ecmarchitect.com/alfresco-developer-series-tutorials/webscripts/tutorial/tutorial.html">web script tutorial</a>, the spring bean would look something like this:


<bean id="webscript.com.someco.ratings.rating.post" class="com.someco.scripts.PostRating" parent="webscript">
        <property name="ratingBean">
            <ref bean="ratingBean" />      
        </property>
        <property name="nodeService">
            <ref bean="NodeService" />
        </property>
    </bean>


Your ID would be different based on how you've structured your web script files. Your class name would be different. And your list of dependencies would be different (for example, you'd point to the PersonService).

Hope that helps,

Jeff