@Transactional
public class FnRoleService {
- private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FnRoleService.class);
+ private final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FnRoleService.class);
private final FnRoleDao fnRoleDao;
}
public FnRole getRole(final Long appId, final Long appRoleId) {
-
- String sql = "SELECT * FROM fn_role where APP_ID = :appId AND APP_ROLE_ID = :appRoleId";
-
List<FnRole> roles = Optional.of(fnRoleDao.retrieveAppRoleByAppRoleIdAndByAppId(appId, appRoleId))
.orElse(new ArrayList<>());
if (!roles.isEmpty()) {
return null;
}
+ public List<FnRole> getAppRoles(Long appId) {
+ List<FnRole> applicationRoles;
+ try {
+ if (appId == 1) {
+ applicationRoles = retrieveAppRolesWhereAppIdIsNull();
+ } else {
+ applicationRoles = retrieveAppRolesByAppId(appId);
+ }
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getAppRoles: failed", e);
+ throw e;
+ }
+ return applicationRoles;
+ }
+
public List<FnRole> retrieveAppRoleByAppRoleIdAndByAppId(final Long appId, final Long appRoleId) {
return Optional.of(fnRoleDao.retrieveAppRoleByAppRoleIdAndByAppId(appId, appRoleId)).orElse(new ArrayList<>());
}
public List<FnRole> retrieveAppRolesByRoleNameAndByAppId(final String roleName, final Long appId) {
return Optional.of(fnRoleDao.retrieveAppRolesByRoleNameAndByAppId(roleName, appId)).orElse(new ArrayList<>());
}
+
+ public List<FnRole> retrieveActiveRolesOfApplication(final Long appId) {
+ return Optional.of(fnRoleDao.retrieveActiveRolesOfApplication(appId)).orElse(new ArrayList<>());
+ }
+
+ public List<FnRole> getGlobalRolesOfPortal() {
+ List<FnRole> globalRoles = new ArrayList<>();
+ try {
+ globalRoles = Optional.of(fnRoleDao.getGlobalRolesOfPortal()).orElse(new ArrayList<>());
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getGlobalRolesOfPortal failed", e);
+ }
+ return globalRoles;
+ }
+
+ public Long getSysAdminRoleId(){
+ FnRole role = fnRoleDao.getSysAdminRoleId();
+ return role.getId();
+ }
+
+ public void delete(FnRole role) {
+ fnRoleDao.delete(role);
+ }
+
+ public FnRole saveOne(final FnRole role){
+ return fnRoleDao.save(role);
+ }
}