Search in sources :

Example 46 with FileStore

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

the class FileStoreService method getStores.

/**
 * List all file-stores that the user has read permission for
 */
public List<FileStore> getStores() {
    List<FileStore> stores = new ArrayList<>();
    this.customizedQuery(new ConditionSortLimit(null, null, null, null), (item) -> stores.add(item));
    PermissionHolder user = Common.getUser();
    Collection<FileStoreDefinition> moduleDefs = ModuleRegistry.getFileStoreDefinitions().values();
    for (FileStoreDefinition def : moduleDefs) {
        if (this.permissionService.hasPermission(user, def.getReadPermission())) {
            stores.add(def.toFileStore());
        }
    }
    return stores;
}
Also used : FileStore(com.serotonin.m2m2.vo.FileStore) ArrayList(java.util.ArrayList) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) ConditionSortLimit(com.infiniteautomation.mango.db.query.ConditionSortLimit) FileStoreDefinition(com.serotonin.m2m2.module.FileStoreDefinition)

Example 47 with FileStore

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

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;
}
Also used : FileStore(com.serotonin.m2m2.vo.FileStore)

Example 48 with FileStore

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

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);
}
Also used : Path(java.nio.file.Path) TranslatableIllegalArgumentException(com.infiniteautomation.mango.util.exception.TranslatableIllegalArgumentException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Aggregations

FileStore (com.serotonin.m2m2.vo.FileStore)38 Path (java.nio.file.Path)18 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)17 IOException (java.io.IOException)15 TranslatableIllegalArgumentException (com.infiniteautomation.mango.util.exception.TranslatableIllegalArgumentException)10 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)7 TranslatableRuntimeException (com.infiniteautomation.mango.util.exception.TranslatableRuntimeException)6 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)6 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)6 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)6 NoSuchFileException (java.nio.file.NoSuchFileException)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)4 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)4 ApiOperation (io.swagger.annotations.ApiOperation)4 ArrayList (java.util.ArrayList)4 FileStoreModel (com.infiniteautomation.mango.rest.latest.model.filestore.FileStoreModel)3 ConditionSortLimit (com.infiniteautomation.mango.db.query.ConditionSortLimit)2 MangoScript (com.infiniteautomation.mango.spring.script.MangoScript)2 LoadFileStorePermission (com.infiniteautomation.mango.spring.script.permissions.LoadFileStorePermission)2