<commit_before>package controllers;

import static play.data.Form.form;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import models.Permission;
import models.Role;
import models.User;

import org.apache.commons.lang3.StringUtils;

import play.Logger;
import play.data.DynamicForm;
import play.data.Form;
import play.libs.Json;
import play.mvc.BodyParser;
import play.mvc.Result;
import play.mvc.Security;
import uk.bl.Const;
import views.html.roles.newForm;
import views.html.roles.list;
import views.html.roles.admin;
import views.html.roles.edit;
import views.html.roles.view;

import com.fasterxml.jackson.databind.JsonNode;

/**
 * Manage roles.
 */
@Security.Authenticated(SecuredController.class)
public class RoleController extends AbstractController {
  
    /**
     * Display the role.
     */
    public static Result index() {
    	Logger.debug("Roles.index()");
        return GO_HOME;
    }
    
    public static Result GO_HOME = redirect(
            routes.RoleController.list(0, "name", "asc", "")
        );
    
    /**
     * Display the role edit panel for this URL.
     */
    public static Result edit(Long id) {
    	User user = User.findByEmail(request().username());
		Role role = Role.findById(id);
		Form<Role> roleForm = Form.form(Role.class);
		roleForm = roleForm.fill(role);
		List<Permission> permissions = Permission.findAll();
		List<Permission> rolePermissions = role.permissions;
      	return ok(
	              edit.render(roleForm, user, id, permissions, rolePermissions)
	            );
    }
    
    public static Result view(Long id) {
        return ok(
                view.render(
                        Role.findById(id), User.findByEmail(request().username())
                )
            );
    }
    
    /**
     * Administer roles
     * @param url
     * @return
     */
    public static Result admin(Long id) {
        return ok(
                admin.render(
                        Role.findById(id), User.findByEmail(request().username())
                )
            );
    }
    
    /**
     * This method enables searching for given URL and redirection in order to add new entry
     * if required.
     * @return
     */
    public static Result search() {
    	DynamicForm form = form().bindFromRequest();
    	String action = form.get("action");
    	String query = form.get(Const.QUERY);
		Logger.debug("query: " + query);
		Logger.debug("action: " + action);
    	
    	if (StringUtils.isBlank(query)) {
			Logger.debug("Role name is empty. Please write name in search window.");<commit_msg>499 Role URL with Invalid ID no longer Crashes the App<commit_after>package controllers;

import static play.data.Form.form;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import models.Permission;
import models.Role;
import models.User;

import org.apache.commons.lang3.StringUtils;

import play.Logger;
import play.data.DynamicForm;
import play.data.Form;
import play.libs.Json;
import play.mvc.BodyParser;
import play.mvc.Result;
import play.mvc.Security;
import uk.bl.Const;
import views.html.roles.newForm;
import views.html.roles.list;
import views.html.roles.admin;
import views.html.roles.edit;
import views.html.roles.view;

import com.fasterxml.jackson.databind.JsonNode;

/**
 * Manage roles.
 */
@Security.Authenticated(SecuredController.class)
public class RoleController extends AbstractController {
  
    /**
     * Display the role.
     */
    public static Result index() {
    	Logger.debug("Roles.index()");
        return GO_HOME;
    }
    
    public static Result GO_HOME = redirect(
            routes.RoleController.list(0, "name", "asc", "")
        );
    
    /**
     * Display the role edit panel for this URL.
     */
    public static Result edit(Long id) {
    	User user = User.findByEmail(request().username());
		Role role = Role.findById(id);
		Form<Role> roleForm = Form.form(Role.class);
		roleForm = roleForm.fill(role);
		List<Permission> permissions = Permission.findAll();
		List<Permission> rolePermissions = role.permissions;
      	return ok(
	              edit.render(roleForm, user, id, permissions, rolePermissions)
	            );
    }
    
    public static Result view(Long id) {
		
		Role role = Role.findById(id);
		if (role != null) {
			if (request().accepts("text/html")) {
				return ok(view.render(role, User.findByEmail(request().username())));
			} else { 
			    return ok(Json.toJson(role));
			}
		} else {
			return notFound("There is no Role with ID " + id);
		}
			
    }
    
    /**
     * Administer roles
     * @param url
     * @return
     */
    public static Result admin(Long id) {
        return ok(
                admin.render(
                        Role.findById(id), User.findByEmail(request().username())
                )
            );
    }
    
    /**
     * This method enables searching for given URL and redirection in order to add new entry
     * if required.
     * @return
     */
    public static Result search() {
    	DynamicForm form = form().bindFromRequest();
    	String action = form.get("action");
    	String query = form.get(Const.QUERY);
		Logger.debug("query: " + query);
		Logger.debug("action: " + action);
    	
    	if (StringUtils.isBlank(query)) {
			Logger.debug("Role name is empty. Please write name in search window.");
{'fraction_non_alphanumeric': 0.12041006523765145, 'fraction_numerical': 0.00130475302889096, 'mean_word_length': 2.565448504983389, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2118823', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1589, 'n_words': 391}