boolean result = true;
for (PapContainer papContainer : PapContainer.getContainers(PapManager.getInstance().getLocalPaps())) {
PolicySetType rootPS;
try {
rootPS = papContainer.getRootPolicySet();
} catch (RepositoryException e) {
String rootAlias = papContainer.getPap().getAlias();
String action = String.format("remove all policies and and policy sets for root policy set %s",
rootAlias);
log.error(String.format("The root policy set %s (id=%s) is corrupted. Suggested action: %s",
rootAlias,
action));
if (repair) {
log.info("Automatic repair is set. Action: " + action);
papContainer.deleteAllPolicies();
papContainer.deleteAllPolicySets();
papContainer.createRootPolicySet();
log.info("Automatic repair successfully completed (deleted root policy set " + rootAlias
+ ")");
} else {
result = false;
}
continue;
}
// check referenced policy sets (the root policy set doesn't have references to
// policies)
for (String policySetId : PolicySetHelper.getPolicySetIdReferencesValues(rootPS)) {
PolicySetType policySet;
try {
policySet = papContainer.getPolicySet(policySetId);
} catch (RepositoryException e) {
String action = String.format("remove policy set %s", policySetId);
log.error(String.format("The policy set \"%s\" is corrupted. Suggested action: %s",
policySetId,
action));
if (repair) {
log.info("Automatic repair is set. Action: " + action);
PolicySetHelper.deletePolicySetReference(rootPS, policySetId);
String version = rootPS.getVersion();
PolicySetWizard.increaseVersion(rootPS);
papContainer.updatePolicySet(version, rootPS);
papContainer.deletePolicySet(policySetId);
log.info("Automatic repair successfully completed (deleted policy set " + policySetId
+ ")");
} else {
result = false;
}
continue;
}
// check referenced policies (non-root policy sets don't have references to policy
// sets)
for (String policyId : PolicySetHelper.getPolicyIdReferencesValues(policySet)) {
try {
papContainer.getPolicy(policyId);
} catch (RepositoryException e) {
String action = String.format("remove policy %s", policyId);
log.error(String.format("The policy \"%s\" is corrupted. Suggested action: %s",
policyId,
action));
if (repair) {
log.info("Automatic repair is set. Action: " + action);
PolicySetHelper.deletePolicyReference(policySet, policyId);
String version = policySet.getVersion();
PolicySetWizard.increaseVersion(policySet);
papContainer.updatePolicySet(version, policySet);
papContainer.deletePolicy(policyId);
log.info("Automatic repair successfully completed (deleted policy " + policyId
+ ")");