001 package org.hackystat.sensorbase.resource.sensordata; 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 Resource for processing host/sensordata requests and returning an index to 013 * all sensor data for all users in the SensorBase. 014 * This is an admin-only operation that could return quite a large amount of data. 015 * @author Philip Johnson 016 */ 017 public class SensorDataResource extends SensorBaseResource { 018 019 /** 020 * The standard constructor. 021 * @param context The context. 022 * @param request The request object. 023 * @param response The response object. 024 */ 025 public SensorDataResource(Context context, Request request, Response response) { 026 super(context, request, response); 027 } 028 029 /** 030 * Returns an index to all sensor data defined for all users in this system. 031 * @param variant The representational variant requested. 032 * @return The representation. 033 */ 034 @Override 035 public Representation represent(Variant variant) { 036 try { 037 if (!validateAuthUserIsAdmin()) { 038 return null; 039 } 040 if (variant.getMediaType().equals(MediaType.TEXT_XML)) { 041 String xmlData = super.sensorDataManager.getSensorDataIndex(); 042 return super.getStringRepresentation(xmlData); 043 } 044 } 045 catch (RuntimeException e) { 046 setStatusInternalError(e); 047 } 048 return null; 049 } 050 }