001    package org.hackystat.sensorbase.resource.projects;
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 the Resource for processing GET {host}/projects requests to obtain an index for
013     * all Projects defined in this SensorBase for all users.  
014     * Requires the admin user. 
015     * @author Philip Johnson
016     */
017    public class ProjectsResource 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 ProjectsResource(Context context, Request request, Response response) {
026        super(context, request, response);
027      }
028      
029      /**
030       * Returns an index of all Projects for all Users, or null if the request is not authorized. 
031       * This requires admin authorization. 
032       * @param variant The representational variant requested.
033       * @return The representation. 
034       */
035      @Override
036      public Representation represent(Variant variant) {
037        if (!validateAuthUserIsAdmin()) {
038          return null;
039        }   
040        if (variant.getMediaType().equals(MediaType.TEXT_XML)) {
041          String xmlData = super.projectManager.getProjectIndex();
042          return super.getStringRepresentation(xmlData);      
043        }
044        return null;
045      }
046    }