<commit_before>package be.cytomine.command
import grails.converters.JSON
import be.cytomine.SequenceDomain
import be.cytomine.security.User
import be.cytomine.project.Project

class Command extends SequenceDomain {

    def messageSource

    String data
    String postData
    User user
    Project project

    boolean printMessage = true

    static Integer MAXSIZEREQUEST = 102400

    String actionMessage

    boolean saveOnUndoRedoStack = false //by default, don't save command on stack

    static mapping = {
        version : false
    }
    static constraints = {
        data (type:'text', maxSize:Command.MAXSIZEREQUEST, nullable : true)
        postData (type:'text', maxSize:Command.MAXSIZEREQUEST)
        actionMessage(nullable : true)
        project(nullable : true)
    }

    void changeCurrentProject(Project project) { //setCur... doesn't work with spring
        println "setCurrentProject=" +project
        this.project = project;
    }

    static void registerMarshaller() {
        println "Register custom JSON renderer for " + Command.class
        JSON.registerObjectMarshaller(Command) {
            def returnArray = [:]

            returnArray['CLASSNAME'] = it.class
            returnArray['action'] = it.getActionMessage()
            returnArray['data'] = it.data
            returnArray['type'] = "UNKNOWN"
            if(it instanceof AddCommand) returnArray['type'] = "ADD"
            else if(it instanceof EditCommand) returnArray['type'] = "EDIT"
            else if(it instanceof DeleteCommand) returnArray['type'] = "DELETE"

            returnArray['created'] = it.created? it.created.time.toString() : null
            returnArray['updated'] = it.updated? it.updated.time.toString() : null

            return returnArray
        }
    }

    String getActionMessage()
    {
        return  actionMessage
    }

    public String toString() {
        return this.id + "["+this.created+"]";
    }

    /**
     * Get the class name of an object without package name
     * @param o Object
     * @return Class name (without package) of o
     */
    protected String getClassName(Object o) {
        log.info("getClassName="+o.getClass());
        String name = o.getClass()   //be.cytomine.image.Image
        String[] array =  name.split("\\.")  //[be,cytomine,image,Image]
        log.info array.length
        return array[array.length-1] // Image
    }

}
<commit_msg>Add user for command message<commit_after>package be.cytomine.command
import grails.converters.JSON
import be.cytomine.SequenceDomain
import be.cytomine.security.User
import be.cytomine.project.Project

class Command extends SequenceDomain {

    def messageSource

    String data
    String postData
    User user
    Project project

    boolean printMessage = true

    static Integer MAXSIZEREQUEST = 102400

    String actionMessage

    boolean saveOnUndoRedoStack = false //by default, don't save command on stack

    static mapping = {
        version : false
    }
    static constraints = {
        data (type:'text', maxSize:Command.MAXSIZEREQUEST, nullable : true)
        postData (type:'text', maxSize:Command.MAXSIZEREQUEST)
        actionMessage(nullable : true)
        project(nullable : true)
    }

    void changeCurrentProject(Project project) { //setCur... doesn't work with spring
        println "setCurrentProject=" +project
        this.project = project;
    }

    static void registerMarshaller() {
        println "Register custom JSON renderer for " + Command.class
        JSON.registerObjectMarshaller(Command) {
            def returnArray = [:]

            returnArray['CLASSNAME'] = it.class
            returnArray['action'] = it.getActionMessage() + " by " +  it?.user?.username
            returnArray['data'] = it.data
            returnArray['user'] = it?.userId
            returnArray['type'] = "UNKNOWN"
            if(it instanceof AddCommand) returnArray['type'] = "ADD"
            else if(it instanceof EditCommand) returnArray['type'] = "EDIT"
            else if(it instanceof DeleteCommand) returnArray['type'] = "DELETE"

            returnArray['created'] = it.created? it.created.time.toString() : null
            returnArray['updated'] = it.updated? it.updated.time.toString() : null

            return returnArray
        }
    }

    String getActionMessage()
    {
        return  actionMessage
    }

    public String toString() {
        return this.id + "["+this.created+"]";
    }

    /**
     * Get the class name of an object without package name
     * @param o Object
     * @return Class name (without package) of o
     */
    protected String getClassName(Object o) {
        log.info("getClassName="+o.getClass());
        String name = o.getClass()   //be.cytomine.image.Image
        String[] array =  name.split("\\.")  //[be,cytomine,image,Image]
        log.info array.length
        return array[array.length-1] // Image
    }

}

{'fraction_non_alphanumeric': 0.10471946526230505, 'fraction_numerical': 0.0028357302005266355, 'mean_word_length': 2.497167138810198, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '410698', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1331, 'n_words': 348}