Search in sources :

Example 6 with NotFoundException

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

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 7 with NotFoundException

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

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 8 with NotFoundException

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

the class FileStoreService method deleteFileOrFolder.

public FileStorePath deleteFileOrFolder(String xid, String toDelete, boolean recursive) {
    FileStore fileStore = getWithoutPermissionCheck(xid);
    ensureEditPermission(Common.getUser(), fileStore);
    FileStorePath toDeletePath = getPathWithinFileStore(fileStore, toDelete);
    if (toDeletePath.absolutePath.equals(toDeletePath.getFileStoreRoot())) {
        throw new FileStoreException(new TranslatableMessage("filestore.deleteRootNotPermitted"));
    }
    if (!Files.exists(toDeletePath.absolutePath)) {
        throw new NotFoundException();
    }
    try {
        if (Files.isDirectory(toDeletePath.absolutePath) && recursive) {
            FileUtils.deleteDirectory(toDeletePath.absolutePath.toFile());
        } else {
            Files.delete(toDeletePath.absolutePath);
        }
        return toDeletePath;
    } catch (NoSuchFileException e) {
        throw new NotFoundException();
    } catch (Exception e) {
        throw new FileStoreException(new TranslatableMessage("filestore.errorDeletingFile"));
    }
}
Also used : FileStore(com.serotonin.m2m2.vo.FileStore) NoSuchFileException(java.nio.file.NoSuchFileException) 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 9 with NotFoundException

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

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)

Example 10 with NotFoundException

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

the class DataSourceService method getDefinition.

/**
 * Get a definition for a data source
 */
public DataSourceDefinition<DataSourceVO> getDefinition(String dataSourceType, PermissionHolder user) throws NotFoundException, PermissionException {
    permissionService.ensurePermission(user, createPermission.getPermission());
    DataSourceDefinition<DataSourceVO> def = ModuleRegistry.getDataSourceDefinition(dataSourceType);
    if (def == null)
        throw new NotFoundException();
    return def;
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) PollingDataSourceVO(com.serotonin.m2m2.vo.dataSource.PollingDataSourceVO) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException)

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