// Path: app/models/actions/Action.java
// public abstract class Action {
// 
//     private static Map<String,Action> actions = Maps.newHashMap();
//     private String name;
// 
//     public abstract Boolean apply(
//             Request request,
//             User    user,
//             Map<String, String> params
//             );
// 
//     public static Boolean doAction(String acName,
//             Request request,
//             User    user,
//             Map<String, String> params) {
//         Action action = actions.get(acName.toLowerCase());
//         if (action == null) {
//             Logger.info("No Action found for action string:" + acName);
//             return Boolean.FALSE;
//         } else {
//             Logger.info("Action found for action string:" + acName);
//             return action.apply(request, user, params);
//         }
//     }
// 
//     // instantiate all Actions
//     public static void start() {
//         for (Class c : 
//                 Collections2.filter(MongoEntity.getClasses("models.actions"),
//                     new Predicate<Class>() {
//                     public boolean apply(Class t) {
//                         return ! "models.actions.Action".equals(t.getName());
//                     }
//                 })
//             )
//             actions.put(c.getSimpleName().toLowerCase(), getByName(c.getName()));
//     }
//     
//     private static <T extends Action> T getByName(String name) {
//         Logger.info("Action.getByName::" + name);
//         T le = null;
//         try {
//             Class<T> fu = (Class<T>) Class.forName(name);
//             le = fu.newInstance();
//         } catch (Exception ex) {
//             Logger.info("Action.getByName::" + name + ex.toString());
//         }
//         return le;
//     }
// 
//     protected String getName() {
//         return name;
//     }
// 
//     private void setName(String newName) {
//         name = newName;
//     }
// 
// }
// 
// Path: app/models/MongoEntity.java
// public static ObjectId toId(String x) {
//     ObjectId bubu = null;
//     try { bubu = new ObjectId(x);} catch (Exception e ) {};
//     return bubu;
// }


import models.actions.Action;
import java.util.Map;
import org.bson.types.ObjectId;
import java.io.File;
import play.mvc.*;
import play.Logger;
import models.*;
import play.cache.Cache;
import play.mvc.Controller;
import static models.MongoEntity.toId;
/*
    Kyberia Haiku - advanced community web application
    Copyright (C) 2010 Robert Hritz

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package controllers;


@With(Secure.class)
public class Application extends Controller {

    @Before
    static void setConnectedUser() {
        renderArgs.put("reqstart", System.currentTimeMillis());
        String uid;
        if(Security.isConnected()) {
            uid = session.get(User.ID);
            renderArgs.put("user",   session.get(User.USERNAME));
            renderArgs.put("userid", uid);
            renderArgs.put("uid", uid);
// Path: app/models/actions/Action.java
// public abstract class Action {
// 
//     private static Map<String,Action> actions = Maps.newHashMap();
//     private String name;
// 
//     public abstract Boolean apply(
//             Request request,
//             User    user,
//             Map<String, String> params
//             );
// 
//     public static Boolean doAction(String acName,
//             Request request,
//             User    user,
//             Map<String, String> params) {
//         Action action = actions.get(acName.toLowerCase());
//         if (action == null) {
//             Logger.info("No Action found for action string:" + acName);
//             return Boolean.FALSE;
//         } else {
//             Logger.info("Action found for action string:" + acName);
//             return action.apply(request, user, params);
//         }
//     }
// 
//     // instantiate all Actions
//     public static void start() {
//         for (Class c : 
//                 Collections2.filter(MongoEntity.getClasses("models.actions"),
//                     new Predicate<Class>() {
//                     public boolean apply(Class t) {
//                         return ! "models.actions.Action".equals(t.getName());
//                     }
//                 })
//             )
//             actions.put(c.getSimpleName().toLowerCase(), getByName(c.getName()));
//     }
//     
//     private static <T extends Action> T getByName(String name) {
//         Logger.info("Action.getByName::" + name);
//         T le = null;
//         try {
//             Class<T> fu = (Class<T>) Class.forName(name);
//             le = fu.newInstance();
//         } catch (Exception ex) {
//             Logger.info("Action.getByName::" + name + ex.toString());
//         }
//         return le;
//     }
// 
//     protected String getName() {
//         return name;
//     }
// 
//     private void setName(String newName) {
//         name = newName;
//     }
// 
// }
// 
// Path: app/models/MongoEntity.java
// public static ObjectId toId(String x) {
//     ObjectId bubu = null;
//     try { bubu = new ObjectId(x);} catch (Exception e ) {};
//     return bubu;
// }


// Path: app/controllers/Application.java
import models.actions.Action;
import java.util.Map;
import org.bson.types.ObjectId;
import java.io.File;
import play.mvc.*;
import play.Logger;
import models.*;
import play.cache.Cache;
import play.mvc.Controller;
import static models.MongoEntity.toId;

/*
    Kyberia Haiku - advanced community web application
    Copyright (C) 2010 Robert Hritz

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package controllers;


@With(Secure.class)
public class Application extends Controller {

    @Before
    static void setConnectedUser() {
        renderArgs.put("reqstart", System.currentTimeMillis());
        String uid;
        if(Security.isConnected()) {
            uid = session.get(User.ID);
            renderArgs.put("user",   session.get(User.USERNAME));
            renderArgs.put("userid", uid);
            renderArgs.put("uid", uid);
            renderArgs.put("newMail", MessageThread.getUnreadMailNotif(toId(uid)));