CcmNG: Implementation of the delete method for WebDAV access to theme files.
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5452 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
b3d9cf0f82
commit
3fbecb1dce
|
|
@ -353,6 +353,15 @@ public class StaticThemeProvider implements ThemeProvider {
|
|||
ThemeProvider.class.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteThemeFile(final String theme, final String path) {
|
||||
|
||||
throw new UnsupportedOperationException(String
|
||||
.format("This implementation of %s interface does not support "
|
||||
+ "changes to the theme files.",
|
||||
ThemeProvider.class.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsChanges() {
|
||||
return false;
|
||||
|
|
@ -410,10 +419,10 @@ public class StaticThemeProvider implements ThemeProvider {
|
|||
final String fileName = path.get(0);
|
||||
|
||||
final Optional<JsonObject> fileData = currentDirectory
|
||||
.stream()
|
||||
.map(value -> (JsonObject) value)
|
||||
.filter(value -> filterFileData(value, fileName))
|
||||
.findAny();
|
||||
.stream()
|
||||
.map(value -> (JsonObject) value)
|
||||
.filter(value -> filterFileData(value, fileName))
|
||||
.findAny();
|
||||
if (path.size() == 1) {
|
||||
return fileData;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -153,6 +153,8 @@ public interface ThemeProvider extends Serializable {
|
|||
*/
|
||||
OutputStream getOutputStreamForThemeFile(String theme, String path);
|
||||
|
||||
void deleteThemeFile(String theme, String path);
|
||||
|
||||
/**
|
||||
* Determines if the implementation supports changes to the files of the
|
||||
* themes.
|
||||
|
|
|
|||
|
|
@ -226,4 +226,23 @@ public class Themes implements Serializable {
|
|||
path);
|
||||
}
|
||||
|
||||
public void deleteThemeFile(final ThemeInfo theme,
|
||||
final String path) {
|
||||
|
||||
final Instance<? extends ThemeProvider> forTheme = providers.select(
|
||||
theme.getProvider());
|
||||
|
||||
if (forTheme.isUnsatisfied()) {
|
||||
LOGGER.error("ThemeProvider \"{}\" not found.",
|
||||
theme.getProvider().getName());
|
||||
throw new UnexpectedErrorException(String.format(
|
||||
"ThemeProvider \"%s\" not found.",
|
||||
theme.getProvider().getName()));
|
||||
}
|
||||
|
||||
final ThemeProvider provider = forTheme.get();
|
||||
provider.deleteThemeFile(theme.getName(), path);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -210,8 +210,8 @@ public class DatabaseThemeProvider implements ThemeProvider {
|
|||
return new DataFileOutputStream((DataFile) file);
|
||||
} else {
|
||||
throw new IllegalArgumentException(String
|
||||
.format("The path \"%s\" does not point to a DataFile.",
|
||||
path));
|
||||
.format("The path \"%s\" does not point to a DataFile.",
|
||||
path));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -239,9 +239,39 @@ public class DatabaseThemeProvider implements ThemeProvider {
|
|||
return fileManager.createDataFile(theme, parentDirectory, path);
|
||||
|
||||
} else {
|
||||
throw new IllegalArgumentException(String
|
||||
.format("The path \"%s\" does not point to a directory.",
|
||||
path));
|
||||
throw new IllegalArgumentException(String
|
||||
.format("The path \"%s\" does not point to a directory.",
|
||||
path));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteThemeFile(final String themeName, final String path) {
|
||||
|
||||
Objects.requireNonNull(themeName);
|
||||
Objects.requireNonNull(path);
|
||||
|
||||
if (themeName.matches("\\s*")) {
|
||||
throw new IllegalArgumentException("themeName can't be empty.");
|
||||
}
|
||||
|
||||
if (path.matches("\\s*")) {
|
||||
throw new IllegalArgumentException("path can't be empty.");
|
||||
}
|
||||
|
||||
final Theme theme = themeRepository
|
||||
.findThemeByName(path, ThemeVersion.DRAFT)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("Theme \"%s\" does not exist.", themeName)));
|
||||
|
||||
final ThemeFile file = fileRepository
|
||||
.findByPath(theme, path, ThemeVersion.DRAFT)
|
||||
.orElse(createDataFile(theme, path));
|
||||
|
||||
if (file instanceof DataFile) {
|
||||
fileManager.delete(file);
|
||||
} else if(file instanceof Directory) {
|
||||
fileManager.deleteRecursive(file);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.HeaderParam;
|
||||
import javax.ws.rs.OPTIONS;
|
||||
import javax.ws.rs.core.Context;
|
||||
|
|
@ -93,6 +94,20 @@ public class ThemeFiles {
|
|||
@Inject
|
||||
private ThemeFilesLockManager lockManager;
|
||||
|
||||
@DELETE
|
||||
@Path("/{path}")
|
||||
public void delete(@PathParam("theme") final String theme,
|
||||
@PathParam("path") final String path) {
|
||||
|
||||
final ThemeInfo info = themes
|
||||
.getTheme(theme, ThemeVersion.LIVE)
|
||||
.orElseThrow(() -> new NotFoundException(String
|
||||
.format("Theme \"%s\" does not exist.", theme)));
|
||||
|
||||
lockManager.unlockFile(String.format("%s/%s", theme, path));
|
||||
themes.deleteThemeFile(info, path);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{path}")
|
||||
public Response getFile(@PathParam("theme") final String theme,
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.libreccm.theming.webdav;
|
||||
|
||||
import org.libreccm.webdav.conditions.LockTokenSubmitted;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
|
@ -95,4 +97,11 @@ class ThemeFilesLockManager {
|
|||
lockedFiles.remove(file);
|
||||
}
|
||||
|
||||
protected void unlockFile(final String file) {
|
||||
|
||||
final String lockToken = lockedFiles.get(file);
|
||||
lockedFiles.remove(file);
|
||||
locks.remove(lockToken);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue