Search in sources :

Example 46 with NotFoundException

use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by infiniteautomation.

the class PermissionService method get.

/**
 * Get a permission from the cache, load from db if necessary
 * @param id
 * @return
 * @throws NotFoundException if permission with this ID not found
 */
public MangoPermission get(Integer id) throws NotFoundException {
    Objects.requireNonNull(id);
    MangoPermission permission = permissionCache.computeIfAbsent(id, this::loadPermission);
    if (permission == null) {
        throw new NotFoundException();
    } else {
        return permission.withId(id);
    }
}
Also used : NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 47 with NotFoundException

use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by infiniteautomation.

the class DataPointService method getReadPermission.

/**
 * Get the read permission for this data point
 */
public MangoPermission getReadPermission(int dataPointId) throws NotFoundException, PermissionException {
    PermissionHolder user = Common.getUser();
    Integer permissionId = dao.getReadPermissionId(dataPointId);
    if (permissionId == null) {
        throw new NotFoundException();
    }
    MangoPermission read = permissionService.get(permissionId);
    permissionService.ensurePermission(user, read);
    return read;
}
Also used : NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 48 with NotFoundException

use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by infiniteautomation.

the class DataPointService method getSummary.

/**
 * Get a summary for a data point.
 *  A summary is a subset of a data point configuration.
 */
public DataPointSummary getSummary(String xid) {
    DataPointSummary vo = dao.getSummary(xid);
    if (vo == null) {
        throw new NotFoundException();
    }
    permissionService.ensurePermission(Common.getUser(), vo.getReadPermission());
    return vo;
}
Also used : DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException)

Example 49 with NotFoundException

use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by infiniteautomation.

the class FileStoreService method moveFileOrFolder.

public FileStorePath moveFileOrFolder(String xid, String src, String dst) {
    FileStore fileStore = getWithoutPermissionCheck(xid);
    ensureEditPermission(Common.getUser(), fileStore);
    FileStorePath srcPath = getPathWithinFileStore(fileStore, src);
    if (!Files.exists(srcPath.absolutePath)) {
        throw new NotFoundException();
    }
    FileStorePath dstPath = srcPath.getParent().resolve(Paths.get(dst));
    if (Files.isDirectory(dstPath.absolutePath)) {
        Path pathWithFileName = dstPath.absolutePath.resolve(srcPath.absolutePath.getFileName());
        dstPath = new FileStorePath(fileStore, pathWithFileName);
    }
    try {
        Files.move(srcPath.absolutePath, dstPath.absolutePath);
        return dstPath;
    } catch (FileAlreadyExistsException e) {
        throw new FileStoreException(new TranslatableMessage("filestore.fileExists", dstPath.standardizedPath()));
    } catch (Exception e) {
        throw new FileStoreException(new TranslatableMessage("filestore.errorMovingFile"));
    }
}
Also used : Path(java.nio.file.Path) FileStore(com.serotonin.m2m2.vo.FileStore) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) NoSuchFileException(java.nio.file.NoSuchFileException) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableRuntimeException(com.infiniteautomation.mango.util.exception.TranslatableRuntimeException) TranslatableIllegalArgumentException(com.infiniteautomation.mango.util.exception.TranslatableIllegalArgumentException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException)

Example 50 with NotFoundException

use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by infiniteautomation.

the class FileStoreService method copyFileOrFolder.

public FileStorePath copyFileOrFolder(String xid, String src, String dst) {
    FileStore fileStore = getWithoutPermissionCheck(xid);
    ensureEditPermission(Common.getUser(), fileStore);
    FileStorePath srcPath = getPathWithinFileStore(fileStore, src);
    if (!Files.exists(srcPath.absolutePath)) {
        throw new NotFoundException();
    }
    FileStorePath dstPath = srcPath.getParent().resolve(Paths.get(dst));
    if (Files.isDirectory(dstPath.absolutePath)) {
        Path pathWithFileName = dstPath.absolutePath.resolve(srcPath.absolutePath.getFileName());
        dstPath = new FileStorePath(fileStore, pathWithFileName);
    }
    if (Files.exists(dstPath.absolutePath)) {
        throw new FileStoreException(new TranslatableMessage("filestore.fileExists", dstPath.standardizedPath()));
    }
    try {
        if (Files.isDirectory(srcPath.absolutePath)) {
            FileUtils.copyDirectory(srcPath.absolutePath.toFile(), dstPath.absolutePath.toFile());
        } else {
            Files.copy(srcPath.absolutePath, dstPath.absolutePath);
        }
        return dstPath;
    } catch (FileAlreadyExistsException e) {
        throw new FileStoreException(new TranslatableMessage("filestore.fileExists", dstPath.standardizedPath()));
    } catch (Exception e) {
        throw new FileStoreException(new TranslatableMessage("filestore.errorCopyingFile"));
    }
}
Also used : Path(java.nio.file.Path) FileStore(com.serotonin.m2m2.vo.FileStore) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) NoSuchFileException(java.nio.file.NoSuchFileException) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TranslatableRuntimeException(com.infiniteautomation.mango.util.exception.TranslatableRuntimeException) TranslatableIllegalArgumentException(com.infiniteautomation.mango.util.exception.TranslatableIllegalArgumentException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException)

Aggregations

NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)74 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)26 JsonException (com.serotonin.json.JsonException)20 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)18 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)18 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)15 User (com.serotonin.m2m2.vo.User)15 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)15 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)12 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)10 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)9 JsonArray (com.serotonin.json.type.JsonArray)8 TranslatableIllegalArgumentException (com.infiniteautomation.mango.util.exception.TranslatableIllegalArgumentException)6 TranslatableRuntimeException (com.infiniteautomation.mango.util.exception.TranslatableRuntimeException)6 FileStore (com.serotonin.m2m2.vo.FileStore)6 AbstractEventHandlerVO (com.serotonin.m2m2.vo.event.AbstractEventHandlerVO)6 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)6 PublisherVO (com.serotonin.m2m2.vo.publish.PublisherVO)6 ApiOperation (io.swagger.annotations.ApiOperation)6 IOException (java.io.IOException)6