<commit_before>/*
 * Wegas
 * http://www.albasim.ch/wegas/
 *
 * Copyright (c) 2013 School of Business and Engineering Vaud, Comem
 * Licensed under the MIT License
 */
package com.wegas.core.rest;

import com.wegas.core.ejb.RequestFacade;
import com.wegas.core.ejb.ScriptFacade;
import com.wegas.core.exception.WegasException;
import com.wegas.core.persistence.game.Script;
import com.wegas.core.security.ejb.UserFacade;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.script.ScriptException;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.UnauthorizedException;

/**
 *
 * @author <NAME> <<EMAIL>>
 */
@Stateless
@Path("GameModel/{gameModelId : [1-9][0-9]*}/{opt: (VariableDescriptor/)?}Script/")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class ScriptController {

    /**
     *
     */
    @EJB
    private ScriptFacade scriptManager;
    @EJB
    private UserFacade userFacade;
    @EJB
    private RequestFacade requestFacade;

    /**
     *
     * @param gameModelId
     * @param playerId
     * @param script
     * @return p
     * @throws ScriptException
     * @throws WegasException
     */
    @POST
    @Path("/Run/{playerId : [1-9][0-9]*}")
    public Object run(@PathParam("gameModelId") Long gameModelId,
            @PathParam("playerId") Long playerId, Script script)
            throws ScriptException, WegasException {

        if (SecurityUtils.getSubject().isPermitted("GameModel:Edit:gm" + gameModelId)
                || userFacade.matchCurrentUser(playerId)) {
            Object r = scriptManager.eval(playerId, script);
            requestFacade.commit();
            return r;
        } else {
            throw new UnauthorizedException();

        }
    }
}<commit_msg>Fix ScriptController<commit_after>/*
 * Wegas
 * http://www.albasim.ch/wegas/
 *
 * Copyright (c) 2013 School of Business and Engineering Vaud, Comem
 * Licensed under the MIT License
 */
package com.wegas.core.rest;

import com.wegas.core.ejb.RequestFacade;
import com.wegas.core.ejb.ScriptFacade;
import com.wegas.core.exception.WegasException;
import com.wegas.core.persistence.game.Script;
import com.wegas.core.security.ejb.UserFacade;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.script.ScriptException;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.UnauthorizedException;

/**
 *
 * @author <NAME> <<EMAIL>>
 */
@Stateless
@Path("GameModel/{gameModelId : [1-9][0-9]*}/{opt : (VariableDescriptor/)?}Script/")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class ScriptController {

    /**
     *
     */
    @EJB
    private ScriptFacade scriptManager;
    @EJB
    private UserFacade userFacade;
    @EJB
    private RequestFacade requestFacade;

    /**
     *
     * @param gameModelId
     * @param playerId
     * @param script
     * @return p
     * @throws ScriptException
     * @throws WegasException
     */
    @POST
    @Path("Run/{playerId : [1-9][0-9]*}")
    public Object run(@PathParam("gameModelId") Long gameModelId,
            @PathParam("playerId") Long playerId, Script script)
            throws ScriptException, WegasException {

        if (SecurityUtils.getSubject().isPermitted("GameModel:Edit:gm" + gameModelId)
                || userFacade.matchCurrentUser(playerId)) {
            Object r = scriptManager.eval(playerId, script);
            requestFacade.commit();
            return r;
        } else {
            throw new UnauthorizedException();

        }
    }
}
{'fraction_non_alphanumeric': 0.12578103776147787, 'fraction_numerical': 0.006519967400162999, 'mean_word_length': 3.1185682326621924, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '3523051', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1159, 'n_words': 223}