+ private void deletePolicyInScope(String username, GroupEntity groupToUpdateInDB, PDPPolicy pol,
+ String[] scopeAndName) {
+ PolicyEntity policyToDelete;
+ if (scopeAndName == null) {
+ return;
+ }
+ try {
+ policyToDelete = getPolicy(scopeAndName[0], scopeAndName[1]);
+ if ("XACMLPapServlet.doDelete".equals(username)) {
+ Iterator<PolicyEntity> dbPolicyIt = groupToUpdateInDB.getPolicies().iterator();
+ String policyName = getPolicyNameAndVersionFromPolicyFileName(policyToDelete.getPolicyName())[0];
+
+ logger.info("PolicyDBDao: delete policy from GroupEntity");
+ deletePolicyFromGroupEntity(groupToUpdateInDB, policyToDelete, dbPolicyIt, policyName);
+ }
+ } catch (Exception e) {
+ PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, policyDBDaoVar,
+ "Could not get policy to remove: " + pol.getId());
+ throw new PersistenceException("Could not get policy to remove: " + pol.getId());
+ }
+ }
+
+ private void deletePolicyFromGroupEntity(GroupEntity groupToUpdateInDB, PolicyEntity policyToDelete,
+ Iterator<PolicyEntity> dbPolicyIt, String policyName) {
+ try {
+ while (dbPolicyIt.hasNext()) {
+ PolicyEntity dbpolicy = dbPolicyIt.next();
+ if (policyToDelete.getScope().equals(dbpolicy.getScope())
+ && getPolicyNameAndVersionFromPolicyFileName(dbpolicy.getPolicyName())[0]
+ .equals(policyName)) {
+ dbPolicyIt.remove();
+
+ logger.info("PolicyDBDao: deleting policy from the existing group:\n " + "policyName is "
+ + policyToDelete.getScope() + "." + policyToDelete.getPolicyName() + "\n" + "group is "
+ + groupToUpdateInDB.getGroupId());
+ }
+ }
+ } catch (Exception e) {
+ logger.debug(e);
+ PolicyLogger.error("Could not delete policy with name: " + policyToDelete.getScope() + "."
+ + policyToDelete.getPolicyName() + "\n ID: " + policyToDelete.getPolicyId());
+ }
+ }
+