@SuppressWarnings({ "unchecked", "rawtypes" }) @GET @Produces({ BASE_JSON_MEDIA_TYPE, BASE_XML_MEDIA_TYPE }) public Response search() { if(searchRepository.get() == null) { return Response.status(Response.Status.SERVICE_UNAVAILABLE).build(); } Collection<Conference> conferences = searchRepository.get().search(new ConferenceCriteria()); Collection<ConferenceRepresentation> conferenceRepresentations = getConverter().from(getUriInfo(), (Collection)conferences); return Response.ok(new GenericEntity<Collection<ConferenceRepresentation>>(conferenceRepresentations){}) .type( matchMediaType(CONFERENCE_XML_MEDIA_TYPE, CONFERENCE_JSON_MEDIA_TYPE)) .build(); }
@PUT @Path("/{id}") @Consumes({ BASE_JSON_MEDIA_TYPE, BASE_XML_MEDIA_TYPE }) public Response update(@PathParam("id") String id, REP representation) { DOMAIN entity = getRepository().get(id); if (entity == null) { return Response.status(Status.BAD_REQUEST).build(); // TODO: Need Business Exception type to explain why? } DOMAIN updatedEntity = getConverter().update(uriInfo, representation, entity); getRepository().store(updatedEntity); return Response.noContent().build(); }
@POST @Consumes({ BASE_JSON_MEDIA_TYPE, BASE_XML_MEDIA_TYPE }) public Response create(REP representation) { DOMAIN entity = getConverter().to(uriInfo, representation); getRepository().store(entity); return Response.created( UriBuilder.fromResource(getResourceClass()).segment("{id}").build(entity.getId())).build(); }
@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(); }
@GET @Path("/{id}") @Produces({ BASE_JSON_MEDIA_TYPE, BASE_XML_MEDIA_TYPE }) public Response get(@PathParam("id") String id) { DOMAIN entity = getRepository().get(id); if (entity == null) { return Response.status(Status.NOT_FOUND).type(getMediaType()).build(); } return Response.ok(getConverter().from(uriInfo, entity)) .type(getMediaType()) .lastModified(entity.getLastModified()) .build(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @GET @Path("/{c_id}/session") @Produces({ BASE_JSON_MEDIA_TYPE, BASE_XML_MEDIA_TYPE }) public Response getSessions(@PathParam("c_id") String conferenceId) { Conference conference = getRepository().get(conferenceId); if (conference == null) { return Response.status(Status.BAD_REQUEST).build(); // TODO: Need Business Exception type to explain why? } Collection<SessionRepresentation> sessions = sessionConverter.from(getUriInfo(), (Collection)conference.getSessions()); return Response.ok(new GenericEntity<Collection<SessionRepresentation>>(sessions){}) .type(matchMediaType( SessionResource.SESSION_XML_MEDIA_TYPE, SessionResource.SESSION_JSON_MEDIA_TYPE)) .build(); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) @GET @Path("{sourceObj}/{source}/{rel}/{targetObj}") @Produces({BASE_XML_MEDIA_TYPE, BASE_JSON_MEDIA_TYPE}) public Response get( @PathParam("sourceObj") String sourceDescription, @PathParam("source") String sourceId, @PathParam("rel") String relationship, @PathParam("targetObj") String targetDescription) { Repository<? extends Identifiable> sourceRepo = locateRepository(repositories, sourceDescription); Repository<? extends Identifiable> targetRepo = locateRepository(repositories, targetDescription); if(sourceRepo == null || targetRepo == null) { return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } RepresentationConverter<Object, Object> converter = locateCoverterForType(manager, targetRepo.getType()); if(converter == null) { return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } Identifiable source = sourceRepo.get(sourceId); if(source == null) { return Response.status(Status.NOT_FOUND).build(); } Collection<? extends Identifiable> targets = repositry.findTargets(source, relationship, targetRepo.getType()); if(targets == null || targets.size() == 0) { return Response.noContent().build(); } // Strange JVM Bug? Needs to cast to Collection for it to select the from(y, Collection<X>) method // Using/casting to generic Collection<X> cause it to select the from(y, X) method. return Response.ok(new GenericEntity<Collection<Object>>(converter.from(uriInfo, (Collection)targets)){}).build(); }
@GET @Path("/{id}") @Produces({BASE_XML_MEDIA_TYPE, BASE_JSON_MEDIA_TYPE}) public Response get(@PathParam("id") String id) { return Response.ok(converter.from(uriInfo, repo.get(id))).build(); }