public static final String duplicatePolicyId = "Somehow, more than one policy with the id ";
public static final String foundInDB = " were found in the database";
public static final String duplicatePolicyId = "Somehow, more than one policy with the id ";
public static final String foundInDB = " were found in the database";
for(PDPPolicy policy : policies){
try{
String[] stringArray = getNameScopeAndVersionFromPdpPolicy(policy.getId());
for(PDPPolicy policy : policies){
try{
String[] stringArray = getNameScopeAndVersionFromPdpPolicy(policy.getId());
List<PolicyEntity> policyEntityList;
Query getPolicyEntitiesQuery = em.createNamedQuery("PolicyEntity.findByNameAndScope");
getPolicyEntitiesQuery.setParameter("name", stringArray[0]);
List<PolicyEntity> policyEntityList;
Query getPolicyEntitiesQuery = em.createNamedQuery("PolicyEntity.findByNameAndScope");
getPolicyEntitiesQuery.setParameter("name", stringArray[0]);
private String[] getNameScopeAndVersionFromPdpPolicy(String fileName){
String[] splitByDots = fileName.split("\\.");
if(splitByDots.length < 3){
private String[] getNameScopeAndVersionFromPdpPolicy(String fileName){
String[] splitByDots = fileName.split("\\.");
if(splitByDots.length < 3){
}
String policyName = splitByDots[splitByDots.length-3];
String version = splitByDots[splitByDots.length-2];
}
String policyName = splitByDots[splitByDots.length-3];
String version = splitByDots[splitByDots.length-2];
policyId = policyName;
policyQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.policyName=:name AND p.scope=:scope");
policyQuery.setParameter("name", policyId);
policyId = policyName;
policyQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.policyName=:name AND p.scope=:scope");
policyQuery.setParameter("name", policyId);
configDataString = IOUtils.toString(configContentStream);
} catch (FileNotFoundException e) {
logger.error("Caught FileNotFoundException on new FileInputStream("+configPath+")",e);
throw new IllegalArgumentException("The config file path does not exist");
} catch(IOException e2){
configDataString = IOUtils.toString(configContentStream);
} catch (FileNotFoundException e) {
logger.error("Caught FileNotFoundException on new FileInputStream("+configPath+")",e);
throw new IllegalArgumentException("The config file path does not exist");
} catch(IOException e2){
}
if(configDataString == null){
throw new IllegalArgumentException("The config file path cannot be read");
}
if(configDataString == null){
throw new IllegalArgumentException("The config file path cannot be read");
//we need to convert the form of the policy id that is used groups into the form that is used
//for the database. (com.Config_mypol.1.xml) to (Config_mypol.xml)
//we need to convert the form of the policy id that is used groups into the form that is used
//for the database. (com.Config_mypol.1.xml) to (Config_mypol.xml)
- String[] policyNameScopeAndVersion = getNameScopeAndVersionFromPdpPolicy(policyID);
+ String[] policyNameScopeAndVersion = getNameScopeAndVersionFromPdpPolicy(policyID);
+ if(policyNameScopeAndVersion == null) {
+ throw new IllegalArgumentException("Invalid input - policyID must contain name, scope and version");
+ }
Query policyQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.policyName=:policyName AND p.scope=:scope AND p.deleted=:deleted");
policyQuery.setParameter("policyName", policyNameScopeAndVersion[0]);
policyQuery.setParameter(scope, policyNameScopeAndVersion[1]);
Query policyQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.policyName=:policyName AND p.scope=:scope AND p.deleted=:deleted");
policyQuery.setParameter("policyName", policyNameScopeAndVersion[0]);
policyQuery.setParameter(scope, policyNameScopeAndVersion[1]);