import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
protected static void initializeJSONLoad() {
closedLoopJsonLocation = Paths.get(XACMLProperties
.getProperty(XACMLRestProperties.PROP_ADMIN_CLOSEDLOOP));
- FileInputStream inputStream = null;
- JsonReader jsonReader = null;
String location = closedLoopJsonLocation.toString();
- try {
- inputStream = new FileInputStream(location);
- if (location.endsWith("json")) {
- jsonReader = Json.createReader(inputStream);
- policyNames = jsonReader.readArray();
- serviceTypeNamesList = new ArrayList<>();
- for (int i = 0; i < policyNames.size(); i++) {
- javax.json.JsonObject policyName = policyNames.getJsonObject(i);
- String name = policyName.getJsonString("serviceTypePolicyName").getString();
- serviceTypeNamesList.add(name);
- }
+ if (! location.endsWith("json")) {
+ LOGGER.warn("JSONConfig file does not end with extension .json");
+ return;
+ }
+ try (FileInputStream inputStream = new FileInputStream(location);
+ JsonReader jsonReader = Json.createReader(inputStream)) {
+ policyNames = jsonReader.readArray();
+ serviceTypeNamesList = new ArrayList<>();
+ for (int i = 0; i < policyNames.size(); i++) {
+ javax.json.JsonObject policyName = policyNames.getJsonObject(i);
+ String name = policyName.getJsonString("serviceTypePolicyName").getString();
+ serviceTypeNamesList.add(name);
}
- } catch (FileNotFoundException e) {
+ } catch (IOException e) {
LOGGER.error("Exception Occured while initializing the JSONConfig file"+e);
- }finally{
- try {
- if(inputStream != null){
- inputStream.close();
- }
- if(jsonReader != null){
- jsonReader.close();
- }
- } catch (IOException e) {
- LOGGER.error("Exception Occured while closing the File InputStream"+e);
- }
}
}
}
}
- JSONObject responseJsonObject = null;
+ JSONObject responseJsonObject;
responseJsonObject = this.success();
response.setContentType(CONTENTTYPE);
PrintWriter out = response.getWriter();
policyParams.put("newPolicySplit_0", newPolicySplit[0]);
List<Object> queryData = controller.getDataByQuery(policyEntityquery, policyParams);
if(!queryData.isEmpty()){
- entity = (PolicyEntity) queryData.get(0);
return error("Policy rename failed. Since, the policy with same name already exists.");
}
params.put("oldPolicySplit_0", oldPolicySplit[0]);
List<Object> oldEntityData = controller.getDataByQuery(oldpolicyEntityquery, params);
if(!oldEntityData.isEmpty()){
- String groupQuery = "FROM PolicyGroupEntity where (";
+ StringBuilder groupQuery = new StringBuilder();
+ groupQuery.append("FROM PolicyGroupEntity where (");
SimpleBindings geParams = new SimpleBindings();
for(int i=0; i<oldEntityData.size(); i++){
entity = (PolicyEntity) oldEntityData.get(i);
if(i == 0){
- groupQuery = groupQuery + "policyid = :policyId";
+ groupQuery.append("policyid = :policyId");
geParams.put("policyId", entity.getPolicyId());
}else{
- groupQuery = groupQuery + " or policyid = :policyId" + i;
+ groupQuery.append(" or policyid = :policyId" + i);
geParams.put("policyId" + i, entity.getPolicyId());
}
}
- groupQuery = groupQuery + ")";
- List<Object> groupEntityData = controller.getDataByQuery(groupQuery, geParams);
+ groupQuery.append(")");
+ List<Object> groupEntityData = controller.getDataByQuery(groupQuery.toString(), geParams);
if(! groupEntityData.isEmpty()){
return error("Policy rename failed. Since the policy or its version is active in PDP Groups.");
}
String path = params.getString("path");
try{
if(params.has("subScopename")){
- if(!params.getString("subScopename").equals("")){
+ if(! "".equals(params.getString("subScopename"))) {
name = params.getString("path").replace("/", File.separator) + File.separator +params.getString("subScopename");
}
}else{
}
}
LOGGER.debug("addFolder path: {} name: {}" + path +name);
- if(!name.equals("")){
+ if(! "".equals(name)){
if(name.startsWith(File.separator)){
name = name.substring(1);
}