class SoapFolderService extends AbstractService implements FolderService {

	@Override
	public void grantGroup(String sid, long folderId, long groupId, int permissions, boolean recursive)
			throws Exception {
		User sessionUser = validateSession(sid);

		FolderDAO folderDao = (FolderDAO) Context.get().getBean(FolderDAO.class);
		// Check if the session user has the Security Permission of this folder
		if (!folderDao.isPermissionEnabled(Permission.SECURITY, folderId, sessionUser.getId()))
			throw new Exception(String.format("Security Rights not granted to the user on folder id %s", folderId));
		try {
			Folder folder = folderDao.findById(folderId);
			folderDao.initialize(folder);
			folder.setSecurityRef(null);

			FolderGroup fg = new FolderGroup();
			fg.setGroupId(groupId);
			fg.setPermissions(permissions);
			folder.addFolderGroup(fg);

			FolderHistory history = new FolderHistory();
			history.setEvent(FolderEvent.PERMISSION.toString());
			history.setSession(SessionManager.get().get(sid));
			folderDao.store(folder, history);

			if (recursive) {
				folderDao.initialize(folder);
				FolderHistory transaction = new FolderHistory();
				transaction.setUser(sessionUser);
				transaction.setSessionId(sid);
				folderDao.applyRightToTree(folder.getId(), transaction);
			}
		} catch (Throwable e) {
			log.error("Some errors occurred", e);
			throw new Exception("error", e);
		}
	}

}