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;
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;
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;
if (!item.isFormField()) {
// Process form file field (input type="file").
files.put(item.getName(), item.getInputStream());
- if(item.getName().endsWith(".xls")){
- OutputStream outputStream = null;
- try{
- File file = new File(item.getName());
- outputStream = new FileOutputStream(file);
+ if(item.getName().endsWith(".xls") && item.getSize() <= PolicyController.getFileSizeLimit()){
+ File file = new File(item.getName());
+ try (OutputStream outputStream = new FileOutputStream(file);)
+ {
IOUtils.copy(item.getInputStream(), outputStream);
- outputStream.close();
newFile = file.toString();
PolicyExportAndImportController importController = new PolicyExportAndImportController();
importController.importRepositoryFile(newFile, request);
}catch(Exception e){
LOGGER.error("Upload error : " + e);
- }finally{
- if(outputStream != null){
- outputStream.close();
- }
}
}
+ else if (!item.getName().endsWith(".xls")) {
+ LOGGER.error("Non .xls filetype uploaded: " + item.getName());
+ }
+ else { //uploaded file size is greater than allowed
+ LOGGER.error("Upload file size limit exceeded! File size (Bytes) is: " + item.getSize());
+ }
}
}
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:
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());
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());
entityItem.setPolicyName(policyName);
entityItem.setCreatedBy(userId);
entityItem.setModifiedBy(userId);
+ entityItem.setModifiedDate(new Date());
controller.saveData(entityItem);
}
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;
//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());
}
}
//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());
}
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());
}
}
policyAdapter.setReadOnly(false);
policyAdapter.setEditPolicy(true);
}
- policyAdapter.setDomain(domain);
+
policyAdapter.setDomainDir(domain);
policyAdapter.setPolicyData(policy);
String policyName = path.replace(".xml", "");