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 org.opencms.util.CmsPair;
031
032import java.util.Map;
033
034import com.google.gwt.user.client.rpc.IsSerializable;
035
036/**
037 * The entity validation result containing all errors and warnings for a set of entities.<p>
038 */
039public class CmsValidationResult implements IsSerializable {
040
041    /** The error messages by entity and attribute. */
042    private Map<String, Map<String[], CmsPair<String, String>>> m_errors;
043
044    /** The warning messages by entity and attribute. */
045    private Map<String, Map<String[], CmsPair<String, String>>> m_warnings;
046
047    /**
048     * Constructor.<p>
049     *
050     * @param errors the error messages by entity and attribute
051     * @param warnings the warning messages by entity and attribute
052     */
053    public CmsValidationResult(
054        Map<String, Map<String[], CmsPair<String, String>>> errors,
055        Map<String, Map<String[], CmsPair<String, String>>> warnings) {
056
057        m_errors = errors;
058        m_warnings = warnings;
059    }
060
061    /**
062     * Constructor. For serialization only.<p>
063     */
064    protected CmsValidationResult() {
065
066        // nothing to do
067    }
068
069    /**
070     * Returns all error messages by entity id and attribute.<p>
071     *
072     * @return the error messages by entity id and attribute
073     */
074    public Map<String, Map<String[], CmsPair<String, String>>> getErrors() {
075
076        return m_errors;
077    }
078
079    /**
080     * Returns the error messages for the given entity.<p>
081     *
082     * @param entityId the entity id
083     *
084     * @return the error messages for the given entity
085     */
086    public Map<String[], CmsPair<String, String>> getErrors(String entityId) {
087
088        return m_errors != null ? m_errors.get(entityId) : null;
089    }
090
091    /**
092     * Returns all warning messages by entity id and attribute.<p>
093     *
094     * @return the warning messages by entity id and attribute
095     */
096    public Map<String, Map<String[], CmsPair<String, String>>> getWarnings() {
097
098        return m_warnings;
099    }
100
101    /**
102     * Returns the warning messages for the given entity.<p>
103     *
104     * @param entityId the entity id
105     *
106     * @return the warning messages for the given entity
107     */
108    public Map<String[], CmsPair<String, String>> getWarnings(String entityId) {
109
110        return m_warnings != null ? m_warnings.get(entityId) : null;
111    }
112
113    /**
114     * Returns if there are any errors.<p>
115     *
116     * @return <code>true</code> if there are any errors
117     */
118    public boolean hasErrors() {
119
120        return (m_errors != null) && !m_errors.isEmpty();
121    }
122
123    /**
124     * Returns if the entity of the given id has errors.<p>
125     *
126     * @param entityId the entity id
127     *
128     * @return <code>true</code> if the entity of the given id has errors
129     */
130    public boolean hasErrors(String entityId) {
131
132        return (m_errors != null) && (m_errors.get(entityId) != null);
133    }
134
135    /**
136     * Returns if there are any warnings.<p>
137     *
138     * @return <code>true</code> if there are any warnings
139     */
140    public boolean hasWarnings() {
141
142        return (m_warnings != null) && !m_warnings.isEmpty();
143    }
144
145    /**
146     * Returns if the entity of the given id has warnings.<p>
147     *
148     * @param entityId the entity id
149     *
150     * @return <code>true</code> if the entity of the given id has warnings
151     */
152    public boolean hasWarnings(String entityId) {
153
154        return (m_warnings != null) && (m_warnings.get(entityId) != null);
155    }
156
157}