RepositoryApiService.java

/*
 * Copyright 2024 Global Crop Diversity Trust
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gringlobal.api.v2.facade;

import org.genesys.filerepository.FolderNotEmptyException;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.NoSuchRepositoryFolderException;
import org.genesys.filerepository.model.RepositoryFile;
import org.gringlobal.api.model.ImageGalleryDTO;
import org.gringlobal.api.model.RepositoryFileDTO;
import org.gringlobal.api.model.RepositoryFolderDTO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.List;
import java.util.UUID;

public interface RepositoryApiService {

	void downloadFile(UUID fileUuid, HttpServletRequest request, HttpServletResponse response) throws IOException, NoSuchRepositoryFileException;

	void downloadFolderAsZip(UUID folderUuid, HttpServletResponse response) throws IOException, InvalidRepositoryPathException;

	<T extends RepositoryFileDTO> T addFile(Path repositoryPath, String originalFilename, String contentType, byte[] bytes, T metaData) throws InvalidRepositoryPathException, InvalidRepositoryFileDataException, IOException;

	<T extends RepositoryFileDTO> T addFile(Path repositoryPath, String originalFilename, String contentType, File fileWithData, T metaData) throws InvalidRepositoryPathException, InvalidRepositoryFileDataException, IOException;

	<T extends RepositoryFileDTO> T addFile(Path repositoryPath, String originalFilename, String contentType, InputStream inputStream, T metaData) throws InvalidRepositoryPathException, InvalidRepositoryFileDataException, IOException;

	<T extends RepositoryFileDTO> T getFile(UUID fileUuid) throws NoSuchRepositoryFileException;

	<T extends RepositoryFileDTO> T getFile(UUID fileUuid, int version) throws NoSuchRepositoryFileException;

	<T extends RepositoryFileDTO> T getFile(Path path, String filename) throws NoSuchRepositoryFileException, InvalidRepositoryPathException;

	List<RepositoryFileDTO> extractZip(final UUID fileUuid) throws InvalidRepositoryFileDataException, IOException, InvalidRepositoryPathException, NoSuchRepositoryFileException;

	Page<RepositoryFileDTO> listFiles(Path folderPath, Pageable page) throws InvalidRepositoryPathException;

	<T extends RepositoryFileDTO> T updateMetadata(T repositoryFileDTO) throws NoSuchRepositoryFileException;

	<T extends RepositoryFileDTO> T removeFile(UUID fileUuid) throws NoSuchRepositoryFileException, IOException;

	<T extends RepositoryFileDTO> T moveAndRenameFile(T repositoryFileDTO, Path fullPath) throws InvalidRepositoryPathException, InvalidRepositoryFileDataException;

	RepositoryFolderDTO getFolder(UUID uuid);

	RepositoryFolderDTO getFolder(Path folderPath) throws InvalidRepositoryPathException;

	RepositoryFolderDTO updateFolder(RepositoryFolderDTO folder) throws NoSuchRepositoryFolderException, InvalidRepositoryPathException;

	RepositoryFolderDTO ensureFolder(Path path) throws InvalidRepositoryPathException;

	RepositoryFolderDTO deleteFolder(Path path) throws FolderNotEmptyException, InvalidRepositoryPathException;

	Page<RepositoryFolderDTO> listFolders(Path root, Pageable page) throws InvalidRepositoryPathException;

	FolderDetails renameFolder(UUID folderUuid, String fullPath) throws InvalidRepositoryPathException;

	FolderDetails folderDetails(Path path) throws InvalidRepositoryPathException;

	ImageGalleryDTO getGallery(Path path) throws InvalidRepositoryPathException;

	ImageGalleryDTO createImageGallery(Path path, String title, String description) throws InvalidRepositoryPathException;

	ImageGalleryDTO removeGallery(Path path) throws InvalidRepositoryPathException;

	RepositoryFileDTO getMetadata(String path, String uuid, String ext) throws NoSuchRepositoryFileException;

	void sanityCheck(Path path, String ext, RepositoryFile repositoryFile);

	/**
	 * The Class FolderDetails.
	 */
	class FolderDetails {

		/** The folder itself (may be null for /). */
		public RepositoryFolderDTO folder;

		/** Subfolders */
		public Page<RepositoryFolderDTO> subFolders;

		/** The files. */
		public Page<RepositoryFileDTO> files;

		/** The gallery. */
		public ImageGalleryDTO gallery;
	}
}