if (!policySetFile.exists()) {
throw new NotFoundException(policySetNotFoundExceptionMsg(policySetId));
}
Map<String, PolicySetTypeString> papCache = getPapCache(papId);
PolicySetTypeString oldPolicySetString = papCache.get(policySetId);
if (oldPolicySetString == null) {
try {
oldPolicySetString = new PolicySetTypeString(policySetHelper.buildFromFile(policySetFile));
log.debug("update(): PolicySet retrieved from file: id=" + policySetId);
} catch (Throwable e) {
throw new RepositoryException(e);
}
} else {
log.debug("update(): PolicySet retrieved from cache: id=" + policySetId);
}
String repositoryVersion = oldPolicySetString.getVersion();
TypeStringUtils.releaseUnneededMemory(oldPolicySetString);
if (!(repositoryVersion.equals(policySetVersion))) {
throw new InvalidVersionException(String.format("Attempting to update the wrong version of PolicySetId=\"%s\" (requestedVersion=\"%s\", repositoryVersion=\"%s\")",
policySetId,
policySetVersion,
repositoryVersion));
}
PolicySetHelper.toFile(policySetFile, newPolicySet);
PolicySetTypeString newPolicySetTypeString = TypeStringUtils.cloneAsPolicySetTypeString(newPolicySet);
papCache.put(policySetId, newPolicySetTypeString);
}