Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Applied refactoring patch
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/rave/branches/0.20.1@1453386 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mfranklin committed Mar 6, 2013
1 parent 73dbc7a commit 546edba
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,23 @@ public interface UserService extends UserDetailsService, AuthenticationUserDetai
*/
User getUserByOpenId(String openId);

/**
* Gets a limited {@link SearchResult} for {@link org.apache.rave.portal.model.Person}'s
*
* @param offset start point within the resultset (for paging)
* @param pageSize maximum number of items to be returned (for paging)
* @return SearchResult
*/
SearchResult<Person> getLimitedListOfPersons(int offset, int pageSize);

/**
* Gets a {@link SearchResult} for {@link org.apache.rave.portal.model.Person}'s that match the search term
*
* @param searchTerm free text input to search on users
* @param offset start point within the resultset (for paging)
* @param pageSize maximum number of items to be returned (for paging)
* @return SearchResult
*/
SearchResult<Person> getPersonsByFreeTextSearch(String searchTerm, int offset, int pageSize);

}
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,21 @@ public SearchResult<User> getLimitedListOfUsers(int offset, int pageSize) {
searchResult.setPageSize(pageSize);
return searchResult;
}


@Override
public SearchResult<Person> getLimitedListOfPersons(int offset, int pageSize) {
SearchResult<User> users = getLimitedListOfUsers(offset, pageSize);
int count = users.getTotalResults();
List<Person> people = new ArrayList<Person>();
Person person = null;
for(User user : users.getResultSet()){
person = user.toPerson();
person.setId(user.getId());
people.add(person);
}
return new SearchResult<Person>(people, count);
}

@Override
public SearchResult<User> getUsersByFreeTextSearch(String searchTerm, int offset, int pageSize) {
Expand All @@ -233,6 +248,20 @@ public SearchResult<User> getUsersByFreeTextSearch(String searchTerm, int offset
searchResult.setPageSize(pageSize);
return searchResult;
}

@Override
public SearchResult<Person> getPersonsByFreeTextSearch(String searchTerm, int offset, int pageSize) {
SearchResult<User> users = getUsersByFreeTextSearch(searchTerm, offset, pageSize);
int count = users.getTotalResults();
List<Person> people = new ArrayList<Person>();
Person person = null;
for(User user : users.getResultSet()){
person = user.toPerson();
person.setId(user.getId());
people.add(person);
}
return new SearchResult<Person>(people, count);
}

@Override
@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,19 @@
*/
package org.apache.rave.portal.web.api.rpc;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.List;

import org.apache.rave.portal.model.Person;
import org.apache.rave.portal.model.util.SearchResult;
import org.apache.rave.portal.service.UserService;
import org.apache.rave.portal.web.api.rpc.model.RpcOperation;
import org.apache.rave.portal.web.api.rpc.model.RpcResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.List;

/**
* Defines RPC operations for adding and removing friends
Expand All @@ -41,6 +39,8 @@
@RequestMapping(value = "/api/rpc/person/*")
public class PersonApi {

public static final int DEFAULT_PAGE_SIZE = 10;

private final UserService userService;

@Autowired
Expand Down Expand Up @@ -130,4 +130,26 @@ public Boolean execute() {
}
}.getResult();
}

@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "get")
public RpcResult<SearchResult<Person>> viewUsers(@RequestParam final int offset) {
return new RpcOperation<SearchResult<Person>>() {
@Override
public SearchResult<Person> execute() {
return userService.getLimitedListOfPersons(offset, DEFAULT_PAGE_SIZE);
}
}.getResult();
}

@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "search")
public RpcResult<SearchResult<Person>> searchUsers(@RequestParam final String searchTerm, @RequestParam final int offset) {
return new RpcOperation<SearchResult<Person>>() {
@Override
public SearchResult<Person> execute() {
return userService.getPersonsByFreeTextSearch(searchTerm, offset, DEFAULT_PAGE_SIZE);
}
}.getResult();
}
}

This file was deleted.

12 changes: 6 additions & 6 deletions rave-portal-resources/src/main/webapp/static/script/rave_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ rave.api = rave.api || (function() {

if (addedWidget != undefined && addedWidget.title != undefined && addedWidget.title.length > 0) {
widgetTitle = addedWidget.title;
}
// if a callback is supplied, invoke it with the regionwidget id
if (args.successCallback && addedWidget != undefined){
args.successCallback(result.result.id);
}
// if a callback is supplied, invoke it with the regionwidget id
if (args.successCallback && addedWidget != undefined){
args.successCallback(result.result.id);
}
rave.showInfoMessage(widgetTitle + ' ' + rave.getClientMessage("widget.add_suffix"));

Expand Down Expand Up @@ -490,7 +490,7 @@ rave.api = rave.api || (function() {

function getUsers(args){
var offset = args.offset;
$.get(rave.getContext() + path + "users/get",
$.get(rave.getContext() + path + "person/get",
{"offset": offset},
function(result) {
if (result.error) {
Expand All @@ -511,7 +511,7 @@ rave.api = rave.api || (function() {
alert(rave.getClientMessage("api.rpc.empty.search.term"));
return;
}
$.get(rave.getContext() + path + "users/search",
$.get(rave.getContext() + path + "person/search",
{"searchTerm": searchTerm, "offset": offset},
function(result) {
if (result.error) {
Expand Down

0 comments on commit 546edba

Please sign in to comment.