@Test void testPrepareIncludeAssertionPolicyInDependentBundle() throws DocumentParseException { String policyPath = "my/policy/path.xml"; Policy policy = new Policy(); policy.setGuid("123-abc-567"); policy.setId("id1"); policy.setName("path.xml"); Bundle dependentBundle = new Bundle(); dependentBundle.getPolicies().put(policyPath, policy); bundle.getDependencies().add(dependentBundle); bundle.getDependencies().add(new Bundle()); Element includeAssertionElement = createIncludeAssertionElement(document, policyPath); document.appendChild(includeAssertionElement); policyBuilderContext = new PolicyBuilderContext("path.xml", document, bundle, new IdGenerator()); policyBuilderContext.withPolicy(policy); policyBuilderContext.withAnnotatedBundle(new AnnotatedBundle(bundle, null, null)); includeAssertionBuilder.buildAssertionElement(includeAssertionElement, policyBuilderContext); Element policyGuidElement = getSingleElement(includeAssertionElement, POLICY_GUID); assertEquals(policy.getGuid(), policyGuidElement.getAttribute(PolicyEntityBuilder.STRING_VALUE)); assertFalse(policyGuidElement.hasAttribute(IncludeAssertionBuilder.POLICY_PATH)); }
@Override public void buildAssertionElement(Element includeAssertionElement, PolicyBuilderContext policyBuilderContext) { final Bundle bundle = policyBuilderContext.getBundle(); final AnnotatedBundle annotatedBundle = policyBuilderContext.getAnnotatedBundle(); final Policy policy = policyBuilderContext.getPolicy(); Element policyGuidElement; try { policyGuidElement = getSingleElement(includeAssertionElement, POLICY_GUID); } catch (DocumentParseException e) { throw new EntityBuilderException("Could not find PolicyGuid element in Include Assertion", e); } final String policyPath = policyGuidElement.getAttribute(POLICY_PATH); LOGGER.log(Level.FINE, "Looking for referenced policy include: {0}", policyPath); final AtomicReference<Policy> includedPolicy; if (annotatedBundle != null) { includedPolicy = new AtomicReference<>(annotatedBundle.getPolicies().get(policyPath)); } else { includedPolicy = new AtomicReference<>(bundle.getPolicies().get(policyPath)); } if (includedPolicy.get() != null) { policy.getDependencies().add(includedPolicy.get()); } else { bundle.getDependencies().forEach(b -> { Policy policyFromDependencies = Optional.ofNullable(b.getPolicies().get(policyPath)).orElse(b.getPolicies().get(PathUtils.extractName(policyPath))); if (policyFromDependencies != null) { if (!includedPolicy.compareAndSet(null, policyFromDependencies)) { throw new EntityBuilderException("Found multiple policies in dependency bundles with policy path: " + policyPath); } DependentBundle dependentBundle = b.getDependentBundleFrom(); if (dependentBundle != null && dependentBundle.getType() != null) { if (annotatedBundle != null) { annotatedBundle.addDependentBundle(dependentBundle); } else { bundle.addDependentBundle(dependentBundle); } } } }); final MissingGatewayEntity missingEntity = bundle.getMissingEntities().get(policyPath); if (missingEntity != null && missingEntity.isExcluded()) { LOGGER.log(Level.WARNING, "Resolving the referenced policy {0} as known excluded entity with guid: {1}", new Object[]{policyPath, missingEntity.getGuid()}); includedPolicy.set(new Policy()); includedPolicy.get().setGuid(missingEntity.getGuid()); } } if (includedPolicy.get() == null) { throw new EntityBuilderException("Could not find referenced policy include with path: " + policyPath); } policyGuidElement.setAttribute(STRING_VALUE, includedPolicy.get().getGuid()); policyGuidElement.removeAttribute(POLICY_PATH); }
IncludeAssertionBuilder implements PolicyAssertionBuilder { @Override public void buildAssertionElement(Element includeAssertionElement, PolicyBuilderContext policyBuilderContext) { final Bundle bundle = policyBuilderContext.getBundle(); final AnnotatedBundle annotatedBundle = policyBuilderContext.getAnnotatedBundle(); final Policy policy = policyBuilderContext.getPolicy(); Element policyGuidElement; try { policyGuidElement = getSingleElement(includeAssertionElement, POLICY_GUID); } catch (DocumentParseException e) { throw new EntityBuilderException("Could not find PolicyGuid element in Include Assertion", e); } final String policyPath = policyGuidElement.getAttribute(POLICY_PATH); LOGGER.log(Level.FINE, "Looking for referenced policy include: {0}", policyPath); final AtomicReference<Policy> includedPolicy; if (annotatedBundle != null) { includedPolicy = new AtomicReference<>(annotatedBundle.getPolicies().get(policyPath)); } else { includedPolicy = new AtomicReference<>(bundle.getPolicies().get(policyPath)); } if (includedPolicy.get() != null) { policy.getDependencies().add(includedPolicy.get()); } else { bundle.getDependencies().forEach(b -> { Policy policyFromDependencies = Optional.ofNullable(b.getPolicies().get(policyPath)).orElse(b.getPolicies().get(PathUtils.extractName(policyPath))); if (policyFromDependencies != null) { if (!includedPolicy.compareAndSet(null, policyFromDependencies)) { throw new EntityBuilderException("Found multiple policies in dependency bundles with policy path: " + policyPath); } DependentBundle dependentBundle = b.getDependentBundleFrom(); if (dependentBundle != null && dependentBundle.getType() != null) { if (annotatedBundle != null) { annotatedBundle.addDependentBundle(dependentBundle); } else { bundle.addDependentBundle(dependentBundle); } } } }); final MissingGatewayEntity missingEntity = bundle.getMissingEntities().get(policyPath); if (missingEntity != null && missingEntity.isExcluded()) { LOGGER.log(Level.WARNING, "Resolving the referenced policy {0} as known excluded entity with guid: {1}", new Object[]{policyPath, missingEntity.getGuid()}); includedPolicy.set(new Policy()); includedPolicy.get().setGuid(missingEntity.getGuid()); } } if (includedPolicy.get() == null) { throw new EntityBuilderException("Could not find referenced policy include with path: " + policyPath); } policyGuidElement.setAttribute(STRING_VALUE, includedPolicy.get().getGuid()); policyGuidElement.removeAttribute(POLICY_PATH); } }
IncludeAssertionBuilder implements PolicyAssertionBuilder { @Override public void buildAssertionElement(Element includeAssertionElement, PolicyBuilderContext policyBuilderContext) { final Bundle bundle = policyBuilderContext.getBundle(); final AnnotatedBundle annotatedBundle = policyBuilderContext.getAnnotatedBundle(); final Policy policy = policyBuilderContext.getPolicy(); Element policyGuidElement; try { policyGuidElement = getSingleElement(includeAssertionElement, POLICY_GUID); } catch (DocumentParseException e) { throw new EntityBuilderException("Could not find PolicyGuid element in Include Assertion", e); } final String policyPath = policyGuidElement.getAttribute(POLICY_PATH); LOGGER.log(Level.FINE, "Looking for referenced policy include: {0}", policyPath); final AtomicReference<Policy> includedPolicy; if (annotatedBundle != null) { includedPolicy = new AtomicReference<>(annotatedBundle.getPolicies().get(policyPath)); } else { includedPolicy = new AtomicReference<>(bundle.getPolicies().get(policyPath)); } if (includedPolicy.get() != null) { policy.getDependencies().add(includedPolicy.get()); } else { bundle.getDependencies().forEach(b -> { Policy policyFromDependencies = Optional.ofNullable(b.getPolicies().get(policyPath)).orElse(b.getPolicies().get(PathUtils.extractName(policyPath))); if (policyFromDependencies != null) { if (!includedPolicy.compareAndSet(null, policyFromDependencies)) { throw new EntityBuilderException("Found multiple policies in dependency bundles with policy path: " + policyPath); } DependentBundle dependentBundle = b.getDependentBundleFrom(); if (dependentBundle != null && dependentBundle.getType() != null) { if (annotatedBundle != null) { annotatedBundle.addDependentBundle(dependentBundle); } else { bundle.addDependentBundle(dependentBundle); } } } }); final MissingGatewayEntity missingEntity = bundle.getMissingEntities().get(policyPath); if (missingEntity != null && missingEntity.isExcluded()) { LOGGER.log(Level.WARNING, "Resolving the referenced policy {0} as known excluded entity with guid: {1}", new Object[]{policyPath, missingEntity.getGuid()}); includedPolicy.set(new Policy()); includedPolicy.get().setGuid(missingEntity.getGuid()); } } if (includedPolicy.get() == null) { throw new EntityBuilderException("Could not find referenced policy include with path: " + policyPath); } policyGuidElement.setAttribute(STRING_VALUE, includedPolicy.get().getGuid()); policyGuidElement.removeAttribute(POLICY_PATH); }  }
IncludeAssertionBuilder implements PolicyAssertionBuilder { @Override public void buildAssertionElement(Element includeAssertionElement, PolicyBuilderContext policyBuilderContext) { final Bundle bundle = policyBuilderContext.getBundle(); final AnnotatedBundle annotatedBundle = policyBuilderContext.getAnnotatedBundle(); final Policy policy = policyBuilderContext.getPolicy(); Element policyGuidElement; try { policyGuidElement = getSingleElement(includeAssertionElement, POLICY_GUID); } catch (DocumentParseException e) { throw new EntityBuilderException("Could not find PolicyGuid element in Include Assertion", e); } final String policyPath = policyGuidElement.getAttribute(POLICY_PATH); LOGGER.log(Level.FINE, "Looking for referenced policy include: {0}", policyPath); final AtomicReference<Policy> includedPolicy; if (annotatedBundle != null) { includedPolicy = new AtomicReference<>(annotatedBundle.getPolicies().get(policyPath)); } else { includedPolicy = new AtomicReference<>(bundle.getPolicies().get(policyPath)); } if (includedPolicy.get() != null) { policy.getDependencies().add(includedPolicy.get()); } else { bundle.getDependencies().forEach(b -> { Policy policyFromDependencies = Optional.ofNullable(b.getPolicies().get(policyPath)).orElse(b.getPolicies().get(PathUtils.extractName(policyPath))); if (policyFromDependencies != null) { if (!includedPolicy.compareAndSet(null, policyFromDependencies)) { throw new EntityBuilderException("Found multiple policies in dependency bundles with policy path: " + policyPath); } DependentBundle dependentBundle = b.getDependentBundleFrom(); if (dependentBundle != null && dependentBundle.getType() != null) { if (annotatedBundle != null) { annotatedBundle.addDependentBundle(dependentBundle); } else { bundle.addDependentBundle(dependentBundle); } } } }); final MissingGatewayEntity missingEntity = bundle.getMissingEntities().get(policyPath); if (missingEntity != null && missingEntity.isExcluded()) { LOGGER.log(Level.WARNING, "Resolving the referenced policy {0} as known excluded entity with guid: {1}", new Object[]{policyPath, missingEntity.getGuid()}); includedPolicy.set(new Policy()); includedPolicy.get().setGuid(missingEntity.getGuid()); } } if (includedPolicy.get() == null) { throw new EntityBuilderException("Could not find referenced policy include with path: " + policyPath); } policyGuidElement.setAttribute(STRING_VALUE, includedPolicy.get().getGuid()); policyGuidElement.removeAttribute(POLICY_PATH); }  @Override void buildAssertionElement(Element includeAssertionElement, PolicyBuilderContext policyBuilderContext); @Override String getAssertionTagName(); }
IncludeAssertionBuilder implements PolicyAssertionBuilder { @Override public void buildAssertionElement(Element includeAssertionElement, PolicyBuilderContext policyBuilderContext) { final Bundle bundle = policyBuilderContext.getBundle(); final AnnotatedBundle annotatedBundle = policyBuilderContext.getAnnotatedBundle(); final Policy policy = policyBuilderContext.getPolicy(); Element policyGuidElement; try { policyGuidElement = getSingleElement(includeAssertionElement, POLICY_GUID); } catch (DocumentParseException e) { throw new EntityBuilderException("Could not find PolicyGuid element in Include Assertion", e); } final String policyPath = policyGuidElement.getAttribute(POLICY_PATH); LOGGER.log(Level.FINE, "Looking for referenced policy include: {0}", policyPath); final AtomicReference<Policy> includedPolicy; if (annotatedBundle != null) { includedPolicy = new AtomicReference<>(annotatedBundle.getPolicies().get(policyPath)); } else { includedPolicy = new AtomicReference<>(bundle.getPolicies().get(policyPath)); } if (includedPolicy.get() != null) { policy.getDependencies().add(includedPolicy.get()); } else { bundle.getDependencies().forEach(b -> { Policy policyFromDependencies = Optional.ofNullable(b.getPolicies().get(policyPath)).orElse(b.getPolicies().get(PathUtils.extractName(policyPath))); if (policyFromDependencies != null) { if (!includedPolicy.compareAndSet(null, policyFromDependencies)) { throw new EntityBuilderException("Found multiple policies in dependency bundles with policy path: " + policyPath); } DependentBundle dependentBundle = b.getDependentBundleFrom(); if (dependentBundle != null && dependentBundle.getType() != null) { if (annotatedBundle != null) { annotatedBundle.addDependentBundle(dependentBundle); } else { bundle.addDependentBundle(dependentBundle); } } } }); final MissingGatewayEntity missingEntity = bundle.getMissingEntities().get(policyPath); if (missingEntity != null && missingEntity.isExcluded()) { LOGGER.log(Level.WARNING, "Resolving the referenced policy {0} as known excluded entity with guid: {1}", new Object[]{policyPath, missingEntity.getGuid()}); includedPolicy.set(new Policy()); includedPolicy.get().setGuid(missingEntity.getGuid()); } } if (includedPolicy.get() == null) { throw new EntityBuilderException("Could not find referenced policy include with path: " + policyPath); } policyGuidElement.setAttribute(STRING_VALUE, includedPolicy.get().getGuid()); policyGuidElement.removeAttribute(POLICY_PATH); }  @Override void buildAssertionElement(Element includeAssertionElement, PolicyBuilderContext policyBuilderContext); @Override String getAssertionTagName();  }