Search in sources :

Example 26 with FileStore

use of com.serotonin.m2m2.vo.FileStore in project ma-core-public by infiniteautomation.

the class FileStoreService method resolveFileStore.

private FileStorePath resolveFileStore(Path path) {
    Path absolutePath = path.toAbsolutePath().normalize();
    if (!absolutePath.startsWith(fileStoreRoot)) {
        throw new TranslatableIllegalArgumentException(new TranslatableMessage("filestore.invalidPath"));
    }
    Path relative = fileStoreRoot.relativize(absolutePath);
    if (relative.getNameCount() == 0) {
        throw new TranslatableIllegalArgumentException(new TranslatableMessage("filestore.invalidPath"));
    }
    String fileStoreName = relative.getName(0).toString();
    FileStore fileStore = getWithoutPermissionCheck(fileStoreName);
    return new FileStorePath(fileStore, absolutePath);
}
Also used : Path(java.nio.file.Path) FileStore(com.serotonin.m2m2.vo.FileStore) TranslatableIllegalArgumentException(com.infiniteautomation.mango.util.exception.TranslatableIllegalArgumentException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 27 with FileStore

use of com.serotonin.m2m2.vo.FileStore in project ma-core-public by infiniteautomation.

the class DiskInfoDefinition method getValue.

@Override
public List<DiskInfo> getValue() {
    FileSystem fs = FileSystems.getDefault();
    List<DiskInfo> disks = new ArrayList<DiskInfo>();
    for (Path root : fs.getRootDirectories()) {
        try {
            FileStore store = Files.getFileStore(root);
            DiskInfo disk = new DiskInfo();
            disk.setName(root.getRoot().toString());
            disk.setTotalSpace(store.getTotalSpace());
            disk.setUsableSpace(store.getUsableSpace());
            disks.add(disk);
        } catch (IOException e) {
        }
    }
    return disks;
}
Also used : Path(java.nio.file.Path) FileStore(java.nio.file.FileStore) FileSystem(java.nio.file.FileSystem) ArrayList(java.util.ArrayList) DiskInfo(com.serotonin.m2m2.module.definitions.settings.DiskInfoDefinition.DiskInfo) IOException(java.io.IOException)

Aggregations

FileStore (com.serotonin.m2m2.vo.FileStore)21 Path (java.nio.file.Path)10 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)9 IOException (java.io.IOException)8 TranslatableIllegalArgumentException (com.infiniteautomation.mango.util.exception.TranslatableIllegalArgumentException)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)4 ApiOperation (io.swagger.annotations.ApiOperation)4 FileStoreModel (com.infiniteautomation.mango.rest.latest.model.filestore.FileStoreModel)3 TranslatableRuntimeException (com.infiniteautomation.mango.util.exception.TranslatableRuntimeException)3 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)3 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)3 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)3 NoSuchFileException (java.nio.file.NoSuchFileException)3 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)2 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 ConditionSortLimit (com.infiniteautomation.mango.db.query.ConditionSortLimit)1 RoleViews (com.infiniteautomation.mango.rest.latest.model.RoleViews)1