<commit_before>import be.cytomine.image.AbstractImage
import be.cytomine.image.AbstractImageGroup
import be.cytomine.image.ImageInstance
import be.cytomine.image.Mime
import be.cytomine.processing.ImageFilter
import be.cytomine.processing.Job
import be.cytomine.processing.Software
import be.cytomine.project.Discipline
import be.cytomine.project.Project
import be.cytomine.project.Slide
import com.vividsolutions.jts.geom.GeometryFactory
import com.vividsolutions.jts.geom.Polygon
import com.vividsolutions.jts.io.WKTReader
import grails.util.GrailsUtil
import java.lang.management.ManagementFactory
import be.cytomine.data.*
import be.cytomine.image.server.*
import be.cytomine.ontology.*
import be.cytomine.security.*
import static org.springframework.security.acls.domain.BasePermission.ADMINISTRATION
import static org.springframework.security.acls.domain.BasePermission.DELETE
import static org.springframework.security.acls.domain.BasePermission.READ
import static org.springframework.security.acls.domain.BasePermission.WRITE
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
import be.cytomine.test.Infos
import org.springframework.security.core.authority.AuthorityUtils
import org.springframework.security.core.context.SecurityContextHolder as SCH
import org.codehaus.groovy.grails.plugins.springsecurity.acl.AclObjectIdentity
import org.codehaus.groovy.grails.plugins.springsecurity.acl.AclSid
import be.cytomine.project.ProjectGroup
import org.codehaus.groovy.grails.plugins.springsecurity.SecurityFilterPosition
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
import org.codehaus.groovy.grails.commons.ConfigurationHolder
import be.cytomine.ViewPortToBuildXML
import be.cytomine.test.BasicInstance
import be.cytomine.image.acquisition.Instrument

class BootStrap {
    def springSecurityService
    def sequenceService
    def marshallersService
    def indexService
    def grailsApplication
    def storageService
    def messageSource
    def imagePropertiesService
    def countersService
    def triggerService
    def grantService
    def userGroupService
    def aclService
    def aclUtilService
    def objectIdentityRetrievalStrategy
    def sessionFactory



    static def development = "development"
    static def production = "production"
    static def test = "test"
    static def perf = "perf"


    def init = { servletContext ->
        //Register API Authentifier

        SpringSecurityUtils.clientRegisterFilter( 'apiAuthentificationFilter', SecurityFilterPosition.DIGEST_AUTH_FILTER.order + 1)
        println "###################" + grailsApplication.config.grails.serverURL + "##################"

        println "GrailsUtil.environment= " + GrailsUtil.environment + " BootStrap.development=" + BootStrap.development
        if (GrailsUtil.environment == BootStrap.development) { //scripts are not present in productions mode
            compileJS();
        }


        marshallersService.initMarshallers()
        sequenceService.initSequences()
        triggerService.initTrigger()
        indexService.initIndex()
        grantService.initGrant()

        grailsApplication.domainClasses.each {domainClass ->//iterate over the domainClasses
            if (domainClass.clazz.name.contains("be.cytomine")) {//only add it to the domains in my plugin

                domainClass.metaClass.retrieveErrors = {
                    def list = delegate?.errors?.allErrors?.collect {messageSource.getMessage(it, null)}
                    return list?.join('\n')
                }
            }
        }

        /* Print JVM infos like XMX/XMS */
        List inputArgs = ManagementFactory.getRuntimeMXBean().getInputArguments();
        for (int i = 0; i < inputArgs.size(); i++) {
            println inputArgs.get(i)
        }

        if (GrailsUtil.environment == BootStrap.test) { //scripts are not present in productions mode and dev mode
            initData(GrailsUtil.environment)
        }

        println "create scanner"
        createScanner()
        println "create user"
        createBasicUser()
        println "create discipline"
        createDiscipline()

        countersService.updateCounters()
        //updateImageProperties()
        //generateAbstractImageOriginalFilename()
        /*
        createProjectGrant()
        createProjectOwner()
        createAnnotationGrant()
        */
        //end of init
    }

