use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by infiniteautomation.
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"));
}
}
use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by infiniteautomation.
the class SystemPermissionService method update.
/**
*/
public void update(MangoPermission permission, PermissionDefinition def) throws ValidationException {
Objects.requireNonNull(def, "Permission definition cannot be null");
permissionService.ensureAdminRole(Common.getUser());
ProcessResult validation = new ProcessResult();
if (permission == null) {
validation.addContextualMessage("permission", "validate.required");
throw new ValidationException(validation);
}
permission.getRoles().stream().flatMap(Collection::stream).forEach(role -> {
try {
roleService.get(role.getXid());
} catch (NotFoundException e) {
validation.addGenericMessage("validate.role.notFound", role.getXid());
}
});
if (validation.getHasMessages()) {
throw new ValidationException(validation);
}
// Execute in transaction as def.setPermission may make database calls
dao.doInTransaction(tx -> {
dao.update(def.getPermissionTypeName(), def.getPermission(), permission);
def.setPermission(permission);
});
this.eventPublisher.publishEvent(new SystemPermissionUpdated(def));
}
use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by infiniteautomation.
the class UsersService method get.
/*
* Nice little hack since Users don't have an XID.
*/
@Override
public User get(String username) throws NotFoundException, PermissionException {
Assert.notNull(username, "Username required");
if (this.userByUsername != null) {
String usernameLower = username.toLowerCase(Locale.ROOT);
User vo = userByUsername.get(usernameLower, dao::getByXid);
if (vo == null) {
throw new NotFoundException();
}
PermissionHolder currentUser = Common.getUser();
ensureReadPermission(currentUser, vo);
return vo;
} else {
return super.get(username);
}
}
use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by infiniteautomation.
the class AbstractBasicVOService method get.
/**
*/
public T get(int id) throws NotFoundException, PermissionException {
T vo = dao.get(id);
if (vo == null)
throw new NotFoundException();
PermissionHolder user = Common.getUser();
ensureReadPermission(user, vo);
return vo;
}
use of com.infiniteautomation.mango.util.exception.NotFoundException in project ma-core-public by infiniteautomation.
the class AbstractVOService method get.
/**
*/
public T get(String xid) throws NotFoundException, PermissionException {
T vo = dao.getByXid(xid);
if (vo == null)
throw new NotFoundException();
PermissionHolder user = Common.getUser();
ensureReadPermission(user, vo);
return vo;
}
Aggregations