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     * The resource for processing GET host/projects/{user} requests.
013     * Returns an index of all Project resource names associated with this user. 
014     * 
015     * @author Philip Johnson
016     */
017    public class UserProjectsResource extends SensorBaseResource {
018      
019    
020      /**
021       * Provides the following representational variants: TEXT_XML.
022       * @param context The context.
023       * @param request The request object.
024       * @param response The response object.
025       */
026      public UserProjectsResource(Context context, Request request, Response response) {
027        super(context, request, response);
028      }
029      
030      /**
031       * Returns a ProjectIndex of all projects associated with this User.
032       * <ul>
033       * <li> The user must be defined.
034       * <li> The authenticated user must be the uriUser or the Admin. 
035       * </ul>
036       * 
037       * @param variant The representational variant requested.
038       * @return The representation. 
039       */
040      @Override
041      public Representation represent(Variant variant) {
042        try {
043          if (!validateUriUserIsUser() ||
044              !validateAuthUserIsAdminOrUriUser()) {
045            return null;
046          }  
047          if (variant.getMediaType().equals(MediaType.TEXT_XML)) {
048            String xmlData = super.projectManager.getProjectIndex(this.user);
049            return super.getStringRepresentation(xmlData);      
050            }
051        }
052        catch (RuntimeException e) {
053          setStatusInternalError(e);
054        }
055        return null;
056      }
057    }