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-94f89814c4df
Former-commit-id: 703eb0dba1
pull/2/head
parent
e060d5bd62
commit
67952baec6
|
|
@ -282,10 +282,10 @@ public class StaticThemeProvider implements ThemeProvider {
|
||||||
final JsonObject indexObj = reader.readObject();
|
final JsonObject indexObj = reader.readObject();
|
||||||
final JsonArray currentDir = indexObj.getJsonArray("files");
|
final JsonArray currentDir = indexObj.getJsonArray("files");
|
||||||
currentDir.forEach(value -> LOGGER.warn(value.toString()));
|
currentDir.forEach(value -> LOGGER.warn(value.toString()));
|
||||||
|
|
||||||
final Optional<JsonObject> targetFile = findFile(pathTokens,
|
final Optional<JsonObject> targetFile = findFile(pathTokens,
|
||||||
currentDir);
|
currentDir);
|
||||||
|
|
||||||
final List<ThemeFileInfo> result;
|
final List<ThemeFileInfo> result;
|
||||||
if (targetFile.isPresent()) {
|
if (targetFile.isPresent()) {
|
||||||
if (targetFile.get().getBoolean("isDirectory")) {
|
if (targetFile.get().getBoolean("isDirectory")) {
|
||||||
|
|
@ -353,6 +353,15 @@ public class StaticThemeProvider implements ThemeProvider {
|
||||||
ThemeProvider.class.getName()));
|
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
|
@Override
|
||||||
public boolean supportsChanges() {
|
public boolean supportsChanges() {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -410,16 +419,16 @@ public class StaticThemeProvider implements ThemeProvider {
|
||||||
final String fileName = path.get(0);
|
final String fileName = path.get(0);
|
||||||
|
|
||||||
final Optional<JsonObject> fileData = currentDirectory
|
final Optional<JsonObject> fileData = currentDirectory
|
||||||
.stream()
|
.stream()
|
||||||
.map(value -> (JsonObject) value)
|
.map(value -> (JsonObject) value)
|
||||||
.filter(value -> filterFileData(value, fileName))
|
.filter(value -> filterFileData(value, fileName))
|
||||||
.findAny();
|
.findAny();
|
||||||
if (path.size() == 1) {
|
if (path.size() == 1) {
|
||||||
return fileData;
|
return fileData;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (fileData.get().getBoolean("isDirectory")) {
|
if (fileData.get().getBoolean("isDirectory")) {
|
||||||
return findFile(path.subList(1, path.size()),
|
return findFile(path.subList(1, path.size()),
|
||||||
fileData.get().getJsonArray("files"));
|
fileData.get().getJsonArray("files"));
|
||||||
} else {
|
} else {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,8 @@ public interface ThemeProvider extends Serializable {
|
||||||
*/
|
*/
|
||||||
OutputStream getOutputStreamForThemeFile(String theme, String path);
|
OutputStream getOutputStreamForThemeFile(String theme, String path);
|
||||||
|
|
||||||
|
void deleteThemeFile(String theme, String path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if the implementation supports changes to the files of the
|
* Determines if the implementation supports changes to the files of the
|
||||||
* themes.
|
* themes.
|
||||||
|
|
|
||||||
|
|
@ -225,5 +225,24 @@ public class Themes implements Serializable {
|
||||||
theme.getVersion(),
|
theme.getVersion(),
|
||||||
path);
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -188,15 +188,15 @@ public class DatabaseThemeProvider implements ThemeProvider {
|
||||||
|
|
||||||
Objects.requireNonNull(themeName);
|
Objects.requireNonNull(themeName);
|
||||||
Objects.requireNonNull(path);
|
Objects.requireNonNull(path);
|
||||||
|
|
||||||
if (themeName.matches("\\s*")) {
|
if (themeName.matches("\\s*")) {
|
||||||
throw new IllegalArgumentException("themeName can't be empty.");
|
throw new IllegalArgumentException("themeName can't be empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path.matches("\\s*")) {
|
if (path.matches("\\s*")) {
|
||||||
throw new IllegalArgumentException("path can't be empty.");
|
throw new IllegalArgumentException("path can't be empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
final Theme theme = themeRepository
|
final Theme theme = themeRepository
|
||||||
.findThemeByName(path, ThemeVersion.DRAFT)
|
.findThemeByName(path, ThemeVersion.DRAFT)
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
.orElseThrow(() -> new IllegalArgumentException(String
|
||||||
|
|
@ -210,8 +210,8 @@ public class DatabaseThemeProvider implements ThemeProvider {
|
||||||
return new DataFileOutputStream((DataFile) file);
|
return new DataFileOutputStream((DataFile) file);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException(String
|
throw new IllegalArgumentException(String
|
||||||
.format("The path \"%s\" does not point to a DataFile.",
|
.format("The path \"%s\" does not point to a DataFile.",
|
||||||
path));
|
path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -232,16 +232,46 @@ public class DatabaseThemeProvider implements ThemeProvider {
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
.orElseThrow(() -> new IllegalArgumentException(String
|
||||||
.format("The path \"%s\" does not point to a directory.",
|
.format("The path \"%s\" does not point to a directory.",
|
||||||
path)));
|
path)));
|
||||||
|
|
||||||
if (parent instanceof Directory) {
|
if (parent instanceof Directory) {
|
||||||
final Directory parentDirectory = (Directory) parent;
|
final Directory parentDirectory = (Directory) parent;
|
||||||
|
|
||||||
return fileManager.createDataFile(theme, parentDirectory, path);
|
return fileManager.createDataFile(theme, parentDirectory, path);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException(String
|
throw new IllegalArgumentException(String
|
||||||
.format("The path \"%s\" does not point to a directory.",
|
.format("The path \"%s\" does not point to a directory.",
|
||||||
path));
|
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.ServletContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
import javax.ws.rs.HeaderParam;
|
import javax.ws.rs.HeaderParam;
|
||||||
import javax.ws.rs.OPTIONS;
|
import javax.ws.rs.OPTIONS;
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.core.Context;
|
||||||
|
|
@ -93,6 +94,20 @@ public class ThemeFiles {
|
||||||
@Inject
|
@Inject
|
||||||
private ThemeFilesLockManager lockManager;
|
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
|
@GET
|
||||||
@Path("/{path}")
|
@Path("/{path}")
|
||||||
public Response getFile(@PathParam("theme") final String theme,
|
public Response getFile(@PathParam("theme") final String theme,
|
||||||
|
|
@ -239,7 +254,7 @@ public class ThemeFiles {
|
||||||
@HeaderParam("Lock-Tocken") final String lockToken) {
|
@HeaderParam("Lock-Tocken") final String lockToken) {
|
||||||
|
|
||||||
lockManager.unlock(lockToken);
|
lockManager.unlock(lockToken);
|
||||||
|
|
||||||
return Response.status(Response.Status.NO_CONTENT).build();
|
return Response.status(Response.Status.NO_CONTENT).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.libreccm.theming.webdav;
|
package org.libreccm.theming.webdav;
|
||||||
|
|
||||||
|
import org.libreccm.webdav.conditions.LockTokenSubmitted;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
@ -94,5 +96,12 @@ class ThemeFilesLockManager {
|
||||||
locks.remove(lockToken);
|
locks.remove(lockToken);
|
||||||
lockedFiles.remove(file);
|
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