<commit_before>/*
 * Copyright (C) 2016 Singular Studios (a.k.a Atom Tecnologia) - www.opensingular.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.opensingular.server.module.executor;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;

import org.opensingular.flow.persistence.entity.ModuleEntity;
import org.opensingular.server.commons.config.ServerStartExecutorBean;
import org.opensingular.server.commons.exception.SingularServerException;
import org.opensingular.server.commons.service.dto.BoxDefinitionData;
import org.opensingular.server.module.SingularModuleConfiguration;
import org.opensingular.server.module.service.BoxService;
import org.opensingular.server.module.service.ModuleService;
import org.opensingular.server.p.commons.config.PServerContext;

/**
 * Classe para abrigar a lógica de carga inicial
 * de caixas no banco do servidor.
 */
@Named
public class BoxUpdaterExecutor {

    @Inject
    private SingularModuleConfiguration singularModuleConfiguration;

    @Inject
    private ServerStartExecutorBean serverStartExecutorBean;

    @Inject
    private BoxService boxService;

    @Inject
    private ModuleService moduleService;

    @PostConstruct
    public void init() {
        serverStartExecutorBean.register(this::saveAllBoxDefinitions);
    }

    /**
     * Percorre todos requerimentos contidos na configuração do módulo
     * e os repassa para salvar/recuperar os dados do banco.
     */
    public void saveAllBoxDefinitions() {
        ModuleEntity module = moduleService.getModule();
        for (PServerContext context : PServerContext.values()) {
            List<BoxDefinitionData> boxDefinitionData = singularModuleConfiguration.buildItemBoxes(context);

            for (BoxDefinitionData boxData : boxDefinitionData) {
                try {
                    boxService.saveBoxDefinition(module, boxData);
                } catch (Exception e) {
                    throw SingularServerException.rethrow(String.format("Erro ao salvar a caixa %s", boxData.getItemBox().getName()), e);<commit_msg>Comentando a inicialização do serviço de definição de caixas<commit_after>/*
 * Copyright (C) 2016 Singular Studios (a.k.a Atom Tecnologia) - www.opensingular.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.opensingular.server.module.executor;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;

import org.opensingular.flow.persistence.entity.ModuleEntity;
import org.opensingular.server.commons.config.ServerStartExecutorBean;
import org.opensingular.server.commons.exception.SingularServerException;
import org.opensingular.server.commons.service.dto.BoxDefinitionData;
import org.opensingular.server.module.SingularModuleConfiguration;
import org.opensingular.server.module.service.BoxService;
import org.opensingular.server.module.service.ModuleService;
import org.opensingular.server.p.commons.config.PServerContext;

/**
 * Classe para abrigar a lógica de carga inicial
 * de caixas no banco do servidor.
 */
@Named
public class BoxUpdaterExecutor {

    @Inject
    private SingularModuleConfiguration singularModuleConfiguration;

    @Inject
    private ServerStartExecutorBean serverStartExecutorBean;

    @Inject
    private BoxService boxService;

    @Inject
    private ModuleService moduleService;

//    @PostConstruct
//    public void init() {
//        serverStartExecutorBean.register(this::saveAllBoxDefinitions);
//    }

    /**
     * Percorre todos requerimentos contidos na configuração do módulo
     * e os repassa para salvar/recuperar os dados do banco.
     */
    public void saveAllBoxDefinitions() {
        ModuleEntity module = moduleService.getModule();
        for (PServerContext context : PServerContext.values()) {
            List<BoxDefinitionData> boxDefinitionData = singularModuleConfiguration.buildItemBoxes(context);

            for (BoxDefinitionData boxData : boxDefinitionData) {
                try {
                    boxService.saveBoxDefinition(module, boxData);
                } catch (Exception e) {
                    throw SingularServerException.rethrow(String.format("Erro ao salvar a caixa %s", boxData.getItemBox().getName()), e);
{'fraction_non_alphanumeric': 0.08059981255857544, 'fraction_numerical': 0.002999062792877226, 'mean_word_length': 3.8553230209281164, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '6726095', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1424, 'n_words': 411}