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);
}
}
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;
}
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;
}
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"));
}
}
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"));
}
}
Aggregations