Domain model change
[portal.git] / portal-BE / src / main / java / org / onap / portal / service / fn / FnRoleService.java
index aa859db..39a886c 100644 (file)
@@ -55,7 +55,7 @@ import org.springframework.transaction.annotation.Transactional;
 @Transactional
 public class FnRoleService {
 
-  private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FnRoleService.class);
+  private final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FnRoleService.class);
 
 
   private final FnRoleDao fnRoleDao;
@@ -70,9 +70,6 @@ public class FnRoleService {
   }
 
   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()) {
@@ -87,6 +84,21 @@ public class FnRoleService {
     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<>());
   }
@@ -110,4 +122,31 @@ public class FnRoleService {
   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);
+  }
 }