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.List; 022import java.util.zip.ZipOutputStream; 023 024import org.ametys.runtime.i18n.I18nizableText; 025 026/** 027 * Component responsible to archive data. 028 */ 029public interface Archiver 030{ 031 /** 032 * Get the {@link ManifestReaderWriter} 033 * @return the {@link ManifestReaderWriter} 034 */ 035 public ManifestReaderWriter getManifestReaderWriter(); 036 037 /** 038 * Export data into the destination archive 039 * @param zos the output data stream. 040 * @throws IOException if an error occurs while writing entries to the archive. 041 */ 042 public void export(ZipOutputStream zos) throws IOException; 043 044 /** 045 * Returns the partial imports, among the given ones, that this {@link Archiver} is able to manage. 046 * @param partialImports The partial imports to filter 047 * @return The managed partial imports 048 */ 049 public Collection<String> managedPartialImports(Collection<String> partialImports); 050 051 /** 052 * Import data (limited to the given partial imports) from the source archive 053 * @param zipPath the input zip path 054 * @param partialImports The partial imports to do. The passed collection must already be filtered out by {@link #managedPartialImports} 055 * @param merger The {@link Merger} 056 * @param deleteBefore <code>true</code> if objects need to be deleted before applying the partial imports 057 * @return The {@link ImportReport} 058 * @throws IOException if an error occurs while reading archive entries. 059 */ 060 public ImportReport partialImport(Path zipPath, Collection<String> partialImports, Merger merger, boolean deleteBefore) throws IOException; 061 062 /** 063 * Potential additional information to append to the success mail of the import process 064 * @return the mail additional information 065 */ 066 public default List<I18nizableText> additionalSuccessImportMail() 067 { 068 return List.of( 069 new I18nizableText("plugin.contentio", "PLUGINS_CONTENTIO_ARCHIVE_IMPORT_SCHEDULABLE_MAIL_SUCCESS_BODY_END") 070 ); 071 } 072}