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.genesys.server.api.v2.facade;
import org.genesys.blocks.security.model.AclAwareModel;
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.ReferencedRepositoryFileException;
import org.genesys.filerepository.service.VirusFoundException;
import org.genesys.server.api.v2.model.impl.ImageGalleryDTO;
import org.genesys.server.api.v2.model.impl.RepositoryFileDTO;
import org.genesys.server.api.v2.model.impl.RepositoryFolderDTO;
import org.genesys.server.api.v2.model.impl.RepositoryImageDTO;
import org.genesys.server.exception.NotFoundElement;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Path;
import java.util.List;
import java.util.UUID;
import java.util.stream.Stream;
public interface RepositoryApiService {
<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;
void ensureThumbnails(RepositoryImageDTO repositoryImageDTO);
<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;
byte[] getFileBytes(RepositoryFileDTO repositoryFileDTO) throws IOException;
void streamFileBytes(RepositoryFileDTO repositoryFileDTO, OutputStream outputStream) throws IOException;
OutputStream getFolderAsZip(RepositoryFolderDTO repositoryFolderDTO, OutputStream outputStream, int maxFilesLimit) throws InvalidRepositoryPathException, IOException;
OutputStream getFolderAsZip(RepositoryFolderDTO repositoryFolderDTO, OutputStream outputStream) throws InvalidRepositoryPathException, IOException;
List<RepositoryFileDTO> extractZip(final RepositoryFileDTO repositoryFileDTO) throws InvalidRepositoryFileDataException, IOException, InvalidRepositoryPathException, NoSuchRepositoryFileException;
<T extends RepositoryFileDTO> void scanBytes(T repositoryFileDTO) throws VirusFoundException, IOException;
List<RepositoryFileDTO> getFiles(Path folderPath, Sort sort) throws InvalidRepositoryPathException;
Page<RepositoryFileDTO> listFiles(Path folderPath, Pageable page) throws InvalidRepositoryPathException;
Stream<RepositoryFileDTO> streamFiles(Path root, Sort sort) throws InvalidRepositoryPathException;
<T extends RepositoryFileDTO> T updateMetadata(T repositoryFileDTO) throws NoSuchRepositoryFileException;
<T extends RepositoryFileDTO> T updateBytes(T repositoryFileDTO, String contentType, byte[] bytes) throws NoSuchRepositoryFileException, IOException;
<T extends RepositoryFileDTO> T updateBytes(T repositoryFileDTO, String contentType, InputStream inputStream) throws NoSuchRepositoryFileException, IOException;
<T extends RepositoryFileDTO> T updateBytes(T repositoryFileDTO, String contentType, File fileWithBytes) throws NoSuchRepositoryFileException, IOException;
/** @deprecated */
@Deprecated
RepositoryImageDTO updateImageBytes(RepositoryImageDTO repositoryImageDTO, String contentType, byte[] bytes) throws NoSuchRepositoryFileException, IOException;
<T extends RepositoryFileDTO> T removeFileIfPossible(T repositoryFileDTO) throws NoSuchRepositoryFileException, ReferencedRepositoryFileException, IOException;
<T extends RepositoryFileDTO> T removeFile(T repositoryFileDTO) throws NoSuchRepositoryFileException, IOException;
<T extends RepositoryFileDTO> T moveFile(T repositoryFileDTO, Path target) throws NoSuchRepositoryFileException, InvalidRepositoryPathException;
<T extends RepositoryFileDTO> T moveAndRenameFile(T repositoryFileDTO, Path fullPath) throws InvalidRepositoryPathException, InvalidRepositoryFileDataException;
List<RepositoryImageDTO> listImages(Path path, Sort sort);
List<RepositoryFolderDTO> listPathsRecursively(Path root) throws InvalidRepositoryPathException;
/** @deprecated */
@Deprecated
RepositoryImageDTO addImage(Path repositoryPath, String originalFilename, String contentType, byte[] bytes, RepositoryImageDTO metaData) throws InvalidRepositoryPathException, InvalidRepositoryFileDataException, IOException;
/** @deprecated */
@Deprecated
RepositoryImageDTO updateImageMetadata(RepositoryImageDTO repositoryImageDTO) throws NoSuchRepositoryFileException;
/** @deprecated */
@Deprecated
RepositoryImageDTO removeImage(RepositoryImageDTO repositoryImageDTO) throws NoSuchRepositoryFileException, IOException, ReferencedRepositoryFileException;
RepositoryFolderDTO getFolder(UUID uuid);
RepositoryFolderDTO getFolder(Path folderPath) throws InvalidRepositoryPathException;
RepositoryFolderDTO updateFolder(RepositoryFolderDTO folder) throws NoSuchRepositoryFolderException, InvalidRepositoryPathException;
boolean hasPath(Path path) throws InvalidRepositoryPathException;
RepositoryFolderDTO renamePath(Path currentPath, Path newPath) throws InvalidRepositoryPathException;
RepositoryFolderDTO ensureFolder(Path path) throws InvalidRepositoryPathException;
RepositoryFolderDTO ensureFolder(Path path, AclAwareModel aclParentObject) throws InvalidRepositoryPathException;
RepositoryFolderDTO deleteFolder(Path path) throws FolderNotEmptyException, InvalidRepositoryPathException;
List<RepositoryFolderDTO> getFolders(Path root, Sort sort) throws InvalidRepositoryPathException;
Page<RepositoryFolderDTO> listFolders(Path root, Pageable page) throws InvalidRepositoryPathException;
byte[] getThumbnail(final Path path, String name, String extension, RepositoryFileDTO repositoryFileDTO) throws Exception;
FolderDetails renameFolder(UUID folderUuid, String fullPath) throws InvalidRepositoryPathException;
FolderDetails folderDetails(Path path) throws InvalidRepositoryPathException;
/**
* 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;
}
void downloadFolderMetadata(final HttpServletRequest request, final HttpServletResponse response, String controllerUrl)
throws NotFoundElement, IOException, InvalidRepositoryPathException;
}