* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import javax.annotation.PostConstruct;
import javax.mail.MessagingException;
+import javax.script.SimpleBindings;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONObject;
import org.onap.policy.admin.PolicyNotificationMail;
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.rest.XACMLRestProperties;
import org.onap.policy.rest.XacmlAdminAuthorization;
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.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.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
-import org.onap.policy.xacml.api.XACMLErrorConstants;
-import org.onap.policy.xacml.api.pap.PAPPolicyEngine;
-
import com.att.research.xacml.util.XACMLProperties;
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.onap.policy.common.logging.flexlogger.FlexLogger;
-import org.onap.policy.common.logging.flexlogger.Logger;
-
@Controller
@RequestMapping("/")
private static final Logger policyLogger = FlexLogger.getLogger(PolicyController.class);
private static CommonClassDao commonClassDao;
-
+
// Our authorization object
//
XacmlAdminAuthorization authorizer = new XacmlAdminAuthorization();
private static final String characterEncoding = "UTF-8";
private static final String contentType = "application/json";
private static final String file = "file";
-
+
//Smtp Java Mail Properties
private static String smtpHost = null;
private static String smtpPort = null;
private static String xacmldbUserName = null;
private static String xacmldbPassword = null;
- //AutoPush feature.
+ //AutoPush feature.
private static String autoPushAvailable;
private static String autoPushDSClosedLoop;
private static String autoPushDSFirewall;
private static String autoPushDSMicroservice;
private static String autoPushPDPGroup;
-
+
//papURL
private static String papUrl;
-
+
//MicroService Model Properties
private static String msOnapName;
private static String msPolicyName;
-
+
//WebApp directories
private static String configHome;
private static String actionHome;
+
+ private static boolean jUnit = false;
+
+
+ public static boolean isjUnit() {
+ return jUnit;
+ }
+
+ public static void setjUnit(boolean jUnit) {
+ PolicyController.jUnit = jUnit;
+ }
@Autowired
private PolicyController(CommonClassDao commonClassDao){
Properties prop = new Properties();
InputStream input = null;
try {
- input = new FileInputStream("xacml.admin.properties");
+ if(jUnit){
+ File file = new File(new File(".").getCanonicalPath() + File.separator + "src"+ File.separator + "test" + File.separator + "resources" + File.separator + "JSONConfig.json");
+ input = new FileInputStream(file);
+ }else{
+ input = new FileInputStream("xacml.admin.properties");
+ }
// load a properties file
prop.load(input);
//pap url
- setPapUrl(prop.getProperty("xacml.rest.pap.url"));
+ setPapUrl(prop.getProperty("xacml.rest.pap.url"));
// get the property values
setSmtpHost(prop.getProperty("onap.smtp.host"));
setSmtpPort(prop.getProperty("onap.smtp.port"));
//WebApp directories
setConfigHome(prop.getProperty("xacml.rest.config.webapps") + "Config");
setActionHome(prop.getProperty("xacml.rest.config.webapps") + "Action");
- //Get the Property Values for Dashboard tab Limit
+ //Get the Property Values for Dashboard tab Limit
try{
setLogTableLimit(prop.getProperty("xacml.onap.dashboard.logTableLimit"));
setSystemAlertTableLimit(prop.getProperty("xacml.onap.dashboard.systemAlertTableLimit"));
}
}
- //Initialize the FunctionDefinition table at Server Start up
+ //Initialize the FunctionDefinition table at Server Start up
Map<Datatype, List<FunctionDefinition>> functionMap = getFunctionDatatypeMap();
for (Datatype id : functionMap.keySet()) {
List<FunctionDefinition> functionDefinations = functionMap.get(id);
}
- public static Map<Datatype, List<FunctionDefinition>> getFunctionDatatypeMap() {
+ public static Map<Datatype, List<FunctionDefinition>> getFunctionDatatypeMap() {
synchronized(mapAccess) {
if (mapDatatype2Function == null) {
buildFunctionMaps();
private static void buildFunctionMaps() {
mapDatatype2Function = new HashMap<>();
- mapID2Function = new HashMap<>();
- List<Object> functiondefinitions = commonClassDao.getData(FunctionDefinition.class);
+ mapID2Function = new HashMap<>();
+ List<Object> functiondefinitions = commonClassDao.getData(FunctionDefinition.class);
for (int i = 0; i < functiondefinitions.size(); i ++) {
FunctionDefinition value = (FunctionDefinition) functiondefinitions.get(i);
mapID2Function.put(value.getXacmlid(), value);
policyLogger.error(XACMLErrorConstants.ERROR_DATA_ISSUE +"Error while retriving the Function Definition data"+e);
}
}
-
+
public PolicyEntity getPolicyEntityData(String scope, String policyName){
String key = scope + ":" + policyName;
List<Object> data = commonClassDao.getDataById(PolicyEntity.class, "scope:policyName", key);
}
}
- //Policy tabs Model and View
- @RequestMapping(value= {"/policy", "/policy/Editor" } , method = RequestMethod.GET)
+ //Policy tabs Model and View
+ @RequestMapping(value= {"/policy", "/policy/Editor" } , method = RequestMethod.GET)
public ModelAndView view(HttpServletRequest request){
String myRequestURL = request.getRequestURL().toString();
try {
//
// Set the URL for the RESTful PAP Engine
- //
+ //
setPapEngine((PAPPolicyEngine) new RESTfulPAPEngine(myRequestURL));
new PDPGroupContainer((PAPPolicyEngine) new RESTfulPAPEngine(myRequestURL));
} catch (Exception e) {
policyLogger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR+"Exception Occured while loading PAP"+e);
- }
+ }
Map<String, Object> model = new HashMap<>();
return new ModelAndView("policy_Editor","model", model);
}
return papEngine;
}
- public void setPapEngine(PAPPolicyEngine papEngine) {
+ public static void setPapEngine(PAPPolicyEngine papEngine) {
PolicyController.papEngine = papEngine;
}
}
public static boolean getActivePolicy(String query) {
- if(commonClassDao.getDataByQuery(query).size() > 0){
+ if(!commonClassDao.getDataByQuery(query, new SimpleBindings()).isEmpty()){
return true;
}else{
return false;
}
public void executeQuery(String query) {
- commonClassDao.updateQuery(query);
+ commonClassDao.updateQuery(query);
}
-
+
public void saveData(Object cloneEntity) {
commonClassDao.save(cloneEntity);
}
public void deleteData(Object entity) {
commonClassDao.delete(entity);
}
-
+
public List<Object> getData(@SuppressWarnings("rawtypes") Class className){
return commonClassDao.getData(className);
}
return (PolicyVersion) commonClassDao.getEntityItem(PolicyVersion.class, "policyName", query);
}
- public List<Object> getDataByQuery(String query){
- return commonClassDao.getDataByQuery(query);
+ public List<Object> getDataByQuery(String query, SimpleBindings params){
+ return commonClassDao.getDataByQuery(query, params);
}
public Object getEntityItem(Class className, String columname, String key){
return commonClassDao.getEntityItem(className, columname, key);
}
-
-
+
+
public void watchPolicyFunction(PolicyVersion entity, String policyName, String mode){
PolicyNotificationMail email = new PolicyNotificationMail();
try {
dbCheckName = dbCheckName.replace(".Decision_", ":Decision_");
}
String[] splitDBCheckName = dbCheckName.split(":");
- String query = "FROM PolicyEntity where policyName like'"+splitDBCheckName[1]+"%' and scope ='"+splitDBCheckName[0]+"'";
- List<Object> policyEntity = commonClassDao.getDataByQuery(query);
+ String query = "FROM PolicyEntity where policyName like :splitDBCheckName1 and scope = :splitDBCheckName0";
+ SimpleBindings params = new SimpleBindings();
+ params.put("splitDBCheckName1", splitDBCheckName[1] + "%");
+ params.put("splitDBCheckName0", splitDBCheckName[0]);
+ List<Object> policyEntity = commonClassDao.getDataByQuery(query, params);
List<String> av = new ArrayList<>();
for(Object entity : policyEntity){
PolicyEntity pEntity = (PolicyEntity) entity;
public static void setSystemAlertTableLimit(String systemAlertTableLimit) {
PolicyController.systemAlertTableLimit = systemAlertTableLimit;
}
-
+
public static CommonClassDao getCommonClassDao() {
return commonClassDao;
}
public static String getFile() {
return file;
}
+
+ public String convertDate(String dateTTL) {
+ String formateDate = null;
+ if(dateTTL.contains("-")){
+ formateDate = dateTTL.replace("-", "/");
+ }
+ return formateDate;
+ }
}
-