summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-common/src/main
diff options
context:
space:
mode:
authorPawel <pawel.kasperkiewicz@nokia.com>2019-02-19 09:44:39 -0500
committerKasperkiewicz Pawel <pawel.kasperkiewicz@nokia.com>2019-02-20 10:44:37 +0100
commit10bff6ef90eb70af530dbe5ccf4f06cb934f1881 (patch)
treeebabc1d6b7da119ef00bcd9edc1f94bcf6e9efcf /ecomp-sdk/epsdk-app-common/src/main
parent7b740b078f8fb593c2615e8b6689d30ea46a0c86 (diff)
Solve sonar issues in RoleController.java
Issue-ID: PORTAL-527 Change-Id: I3083e1f0deb9243bf1b919d163aceab18a1a6156 Signed-off-by: Pawel <pawel.kasperkiewicz@nokia.com>
Diffstat (limited to 'ecomp-sdk/epsdk-app-common/src/main')
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/RoleController.java70
1 files changed, 37 insertions, 33 deletions
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/RoleController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/RoleController.java
index 8306e91d..52dedd46 100644
--- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/RoleController.java
+++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/RoleController.java
@@ -76,6 +76,10 @@ import com.fasterxml.jackson.databind.type.TypeFactory;
public class RoleController extends RestrictedBaseController {
private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RoleController.class);
+ public static final String APPLICATION_JSON = "application/json";
+ public static final String ROLE_ID = "role_id";
+ public static final String UTF_8 = "UTF-8";
+ public static final String ROLE = "{role: ";
@Autowired
private RoleService roleService;
@@ -89,8 +93,8 @@ public class RoleController extends RestrictedBaseController {
User user = UserUtils.getUserSession(request);
Role role = roleService.getRole(user.getOrgUserId(),
- new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0)));
- logger.info("role_id" + role.getId());
+ new Long(ServletRequestUtils.getIntParameter(request, ROLE_ID, 0)));
+ logger.info(ROLE_ID + role.getId());
try {
model.put("availableRoleFunctions",
mapper.writeValueAsString(roleService.getRoleFunctions(user.getOrgUserId())));
@@ -111,8 +115,8 @@ public class RoleController extends RestrictedBaseController {
User user = UserUtils.getUserSession(request);
Role role = roleService.getRole(user.getOrgUserId(),
- new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0)));
- logger.info(EELFLoggerDelegate.applicationLogger, "role_id" + role.getId());
+ new Long(ServletRequestUtils.getIntParameter(request, ROLE_ID, 0)));
+ logger.info(EELFLoggerDelegate.applicationLogger, ROLE_ID + role.getId());
try {
model.put("availableRoleFunctions",
mapper.writeValueAsString(roleService.getRoleFunctions(user.getOrgUserId())));
@@ -172,13 +176,13 @@ public class RoleController extends RestrictedBaseController {
domainRole = new Role();
domainRole.setName(role.getName());
domainRole.setPriority(role.getPriority());
- if (role.getChildRoles() != null && role.getChildRoles().size() > 0) {
+ if (role.getChildRoles() != null && !role.getChildRoles().isEmpty()) {
for (Object childRole : childRoles) {
domainRole.addChildRole((Role) childRole);
}
}
}
- if (role.getRoleFunctions() != null && role.getRoleFunctions().size() > 0) {
+ if (role.getRoleFunctions() != null && !role.getRoleFunctions().isEmpty()) {
domainRole.setRoleFunctions(new TreeSet());
for (Object roleFunction : roleFunctions) {
domainRole.addRoleFunction((RoleFunction) roleFunction);
@@ -187,15 +191,15 @@ public class RoleController extends RestrictedBaseController {
roleService.saveRole(user.getOrgUserId(), domainRole);
String responseString = mapper.writeValueAsString(domainRole);
- j = new JSONObject("{role: " + responseString + "}");
+ j = new JSONObject(ROLE + responseString + "}");
} catch (Exception e) {
// Produce JSON error message
logger.error(EELFLoggerDelegate.errorLogger, "saveRole failed", e);
j = new JSONObject("{error: '" + e.getMessage() + "'}");
}
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application/json");
+ response.setCharacterEncoding(UTF_8);
+ response.setContentType(APPLICATION_JSON);
PrintWriter out = response.getWriter();
out.write(j.toString());
return null;
@@ -213,24 +217,24 @@ public class RoleController extends RestrictedBaseController {
RoleFunction roleFunction = mapper.readValue(root.get("roleFunction").toString(), RoleFunction.class);
Role domainRole = roleService.getRole(user.getOrgUserId(),
- new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0)));
+ new Long(ServletRequestUtils.getIntParameter(request, ROLE_ID, 0)));
doAuditLog("Remove role function {} from role {}", roleFunction.getCode(),
- ServletRequestUtils.getIntParameter(request, "role_id", 0));
+ ServletRequestUtils.getIntParameter(request, ROLE_ID, 0));
domainRole.removeRoleFunction(roleFunction.getCode());
roleService.saveRole(user.getOrgUserId(), domainRole);
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application/json");
+ response.setCharacterEncoding(UTF_8);
+ response.setContentType(APPLICATION_JSON);
String responseString = mapper.writeValueAsString(domainRole);
- JSONObject j = new JSONObject("{role: " + responseString + "}");
+ JSONObject j = new JSONObject(ROLE + responseString + "}");
PrintWriter out = response.getWriter();
out.write(j.toString());
return null;
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "removeRole failed", e);
- response.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(UTF_8);
PrintWriter out = response.getWriter();
out.write("An error occurred removeRole failed in the removeRoleFunction");
return null;
@@ -250,24 +254,24 @@ public class RoleController extends RestrictedBaseController {
RoleFunction roleFunction = mapper.readValue(root.get("roleFunction").toString(), RoleFunction.class);
Role domainRole = roleService.getRole(user.getOrgUserId(),
- new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0)));
+ new Long(ServletRequestUtils.getIntParameter(request, ROLE_ID, 0)));
domainRole.addRoleFunction(roleFunction);
roleService.saveRole(user.getOrgUserId(), domainRole);
doAuditLog("Add role function {} to role {}", roleFunction.getCode(),
- ServletRequestUtils.getIntParameter(request, "role_id", 0));
+ ServletRequestUtils.getIntParameter(request, ROLE_ID, 0));
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application/json");
+ response.setCharacterEncoding(UTF_8);
+ response.setContentType(APPLICATION_JSON);
String responseString = mapper.writeValueAsString(domainRole);
- JSONObject j = new JSONObject("{role: " + responseString + "}");
+ JSONObject j = new JSONObject(ROLE + responseString + "}");
PrintWriter out = response.getWriter();
out.write(j.toString());
return null;
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "removeRoleFunction failed", e);
- response.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(UTF_8);
PrintWriter out = response.getWriter();
out.write("An error occurred removeRoleFunction failed in the removeRoleFunction");
return null;
@@ -286,24 +290,24 @@ public class RoleController extends RestrictedBaseController {
Role childRole = mapper.readValue(root.get("childRole").toString(), Role.class);
Role domainRole = roleService.getRole(user.getOrgUserId(),
- new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0)));
+ new Long(ServletRequestUtils.getIntParameter(request, ROLE_ID, 0)));
domainRole.removeChildRole(childRole.getId());
doAuditLog("remove child role {} from role {}", childRole.getId(),
- ServletRequestUtils.getIntParameter(request, "role_id", 0));
+ ServletRequestUtils.getIntParameter(request, ROLE_ID, 0));
roleService.saveRole(user.getOrgUserId(), domainRole);
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application/json");
+ response.setCharacterEncoding(UTF_8);
+ response.setContentType(APPLICATION_JSON);
String responseString = mapper.writeValueAsString(domainRole);
- JSONObject j = new JSONObject("{role: " + responseString + "}");
+ JSONObject j = new JSONObject(ROLE + responseString + "}");
PrintWriter out = response.getWriter();
out.write(j.toString());
return null;
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "removeChildRole failed", e);
- response.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(UTF_8);
PrintWriter out = response.getWriter();
out.write("An error occurred removeChildRole failed in the removeChildRole()");
return null;
@@ -321,7 +325,7 @@ public class RoleController extends RestrictedBaseController {
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JsonNode root = mapper.readTree(request.getReader());
Role childRole = mapper.readValue(root.get("childRole").toString(), Role.class);
- Long role_id = new Long(ServletRequestUtils.getIntParameter(request, "role_id", 0));
+ Long role_id = new Long(ServletRequestUtils.getIntParameter(request, ROLE_ID, 0));
Role domainRole = roleService.getRole(user.getOrgUserId(), role_id);
@@ -329,18 +333,18 @@ public class RoleController extends RestrictedBaseController {
roleService.saveRole(user.getOrgUserId(), domainRole);
doAuditLog("Add child role {} to role {}", childRole.getId(),
- ServletRequestUtils.getIntParameter(request, "role_id", 0));
+ ServletRequestUtils.getIntParameter(request, ROLE_ID, 0));
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application/json");
+ response.setCharacterEncoding(UTF_8);
+ response.setContentType(APPLICATION_JSON);
String responseString = mapper.writeValueAsString(domainRole);
- JSONObject j = new JSONObject("{role: " + responseString + "}");
+ JSONObject j = new JSONObject(ROLE + responseString + "}");
PrintWriter out = response.getWriter();
out.write(j.toString());
return null;
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "addChildRole failed", e);
- response.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(UTF_8);
PrintWriter out = response.getWriter();
out.write("An error occurred addChildRole failed in the addChildRole()");
return null;