Commit 577005e0 authored by Matija Obreza's avatar Matija Obreza

Revert "Fix: FolderNotEmptyException is thrown for no good reason"

This reverts commit 53c8489f.
parent 1b2d0eba
Pipeline #11904 passed with stage
in 1 minute and 38 seconds
/*
* Copyright 2018 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.filerepository;
/**
* The InvalidRepositoryPathException is thrown when Repository is not happy
* with your selected path.
*/
public class FolderNotEmptyException extends FileRepositoryException {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
/**
* Instantiates a new invalid repository path exception.
*
* @param message the message
*/
public FolderNotEmptyException(final String message) {
super(message);
}
}
......@@ -23,6 +23,7 @@ import java.util.UUID;
import java.util.stream.Stream;
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;
......@@ -332,7 +333,7 @@ public interface RepositoryService {
* @throws FolderNotEmptyException if folder contains sub-folders or files
* @throws InvalidRepositoryPathException if path is not a valid repository path
*/
RepositoryFolder deleteFolder(Path path) throws InvalidRepositoryPathException;
RepositoryFolder deleteFolder(Path path) throws FolderNotEmptyException, InvalidRepositoryPathException;
/**
* Get subfolders of root
......
......@@ -38,6 +38,7 @@ import org.apache.tika.Tika;
import org.genesys.blocks.security.SecurityContextUtil;
import org.genesys.blocks.security.model.AclAwareModel;
import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.filerepository.FolderNotEmptyException;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
......@@ -993,12 +994,16 @@ public class RepositoryServiceImpl implements RepositoryService, InitializingBea
*/
@Override
@Transactional
public RepositoryFolder deleteFolder(Path path) throws InvalidRepositoryPathException {
public RepositoryFolder deleteFolder(Path path) throws FolderNotEmptyException, InvalidRepositoryPathException {
PathValidator.checkValidPath(path);
final Path cPath = path.normalize().toAbsolutePath();
RepositoryFolder folder = folderRepository.findByPath(cPath.toString());
if (folder != null) {
if (folder.getChildren().size() > 0 || folder.getFiles().size() > 0) {
throw new FolderNotEmptyException("Folder " + path.toString() + " is not empty.");
}
folderRepository.delete(folder);
}
return folder;
......
......@@ -23,6 +23,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import org.genesys.filerepository.FolderNotEmptyException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFolderException;
import org.genesys.filerepository.model.RepositoryFolder;
......@@ -150,7 +151,7 @@ public class RepositoryFolderTest extends RepositoryServiceTest {
}
@Test
public void deleteEmptyFolder() throws InvalidRepositoryPathException {
public void deleteEmptyFolder() throws InvalidRepositoryPathException, FolderNotEmptyException {
Path path = Paths.get("/bbbb/cccc/dddd/eeee");
RepositoryFolder folder = repositoryService.ensureFolder(path);
assertThat(folder, notNullValue());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment