001/*
002 * This library is part of OpenCms -
003 * The Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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 GmbH & Co. KG, please see the
018 * company website: https://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: https://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.db.storage.s3;
029
030import java.util.Collection;
031import java.util.Collections;
032import java.util.LinkedHashMap;
033import java.util.LinkedHashSet;
034import java.util.Map;
035import java.util.Set;
036
037/**
038 * Result of an S3 multi-object delete operation.<p>
039 */
040public final class CmsS3DeleteResult {
041
042    /** The successfully deleted object keys. */
043    private final Set<String> m_deletedKeys;
044
045    /** The failures by object key. */
046    private final Map<String, Exception> m_failures;
047
048    /**
049     * Creates a delete result.<p>
050     *
051     * Keys without a reported failure are treated as successfully deleted because
052     * S3 deletes are idempotent and quiet responses may omit successful keys.<p>
053     *
054     * @param requestedKeys the requested object keys
055     * @param failures the failures by object key
056     */
057    public CmsS3DeleteResult(Collection<String> requestedKeys, Map<String, Exception> failures) {
058
059        LinkedHashSet<String> deletedKeys = new LinkedHashSet<String>(requestedKeys);
060        m_failures = Collections.unmodifiableMap(new LinkedHashMap<String, Exception>(failures));
061        deletedKeys.removeAll(failures.keySet());
062        m_deletedKeys = Collections.unmodifiableSet(deletedKeys);
063    }
064
065    /** Returns the successfully deleted object keys. */
066    public Set<String> getDeletedKeys() {
067
068        return m_deletedKeys;
069    }
070
071    /** Returns the failures by object key. */
072    public Map<String, Exception> getFailures() {
073
074        return m_failures;
075    }
076
077    /** Returns whether every requested object was deleted successfully. */
078    public boolean isSuccessful() {
079
080        return m_failures.isEmpty();
081    }
082}