001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (C) Alkacon Software (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.acacia.shared;
029
030import java.util.Map;
031
032import com.google.gwt.user.client.rpc.IsSerializable;
033
034/**
035 * The entity validation result containing all errors and warnings for a set of entities.<p>
036 */
037public class CmsValidationResult implements IsSerializable {
038
039    /** The error messages by entity and attribute. */
040    private Map<String, Map<String[], String>> m_errors;
041
042    /** The warning messages by entity and attribute. */
043    private Map<String, Map<String[], String>> m_warnings;
044
045    /**
046     * Constructor.<p>
047     *
048     * @param errors the error messages by entity and attribute
049     * @param warnings the warning messages by entity and attribute
050     */
051    public CmsValidationResult(Map<String, Map<String[], String>> errors, Map<String, Map<String[], String>> warnings) {
052
053        m_errors = errors;
054        m_warnings = warnings;
055    }
056
057    /**
058     * Constructor. For serialization only.<p>
059     */
060    protected CmsValidationResult() {
061
062        // nothing to do
063    }
064
065    /**
066     * Returns all error messages by entity id and attribute.<p>
067     *
068     * @return the error messages by entity id and attribute
069     */
070    public Map<String, Map<String[], String>> getErrors() {
071
072        return m_errors;
073    }
074
075    /**
076     * Returns the error messages for the given entity.<p>
077     *
078     * @param entityId the entity id
079     *
080     * @return the error messages for the given entity
081     */
082    public Map<String[], String> getErrors(String entityId) {
083
084        return m_errors != null ? m_errors.get(entityId) : null;
085    }
086
087    /**
088     * Returns all warning messages by entity id and attribute.<p>
089     *
090     * @return the warning messages by entity id and attribute
091     */
092    public Map<String, Map<String[], String>> getWarnings() {
093
094        return m_warnings;
095    }
096
097    /**
098     * Returns the warning messages for the given entity.<p>
099     *
100     * @param entityId the entity id
101     *
102     * @return the warning messages for the given entity
103     */
104    public Map<String[], String> getWarnings(String entityId) {
105
106        return m_warnings != null ? m_warnings.get(entityId) : null;
107    }
108
109    /**
110     * Returns if there are any errors.<p>
111     *
112     * @return <code>true</code> if there are any errors
113     */
114    public boolean hasErrors() {
115
116        return (m_errors != null) && !m_errors.isEmpty();
117    }
118
119    /**
120     * Returns if the entity of the given id has errors.<p>
121     *
122     * @param entityId the entity id
123     *
124     * @return <code>true</code> if the entity of the given id has errors
125     */
126    public boolean hasErrors(String entityId) {
127
128        return (m_errors != null) && (m_errors.get(entityId) != null);
129    }
130
131    /**
132     * Returns if there are any warnings.<p>
133     *
134     * @return <code>true</code> if there are any warnings
135     */
136    public boolean hasWarnings() {
137
138        return (m_warnings != null) && !m_warnings.isEmpty();
139    }
140
141    /**
142     * Returns if the entity of the given id has warnings.<p>
143     *
144     * @param entityId the entity id
145     *
146     * @return <code>true</code> if the entity of the given id has warnings
147     */
148    public boolean hasWarnings(String entityId) {
149
150        return (m_warnings != null) && (m_warnings.get(entityId) != null);
151    }
152
153}