X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontroller%2FPolicyController.java;h=40f6be8d7a452904f646fcf14209abf3b305921c;hp=78fb87346edab056c1df8caff0ab65096776bc07;hb=f36e53a3637e1204a42491ec0eeed7b3c763f681;hpb=b86c95c99240e8ed0ef91932a70ebed313dbd60c diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyController.java index 78fb87346..40f6be8d7 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyController.java @@ -164,8 +164,8 @@ public class PolicyController extends RestrictedBaseController { return jUnit; } - public static void setjUnit(boolean jUnit) { - PolicyController.jUnit = jUnit; + public static void setjUnit(boolean isJunit) { + PolicyController.jUnit = isJunit; } @Autowired @@ -321,9 +321,7 @@ public class PolicyController extends RestrictedBaseController { ObjectMapper mapper = new ObjectMapper(); model.put("functionDefinitionDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FunctionDefinition.class, "shortname"))); - JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); - JSONObject j = new JSONObject(msg); - response.getWriter().write(j.toString()); + response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(model))).toString()); } catch (Exception e) { policyLogger.error( XACMLErrorConstants.ERROR_DATA_ISSUE + "Error while retriving the Function Definition data" + e); @@ -378,9 +376,7 @@ public class PolicyController extends RestrictedBaseController { Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("userRolesDatas", mapper.writeValueAsString(getRolesOfUser(userId))); - JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); - JSONObject j = new JSONObject(msg); - response.getWriter().write(j.toString()); + response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(model))).toString()); } catch (Exception e) { policyLogger.error("Exception Occured" + e); } @@ -601,11 +597,11 @@ public class PolicyController extends RestrictedBaseController { /** * Switch Version Policy Content. * - * @param pName which is used to find associated versions. + * @param thePolicyName which is used to find associated versions. * @return list of available versions based on policy name. */ - public JSONObject switchVersionPolicyContent(String pName) { - String policyName = pName; + public JSONObject switchVersionPolicyContent(String thePolicyName) { + String policyName = thePolicyName; String dbCheckName = policyName.replace("/", "."); if (dbCheckName.contains("Config_")) { dbCheckName = dbCheckName.replace(".Config_", ":Config_"); @@ -621,14 +617,13 @@ public class PolicyController extends RestrictedBaseController { SimpleBindings params = new SimpleBindings(); params.put("splitDBCheckName1", splitDbCheckName[1] + "%"); params.put("splitDBCheckName0", splitDbCheckName[0]); - List policyEntity = commonClassDao.getDataByQuery(query, params); List av = new ArrayList<>(); - for (Object entity : policyEntity) { - PolicyEntity pEntity = (PolicyEntity) entity; - String removeExtension = pEntity.getPolicyName().replace(".xml", ""); + for (Object entity : commonClassDao.getDataByQuery(query, params)) { + PolicyEntity policyEntity = (PolicyEntity) entity; + String removeExtension = policyEntity.getPolicyName().replace(".xml", ""); String version = removeExtension.substring(removeExtension.lastIndexOf('.') + 1); - String userName = getUserId(pEntity, "@ModifiedBy:"); - av.add(version + " | " + pEntity.getModifiedDate() + " | " + userName); + String userName = getUserId(policyEntity, "@ModifiedBy:"); + av.add(version + " | " + policyEntity.getModifiedDate() + " | " + userName); } if (policyName.contains("/")) { policyName = policyName.replace("/", File.separator); @@ -642,13 +637,20 @@ public class PolicyController extends RestrictedBaseController { return el; } + /** + * getUserId. + * + * @param data PolicyEntity + * @param value String + * @return String + */ public String getUserId(PolicyEntity data, String value) { String userId = ""; - String uValue = value; + String userValue = value; // Why? String description = getDescription(data); - if (description.contains(uValue)) { - userId = description.substring(description.indexOf(uValue) + uValue.length(), - description.lastIndexOf(uValue)); + if (description.contains(userValue)) { + userId = description.substring(description.indexOf(userValue) + userValue.length(), + description.lastIndexOf(userValue)); } UserInfo userInfo = (UserInfo) getEntityItem(UserInfo.class, "userLoginId", userId); if (userInfo == null) { @@ -657,6 +659,12 @@ public class PolicyController extends RestrictedBaseController { return userInfo.getUserName(); } + /** + * getDescription. + * + * @param data PolicyEntity + * @return String + */ public String getDescription(PolicyEntity data) { InputStream stream = new ByteArrayInputStream(data.getPolicyData().getBytes(StandardCharsets.UTF_8)); Object policy = XACMLPolicyScanner.readPolicy(stream); @@ -664,13 +672,19 @@ public class PolicyController extends RestrictedBaseController { return ((PolicySetType) policy).getDescription(); } else if (policy instanceof PolicyType) { return ((PolicyType) policy).getDescription(); - } else { - PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Expecting a PolicySet/Policy/Rule object. Got: " - + policy.getClass().getCanonicalName()); - return null; } + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Expecting a PolicySet/Policy/Rule object. Got: " + + policy.getClass().getCanonicalName()); + return null; } + /** + * getUserInfo. + * + * @param data PolicyEntity + * @param activePolicies list of active policies + * @return array of String + */ public String[] getUserInfo(PolicyEntity data, List activePolicies) { String policyName = data.getScope().replace(".", File.separator) + File.separator + data.getPolicyName().substring(0, data.getPolicyName().indexOf('.')); @@ -963,13 +977,13 @@ public class PolicyController extends RestrictedBaseController { /** * Function to convert date. * - * @param dateTTL input date value. + * @param dateTimeToLive input date value. * @return */ - public String convertDate(String dateTTL) { + public String convertDate(String dateTimeToLive) { String formateDate = null; - if (dateTTL.contains("-")) { - formateDate = dateTTL.replace("-", "/"); + if (dateTimeToLive.contains("-")) { + formateDate = dateTimeToLive.replace("-", "/"); } return formateDate; }