summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-common
diff options
context:
space:
mode:
authorParshad Patel <pars.patel@samsung.com>2019-12-16 14:51:50 +0900
committerParshad Patel <pars.patel@samsung.com>2019-12-16 15:22:50 +0900
commit114070f4684fc453dd5a44c635278293c1f674f7 (patch)
treef6cda7fc64189295f95b210e369807df805d6ba6 /ecomp-portal-BE-common
parentffd9af970318c1f5a0bad46d7aad5d4611414aae (diff)
Fix sonar issues in ecomp-portal-BE-common
A "NullPointerException" could be thrown Replace the type specification in this constructor call with the diamond operator ("<>") Use isEmpty() to check whether the collection is empty or not Issue-ID: PORTAL-562 Change-Id: Idbff965861ec837f058bc0ae7073b359d0fcadcc Signed-off-by: Parshad Patel <pars.patel@samsung.com>
Diffstat (limited to 'ecomp-portal-BE-common')
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduleraux/SchedulerAuxUtil.java64
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPRoleServiceImpl.java294
2 files changed, 182 insertions, 176 deletions
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduleraux/SchedulerAuxUtil.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduleraux/SchedulerAuxUtil.java
index f0f0af5a..4d81c6d0 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduleraux/SchedulerAuxUtil.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduleraux/SchedulerAuxUtil.java
@@ -43,38 +43,36 @@ import org.glassfish.jersey.client.ClientResponse;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
public class SchedulerAuxUtil {
-
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SchedulerAuxUtil.class);
- public static SchedulerAuxResponseWrapper wrapResponse ( String body, int statusCode ) {
-
- SchedulerAuxResponseWrapper w = new SchedulerAuxResponseWrapper();
- w.setStatus (statusCode);
- w.setEntity(body);
-
- return w;
- }
-
- public static SchedulerAuxResponseWrapper wrapResponse (ClientResponse cres) {
- String resp_str = "";
- if ( cres != null ) {
- resp_str = cres.readEntity(String.class);
- }
- int statuscode = cres.getStatus();
- SchedulerAuxResponseWrapper w = SchedulerAuxUtil.wrapResponse ( resp_str, statuscode );
- return (w);
- }
-
- public static SchedulerAuxResponseWrapper wrapResponse (RestObject<String> rs) {
- String resp_str = "";
- int status = 0;
- if ( rs != null ) {
- resp_str = rs.get();
- status = rs.getStatusCode();
- }
- SchedulerAuxResponseWrapper w = SchedulerAuxUtil.wrapResponse ( resp_str, status );
- return (w);
- }
-
-
+ public static SchedulerAuxResponseWrapper wrapResponse(String body, int statusCode) {
+
+ SchedulerAuxResponseWrapper w = new SchedulerAuxResponseWrapper();
+ w.setStatus(statusCode);
+ w.setEntity(body);
+
+ return w;
+ }
+
+ public static SchedulerAuxResponseWrapper wrapResponse(ClientResponse cres) {
+ String respStr = "";
+ int statuscode = 0;
+ if (cres != null) {
+ respStr = cres.readEntity(String.class);
+ statuscode = cres.getStatus();
+ }
+ SchedulerAuxResponseWrapper w = SchedulerAuxUtil.wrapResponse(respStr, statuscode);
+ return (w);
+ }
+
+ public static SchedulerAuxResponseWrapper wrapResponse(RestObject<String> rs) {
+ String respStr = "";
+ int status = 0;
+ if (rs != null) {
+ respStr = rs.get();
+ status = rs.getStatusCode();
+ }
+ SchedulerAuxResponseWrapper w = SchedulerAuxUtil.wrapResponse(respStr, status);
+ return (w);
+ }
+
}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPRoleServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPRoleServiceImpl.java
index 92cbe90e..5d38317a 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPRoleServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPRoleServiceImpl.java
@@ -43,7 +43,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
-
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Service;
@@ -61,146 +60,155 @@ import org.onap.portalsdk.core.service.DataAccessService;
@EnableAspectJAutoProxy
@EPMetricsLog
public class EPRoleServiceImpl implements EPRoleService {
- EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPRoleServiceImpl.class);
-
- @Autowired
- private DataAccessService dataAccessService;
-
- @Autowired
- ExternalAccessRolesService externalAccessRolesService;
-
- @SuppressWarnings("unchecked")
- public List<RoleFunction> getRoleFunctions() {
- // List msgDB = getDataAccessService().getList(Profile.class, null);
- return getDataAccessService().getList(RoleFunction.class, null);
- }
-
- @SuppressWarnings("unchecked")
- public List<EPRole> getAvailableChildRoles(Long roleId) {
- List<EPRole> availableChildRoles = (List<EPRole>) getDataAccessService().getList(EPRole.class, null);
- if (roleId == null || roleId == 0) {
- return availableChildRoles;
- }
-
- EPRole currentRole = (EPRole) getDataAccessService().getDomainObject(EPRole.class, roleId, null);
- Set<EPRole> allParentRoles = new TreeSet<EPRole>();
- allParentRoles = getAllParentRolesAsList(currentRole, allParentRoles);
-
- Iterator<EPRole> availableChildRolesIterator = availableChildRoles.iterator();
- while (availableChildRolesIterator.hasNext()) {
- EPRole role = availableChildRolesIterator.next();
- if (!role.getActive() || allParentRoles.contains(role) || role.getId().equals(roleId)) {
- availableChildRolesIterator.remove();
- }
- }
- return availableChildRoles;
- }
-
- private Set<EPRole> getAllParentRolesAsList(EPRole role, Set<EPRole> allParentRoles) {
- Set<EPRole> parentRoles = role.getParentRoles();
- allParentRoles.addAll(parentRoles);
- Iterator<EPRole> parentRolesIterator = parentRoles.iterator();
- while (parentRolesIterator.hasNext()) {
- getAllParentRolesAsList(parentRolesIterator.next(), allParentRoles);
- }
- return allParentRoles;
- }
-
- public RoleFunction getRoleFunction(String code) {
- return (RoleFunction) getDataAccessService().getDomainObject(RoleFunction.class, code, null);
- }
-
- public void saveRoleFunction(RoleFunction domainRoleFunction) {
- getDataAccessService().saveDomainObject(domainRoleFunction, null);
- }
-
- public void deleteRoleFunction(RoleFunction domainRoleFunction) {
- getDataAccessService().deleteDomainObject(domainRoleFunction, null);
- }
-
- public EPRole getRole(Long id) {
- return (EPRole) getDataAccessService().getDomainObject(EPRole.class, id, null);
- }
-
- // TODO: refactor
- private static final String getAppRoleSqlFormat = "SELECT * FROM fn_role where APP_ID = %s AND APP_ROLE_ID = %s";
-
- @SuppressWarnings("unchecked")
- public EPRole getRole(Long appId, Long appRoleid) {
- if (appId == null || appRoleid == null) {
- logger.error(EELFLoggerDelegate.errorLogger, String.format(
- "getRole does not support null appId or roleId. appRoleid=%s, appRoleid=%s", appId, appRoleid));
- return null;
- }
-
- String sql = String.format(getAppRoleSqlFormat, appId, appRoleid);
-
- List<EPRole> roles = (List<EPRole>) dataAccessService.executeSQLQuery(sql, EPRole.class, null);
- int resultsCount = roles.size();
- if (resultsCount > 1) {
- logger.error(EELFLoggerDelegate.errorLogger,
- String.format(
- "search by appId=%s, appRoleid=%s should have returned 0 or 1 results. Got %d. This is an internal server error.",
- appId, appRoleid, resultsCount));
- logger.error(EELFLoggerDelegate.errorLogger,
- "Trying to recover from duplicates by returning the first search result. This issue should be treated, it is probably not critical because duplicate roles should be similar.");
- return roles.get(0);
- } else if (resultsCount == 1) {
- return roles.get(0);
- }
- return null;
- }
-
- @SuppressWarnings("unchecked")
- public EPRole getAppRole(String roleName, Long appId) {
-
- final Map<String, String> params = new HashMap<String, String>();
- final Map<String, String> portalParams = new HashMap<String, String>();
- List<EPRole> roles = null;
- params.put("appId", appId.toString());
- params.put("roleName", roleName);
- portalParams.put("appRoleName", roleName);
-
- List<EPRole> roleList = externalAccessRolesService.getPortalAppRoleInfo(PortalConstants.ACCOUNT_ADMIN_ROLE_ID);
- EPRole role = new EPRole();
- if(roleList.size()>0){
- role = roleList.get(0);}
- logger.debug(EELFLoggerDelegate.debugLogger, "Requested RoleName is "+role.getName());
-
- if (appId == 1 || roleName.equals(role.getName())) {
- roles = (List<EPRole>) dataAccessService.executeNamedQuery("getPortalAppRoles", portalParams, null);
- } else if (appId != 1 && !roleName.equals(role.getName())) {
- roles = (List<EPRole>) dataAccessService.executeNamedQuery("getAppRoles", params, null);
- }
- int resultsCount = (roles == null ? 0 : roles.size());
- if (resultsCount > 1) {
- logger.error(EELFLoggerDelegate.errorLogger,
- "Trying to recover from duplicates by returning the first search result. This issue should be treated, it is probably not critical because duplicate roles should be similar.");
- return roles.get(0);
- } else if (resultsCount == 1) {
- return roles.get(0);
- }
- return null;
- }
-
- public void saveRole(EPRole domainRole) {
- getDataAccessService().saveDomainObject(domainRole, null);
- }
-
- public void deleteRole(EPRole domainRole) {
- getDataAccessService().deleteDomainObject(domainRole, null);
- }
-
- @SuppressWarnings("unchecked")
- public List<EPRole> getAvailableRoles() {
- return getDataAccessService().getList(EPRole.class, null);
- }
-
- public DataAccessService getDataAccessService() {
- return dataAccessService;
- }
-
- public void setDataAccessService(DataAccessService dataAccessService) {
- this.dataAccessService = dataAccessService;
- }
+ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPRoleServiceImpl.class);
+
+ @Autowired
+ private DataAccessService dataAccessService;
+
+ @Autowired
+ ExternalAccessRolesService externalAccessRolesService;
+
+ @SuppressWarnings("unchecked")
+ public List<RoleFunction> getRoleFunctions() {
+ return getDataAccessService().getList(RoleFunction.class, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<EPRole> getAvailableChildRoles(Long roleId) {
+ List<EPRole> availableChildRoles =
+ (List<EPRole>) getDataAccessService().getList(EPRole.class, null);
+ if (roleId == null || roleId == 0) {
+ return availableChildRoles;
+ }
+
+ EPRole currentRole =
+ (EPRole) getDataAccessService().getDomainObject(EPRole.class, roleId, null);
+ Set<EPRole> allParentRoles = new TreeSet<>();
+ allParentRoles = getAllParentRolesAsList(currentRole, allParentRoles);
+
+ Iterator<EPRole> availableChildRolesIterator = availableChildRoles.iterator();
+ while (availableChildRolesIterator.hasNext()) {
+ EPRole role = availableChildRolesIterator.next();
+ if (!role.getActive() || allParentRoles.contains(role) || role.getId().equals(roleId)) {
+ availableChildRolesIterator.remove();
+ }
+ }
+ return availableChildRoles;
+ }
+
+ private Set<EPRole> getAllParentRolesAsList(EPRole role, Set<EPRole> allParentRoles) {
+ Set<EPRole> parentRoles = role.getParentRoles();
+ allParentRoles.addAll(parentRoles);
+ Iterator<EPRole> parentRolesIterator = parentRoles.iterator();
+ while (parentRolesIterator.hasNext()) {
+ getAllParentRolesAsList(parentRolesIterator.next(), allParentRoles);
+ }
+ return allParentRoles;
+ }
+
+ public RoleFunction getRoleFunction(String code) {
+ return (RoleFunction) getDataAccessService().getDomainObject(RoleFunction.class, code,
+ null);
+ }
+
+ public void saveRoleFunction(RoleFunction domainRoleFunction) {
+ getDataAccessService().saveDomainObject(domainRoleFunction, null);
+ }
+
+ public void deleteRoleFunction(RoleFunction domainRoleFunction) {
+ getDataAccessService().deleteDomainObject(domainRoleFunction, null);
+ }
+
+ public EPRole getRole(Long id) {
+ return (EPRole) getDataAccessService().getDomainObject(EPRole.class, id, null);
+ }
+
+ // TODO: refactor
+ private static final String GET_APP_ROLE_SQL_FORMAT =
+ "SELECT * FROM fn_role where APP_ID = %s AND APP_ROLE_ID = %s";
+
+ @SuppressWarnings("unchecked")
+ public EPRole getRole(Long appId, Long appRoleid) {
+ if (appId == null || appRoleid == null) {
+ logger.error(EELFLoggerDelegate.errorLogger, String.format(
+ "getRole does not support null appId or roleId. appRoleid=%s, appRoleid=%s",
+ appId, appRoleid));
+ return null;
+ }
+
+ String sql = String.format(GET_APP_ROLE_SQL_FORMAT, appId, appRoleid);
+
+ List<EPRole> roles =
+ (List<EPRole>) dataAccessService.executeSQLQuery(sql, EPRole.class, null);
+ int resultsCount = roles.size();
+ if (resultsCount > 1) {
+ logger.error(EELFLoggerDelegate.errorLogger, String.format(
+ "search by appId=%s, appRoleid=%s should have returned 0 or 1 results. Got %d. This is an internal server error.",
+ appId, appRoleid, resultsCount));
+ logger.error(EELFLoggerDelegate.errorLogger,
+ "Trying to recover from duplicates by returning the first search result. This issue should be treated, it is probably not critical because duplicate roles should be similar.");
+ return roles.get(0);
+ } else if (resultsCount == 1) {
+ return roles.get(0);
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ public EPRole getAppRole(String roleName, Long appId) {
+
+ final Map<String, String> params = new HashMap<>();
+ final Map<String, String> portalParams = new HashMap<>();
+ List<EPRole> roles = null;
+ params.put("appId", appId.toString());
+ params.put("roleName", roleName);
+ portalParams.put("appRoleName", roleName);
+
+ List<EPRole> roleList = externalAccessRolesService
+ .getPortalAppRoleInfo(PortalConstants.ACCOUNT_ADMIN_ROLE_ID);
+ EPRole role = new EPRole();
+ if (!roleList.isEmpty()) {
+ role = roleList.get(0);
+ }
+ logger.debug(EELFLoggerDelegate.debugLogger, "Requested RoleName is " + role.getName());
+
+ if (appId == 1 || roleName.equals(role.getName())) {
+ roles = (List<EPRole>) dataAccessService.executeNamedQuery("getPortalAppRoles",
+ portalParams, null);
+ } else if (appId != 1 && !roleName.equals(role.getName())) {
+ roles = (List<EPRole>) dataAccessService.executeNamedQuery("getAppRoles", params, null);
+ }
+ int resultsCount = (roles == null ? 0 : roles.size());
+ if (resultsCount > 1) {
+ logger.error(EELFLoggerDelegate.errorLogger,
+ "Trying to recover from duplicates by returning the first search result. This issue should be treated, it is probably not critical because duplicate roles should be similar.");
+ if (roles != null) {
+ return roles.get(0);
+ }
+ } else if (resultsCount == 1) {
+ return roles.get(0);
+ }
+ return null;
+ }
+
+ public void saveRole(EPRole domainRole) {
+ getDataAccessService().saveDomainObject(domainRole, null);
+ }
+
+ public void deleteRole(EPRole domainRole) {
+ getDataAccessService().deleteDomainObject(domainRole, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<EPRole> getAvailableRoles() {
+ return getDataAccessService().getList(EPRole.class, null);
+ }
+
+ public DataAccessService getDataAccessService() {
+ return dataAccessService;
+ }
+
+ public void setDataAccessService(DataAccessService dataAccessService) {
+ this.dataAccessService = dataAccessService;
+ }
}