public ReservationFailure(String message) { this.setMessage(message); }
public void setEntry(CalendarEntry entry) { if (entry == null) { return; } validateHour(entry.getHour()); entries.set(entry.getHour(), entry); }
UserRegistration _user = new UserRegistration("name","id1");
CalendarEntry entry = c.getEntry(request.getHour()); if (entry.getEventDescription() == null || entry.getEventDescription().trim().isEmpty()) { String address = restaurantService.post(new Form().param("name", request.getReserveName()) .param("phone", request.getContactPhone()) boolean calendarUpdated = response.getStatus() == 200 || response.getStatus() == 204; return Response.ok(new ReservationConfirmation(address, request.getHour(), calendarUpdated)) .build(); } else {
@POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("calendar") public void updateUserCalendar(@FormParam("hour") int hour, @FormParam("event") String eventDescription) { UserAccount account = getAccount(); account.getCalendar().getEntry(hour).setEventDescription(eventDescription); }
public String toString() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 24; i++) { String event = entries.get(i).getEventDescription(); sb.append("Hour: ").append(i).append(", event: ") .append(event == null ? "Not Booked" : event) .append(System.getProperty("line.separator")); } return sb.toString(); } }
@POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("/") public ConsumerRegistration registerForm(@FormParam("appName") String appName, @FormParam("appURI") String appURI) { String clientId = generateClientId(appName, appURI); String clientSecret = generateClientSecret(); Client newClient = new Client(clientId, clientSecret, appName, appURI); manager.registerClient(newClient); return new ConsumerRegistration(clientId, clientSecret); }
public Calendar() { for (int i = 0; i < 24; i++) { entries.add(new CalendarEntry(i, "")); } }
public CalendarEntry getEntry(int hour) { validateHour(hour); return entries.get(hour); }
@GET @Path("failure") @Produces({"text/html", "application/xml;q=0.9" }) public ReservationFailure handleReservationFailure(@QueryParam("code") String errorCode) { LOG.info("Handling the reservation failure"); String message = ERROR_DESCRIPTIONS.get(errorCode); return new ReservationFailure(message); }
private void printUserCalendar() { WebClient client = createClient("http://localhost:" + port + "/services/social/accounts/calendar", "barry@social.com", "1234"); Calendar calendar = client.get(Calendar.class); System.out.println(calendar.toString()); }
updateAndGetUserCalendar(7, "Dinner at " + confirm.getAddress()); } else { System.out.println("Reservation failed");
@POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("/") public UserRegistration register(@FormParam("user") String name, @FormParam("password") String password) { if (accounts.getAccount(name) != null) { throw new WebApplicationException(400); } accounts.setAccount(name, new UserAccount(name, password)); return new UserRegistration(name); } }
@POST public void updateCalendar(@FormParam("hour") int hour, @FormParam("description") String description) { // This permission check can be done in a custom filter; it can be simpler to do // in the actual service code if the context data (such as an hour in this case) // are not available in the request URI but in the message payload OAuthContext oauth = getOAuthContext(); List<OAuthPermission> perms = oauth.getPermissions(); boolean checkPassed = false; for (OAuthPermission perm : perms) { if (perm.getPermission().startsWith(OAuthConstants.UPDATE_CALENDAR_SCOPE)) { int authorizedHour = Integer.valueOf(perm.getPermission().substring(OAuthConstants.UPDATE_CALENDAR_SCOPE.length())); if (authorizedHour == hour) { checkPassed = true; } } } if (!checkPassed) { throw new WebApplicationException(403); } // end of the check Calendar calendar = getUserCalendar(); calendar.getEntry(hour).setEventDescription(description); }
return new ConsumerRegistration(clientId, clientSecret);