diff options
author | rb7147 <rb7147@att.com> | 2017-12-04 16:45:55 -0500 |
---|---|---|
committer | rb7147 <rb7147@att.com> | 2017-12-08 10:45:57 -0500 |
commit | 428150834ee60899b9a8da019bae3c8bf009adf1 (patch) | |
tree | 7197eb324477cad918cf527c7a479302cb5029f7 /POLICY-SDK-APP/src | |
parent | 775f45908025e46a40c9c147fca2066af5c8c5b8 (diff) |
Upgraded the latest ONAP SDK
Upgraded latest ONAP SDK Code.
Change-Id: I669d6cfcefe068b1e4c078889d7d6c77ce788e2e
Issue-ID: POLICY-432
Signed-off-by: rb7147 <rb7147@att.com>
Diffstat (limited to 'POLICY-SDK-APP/src')
26 files changed, 286 insertions, 168 deletions
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java index d65d1da8a..cb373a1bd 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java @@ -33,9 +33,11 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -67,6 +69,7 @@ import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.components.HumanPolicyComponent; import org.onap.policy.controller.PolicyController; import org.onap.policy.controller.PolicyExportAndImportController; +import org.onap.policy.model.Roles; import org.onap.policy.rest.XACMLRest; import org.onap.policy.rest.XACMLRestProperties; import org.onap.policy.rest.adapter.PolicyRestAdapter; @@ -79,8 +82,7 @@ import org.onap.policy.rest.jpa.UserInfo; import org.onap.policy.utils.PolicyUtils; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.util.XACMLPolicyScanner; -import org.openecomp.policy.model.Roles; -import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.onap.portalsdk.core.web.support.UserUtils; import com.att.research.xacml.util.XACMLProperties; import com.fasterxml.jackson.databind.JsonNode; @@ -272,6 +274,12 @@ public class PolicyManagerServlet extends HttpServlet { JSONObject jObj = new JSONObject(sb.toString()); JSONObject params = jObj.getJSONObject("params"); Mode mode = Mode.valueOf(params.getString("mode")); + + String userId = UserUtils.getUserSession(request).getOrgUserId(); + LOGGER.info("****************************************Logging UserID while doing actions on Editor tab*******************************************"); + LOGGER.info("UserId: " + userId + "Action Mode: "+ mode.toString() + "Action Params: "+params.toString()); + LOGGER.info("***********************************************************************************************************************************"); + switch (mode) { case ADDFOLDER: case ADDSUBSCOPE: @@ -623,7 +631,7 @@ public class PolicyManagerServlet extends HttpServlet { if(!(scope.getScopeName().contains(File.separator))){ JSONObject el = new JSONObject(); el.put("name", scope.getScopeName()); - el.put("date", scope.getCreatedDate()); + el.put("date", scope.getModifiedDate()); el.put("size", ""); el.put("type", "dir"); el.put("createdBy", scope.getUserCreatedBy().getUserName()); @@ -638,7 +646,7 @@ public class PolicyManagerServlet extends HttpServlet { if(!scopesList.isEmpty()){ PolicyEditorScopes scopeById = (PolicyEditorScopes) scopesList.get(0); el.put("name", scopeById.getScopeName()); - el.put("date", scopeById.getCreatedDate()); + el.put("date", scopeById.getModifiedDate()); el.put("size", ""); el.put("type", "dir"); el.put("createdBy", scopeById.getUserCreatedBy().getUserName()); @@ -1149,6 +1157,7 @@ public class PolicyManagerServlet extends HttpServlet { entityItem.setPolicyName(policyName); entityItem.setCreatedBy(userId); entityItem.setModifiedBy(userId); + entityItem.setModifiedDate(new Date()); controller.saveData(entityItem); } @@ -1212,9 +1221,9 @@ public class PolicyManagerServlet extends HttpServlet { if(!policyEntityobjects.isEmpty()){ for(Object object : policyEntityobjects){ policyEntity = (PolicyEntity) object; - String groupEntityquery = "from PolicyGroupEntity where policyid = :policyId"; + String groupEntityquery = "from PolicyGroupEntity where policyid ='"+policyEntity.getPolicyId()+"'"; SimpleBindings pgeParams = new SimpleBindings(); - pgeParams.put("policyId", policyEntity.getPolicyId()); + //pgeParams.put("policyIdValue", policyEntity.getPolicyId()); List<Object> groupobject = controller.getDataByQuery(groupEntityquery, pgeParams); if(!groupobject.isEmpty()){ pdpCheck = true; @@ -1226,8 +1235,10 @@ public class PolicyManagerServlet extends HttpServlet { //Delete the entity from Policy Entity table controller.deleteData(policyEntity); if(policyNamewithoutExtension.contains("Config_")){ + Files.deleteIfExists(Paths.get(PolicyController.getConfigHome() + File.separator + policyEntity.getConfigurationData().getConfigurationName())); controller.deleteData(policyEntity.getConfigurationData()); }else if(policyNamewithoutExtension.contains("Action_")){ + Files.deleteIfExists(Paths.get(PolicyController.getActionHome() + File.separator + policyEntity.getActionBodyEntity().getActionBodyName())); controller.deleteData(policyEntity.getActionBodyEntity()); } } @@ -1279,8 +1290,10 @@ public class PolicyManagerServlet extends HttpServlet { //Delete the entity from Policy Entity table controller.deleteData(policyEntity); if(policyNamewithoutExtension.contains("Config_")){ + Files.deleteIfExists(Paths.get(PolicyController.getConfigHome() + File.separator + policyEntity.getConfigurationData().getConfigurationName())); controller.deleteData(policyEntity.getConfigurationData()); }else if(policyNamewithoutExtension.contains("Action_")){ + Files.deleteIfExists(Paths.get(PolicyController.getActionHome() + File.separator + policyEntity.getActionBodyEntity().getActionBodyName())); controller.deleteData(policyEntity.getActionBodyEntity()); } @@ -1337,8 +1350,10 @@ public class PolicyManagerServlet extends HttpServlet { controller.deleteData(policyEntity); policyNamewithoutExtension = policyEntity.getPolicyName(); if(policyNamewithoutExtension.contains("Config_")){ + Files.deleteIfExists(Paths.get(PolicyController.getConfigHome() + File.separator + policyEntity.getConfigurationData().getConfigurationName())); controller.deleteData(policyEntity.getConfigurationData()); }else if(policyNamewithoutExtension.contains("Action_")){ + Files.deleteIfExists(Paths.get(PolicyController.getActionHome() + File.separator + policyEntity.getActionBodyEntity().getActionBodyName())); controller.deleteData(policyEntity.getActionBodyEntity()); } } diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyNotificationMail.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyNotificationMail.java index 2326a9fb7..67d9c8813 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyNotificationMail.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyNotificationMail.java @@ -108,6 +108,9 @@ public class PolicyNotificationMail{ } String policyFileName = entityItem.getPolicyName(); String checkPolicyName = policyName; + if(checkPolicyName.endsWith(".xml") || checkPolicyName.contains(".")){ + checkPolicyName = checkPolicyName.substring(0, checkPolicyName.indexOf(".")); + } if(policyFileName.contains("/")){ policyFileName = policyFileName.substring(0, policyFileName.indexOf("/")); policyFileName = policyFileName.replace("/", File.separator); diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java index 08f80304c..f38f3e266 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java @@ -52,8 +52,8 @@ import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.PolicyVersion; import org.onap.policy.utils.PolicyUtils; import org.onap.policy.xacml.api.XACMLErrorConstants; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; -import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.web.support.UserUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -108,7 +108,11 @@ public class PolicyRestController extends RestrictedBaseController{ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); try{ JsonNode root = mapper.readTree(request.getReader()); - + + policyLogger.info("****************************************Logging UserID while Create/Update Policy**************************************************"); + policyLogger.info("UserId: " + userId + "Policy Data Object: "+ root.get(PolicyController.getPolicydata()).get("policy").toString()); + policyLogger.info("***********************************************************************************************************************************"); + PolicyRestAdapter policyData = mapper.readValue(root.get(PolicyController.getPolicydata()).get("policy").toString(), PolicyRestAdapter.class); if("file".equals(root.get(PolicyController.getPolicydata()).get(modal).get("type").toString().replace("\"", ""))){ @@ -204,9 +208,13 @@ public class PolicyRestController extends RestrictedBaseController{ HttpEntity<?> requestEntity = new HttpEntity<>(body, headers); ResponseEntity<?> result = null; HttpClientErrorException exception = null; - + String uri = requestURI; + if(uri.startsWith("/")){ + uri = uri.substring(uri.indexOf('/')+1); + } + uri = "onap" + uri.substring(uri.indexOf('/')); try{ - result = restTemplate.exchange(papUrl + requestURI, method, requestEntity, String.class); + result = restTemplate.exchange(papUrl + uri, method, requestEntity, String.class); }catch(Exception e){ policyLogger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while connecting to " + papUrl, e); exception = new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); @@ -378,11 +386,21 @@ public class PolicyRestController extends RestrictedBaseController{ @RequestMapping(value={"/saveDictionary/*/*"}, method={RequestMethod.POST}) public ModelAndView saveDictionaryController(HttpServletRequest request, HttpServletResponse response) throws IOException{ + String userId = ""; String uri = request.getRequestURI().replace("/saveDictionary", ""); + if(uri.startsWith("/")){ + uri = uri.substring(uri.indexOf('/')+1); + } + uri = "/onap" + uri.substring(uri.indexOf('/')); if(uri.contains(importDictionary)){ - String userId = UserUtils.getUserSession(request).getOrgUserId(); + userId = UserUtils.getUserSession(request).getOrgUserId(); uri = uri+ "?userId=" +userId; } + + policyLogger.info("****************************************Logging UserID while Saving Dictionary*****************************************************"); + policyLogger.info("UserId: " + userId); + policyLogger.info("***********************************************************************************************************************************"); + String body = callPAP(request, "POST", uri.replaceFirst("/", "").trim()); response.getWriter().write(body); return null; @@ -391,6 +409,16 @@ public class PolicyRestController extends RestrictedBaseController{ @RequestMapping(value={"/deleteDictionary/*/*"}, method={RequestMethod.POST}) public ModelAndView deletetDictionaryController(HttpServletRequest request, HttpServletResponse response) throws IOException { String uri = request.getRequestURI().replace("/deleteDictionary", ""); + if(uri.startsWith("/")){ + uri = uri.substring(uri.indexOf('/')+1); + } + uri = "/onap" + uri.substring(uri.indexOf('/')); + + String userId = UserUtils.getUserSession(request).getOrgUserId(); + policyLogger.info("****************************************Logging UserID while Deleting Dictionary*****************************************************"); + policyLogger.info("UserId: " + userId); + policyLogger.info("*************************************************************************************************************************************"); + String body = callPAP(request, "POST", uri.replaceFirst("/", "").trim()); response.getWriter().write(body); return null; @@ -400,6 +428,10 @@ public class PolicyRestController extends RestrictedBaseController{ public ModelAndView searchDictionaryController(HttpServletRequest request, HttpServletResponse response) throws IOException { Object resultList = null; String uri = request.getRequestURI(); + if(uri.startsWith("/")){ + uri = uri.substring(uri.indexOf('/')+1); + } + uri = "/onap" + uri.substring(uri.indexOf('/')); try{ String body = callPAP(request, "POST", uri.replaceFirst("/", "").trim()); if(body.contains("CouldNotConnectException")){ @@ -429,6 +461,10 @@ public class PolicyRestController extends RestrictedBaseController{ public ModelAndView searchPolicy(HttpServletRequest request, HttpServletResponse response) throws IOException{ Object resultList = null; String uri = request.getRequestURI()+"?action=search"; + if(uri.startsWith("/")){ + uri = uri.substring(uri.indexOf('/')+1); + } + uri = "/onap" + uri.substring(uri.indexOf('/')); String body = callPAP(request, "POST", uri.replaceFirst("/", "").trim()); JSONObject json = new JSONObject(body); diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyUserInfoController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyUserInfoController.java index 5020662c8..96205c5b1 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyUserInfoController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyUserInfoController.java @@ -28,9 +28,9 @@ import javax.servlet.http.HttpServletResponse; import org.json.JSONObject; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; -import org.openecomp.portalsdk.core.web.support.JsonMessage; -import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.web.support.JsonMessage; +import org.onap.portalsdk.core.web.support.UserUtils; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ActionPolicyController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ActionPolicyController.java index c8b7a9630..0f66a45e6 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ActionPolicyController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ActionPolicyController.java @@ -29,9 +29,11 @@ import java.util.Map; import javax.xml.bind.JAXBElement; +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.rest.adapter.PolicyRestAdapter; import org.onap.policy.rest.jpa.PolicyEntity; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.controller.RestrictedBaseController; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -48,8 +50,6 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionsType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; -import org.onap.policy.common.logging.flexlogger.FlexLogger; -import org.onap.policy.common.logging.flexlogger.Logger; @Controller @RequestMapping({ "/" }) diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AdminTabController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AdminTabController.java index 3b88f8472..1a43c7646 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AdminTabController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AdminTabController.java @@ -34,8 +34,9 @@ import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.GlobalRoleSettings; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; -import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.web.support.JsonMessage; +import org.onap.portalsdk.core.web.support.UserUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -91,6 +92,10 @@ public class AdminTabController extends RestrictedBaseController{ try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + String userId = UserUtils.getUserSession(request).getOrgUserId(); + LOGGER.info("****************************************Logging UserID for Application Lockdown Function*****************************************"); + LOGGER.info("UserId: " + userId); + LOGGER.info("*********************************************************************************************************************************"); JsonNode root = mapper.readTree(request.getReader()); GlobalRoleSettings globalRole = mapper.readValue(root.get("lockdowndata").toString(), GlobalRoleSettings.class); globalRole.setRole("super-admin"); diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java index c1468e365..d308e7eda 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java @@ -47,6 +47,7 @@ import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.model.PDPGroupContainer; import org.onap.policy.model.PDPPolicyContainer; +import org.onap.policy.model.Roles; import org.onap.policy.rest.adapter.AutoPushTabAdapter; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.PolicyEntity; @@ -55,10 +56,9 @@ import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.api.pap.OnapPDPGroup; import org.onap.policy.xacml.std.pap.StdPDPGroup; import org.onap.policy.xacml.std.pap.StdPDPPolicy; -import org.openecomp.policy.model.Roles; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; -import org.openecomp.portalsdk.core.web.support.JsonMessage; -import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.web.support.JsonMessage; +import org.onap.portalsdk.core.web.support.UserUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -187,6 +187,12 @@ public class AutoPushController extends RestrictedBaseController{ this.container = new PDPGroupContainer(controller.getPapEngine()); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); + + String userId = UserUtils.getUserSession(request).getOrgUserId(); + logger.info("****************************************Logging UserID while Pushing Policy to PDP Group*****************************************"); + logger.info("UserId: " + userId + "Push Policy Data: "+ root.get("pushTabData").toString()); + logger.info("***********************************************************************************************************************************"); + AutoPushTabAdapter adapter = mapper.readValue(root.get("pushTabData").toString(), AutoPushTabAdapter.class); for (Object pdpGroupId : adapter.getPdpDatas()) { LinkedHashMap<?, ?> selectedPDP = (LinkedHashMap<?, ?>)pdpGroupId; @@ -344,6 +350,12 @@ public class AutoPushController extends RestrictedBaseController{ JsonNode root = mapper.readTree(request.getReader()); StdPDPGroup group = (StdPDPGroup)mapper.readValue(root.get("activePdpGroup").toString(), StdPDPGroup.class); JsonNode removePolicyData = root.get("data"); + + String userId = UserUtils.getUserSession(request).getOrgUserId(); + logger.info("****************************************Logging UserID while Removing Policy from PDP Group*****************************************"); + logger.info("UserId: " + userId + "PDP Group Data: "+ root.get("activePdpGroup").toString() + "Remove Policy Data: "+root.get("data")); + logger.info("***********************************************************************************************************************************"); + policyContainer = new PDPPolicyContainer(group); if(removePolicyData.size() > 0){ for(int i = 0 ; i < removePolicyData.size(); i++){ diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java index 4dc45425a..33c58837e 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java @@ -44,7 +44,7 @@ import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.BRMSParamTemplate; import org.onap.policy.rest.jpa.PolicyEntity; import org.onap.policy.xacml.api.XACMLErrorConstants; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.controller.RestrictedBaseController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopFaultController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopFaultController.java index 7a8212c7e..839a79f29 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopFaultController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopFaultController.java @@ -39,7 +39,7 @@ import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.OnapName; import org.onap.policy.rest.jpa.PolicyEntity; import org.onap.policy.rest.jpa.VarbindDictionary; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.controller.RestrictedBaseController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java index 43b62b0c0..7d2fe23c6 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java @@ -73,7 +73,6 @@ import org.json.JSONArray; import org.json.JSONObject; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; -import org.onap.policy.controller.PolicyController; import org.onap.policy.rest.XACMLRestProperties; import org.onap.policy.rest.adapter.PolicyRestAdapter; import org.onap.policy.rest.dao.CommonClassDao; @@ -83,8 +82,8 @@ import org.onap.policy.rest.jpa.PolicyEntity; import org.onap.policy.rest.util.MSAttributeObject; import org.onap.policy.rest.util.MSModelUtils; import org.onap.policy.rest.util.MSModelUtils.MODEL_TYPE; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; -import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.web.support.JsonMessage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -141,6 +140,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { Set<String> uniqueDataKeys= new HashSet<>(); StringBuilder dataListBuffer=new StringBuilder(); List<String> dataConstraints= new ArrayList <>(); + Set<String> allManyTrueKeys= new HashSet <>(); public static final String DATATYPE = "data_types.policy.data."; public static final String PROPERTIES=".properties."; @@ -991,11 +991,13 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { MicroServiceModels returnModel = getAttributeObject(servicename, version); - //get all keys with "MANY-true" defined in their value from subAttribute + //Get all keys with "MANY-true" defined in their value from subAttribute Set<String> allkeys = null; if(returnModel.getSub_attributes() != null && !returnModel.getSub_attributes().isEmpty()){ - JSONObject json = new JSONObject(returnModel.getSub_attributes()); - allkeys = getAllKeys(json); + JSONObject json = new JSONObject(returnModel.getSub_attributes()); + getAllKeys(json); + allkeys = allManyTrueKeys; + allManyTrueKeys = new HashSet <>(); LOGGER.info("allkeys : " + allkeys); } @@ -1044,7 +1046,12 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { List<Object> list = new ArrayList<>(); PrintWriter out = response.getWriter(); String responseString = mapper.writeValueAsString(returnModel); - JSONObject j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + ",allManyTrueKeys: " + allManyTrueKeys+ "}"); + JSONObject j = null; + if("".equals(allManyTrueKeys)){ + j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + "}"); + }else{ + j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + ",allManyTrueKeys: " + allManyTrueKeys+ "}"); + } list.add(j); out.write(list.toString()); return null; @@ -1153,19 +1160,6 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { return object; } - //call this method to check if the key is in the many-true key set - private boolean isKeyFound(Set<String> allManyTruekeys, String key){ - - if(allManyTruekeys != null && key != null){ - Iterator<String> iter = allManyTruekeys.iterator(); - while(iter.hasNext()){ - if(key.equals(iter.next())){ - return true; - } - } - } - return false; - } public static JSONObject convertToArrayElement(JSONObject json, String keyValue) { return convertToArrayElement(json, new HashSet<>(), keyValue); @@ -1239,7 +1233,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { if(obj instanceof String && ((String) obj).contains("MANY-true")){ LOGGER.info("key : " + key); LOGGER.info("obj : " + obj); - keys.addAll(json.keySet()); + allManyTrueKeys.add(key); } if (obj instanceof JSONObject) keys.addAll(getAllKeys(json.getJSONObject(key))); if (obj instanceof JSONArray) keys.addAll(getAllKeys(json.getJSONArray(key))); @@ -1579,23 +1573,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { } } - - if(!errorMsg.isEmpty()){ - - PrintWriter out = response.getWriter(); - - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); - - ObjectMapper mapper = new ObjectMapper(); - JSONObject j = new JSONObject(); - j.put("errorMsg", errorMsg); - out.write(j.toString()); - return; - } - - List<File> fileList = new ArrayList<>();; + List<File> fileList = new ArrayList<>(); this.directory = "model"; if (zip){ extractFolder(this.newFile); diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java index 9832f5803..a4b758924 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java @@ -39,6 +39,7 @@ import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.rest.adapter.AddressGroupJson; import org.onap.policy.rest.adapter.AddressJson; import org.onap.policy.rest.adapter.AddressMembers; +import org.onap.policy.rest.adapter.AddressMembersJson; import org.onap.policy.rest.adapter.DeployNowJson; import org.onap.policy.rest.adapter.IdMap; import org.onap.policy.rest.adapter.PolicyRestAdapter; @@ -62,12 +63,15 @@ import org.onap.policy.rest.jpa.SecurityZone; import org.onap.policy.rest.jpa.ServiceList; import org.onap.policy.rest.jpa.TermList; import org.onap.policy.xacml.api.XACMLErrorConstants; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.controller.RestrictedBaseController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; +import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; @@ -84,6 +88,8 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; @RequestMapping("/") public class CreateFirewallController extends RestrictedBaseController { private static Logger policyLogger = FlexLogger.getLogger(CreateFirewallController.class); + private static final String ANY="ANY"; + private static final String GROUP="Group_"; @Autowired SessionFactory sessionFactory; @@ -99,7 +105,7 @@ public class CreateFirewallController extends RestrictedBaseController { } private List<String> tagCollectorList; - private String jsonBody; + List<String> expandablePrefixIPList = new ArrayList<>(); List<String> expandableServicesList= new ArrayList<>(); @Autowired @@ -109,14 +115,14 @@ public class CreateFirewallController extends RestrictedBaseController { public CreateFirewallController(){} private List<String> termCollectorList; - private ArrayList<Object> attributeList; + public PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter policyData){ - - termCollectorList = new ArrayList<>(); - tagCollectorList = new ArrayList<>(); - if(!policyData.getAttributes().isEmpty()){ + String jsonBody=""; + termCollectorList = new ArrayList <>(); + tagCollectorList = new ArrayList <>(); + if(policyData.getAttributes().size() > 0){ for(Object attribute : policyData.getAttributes()){ if(attribute instanceof LinkedHashMap<?, ?>){ String key = ((LinkedHashMap<?, ?>) attribute).get("key").toString(); @@ -139,14 +145,16 @@ public class CreateFirewallController extends RestrictedBaseController { } private List<String> mapping(String expandableList) { + String value = null; + String desc = null; List <String> valueDesc= new ArrayList<>(); List<Object> prefixListData = commonClassDao.getData(PrefixList.class); for (int i = 0; i< prefixListData.size(); i++) { PrefixList prefixList = (PrefixList) prefixListData.get(i); if (prefixList.getPrefixListName().equals(expandableList)) { - String value = prefixList.getPrefixListValue(); + value = prefixList.getPrefixListValue(); valueDesc.add(value); - String desc= prefixList.getDescription(); + desc= prefixList.getDescription(); valueDesc.add(desc); break; } @@ -193,6 +201,7 @@ public class CreateFirewallController extends RestrictedBaseController { } public void prePopulateFWPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) { + ArrayList<Object> attributeList; attributeList = new ArrayList<>(); if (policyAdapter.getPolicyData() instanceof PolicyType) { Object policyData = policyAdapter.getPolicyData(); @@ -221,7 +230,7 @@ public class CreateFirewallController extends RestrictedBaseController { String data=null; SecurityZone jpaSecurityZone; data = entity.getConfigurationData().getConfigBody(); - tc1 = (TermCollector)mapper.readValue(data, TermCollector.class); + tc1 = mapper.readValue(data, TermCollector.class); List<Object> securityZoneData = commonClassDao.getData(SecurityZone.class); for (int i = 0; i < securityZoneData.size() ; i++) { jpaSecurityZone = (SecurityZone) securityZoneData.get(i); @@ -238,7 +247,7 @@ public class CreateFirewallController extends RestrictedBaseController { Map<String, String> termTagMap=null; if(tc1 != null){ for(int i=0;i<tc1.getFirewallRuleList().size();i++){ - termTagMap = new HashMap<String, String>(); + termTagMap = new HashMap <>(); String ruleName= tc1.getFirewallRuleList().get(i).getRuleName(); String tagPickerName=tc1.getRuleToTag().get(i).getTagPickerName(); termTagMap.put("key", ruleName); @@ -277,16 +286,16 @@ public class CreateFirewallController extends RestrictedBaseController { String value = (String) attributeValue.getContent().get(0); AttributeDesignatorType designator = match.getAttributeDesignator(); String attributeId = designator.getAttributeId(); - if (attributeId.equals("ConfigName")) { + if (("ConfigName").equals(attributeId)) { policyAdapter.setConfigName(value); } - if (attributeId.equals("RiskType")){ + if (("RiskType").equals(attributeId)){ policyAdapter.setRiskType(value); } - if (attributeId.equals("RiskLevel")){ + if (("RiskLevel").equals(attributeId)){ policyAdapter.setRiskLevel(value); } - if (attributeId.equals("guard")){ + if (("guard").equals(attributeId)){ policyAdapter.setGuard(value); } if (attributeId.equals("TTLDate") && !value.contains("NA")){ @@ -305,14 +314,14 @@ public class CreateFirewallController extends RestrictedBaseController { } @RequestMapping(value={"/policyController/ViewFWPolicyRule.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public void setFWViewRule(HttpServletRequest request, HttpServletResponse response){ + public ModelAndView setFWViewRule(HttpServletRequest request, HttpServletResponse response){ try { termCollectorList = new ArrayList<>(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); - PolicyRestAdapter policyData = (PolicyRestAdapter)mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); - if(!policyData.getAttributes().isEmpty()){ + PolicyRestAdapter policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class); + if(policyData.getAttributes().size() > 0){ for(Object attribute : policyData.getAttributes()){ if(attribute instanceof LinkedHashMap<?, ?>){ String key = ((LinkedHashMap<?, ?>) attribute).get("key").toString(); @@ -332,13 +341,13 @@ public class CreateFirewallController extends RestrictedBaseController { List<Object> tmList = commonClassDao.getDataById(TermList.class, "termName", id); jpaTermList = (TermList) tmList.get(0); if (jpaTermList != null){ - ruleSrcList= ((TermList) jpaTermList).getSrcIPList(); + ruleSrcList= jpaTermList.getSrcIPList(); if ((ruleSrcList!= null) && (!ruleSrcList.isEmpty()) && !ruleSrcList.equals("null")){ - displayString.append("Source IP List: " + ((TermList) jpaTermList).getSrcIPList()); + displayString.append("Source IP List: " + jpaTermList.getSrcIPList()); displayString.append(" ; \t\n"); for(String srcList:ruleSrcList.split(",")){ - if(srcList.startsWith("Group_")){ - AddressGroup ag= new AddressGroup(); + if(srcList.startsWith(GROUP)){ + AddressGroup ag; ag= mappingAddressGroup(srcList); displayString.append("\n\t"+"Group has :"+ag.getPrefixList()+"\n"); for(String groupItems:ag.getPrefixList().split(",")){ @@ -351,7 +360,7 @@ public class CreateFirewallController extends RestrictedBaseController { displayString.append("\n"); } }else{ - if(!srcList.equals("ANY")){ + if(!srcList.equals(ANY)){ valueDesc=mapping(srcList); displayString.append("\n\t"+"Name: "+srcList); displayString.append("\n\t"+"Description: "+valueDesc.get(1)); @@ -362,13 +371,13 @@ public class CreateFirewallController extends RestrictedBaseController { } displayString.append("\n"); } - ruleDestList= ((TermList) jpaTermList).getDestIPList(); + ruleDestList= jpaTermList.getDestIPList(); if ( ruleDestList!= null && (!ruleDestList.isEmpty())&& !ruleDestList.equals("null")){ - displayString.append("Destination IP List: " + ((TermList) jpaTermList).getDestIPList()); + displayString.append("Destination IP List: " + jpaTermList.getDestIPList()); displayString.append(" ; \t\n"); for(String destList:ruleDestList.split(",")){ - if(destList.startsWith("Group_")){ - AddressGroup ag= new AddressGroup(); + if(destList.startsWith(GROUP)){ + AddressGroup ag; ag= mappingAddressGroup(destList); displayString.append("\n\t"+"Group has :"+ag.getPrefixList()+"\n"); for(String groupItems:ag.getPrefixList().split(",")){ @@ -379,7 +388,7 @@ public class CreateFirewallController extends RestrictedBaseController { displayString.append("\n\t"); } }else{ - if(!destList.equals("ANY")){ + if(!destList.equals(ANY)){ valueDesc=mapping(destList); displayString.append("\n\t"+"Name: "+destList); displayString.append("\n\t"+"Description: "+valueDesc.get(1)); @@ -391,25 +400,25 @@ public class CreateFirewallController extends RestrictedBaseController { displayString.append("\n"); } - ruleSrcPort=((TermList) jpaTermList).getSrcPortList(); + ruleSrcPort=jpaTermList.getSrcPortList(); if ( ruleSrcPort!= null && (!ruleSrcPort.isEmpty())&& !ruleSrcPort.equals("null")) { displayString.append("\n"+"Source Port List:" + ruleSrcPort); displayString.append(" ; \t\n"); } - ruleDestPort= ((TermList) jpaTermList).getDestPortList(); + ruleDestPort= jpaTermList.getDestPortList(); if (ruleDestPort != null && (!ruleDestPort.isEmpty())&& !ruleDestPort.equals("null")) { displayString.append("\n"+"Destination Port List:" + ruleDestPort); displayString.append(" ; \t\n"); for(String destServices:ruleDestPort.split(",")){ - if(destServices.startsWith("Group_")){ - GroupServiceList sg= new GroupServiceList(); + if(destServices.startsWith(GROUP)){ + GroupServiceList sg; sg= mappingServiceGroup(destServices); displayString.append("\n\t"+"Service Group has :"+sg.getServiceList()+"\n"); for(String groupItems:sg.getServiceList().split(",")){ - ServiceList sl= new ServiceList(); + ServiceList sl; sl= mappingServiceList(groupItems); displayString.append("\n\t"+"Name: "+ sl.getServiceName()); @@ -423,8 +432,8 @@ public class CreateFirewallController extends RestrictedBaseController { } } else{ - if(!destServices.equals("ANY")){ - ServiceList sl= new ServiceList(); + if(!destServices.equals(ANY)){ + ServiceList sl; sl= mappingServiceList(destServices); displayString.append("\n\t"+"Name: "+ sl.getServiceName()); @@ -438,7 +447,7 @@ public class CreateFirewallController extends RestrictedBaseController { } } } - displayString.append("\n"); + displayString.append("\n"); } ruleAction=(jpaTermList).getAction(); @@ -457,9 +466,11 @@ public class CreateFirewallController extends RestrictedBaseController { String responseString = mapper.writeValueAsString(displayString); JSONObject j = new JSONObject("{policyData: " + responseString + "}"); out.write(j.toString()); + return null; } catch (Exception e) { policyLogger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } + return null; } private String constructJson(PolicyRestAdapter policyData) { @@ -497,6 +508,7 @@ public class CreateFirewallController extends RestrictedBaseController { TagDefines tagDefine= new TagDefines(); List<TagDefines> tagList=null; ServiceListJson targetSl=null; + AddressMembers addressMembersJson=null; int i=0; try{ String networkRole=""; @@ -509,7 +521,7 @@ public class CreateFirewallController extends RestrictedBaseController { String tagValues=jpaTagPickerList.getTagValues(); tagList= new ArrayList<>(); for(String val:tagValues.split("#")) { - int index=val.indexOf(":"); + int index=val.indexOf(':'); String keyToStore=val.substring(0,index); String valueToStore=val.substring(index+1,val.length()); @@ -626,12 +638,12 @@ public class CreateFirewallController extends RestrictedBaseController { for(String destServices:destPort_map.get(tl).split(",") ){ ServicesJson destServicesJson= new ServicesJson(); destServicesJson.setType("REFERENCE"); - if(destServices.equals("ANY")){ + if(destServices.equals(ANY)){ destServicesJson.setName("any"); destServicesJsonList.add(destServicesJson); break; }else{ - if(destServices.startsWith("Group_")){ + if(destServices.startsWith(GROUP)){ destServicesJson.setName(destServices.substring(6,destServices.length())); } else{ destServicesJson.setName(destServices); @@ -656,13 +668,13 @@ public class CreateFirewallController extends RestrictedBaseController { List<AddressJson> sourceListArrayJson= new ArrayList<>(); for(String srcList:srcIP_map.get(tl).split(",") ){ AddressJson srcListJson= new AddressJson(); - if(srcList.equals("ANY")){ + if(srcList.equals(ANY)){ srcListJson.setType("any"); sourceListArrayJson.add(srcListJson); break; }else{ srcListJson.setType("REFERENCE"); - if(srcList.startsWith("Group_")){ + if(srcList.startsWith(GROUP)){ srcListJson.setName(srcList.substring(6,srcList.length())); }else{ srcListJson.setName(srcList); @@ -677,13 +689,13 @@ public class CreateFirewallController extends RestrictedBaseController { List<AddressJson> destListArrayJson= new ArrayList<>(); for(String destList:destIP_map.get(tl).split(",")){ AddressJson destListJson= new AddressJson(); - if(destList.equals("ANY")){ + if(destList.equals(ANY)){ destListJson.setType("any"); destListArrayJson.add(destListJson); break; }else{ destListJson.setType("REFERENCE"); - if(destList.startsWith("Group_")){ + if(destList.startsWith(GROUP)){ destListJson.setName(destList.substring(6,destList.length())); }else{ destListJson.setName(destList); @@ -707,7 +719,7 @@ public class CreateFirewallController extends RestrictedBaseController { expandablePrefixIPList.add(destIP_map.get(tl)); } termList.add(targetTerm); - targetTerm.setPosition("" + (ruleCount++)); + targetTerm.setPosition(Integer.toString (ruleCount++)); } List<Object> securityZoneData = commonClassDao.getData(SecurityZone.class); @@ -719,7 +731,7 @@ public class CreateFirewallController extends RestrictedBaseController { idMapInstance.setAstraId(jpaSecurityZone.getZoneValue()); idMapInstance.setVendorId("deviceGroup:dev"); - List<IdMap> idMap = new ArrayList<IdMap>(); + List<IdMap> idMap = new ArrayList <>(); idMap.add(idMapInstance); VendorSpecificData vendorStructure= new VendorSpecificData(); @@ -741,6 +753,7 @@ public class CreateFirewallController extends RestrictedBaseController { Set<ServiceListJson> servListArray = new HashSet<>(); Set<ServiceGroupJson> servGroupArray= new HashSet<>(); Set<AddressGroupJson> addrGroupArray= new HashSet<>(); + Set<AddressMembers> addrArray= new HashSet<> (); ServiceGroupJson targetSg= null; AddressGroupJson addressSg=null; @@ -750,9 +763,9 @@ public class CreateFirewallController extends RestrictedBaseController { for(String serviceList:expandableServicesList){ for(String t: serviceList.split(",")){ - if((!t.startsWith("Group_"))){ - if(!t.equals("ANY")){ - ServiceList sl = new ServiceList(); + if((!t.startsWith(GROUP))){ + if(!t.equals(ANY)){ + ServiceList sl; targetSl= new ServiceListJson(); sl= mappingServiceList(t); targetSl.setName(sl.getServiceName()); @@ -789,7 +802,7 @@ public class CreateFirewallController extends RestrictedBaseController { servListArray.add(targetAnyUdp); } }else{//This is a group - GroupServiceList sg= new GroupServiceList(); + GroupServiceList sg; targetSg= new ServiceGroupJson(); sg= mappingServiceGroup(t); @@ -804,7 +817,7 @@ public class CreateFirewallController extends RestrictedBaseController { serviceMembers.setName(groupString); servMembersList.add(serviceMembers); //Expand the group Name - ServiceList expandGroupSl = new ServiceList(); + ServiceList expandGroupSl ; targetSl= new ServiceListJson(); expandGroupSl= mappingServiceList(groupString); @@ -826,10 +839,10 @@ public class CreateFirewallController extends RestrictedBaseController { Set<PrefixIPList> prefixIPList = new HashSet<>(); for(String prefixList:expandablePrefixIPList){ for(String prefixIP: prefixList.split(",")){ - if((!prefixIP.startsWith("Group_"))){ - if(!prefixIP.equals("ANY")){ + if((!prefixIP.startsWith(GROUP))){ + if(!prefixIP.equals(ANY)){ List<AddressMembers> addMembersList= new ArrayList<>(); - List<String> valueDesc= new ArrayList<>(); + List<String> valueDesc; PrefixIPList targetAddressList = new PrefixIPList(); AddressMembers addressMembers= new AddressMembers(); targetAddressList.setName(prefixIP); @@ -853,31 +866,37 @@ public class CreateFirewallController extends RestrictedBaseController { } } else{//This is a group - AddressGroup ag= new AddressGroup(); + AddressGroup ag; addressSg= new AddressGroupJson(); ag= mappingAddressGroup(prefixIP); String name=ag.getGroupName(); //Removing the "Group_" prepending string before packing the JSON addressSg.setName(name.substring(6,name.length())); - - List<AddressMembers> addrMembersList= new ArrayList<>(); + + List<AddressMembersJson> addrMembersList= new ArrayList<>(); for(String groupString: ag.getPrefixList().split(",")){ - List<String> valueDesc= new ArrayList<>(); - AddressMembers addressMembers= new AddressMembers(); - valueDesc= mapping (groupString); - if(valueDesc.size() > 0){ - addressMembers.setValue(valueDesc.get(0)); - } - addressMembers.setType("SUBNET"); + List<String> valueDesc; + AddressMembersJson addressMembers= new AddressMembersJson(); + addressMembers.setType("REFERENCES"); + addressMembers.setName(groupString); addrMembersList.add(addressMembers); //Expand the group Name + PrefixIPList expandGroupPrefix; + addressMembersJson= new AddressMembers(); + valueDesc= mapping (groupString); + + addressMembersJson.setName(groupString); + addressMembersJson.setType("SUBNET"); + addressMembersJson.setValue(valueDesc.get(0)); + + addrArray.add(addressMembersJson); + } addressSg.setMembers(addrMembersList); addrGroupArray.add(addressSg); } - } } @@ -900,6 +919,11 @@ public class CreateFirewallController extends RestrictedBaseController { for(Object addObj1:addrGroupArray){ addressGroup.add(addObj1); } + + for(Object addObj2:addrArray){ + addressGroup.add(addObj2); + } + tc.setServiceGroups(serviceGroup); tc.setAddressGroups(addressGroup); @@ -908,8 +932,10 @@ public class CreateFirewallController extends RestrictedBaseController { ObjectWriter om = new ObjectMapper().writer(); try { json = om.writeValueAsString(tc); - } catch (Exception e) { - policyLogger.error("Exception Occured"+e); + } catch (JsonGenerationException e) { + policyLogger.error("JsonGenerationException Ocured",e); + } catch (JsonMappingException e) { + policyLogger.error("IOException Occured",e); } }catch (Exception e) { diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreatePolicyController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreatePolicyController.java index 71d0b3d03..af4f9ffaf 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreatePolicyController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreatePolicyController.java @@ -31,7 +31,7 @@ import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.rest.adapter.PolicyRestAdapter; import org.onap.policy.rest.jpa.PolicyEntity; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.controller.RestrictedBaseController; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DashboardController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DashboardController.java index aedb94301..dba79e1bb 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DashboardController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DashboardController.java @@ -45,29 +45,28 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.json.JSONObject; +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.dao.SystemLogDbDao; import org.onap.policy.model.PDPGroupContainer; import org.onap.policy.rest.XACMLRestProperties; import org.onap.policy.rest.dao.CommonClassDao; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; -import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.onap.policy.xacml.api.XACMLErrorConstants; +import org.onap.policy.xacml.api.pap.OnapPDP; +import org.onap.policy.xacml.api.pap.OnapPDPGroup; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.web.support.JsonMessage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; -import org.onap.policy.common.logging.flexlogger.FlexLogger; -import org.onap.policy.common.logging.flexlogger.Logger; -import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; -import org.onap.policy.xacml.api.XACMLErrorConstants; -import org.onap.policy.xacml.api.pap.OnapPDP; -import org.onap.policy.xacml.api.pap.OnapPDPGroup; - import com.att.research.xacml.api.pap.PAPException; import com.att.research.xacml.api.pap.PDP; import com.att.research.xacml.api.pap.PDPGroup; import com.att.research.xacml.api.pap.PDPPolicy; import com.att.research.xacml.util.XACMLProperties; +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java index fc77c9316..8427797e8 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java @@ -36,7 +36,7 @@ import org.onap.policy.rest.adapter.PolicyRestAdapter; import org.onap.policy.rest.adapter.RainyDayParams; import org.onap.policy.rest.adapter.YAMLParams; import org.onap.policy.rest.jpa.PolicyEntity; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.controller.RestrictedBaseController; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -82,7 +82,7 @@ public class DecisionPolicyController extends RestrictedBaseController { Object policyData = policyAdapter.getPolicyData(); PolicyType policy = (PolicyType) policyData; policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); - String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("_") + 1); + String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf('_') + 1); policyAdapter.setPolicyName(policyNameValue); String description = ""; try{ diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PDPController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PDPController.java index bb06cb3fe..c0344d337 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PDPController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PDPController.java @@ -38,15 +38,15 @@ import org.onap.policy.admin.RESTfulPAPEngine; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.model.PDPGroupContainer; +import org.onap.policy.model.Roles; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.api.pap.OnapPDPGroup; import org.onap.policy.xacml.api.pap.PAPPolicyEngine; import org.onap.policy.xacml.std.pap.StdPDP; import org.onap.policy.xacml.std.pap.StdPDPGroup; -import org.openecomp.policy.model.Roles; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; -import org.openecomp.portalsdk.core.web.support.JsonMessage; -import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.web.support.JsonMessage; +import org.onap.portalsdk.core.web.support.UserUtils; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -195,6 +195,12 @@ public class PDPController extends RestrictedBaseController { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); this.container = new PDPGroupContainer(controller.getPapEngine()); + + String userId = UserUtils.getUserSession(request).getOrgUserId(); + policyLogger.info("****************************************Logging UserID for Save PDP Group Function*****************************************"); + policyLogger.info("UserId: " + userId + "PDP Group Data: "+ root.get("pdpGroupData").toString()); + policyLogger.info("***************************************************************************************************************************"); + StdPDPGroup pdpGroupData = mapper.readValue(root.get("pdpGroupData").toString().replace("groupName", "name"), StdPDPGroup.class); try { if(pdpGroupData.getId() == null){ @@ -241,6 +247,12 @@ public class PDPController extends RestrictedBaseController { JsonNode root = mapper.readTree(request.getReader()); PolicyController controller = getPolicyControllerInstance(); this.container = new PDPGroupContainer(controller.getPapEngine()); + + String userId = UserUtils.getUserSession(request).getOrgUserId(); + policyLogger.info("****************************************Logging UserID for Remove PDP Group Function*****************************************"); + policyLogger.info("UserId: " + userId + "PDP Group Data: "+ root.get("pdpGroupData").toString()); + policyLogger.info("*****************************************************************************************************************************"); + StdPDPGroup pdpGroupData = mapper.readValue(root.get("pdpGroupData").toString(), StdPDPGroup.class); if(pdpGroupData.getName().equals("Default")) { throw new UnsupportedOperationException("You can't remove the Default Group."); @@ -284,6 +296,12 @@ public class PDPController extends RestrictedBaseController { String update = root.get("update").toString(); PdpData pdpGroupData = (PdpData)mapper.readValue(root.get("pdpInGroup").toString(), PdpData.class); StdPDPGroup activeGroupData = mapper.readValue(root.get("activePDP").toString(), StdPDPGroup.class); + + String userId = UserUtils.getUserSession(request).getOrgUserId(); + policyLogger.info("****************************************Logging UserID while Saving pdp in PDP Group*****************************************"); + policyLogger.info("UserId: " + userId + "PDP Group Data: "+ root.get("pdpInGroup").toString() + "Active Group Data: "+ root.get("activePDP").toString()); + policyLogger.info("*******************************************************************************************************************************"); + try { if(update.contains("false")){ @@ -332,6 +350,11 @@ public class PDPController extends RestrictedBaseController { StdPDP deletePdp = mapper.readValue(root.get("data").toString(), StdPDP.class); StdPDPGroup activeGroupData = mapper.readValue(root.get("activePDP").toString(), StdPDPGroup.class); + String userId = UserUtils.getUserSession(request).getOrgUserId(); + policyLogger.info("****************************************Logging UserID while Removing pdp from PDP Group*****************************************"); + policyLogger.info("UserId: " + userId + "Delete PDP Group Data: "+ root.get("data").toString() + "Active Group Data: "+ root.get("activePDP").toString()); + policyLogger.info("***********************************************************************************************************************************"); + this.container.removePDP(deletePdp, activeGroupData); response.setCharacterEncoding("UTF-8"); response.setContentType("application / json"); 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 321dc72d2..d244cf528 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 @@ -43,6 +43,7 @@ import org.onap.policy.admin.RESTfulPAPEngine; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.model.PDPGroupContainer; +import org.onap.policy.model.Roles; import org.onap.policy.rest.XACMLRestProperties; import org.onap.policy.rest.XacmlAdminAuthorization; import org.onap.policy.rest.dao.CommonClassDao; @@ -53,10 +54,9 @@ import org.onap.policy.rest.jpa.PolicyVersion; import org.onap.policy.rest.jpa.UserInfo; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.api.pap.PAPPolicyEngine; -import org.openecomp.policy.model.Roles; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; -import org.openecomp.portalsdk.core.web.support.JsonMessage; -import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.web.support.JsonMessage; +import org.onap.portalsdk.core.web.support.UserUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -203,7 +203,12 @@ public class PolicyController extends RestrictedBaseController { setAutoPushPDPGroup(prop.getProperty("xacml.autopush.pdpGroup")); //Micro Service Properties setMsOnapName(prop.getProperty("xacml.policy.msOnapName")); + if(getMsOnapName() == null){ + setMsOnapName(prop.getProperty("xacml.policy.msEcompName")); + } + policyLogger.info("getMsOnapName => " + getMsOnapName()); setMsPolicyName(prop.getProperty("xacml.policy.msPolicyName")); + policyLogger.info("setMsPolicyName => " + getMsPolicyName()); //WebApp directories setConfigHome(prop.getProperty("xacml.rest.config.webapps") + "Config"); setActionHome(prop.getProperty("xacml.rest.config.webapps") + "Action"); diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyExportAndImportController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyExportAndImportController.java index 856d825bd..78a8c5ad1 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyExportAndImportController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyExportAndImportController.java @@ -49,6 +49,7 @@ import org.apache.poi.ss.usermodel.Workbook; import org.json.JSONObject; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; +import org.onap.policy.model.Roles; import org.onap.policy.rest.adapter.PolicyExportAdapter; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.ActionBodyEntity; @@ -58,9 +59,8 @@ import org.onap.policy.rest.jpa.PolicyEntity; import org.onap.policy.rest.jpa.PolicyVersion; import org.onap.policy.rest.jpa.UserInfo; import org.onap.policy.xacml.api.XACMLErrorConstants; -import org.openecomp.policy.model.Roles; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; -import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.web.support.UserUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java index f987f906d..845b5f5a7 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java @@ -38,8 +38,8 @@ import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.WatchPolicyNotificationTable; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; -import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.web.support.UserUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyRolesController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyRolesController.java index 6f8b3de8e..798a39d4d 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyRolesController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyRolesController.java @@ -37,8 +37,9 @@ import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.PolicyEditorScopes; import org.onap.policy.rest.jpa.PolicyRoles; import org.onap.policy.rest.jpa.UserInfo; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; -import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.web.support.JsonMessage; +import org.onap.portalsdk.core.web.support.UserUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -83,6 +84,7 @@ public class PolicyRolesController extends RestrictedBaseController{ String scopeName = null; ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + String userId = UserUtils.getUserSession(request).getOrgUserId(); JsonNode root = mapper.readTree(request.getReader()); ReadScopes adapter = mapper.readValue(root.get("editRoleData").toString(), ReadScopes.class); for(int i = 0; i < adapter.getScope().size(); i++){ @@ -92,6 +94,9 @@ public class PolicyRolesController extends RestrictedBaseController{ scopeName = scopeName + "," + adapter.getScope().get(i); } } + LOGGER.info("****************************************Logging UserID for Roles Function********************************************************"); + LOGGER.info("UserId: " + userId + "Updating the Scope for following user" + adapter.getLoginId() + "ScopeNames" + adapter.getScope()); + LOGGER.info("*********************************************************************************************************************************"); PolicyRoles roles = new PolicyRoles(); roles.setId(adapter.getId()); roles.setLoginId(adapter.getLoginId()); diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyValidationController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyValidationController.java index a82fac27a..9a1aac1b5 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyValidationController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyValidationController.java @@ -33,8 +33,8 @@ import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.rest.adapter.PolicyRestAdapter; import org.onap.policy.rest.util.PolicyValidation; import org.onap.policy.rest.util.PolicyValidationRequestWrapper; -import org.openecomp.portalsdk.core.controller.RestrictedBaseController; -import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.web.support.JsonMessage; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @@ -63,7 +63,7 @@ public class PolicyValidationController extends RestrictedBaseController { PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper(); StringBuilder responseString; ObjectMapper mapper = new ObjectMapper(); - + PolicyRestAdapter policyData = wrapper.populateRequestParameters(request); responseString = validation.validatePolicy(policyData); diff --git a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/model/Roles.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/model/Roles.java index 31a41ca7b..51e78d0e5 100644 --- a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/model/Roles.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/model/Roles.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.policy.model; +package org.onap.policy.model; import java.io.Serializable; diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java index 22cc82a23..dc2159bc1 100644 --- a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java @@ -40,6 +40,7 @@ import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.controller.CreateDcaeMicroServiceController; import org.onap.policy.controller.PolicyController; +import org.onap.policy.model.Roles; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.ActionBodyEntity; import org.onap.policy.rest.jpa.ConfigurationDataEntity; @@ -48,7 +49,6 @@ import org.onap.policy.rest.jpa.PolicyEditorScopes; import org.onap.policy.rest.jpa.PolicyEntity; import org.onap.policy.rest.jpa.PolicyVersion; import org.onap.policy.rest.jpa.UserInfo; -import org.openecomp.policy.model.Roles; public class PolicyManagerServletTest extends Mockito{ diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyRestControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyRestControllerTest.java index 1bda7cd41..16cefd854 100644 --- a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyRestControllerTest.java +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyRestControllerTest.java @@ -45,8 +45,8 @@ import org.onap.policy.rest.jpa.PrefixList; import org.onap.policy.rest.jpa.SecurityZone; import org.onap.policy.rest.jpa.ServiceList; import org.onap.policy.rest.jpa.TermList; -import org.openecomp.portalsdk.core.domain.User; -import org.openecomp.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.util.SystemProperties; import org.springframework.mock.web.MockHttpServletResponse; public class PolicyRestControllerTest { diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyUserInfoControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyUserInfoControllerTest.java index f4acaeb9a..7a3401568 100644 --- a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyUserInfoControllerTest.java +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyUserInfoControllerTest.java @@ -29,8 +29,8 @@ import javax.servlet.http.HttpSession; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; -import org.openecomp.portalsdk.core.domain.User; -import org.openecomp.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.util.SystemProperties; import org.springframework.mock.web.MockHttpServletResponse; public class PolicyUserInfoControllerTest { diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/AdminTabControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/AdminTabControllerTest.java index 0109cb503..17ad56457 100644 --- a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/AdminTabControllerTest.java +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/AdminTabControllerTest.java @@ -19,7 +19,8 @@ */ package org.onap.policy.controller; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -30,13 +31,17 @@ import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; import org.junit.Before; import org.junit.Test; +import org.mockito.Mockito; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.GlobalRoleSettings; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.util.SystemProperties; import org.springframework.mock.web.MockHttpServletResponse; public class AdminTabControllerTest { @@ -55,6 +60,12 @@ public class AdminTabControllerTest { request = mock(HttpServletRequest.class); response = new MockHttpServletResponse(); + HttpSession mockSession = mock(HttpSession.class); + User user = new User(); + user.setOrgUserId("Test"); + Mockito.when(mockSession.getAttribute(SystemProperties.getProperty("user_attribute_name"))).thenReturn(user); + Mockito.when(request.getSession(false)).thenReturn(mockSession); + AdminTabController.setCommonClassDao(commonClassDao); GlobalRoleSettings globalRole = new GlobalRoleSettings(); diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PDPControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PDPControllerTest.java index 8433c4740..55a2288c7 100644 --- a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PDPControllerTest.java +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PDPControllerTest.java @@ -34,10 +34,10 @@ import org.junit.Test; import org.mockito.Mockito; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; +import org.onap.policy.model.Roles; import org.onap.policy.xacml.api.pap.OnapPDPGroup; import org.onap.policy.xacml.std.pap.StdPDPGroup; import org.onap.policy.xacml.std.pap.StdPDPGroupStatus; -import org.openecomp.policy.model.Roles; import org.springframework.mock.web.MockHttpServletResponse; |