<commit_before>/*
 * This file is part of ###PROJECT_NAME###
 *
 * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
 *                    Desenvolvemento Tecnolóxico de Galicia
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.navalplanner.web.orders;

import java.util.List;

import org.apache.commons.logging.LogFactory;
import org.hibernate.validator.InvalidValue;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.orders.entities.IOrderLineGroup;
import org.navalplanner.business.orders.entities.Order;
import org.navalplanner.business.orders.entities.OrderElement;
import org.navalplanner.web.common.IMessagesForUser;
import org.navalplanner.web.common.Level;
import org.navalplanner.web.common.MessagesForUser;
import org.navalplanner.web.common.OnlyOneVisible;
import org.navalplanner.web.common.Util;
import org.navalplanner.web.planner.IOrderPlanningControllerEntryPoints;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Label;
import org.zkoss.zul.api.Window;

import static org.navalplanner.web.I18nHelper._;

/**
 * Controller for CRUD actions <br />
 * @author <NAME> <<EMAIL>>
 */
public class OrderCRUDController extends GenericForwardComposer {

    private static final org.apache.commons.logging.Log LOG = LogFactory
            .getLog(OrderCRUDController.class);

    private IOrderModel orderModel;

    private IMessagesForUser messagesForUser;

    private Component messagesContainer;

    private Component editWindow;

    private Component createWindow;

    private Component listWindow;

    private OnlyOneVisible cachedOnlyOneVisible;

    private Window confirmRemove;

    private Window confirmSchedule;

    private boolean confirmingSchedule;

    private IOrderPlanningControllerEntryPoints planningControllerEntryPoints;

    public List<Order> getOrders() {
        return orderModel.getOrders();
    }

    private OnlyOneVisible getVisibility() {
        if (cachedOnlyOneVisible == null) {
            cachedOnlyOneVisible = new OnlyOneVisible(listWindow, editWindow,
                    createWindow);
        }
        return cachedOnlyOneVisible;
    }

    public IOrderLineGroup getOrder() {
        return orderModel.getOrder();
    }

    public void save() {
        try {
            orderModel.save();
            messagesForUser.showMessage(Level.INFO, _("Order saved"));
            goToList();
        } catch (ValidationException e) {
            messagesForUser.showInvalidValues(e, new IMessagesForUser.ICustomLabelCreator() {

                @Override
                public Component createLabelFor(InvalidValue invalidValue) {
                    if (invalidValue.getBean() instanceof OrderElement) {
                        Label result = new Label();

                        String orderElementName = ((OrderElement) invalidValue
                                        .getBean()).getName();

                        result.setValue(orderElementName + " "
                                        + invalidValue.getPropertyName() + ": "
                                        + invalidValue.getMessage());
                        return result;
                    } else {
                        return MessagesForUser
                                        .createLabelFor(invalidValue);
                    }
                }
            });
        }
    }

    public void goToList() {
        Util.reloadBindings(listWindow);
        getVisibility().showOnly(listWindow);
    }

    public void cancel() {
        goToList();
    }

    public void confirmRemove(Order order) {
        orderModel.prepareForRemove(order);
        showConfirmingWindow();
    }

    public void confirmSchedule(Order order) {
        if (!orderModel.isAlreadyScheduled(order)) {
            orderModel.prepareForSchedule(order);
            showScheduleConfirmingWindow();
        } else {
            goToShedulingView(order);
        }
    }
<commit_msg> ItEr29S16CUCreacionProxectoCategorizacionTraballoItEr10S11: Showing error messages that come from checkValid method.<commit_after>/*
 * This file is part of ###PROJECT_NAME###
 *
 * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
 *                    Desenvolvemento Tecnolóxico de Galicia
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.navalplanner.web.orders;

import static org.navalplanner.web.I18nHelper._;

import java.util.List;

import org.apache.commons.logging.LogFactory;
import org.hibernate.validator.InvalidValue;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.orders.entities.IOrderLineGroup;
import org.navalplanner.business.orders.entities.Order;
import org.navalplanner.business.orders.entities.OrderElement;
import org.navalplanner.web.common.IMessagesForUser;
import org.navalplanner.web.common.Level;
import org.navalplanner.web.common.MessagesForUser;
import org.navalplanner.web.common.OnlyOneVisible;
import org.navalplanner.web.common.Util;
import org.navalplanner.web.planner.IOrderPlanningControllerEntryPoints;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Label;
import org.zkoss.zul.api.Window;

/**
 * Controller for CRUD actions <br />
 * @author <NAME> <<EMAIL>>
 */
public class OrderCRUDController extends GenericForwardComposer {

    private static final org.apache.commons.logging.Log LOG = LogFactory
            .getLog(OrderCRUDController.class);

    private IOrderModel orderModel;

    private IMessagesForUser messagesForUser;

    private Component messagesContainer;

    private Component editWindow;

    private Component createWindow;

    private Component listWindow;

    private OnlyOneVisible cachedOnlyOneVisible;

    private Window confirmRemove;

    private Window confirmSchedule;

    private boolean confirmingSchedule;

    private IOrderPlanningControllerEntryPoints planningControllerEntryPoints;

    public List<Order> getOrders() {
        return orderModel.getOrders();
    }

    private OnlyOneVisible getVisibility() {
        if (cachedOnlyOneVisible == null) {
            cachedOnlyOneVisible = new OnlyOneVisible(listWindow, editWindow,
                    createWindow);
        }
        return cachedOnlyOneVisible;
    }

    public IOrderLineGroup getOrder() {
        return orderModel.getOrder();
    }

    public void save() {
        try {
            orderModel.save();
            messagesForUser.showMessage(Level.INFO, _("Order saved"));
            goToList();
        } catch (ValidationException e) {
            if (e.getInvalidValues().length == 0) {
                messagesForUser.showMessage(Level.INFO, e.getMessage());
            } else {
                messagesForUser.showInvalidValues(e,
                        new IMessagesForUser.ICustomLabelCreator() {

                            @Override
                            public Component createLabelFor(
                                    InvalidValue invalidValue) {
                                if (invalidValue.getBean() instanceof OrderElement) {
                                    Label result = new Label();

                                    String orderElementName = ((OrderElement) invalidValue
                                            .getBean()).getName();

                                    result.setValue(orderElementName + " "
                                            + invalidValue.getPropertyName()
                                            + ": " + invalidValue.getMessage());
                                    return result;
                                } else {
                                    return MessagesForUser
                                            .createLabelFor(invalidValue);
                                }
                    }
                });
            }
        }
    }

    public void goToList() {
        Util.reloadBindings(listWindow);
        getVisibility().showOnly(listWindow);
    }

    public void cancel() {
        goToList();
    }

    public void confirmRemove(Order order) {
        orderModel.prepareForRemove(order);
        showConfirmingWindow();
    }

    public void confirmSchedule(Order order) {
        if (!orderModel.isAlreadyScheduled(order)) {
            orderModel.prepareForSchedule(order);
            showScheduleConfirmingWindow();
        } else {
            goToShedulingView(order);
        }
    }

{'fraction_non_alphanumeric': 0.07773600243877654, 'fraction_numerical': 0.002337160857636419, 'mean_word_length': 2.3317535545023698, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4944445', 'n_tokens_mistral': 2499, 'n_tokens_neox': 2410, 'n_words': 628}