001/*
002 *  Copyright 2019 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.plugins.contentio.archive;
017
018import java.io.IOException;
019import java.nio.file.Path;
020import java.util.Collection;
021import java.util.Collections;
022import java.util.List;
023import java.util.zip.ZipOutputStream;
024
025import org.ametys.runtime.i18n.I18nizableText;
026
027/**
028 * Component responsible to archive data.
029 */
030public interface Archiver
031{
032    /**
033     * Get the {@link ManifestReaderWriter}
034     * @return the {@link ManifestReaderWriter}
035     */
036    public ManifestReaderWriter getManifestReaderWriter(); 
037    
038    /**
039     * Export data into the destination archive
040     * @param zos the output data stream.
041     * @throws IOException if an error occurs while writing entries to the archive.
042     */
043    public void export(ZipOutputStream zos) throws IOException;
044
045    /**
046     * Returns the partial imports, among the given ones, that this {@link Archiver} is able to manage.
047     * @param partialImports The partial imports to filter
048     * @return The managed partial imports
049     */
050    public Collection<String> managedPartialImports(Collection<String> partialImports);
051    
052    /**
053     * Import data (limited to the given partial imports) from the source archive
054     * @param zipPath the input zip path
055     * @param partialImports The partial imports to do. The passed collection must already be filtered out by {@link #managedPartialImports}
056     * @param merger The {@link Merger}
057     * @param deleteBefore <code>true</code> if objects need to be deleted before applying the partial imports
058     * @return The {@link ImportReport}
059     * @throws IOException if an error occurs while reading archive entries.
060     */
061    public ImportReport partialImport(Path zipPath, Collection<String> partialImports, Merger merger, boolean deleteBefore) throws IOException;
062    
063    /**
064     * Potential additional information to append to the success mail of the import process
065     * @return the mail additional information
066     */
067    public default List<I18nizableText> additionalSuccessImportMail()
068    {
069        return Collections.EMPTY_LIST;
070    }
071}