@POST @Path("/{c_id}/session") @Consumes({ BASE_JSON_MEDIA_TYPE, BASE_XML_MEDIA_TYPE }) public Response createSession(@PathParam("c_id") String conferenceId, SessionRepresentation sessionRepresentation) { Conference conference = getRepository().get(conferenceId); if (conference == null) { return Response.status(Status.BAD_REQUEST).build(); // TODO: Need Business Exception type to explain why? } Session session = sessionConverter.to(getUriInfo(), sessionRepresentation); conference.addSession(session); getRepository().store(conference); return Response.created( UriBuilder.fromResource( SessionResource.class).segment("{id}") .build(session.getId())) .build(); }
@Override public Session get(String id) { Session session = conferenceRepository.getSessionById(id); if(session == null) { for(Session s: sessions) { if(s.getId().equals(id)) { return s; } } } return session; }
Session getSessionById(String id) { for(Conference conf : getStored()) { for(Session session : conf.getSessions()) { if(session.getId().equals(id)) { return session; } } } return null; }
Conference getConferenceBySessionId(String id) { for(Conference conf : getStored()) { for(Session session : conf.getSessions()) { if(session.getId().equals(id)) { return conf; } } } return null; } }
@Override public void remove(Session entity) { Conference conf = conferenceRepository.getConferenceBySessionId(entity.getId()); if(conf != null) { conf.removeSession(entity); } sessions.remove(entity); }
@Override public SessionRepresentation from(UriInfo uriInfo, Session source) { String id = source.getId(); String parentId = null; if(source.getConference() != null) { parentId = source.getConference().getId(); } SessionRepresentation rep = new SessionRepresentation(id, parentId, uriInfo); rep.setTitle(source.getTitle()); rep.setOutline(source.getOutline()); if(source.getDuration() != null) { rep.setStart(source.getDuration().getStart()); rep.setEnd(source.getDuration().getEnd()); } return rep; }