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.model.RepositoryFile;
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 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 {
<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;
byte[] getFileBytes(RepositoryFileDTO repositoryFileDTO) throws IOException;
Page<RepositoryFileDTO> listFiles(Path folderPath, Pageable page) throws InvalidRepositoryPathException;
<T extends RepositoryFileDTO> T updateMetadata(T repositoryFileDTO) throws NoSuchRepositoryFileException;
/** @deprecated */
@Deprecated
RepositoryImageDTO updateImageBytes(RepositoryImageDTO repositoryImageDTO, String contentType, byte[] bytes) throws NoSuchRepositoryFileException, IOException;
<T extends RepositoryFileDTO> T removeFile(T repositoryFileDTO) throws NoSuchRepositoryFileException, IOException;
/** @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;
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;
Page<RepositoryFolderDTO> listFolders(Path root, Pageable page) throws InvalidRepositoryPathException;
FolderDetails renameFolder(UUID folderUuid, String fullPath) throws InvalidRepositoryPathException;
FolderDetails folderDetails(Path path) throws InvalidRepositoryPathException;
RepositoryFileDTO getMetadata(String path, String uuid, String ext) throws NoSuchRepositoryFileException;
RepositoryFileDTO removeFile(UUID fileUuid) throws NoSuchRepositoryFileException, IOException;
List<RepositoryFileDTO> extractZip(UUID fileUuid) throws NoSuchRepositoryFileException, IOException, InvalidRepositoryPathException, InvalidRepositoryFileDataException;
RepositoryFileDTO moveAndRenameFile(final UUID fileUuid, Path fullPath) throws NoSuchRepositoryFileException, InvalidRepositoryPathException, InvalidRepositoryFileDataException;
/**
* 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 sanityCheck(Path path, String ext, RepositoryFile repositoryFile);
void downloadFolderMetadata(final HttpServletRequest request, final HttpServletResponse response, String controllerUrl)
throws NotFoundElement, IOException, InvalidRepositoryPathException;
}