// Path: dashboard/src/ch/icclab/cyclops/dashboard/util/LoadConfiguration.java
// public class LoadConfiguration extends ClientResource {
// 
//     //Instantiating the Instance variable for saving the config details
//     public static HashMap<String,String> configuration;
// 
//     /**
//      * Loads the configuration file
//      *
//      * Pseudo Code
//      * 1. Create an instance of the ServletContext
//      * 2. Get the relative path of the configuration.txt file
//      * 3. Load the file and save the values into a static HashMap
//      *
//      * @param context
//      * @throws IOException
//      */
//     public void run(Context context) throws IOException {
//         configuration = new HashMap<String,String>();
//         String nextLine;
// 
//         // Extract the ServletContext from the attributes of RestletContext
//         ServletContext servlet = (ServletContext) context.getAttributes().get("org.restlet.ext.servlet.ServletContext");
//         System.out.println("Reading the config file from " + servlet.getRealPath("/WEB-INF/configuration.txt"));
//         // Get the path of the config file relative to the WAR
//         String rootPath = servlet.getRealPath("/WEB-INF/configuration.txt");
// 
//         //Add WEB-INF path to access local images etc.
//         String webInfPath = servlet.getRealPath("/WEB-INF");
//         configuration.put("WEB-INF", webInfPath);
// 
//         Path path = Paths.get(rootPath);
//         File configFile = new File(path.toString());
//         FileRepresentation file = new FileRepresentation(configFile, MediaType.TEXT_PLAIN);
// 
//         // Read the values from the config file
//         try {
//             BufferedReader reader = new BufferedReader(file.getReader());
//             while((nextLine = reader.readLine()) != null ) {
//                 String[] str = nextLine.split("==");
//                 configuration.put(str[0],str[1]);
//             }
//         } catch (IOException e) {
//             System.out.println("Failed to load the Config file");
//             e.printStackTrace();
//         }
//     }
// }


import ch.icclab.cyclops.dashboard.util.LoadConfiguration;
import org.restlet.data.Form;
import org.restlet.data.Header;
import org.restlet.representation.Representation;
import org.restlet.resource.ClientResource;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import org.restlet.util.Series;
/*
 * Copyright (c) 2015. Zuercher Hochschule fuer Angewandte Wissenschaften
 *  All Rights Reserved.
 *
 *     Licensed under the Apache License, Version 2.0 (the "License"); you may
 *     not use this file except in compliance with the License. You may obtain
 *     a copy of the License at
 *
 *          http://www.apache.org/licenses/LICENSE-2.0
 *
 *     Unless required by applicable law or agreed to in writing, software
 *     distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *     WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 *     License for the specific language governing permissions and limitations
 *     under the License.
 */

package ch.icclab.cyclops.dashboard.users;


/**
 * This class provides access to OpenAM user information
 */
public class UserInfo extends ServerResource{

    @Get
    public Representation getUserInfo(){
        Form query = getRequest().getResourceRef().getQueryAsForm();
        String sessionId = query.getFirstValue("session_id", "");
        String user = getRequest().getAttributes().get("user").toString();
// Path: dashboard/src/ch/icclab/cyclops/dashboard/util/LoadConfiguration.java
// public class LoadConfiguration extends ClientResource {
// 
//     //Instantiating the Instance variable for saving the config details
//     public static HashMap<String,String> configuration;
// 
//     /**
//      * Loads the configuration file
//      *
//      * Pseudo Code
//      * 1. Create an instance of the ServletContext
//      * 2. Get the relative path of the configuration.txt file
//      * 3. Load the file and save the values into a static HashMap
//      *
//      * @param context
//      * @throws IOException
//      */
//     public void run(Context context) throws IOException {
//         configuration = new HashMap<String,String>();
//         String nextLine;
// 
//         // Extract the ServletContext from the attributes of RestletContext
//         ServletContext servlet = (ServletContext) context.getAttributes().get("org.restlet.ext.servlet.ServletContext");
//         System.out.println("Reading the config file from " + servlet.getRealPath("/WEB-INF/configuration.txt"));
//         // Get the path of the config file relative to the WAR
//         String rootPath = servlet.getRealPath("/WEB-INF/configuration.txt");
// 
//         //Add WEB-INF path to access local images etc.
//         String webInfPath = servlet.getRealPath("/WEB-INF");
//         configuration.put("WEB-INF", webInfPath);
// 
//         Path path = Paths.get(rootPath);
//         File configFile = new File(path.toString());
//         FileRepresentation file = new FileRepresentation(configFile, MediaType.TEXT_PLAIN);
// 
//         // Read the values from the config file
//         try {
//             BufferedReader reader = new BufferedReader(file.getReader());
//             while((nextLine = reader.readLine()) != null ) {
//                 String[] str = nextLine.split("==");
//                 configuration.put(str[0],str[1]);
//             }
//         } catch (IOException e) {
//             System.out.println("Failed to load the Config file");
//             e.printStackTrace();
//         }
//     }
// }


// Path: dashboard/src/ch/icclab/cyclops/dashboard/users/UserInfo.java
import ch.icclab.cyclops.dashboard.util.LoadConfiguration;
import org.restlet.data.Form;
import org.restlet.data.Header;
import org.restlet.representation.Representation;
import org.restlet.resource.ClientResource;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import org.restlet.util.Series;

/*
 * Copyright (c) 2015. Zuercher Hochschule fuer Angewandte Wissenschaften
 *  All Rights Reserved.
 *
 *     Licensed under the Apache License, Version 2.0 (the "License"); you may
 *     not use this file except in compliance with the License. You may obtain
 *     a copy of the License at
 *
 *          http://www.apache.org/licenses/LICENSE-2.0
 *
 *     Unless required by applicable law or agreed to in writing, software
 *     distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *     WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 *     License for the specific language governing permissions and limitations
 *     under the License.
 */

package ch.icclab.cyclops.dashboard.users;


/**
 * This class provides access to OpenAM user information
 */
public class UserInfo extends ServerResource{

    @Get
    public Representation getUserInfo(){
        Form query = getRequest().getResourceRef().getQueryAsForm();
        String sessionId = query.getFirstValue("session_id", "");
        String user = getRequest().getAttributes().get("user").toString();
        String urlPattern = LoadConfiguration.configuration.get("OPENAM_LIST_USERINFO_URL");