@RestMethod(method = HttpMethod.GET, template = "") public List<TestTeamPojo> getTeams( @QueryParameter(name = "teamType") @Description("Identifies the team type.") String teamType, @QueryParameter(name = "teamName") String teamName, @QueryParameter(name = "city") String cities[]) { List<TestTeamPojo> result = new ArrayList<TestTeamPojo>(); for (TestTeamPojo team : teams) { boolean match = true; if (!StringUtils.isEmpty(teamType)) if (!teamType.equals(team.getType().name())) match = false; if (!StringUtils.isEmpty(teamName)) if (!teamName.equals(team.getName())) match = false; if (cities.length > 0) { boolean found = false; for (String city : cities) { if (!StringUtils.isEmpty(city)) if (city.equals(team.getCity())) found = true; } if (!found) match = false; } if (match == true) result.add(team); } lastMethodCalled = "getTeams"; lastHttpMethodCalled = "GET"; return result; }
@RestMethod(method = HttpMethod.POST, template = "", requestFormat = "application/json") public TestTeamPojo addTeam(@RequestBody TestTeamPojo newTeam) { if (teams.contains(newTeam)) throw new DuplicateKeyConstraintException( String.format("There is already a team in the collection with key %s", newTeam.getKey())); teams.add(newTeam); lastMethodCalled = "addTeam"; lastHttpMethodCalled = "POST"; return newTeam; }
@RestMethod(method = HttpMethod.PUT, template = "", requestFormat = "application/json") public TestTeamPojo updateTeam(@RequestBody TestTeamPojo teamToUpdate) { if (!teams.contains(teamToUpdate)) throw new UnrecongizedKeyException( String.format("No team with key %s is in the collection.", teamToUpdate.getKey())); teams.remove(teamToUpdate); teams.add(teamToUpdate); lastMethodCalled = "updateTeam"; lastHttpMethodCalled = "PUT"; return teamToUpdate; }