001 package org.hackystat.sensorbase.resource.users; 002 003 import org.hackystat.sensorbase.resource.sensorbase.SensorBaseResource; 004 import org.restlet.Context; 005 import org.restlet.data.MediaType; 006 import org.restlet.data.Request; 007 import org.restlet.data.Response; 008 import org.restlet.resource.Representation; 009 import org.restlet.resource.Variant; 010 011 /** 012 * Implements a Restlet Resource representing an index of Hackystat Users. 013 * @author Philip Johnson 014 */ 015 public class UsersResource extends SensorBaseResource { 016 017 /** 018 * Provides the following representational variants: TEXT_XML. 019 * @param context The context. 020 * @param request The request object. 021 * @param response The response object. 022 */ 023 public UsersResource(Context context, Request request, Response response) { 024 super(context, request, response); 025 } 026 027 /** 028 * Returns the representation of an index of all the users in the system. 029 * Only the administrator can request this resource. 030 * @param variant The representational variant requested. 031 * @return The representation. 032 */ 033 @Override 034 public Representation represent(Variant variant) { 035 if (!validateAuthUserIsAdmin()) { 036 return null; 037 } 038 try { 039 if (variant.getMediaType().equals(MediaType.TEXT_XML)) { 040 String xmlData = super.userManager.getUserIndex(); 041 return super.getStringRepresentation(xmlData); 042 } 043 } 044 catch (RuntimeException e) { 045 setStatusInternalError(e); 046 } 047 return null; 048 } 049 }