    public void createBasicUser() {
        if (User.list().isEmpty()) {
            User user = new User()
            user.username = "admin"
            user.firstname = "Admin"
            user.lastname = "Admin"
            user.password = "<PASSWORD>"
            user.email = "<EMAIL>"
            user.enabled = true
            user.accountExpired = false
            user.accountLocked = false
            user.passwordExpired = false
            user.generateKeys()
            println "validate user = " + user.validate()
            println "errors user = " + user.errors
            println "save user = " + user.save(flush: true)

            def userRole = SecRole.findByAuthority("ROLE_USER") ?: new SecRole(authority: "ROLE_USER").save(flush: true)
            def adminRole = SecRole.findByAuthority("ROLE_ADMIN") ?: new SecRole(authority: "ROLE_ADMIN").save(flush: true)

            SecUserSecRole.create(user, userRole)
            SecUserSecRole.create(user, adminRole)
        }
<commit_msg>Add user group during bootstrap<commit_after>import be.cytomine.image.AbstractImage
import be.cytomine.image.AbstractImageGroup
import be.cytomine.image.ImageInstance
import be.cytomine.image.Mime
import be.cytomine.processing.ImageFilter
import be.cytomine.processing.Job
import be.cytomine.processing.Software
import be.cytomine.project.Discipline
import be.cytomine.project.Project
import be.cytomine.project.Slide
import com.vividsolutions.jts.geom.GeometryFactory
import com.vividsolutions.jts.geom.Polygon
import com.vividsolutions.jts.io.WKTReader
import grails.util.GrailsUtil
import java.lang.management.ManagementFactory
import be.cytomine.data.*
import be.cytomine.image.server.*
import be.cytomine.ontology.*
import be.cytomine.security.*
import static org.springframework.security.acls.domain.BasePermission.ADMINISTRATION
import static org.springframework.security.acls.domain.BasePermission.DELETE
import static org.springframework.security.acls.domain.BasePermission.READ
import static org.springframework.security.acls.domain.BasePermission.WRITE
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
import be.cytomine.test.Infos
import org.springframework.security.core.authority.AuthorityUtils
import org.springframework.security.core.context.SecurityContextHolder as SCH
import org.codehaus.groovy.grails.plugins.springsecurity.acl.AclObjectIdentity
import org.codehaus.groovy.grails.plugins.springsecurity.acl.AclSid
import be.cytomine.project.ProjectGroup
import org.codehaus.groovy.grails.plugins.springsecurity.SecurityFilterPosition
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
import org.codehaus.groovy.grails.commons.ConfigurationHolder
import be.cytomine.ViewPortToBuildXML
import be.cytomine.test.BasicInstance
import be.cytomine.image.acquisition.Instrument

class BootStrap {
    def springSecurityService
    def sequenceService
    def marshallersService
    def indexService
    def grailsApplication
    def storageService
    def messageSource
    def imagePropertiesService
    def countersService
    def triggerService
    def grantService
    def userGroupService
    def aclService
    def aclUtilService
    def objectIdentityRetrievalStrategy
    def sessionFactory



    static def development = "development"
    static def production = "production"
    static def test = "test"
    static def perf = "perf"


    def init = { servletContext ->
        //Register API Authentifier

        SpringSecurityUtils.clientRegisterFilter( 'apiAuthentificationFilter', SecurityFilterPosition.DIGEST_AUTH_FILTER.order + 1)
        println "###################" + grailsApplication.config.grails.serverURL + "##################"

        println "GrailsUtil.environment= " + GrailsUtil.environment + " BootStrap.development=" + BootStrap.development
        if (GrailsUtil.environment == BootStrap.development) { //scripts are not present in productions mode
            compileJS();
        }


        marshallersService.initMarshallers()
        sequenceService.initSequences()
        triggerService.initTrigger()
        indexService.initIndex()
        grantService.initGrant()

        grailsApplication.domainClasses.each {domainClass ->//iterate over the domainClasses
            if (domainClass.clazz.name.contains("be.cytomine")) {//only add it to the domains in my plugin

                domainClass.metaClass.retrieveErrors = {
                    def list = delegate?.errors?.allErrors?.collect {messageSource.getMessage(it, null)}
                    return list?.join('\n')
                }
            }
        }

        /* Print JVM infos like XMX/XMS */
        List inputArgs = ManagementFactory.getRuntimeMXBean().getInputArguments();
        for (int i = 0; i < inputArgs.size(); i++) {
            println inputArgs.get(i)
        }

        if (GrailsUtil.environment == BootStrap.test) { //scripts are not present in productions mode and dev mode
            initData(GrailsUtil.environment)
        }

        println "create scanner"
        createScanner()
        println "create user"
        createBasicUser()
        println "create discipline"
        createDiscipline()

        countersService.updateCounters()
        //updateImageProperties()
        //generateAbstractImageOriginalFilename()
        /*
        createProjectGrant()
        createProjectOwner()
        createAnnotationGrant()
        */
        //end of init
    }

    public void createBasicUser() {
        if (User.list().isEmpty()) {
            User user = new User()
            user.username = "admin"
            user.firstname = "Admin"
            user.lastname = "Admin"
            user.password = "<PASSWORD>"
            user.email = "<EMAIL>"
            user.enabled = true
            user.accountExpired = false
            user.accountLocked = false
            user.passwordExpired = false
            user.generateKeys()
            println "validate user = " + user.validate()
            println "errors user = " + user.errors
            println "save user = " + user.save(flush: true)

            def userRole = SecRole.findByAuthority("ROLE_USER") ?: new SecRole(authority: "ROLE_USER").save(flush: true)
            def adminRole = SecRole.findByAuthority("ROLE_ADMIN") ?: new SecRole(authority: "ROLE_ADMIN").save(flush: true)

            SecUserSecRole.create(user, userRole)
            SecUserSecRole.create(user, adminRole)
        }


        if(Group.list().isEmpty()) {
            Group group = new Group()
            group.name = "admin"
            println "validate admin = " + group.validate()
            println "errors admin = " + group.errors
            println "save admin = " + group.save(flush: true)
        }

{'fraction_non_alphanumeric': 0.09297153024911033, 'fraction_numerical': 0.00035587188612099647, 'mean_word_length': 3.0203862660944205, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '5302634', 'n_tokens_mistral': 3076, 'n_tokens_neox': 2963, 'n_words': 618}