use of com.serotonin.m2m2.vo.FileStore in project ma-core-public by infiniteautomation.
the class FileStoreService method get.
/**
* @param xid xid of the user file store, or the storeName of the {@link FileStoreDefinition}
*/
@Override
public FileStore get(String xid) throws PermissionException, NotFoundException {
FileStore vo = getWithoutPermissionCheck(xid);
ensureReadPermission(Common.getUser(), vo);
return vo;
}
use of com.serotonin.m2m2.vo.FileStore in project ma-core-public by infiniteautomation.
the class FileStoreService method delete.
@Override
protected FileStore delete(FileStore vo) throws PermissionException, NotFoundException {
if (ModuleRegistry.getFileStoreDefinitions().containsKey(vo.getXid())) {
throw new UnsupportedOperationException("Deleting a built in filestore is not supported");
}
FileStore deleted = super.delete(vo);
Path root = getFileStoreRoot(deleted);
if (Files.exists(root)) {
try {
FileUtils.deleteDirectory(root.toFile());
} catch (IOException e) {
throw new FileStoreException(new TranslatableMessage("filestore.failedToDeleteFiles", deleted.getXid()), e);
}
}
return deleted;
}
use of com.serotonin.m2m2.vo.FileStore in project ma-core-public by infiniteautomation.
the class FileStoreService method getPathWithinFileStore.
private FileStorePath getPathWithinFileStore(FileStore fileStore, String path) {
Path root = getFileStoreRoot(fileStore);
Path filePath = root.resolve(path).toAbsolutePath().normalize();
if (!filePath.startsWith(root)) {
throw new TranslatableIllegalArgumentException(new TranslatableMessage("filestore.invalidPath"));
}
return new FileStorePath(fileStore, filePath);
}
use of com.serotonin.m2m2.vo.FileStore in project ma-core-public by infiniteautomation.
the class FileStoreService method validate.
@Override
public ProcessResult validate(FileStore vo) {
ProcessResult result = super.validate(vo);
validateXid(result, vo);
PermissionHolder user = Common.getUser();
permissionService.validatePermission(result, "readPermission", user, vo.getReadPermission());
permissionService.validatePermission(result, "writePermission", user, vo.getWritePermission());
return result;
}
use of com.serotonin.m2m2.vo.FileStore in project ma-core-public by infiniteautomation.
the class FileStoreService method update.
@Override
protected FileStore update(FileStore existing, FileStore vo) throws PermissionException, ValidationException {
if (ModuleRegistry.getFileStoreDefinitions().containsKey(existing.getXid())) {
throw new UnsupportedOperationException("Updating a built in filestore is not supported");
}
FileStore updated = super.update(existing, vo);
// move files to the new location if the XID changed
if (!updated.getXid().equals(existing.getXid())) {
Path existingPath = getFileStoreRoot(existing);
Path newPath = getFileStoreRoot(updated);
if (Files.exists(existingPath)) {
try {
Files.move(existingPath, newPath);
} catch (IOException e) {
throw new FileStoreException(new TranslatableMessage("filestore.failedToMoveFiles", updated.getXid()), e);
}
}
}
return updated;
}
Aggregations