diff options
author | Alexander Alexeev | 2016-11-28 20:04:05 +0700 |
---|---|---|
committer | Vitaly Takmazov | 2016-11-28 16:11:10 +0300 |
commit | 915e804c097ed97e39eebc498f1339cab53109cd (patch) | |
tree | 875ddc9572df97af55934cce597bd4b0c25f7f90 /juick-api/src/main | |
parent | 91554cb30eefd48e85ebb744aea0be7efff13e11 (diff) |
WebUtils utilite class ; some inprovements; tests now run successfully
Diffstat (limited to 'juick-api/src/main')
-rw-r--r-- | juick-api/src/main/java/com/juick/api/controllers/Users.java | 40 |
1 files changed, 13 insertions, 27 deletions
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Users.java b/juick-api/src/main/java/com/juick/api/controllers/Users.java index 75dea5f5..396a716c 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/Users.java +++ b/juick-api/src/main/java/com/juick/api/controllers/Users.java @@ -5,6 +5,7 @@ import com.juick.api.util.HttpForbiddenException; import com.juick.api.util.HttpNotFoundException; import com.juick.service.UserService; import com.juick.util.UserUtils; +import com.juick.util.WebUtils; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -15,12 +16,9 @@ import org.springframework.web.bind.annotation.ResponseBody; import javax.inject.Inject; import java.security.Principal; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; import java.util.List; /** - * * @author ugnich */ @Controller @@ -32,39 +30,27 @@ public class Users { @RequestMapping(value = "/users", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public List<User> doGetUsers( - @RequestParam(value = "uname", required = false) String[] punames, - @RequestParam(value = "jid", required = false) String[] pjids) { + @RequestParam(value = "uname", required = false) List<String> unames, + @RequestParam(value = "jid", required = false) List<String> jids) { List<com.juick.User> users = new ArrayList<>(); - if (punames != null) { - ArrayList<String> unames = new ArrayList<>(Arrays.asList(punames)); - Iterator<String> i = unames.iterator(); - while (i.hasNext()) { - if (!i.next().matches("^[a-zA-Z0-9\\-]{2,16}$")) { - i.remove(); - } - } - if (!unames.isEmpty() && unames.size() < 20) { + if (unames != null) { + unames.removeIf(WebUtils::isNotUserName); + + if (!unames.isEmpty() && unames.size() < 20) users.addAll(userService.getUsersByName(unames)); - } } - if (pjids != null) { - List<String> jids = new ArrayList<>(Arrays.asList(pjids)); - Iterator<String> ii = jids.iterator(); - while (ii.hasNext()) { - if (!ii.next().matches("^[a-zA-Z0-9\\-\\_\\@\\.]{6,64}$")) { - ii.remove(); - } - } - if (!jids.isEmpty() && jids.size() < 20) { + if (jids != null) { + jids.removeIf(WebUtils::isNotJid); + + if (!jids.isEmpty() && jids.size() < 20) users.addAll(userService.getUsersByJID(jids)); - } } - if (!users.isEmpty()) { + if (!users.isEmpty()) return users; - } + throw new HttpNotFoundException(); } |