@Test void buildPolicyEntityTest() { PolicyEntityBuilder policyEntityBuilder = new PolicyEntityBuilder(DocumentTools.INSTANCE, new IdGenerator(), policyXMLBuilder); Policy policyToBuild = new Policy(); policyToBuild.setPath("/path"); policyToBuild.setName("path"); policyToBuild.setId("policy-id"); policyToBuild.setGuid("policy-guid-123"); Folder parentFolder = new Folder(); parentFolder.setId("folder-id"); policyToBuild.setParentFolder(parentFolder); Entity policyEntity = policyEntityBuilder.buildPolicyEntity(policyToBuild, null, bundle, document); assertEquals(policyToBuild.getId(), policyEntity.getId()); }
@VisibleForTesting Entity buildPolicyEntity(Policy policy, AnnotatedBundle annotatedBundle, Bundle bundle, Document document) { String policyName = policy.getName(); String policyNameWithPath = EntityBuilderHelper.getPath(policy.getParentFolder(), policyName); policyNameWithPath = CharacterBlacklistUtil.decodePath(policyNameWithPath); AnnotatedEntity annotatedEntity = annotatedBundle != null ? annotatedBundle.getAnnotatedEntity() : null; boolean isRedeployableBundle = false; if (annotatedEntity != null) { isRedeployableBundle = annotatedEntity.isRedeployable(); policyName = annotatedBundle.applyUniqueName(policyName, BundleType.DEPLOYMENT, policy.isParentEntityShared()); policyNameWithPath = PathUtils.extractPath(policyNameWithPath) + policyName; } PolicyTags policyTags = getPolicyTags(policy, bundle); Element policyDetailElement = createElementWithAttributesAndChildren( document, POLICY_DETAIL, ImmutableMap.of(ATTRIBUTE_ID, policy.getId(), ATTRIBUTE_GUID, policy.getGuid(), ATTRIBUTE_FOLDER_ID, policy.getParentFolder().getId()), createElementWithTextContent(document, NAME, policyName), createElementWithTextContent(document, POLICY_TYPE, policyTags == null ? PolicyType.INCLUDE.getType() : policyTags.type.getType()) ); if (policyTags != null) { Builder<String, Object> builder = ImmutableMap.<String, Object>builder().put(PROPERTY_TAG, policyTags.tag); if (policyTags.subtag != null) { builder.put(PROPERTY_SUBTAG, policyTags.subtag); } buildAndAppendPropertiesElement( builder.build(), document, policyDetailElement ); } Element policyElement = createElementWithAttributes( document, BundleElementNames.POLICY, ImmutableMap.of(ATTRIBUTE_ID, policy.getId(), ATTRIBUTE_GUID, policy.getGuid()) ); policyElement.appendChild(policyDetailElement); Element resourcesElement = document.createElement(RESOURCES); Element resourceSetElement = createElementWithAttribute(document, RESOURCE_SET, PROPERTY_TAG, POLICY); Element resourceElement = createElementWithAttribute(document, RESOURCE, TYPE, POLICY); resourceElement.setTextContent(documentTools.elementToString(policy.getPolicyDocument())); resourceSetElement.appendChild(resourceElement); resourcesElement.appendChild(resourceSetElement); policyElement.appendChild(resourcesElement); Entity entity = EntityBuilderHelper.getEntityWithPathMapping(EntityTypes.POLICY_TYPE, policy.getPath(), policyNameWithPath, policy.getId(), policyElement, policy.isHasRouting(), policy); if (isRedeployableBundle) { entity.setMappingAction(MappingActions.NEW_OR_UPDATE); } else if (policy.isParentEntityShared()) { entity.setMappingAction(MappingActions.NEW_OR_EXISTING); } else { entity.setMappingAction(EntityBuilderHelper.getDefaultEntityMappingAction()); } return entity; }
PolicyEntityBuilder implements EntityBuilder { @VisibleForTesting Entity buildPolicyEntity(Policy policy, AnnotatedBundle annotatedBundle, Bundle bundle, Document document) { String policyName = policy.getName(); String policyNameWithPath = EntityBuilderHelper.getPath(policy.getParentFolder(), policyName); policyNameWithPath = CharacterBlacklistUtil.decodePath(policyNameWithPath); AnnotatedEntity annotatedEntity = annotatedBundle != null ? annotatedBundle.getAnnotatedEntity() : null; boolean isRedeployableBundle = false; if (annotatedEntity != null) { isRedeployableBundle = annotatedEntity.isRedeployable(); policyName = annotatedBundle.applyUniqueName(policyName, BundleType.DEPLOYMENT, policy.isParentEntityShared()); policyNameWithPath = PathUtils.extractPath(policyNameWithPath) + policyName; } PolicyTags policyTags = getPolicyTags(policy, bundle); Element policyDetailElement = createElementWithAttributesAndChildren( document, POLICY_DETAIL, ImmutableMap.of(ATTRIBUTE_ID, policy.getId(), ATTRIBUTE_GUID, policy.getGuid(), ATTRIBUTE_FOLDER_ID, policy.getParentFolder().getId()), createElementWithTextContent(document, NAME, policyName), createElementWithTextContent(document, POLICY_TYPE, policyTags == null ? PolicyType.INCLUDE.getType() : policyTags.type.getType()) ); if (policyTags != null) { Builder<String, Object> builder = ImmutableMap.<String, Object>builder().put(PROPERTY_TAG, policyTags.tag); if (policyTags.subtag != null) { builder.put(PROPERTY_SUBTAG, policyTags.subtag); } buildAndAppendPropertiesElement( builder.build(), document, policyDetailElement ); } Element policyElement = createElementWithAttributes( document, BundleElementNames.POLICY, ImmutableMap.of(ATTRIBUTE_ID, policy.getId(), ATTRIBUTE_GUID, policy.getGuid()) ); policyElement.appendChild(policyDetailElement); Element resourcesElement = document.createElement(RESOURCES); Element resourceSetElement = createElementWithAttribute(document, RESOURCE_SET, PROPERTY_TAG, POLICY); Element resourceElement = createElementWithAttribute(document, RESOURCE, TYPE, POLICY); resourceElement.setTextContent(documentTools.elementToString(policy.getPolicyDocument())); resourceSetElement.appendChild(resourceElement); resourcesElement.appendChild(resourceSetElement); policyElement.appendChild(resourcesElement); Entity entity = EntityBuilderHelper.getEntityWithPathMapping(EntityTypes.POLICY_TYPE, policy.getPath(), policyNameWithPath, policy.getId(), policyElement, policy.isHasRouting(), policy); if (isRedeployableBundle) { entity.setMappingAction(MappingActions.NEW_OR_UPDATE); } else if (policy.isParentEntityShared()) { entity.setMappingAction(MappingActions.NEW_OR_EXISTING); } else { entity.setMappingAction(EntityBuilderHelper.getDefaultEntityMappingAction()); } return entity; } }
PolicyEntityBuilder implements EntityBuilder { @VisibleForTesting Entity buildPolicyEntity(Policy policy, AnnotatedBundle annotatedBundle, Bundle bundle, Document document) { String policyName = policy.getName(); String policyNameWithPath = EntityBuilderHelper.getPath(policy.getParentFolder(), policyName); policyNameWithPath = CharacterBlacklistUtil.decodePath(policyNameWithPath); AnnotatedEntity annotatedEntity = annotatedBundle != null ? annotatedBundle.getAnnotatedEntity() : null; boolean isRedeployableBundle = false; if (annotatedEntity != null) { isRedeployableBundle = annotatedEntity.isRedeployable(); policyName = annotatedBundle.applyUniqueName(policyName, BundleType.DEPLOYMENT, policy.isParentEntityShared()); policyNameWithPath = PathUtils.extractPath(policyNameWithPath) + policyName; } PolicyTags policyTags = getPolicyTags(policy, bundle); Element policyDetailElement = createElementWithAttributesAndChildren( document, POLICY_DETAIL, ImmutableMap.of(ATTRIBUTE_ID, policy.getId(), ATTRIBUTE_GUID, policy.getGuid(), ATTRIBUTE_FOLDER_ID, policy.getParentFolder().getId()), createElementWithTextContent(document, NAME, policyName), createElementWithTextContent(document, POLICY_TYPE, policyTags == null ? PolicyType.INCLUDE.getType() : policyTags.type.getType()) ); if (policyTags != null) { Builder<String, Object> builder = ImmutableMap.<String, Object>builder().put(PROPERTY_TAG, policyTags.tag); if (policyTags.subtag != null) { builder.put(PROPERTY_SUBTAG, policyTags.subtag); } buildAndAppendPropertiesElement( builder.build(), document, policyDetailElement ); } Element policyElement = createElementWithAttributes( document, BundleElementNames.POLICY, ImmutableMap.of(ATTRIBUTE_ID, policy.getId(), ATTRIBUTE_GUID, policy.getGuid()) ); policyElement.appendChild(policyDetailElement); Element resourcesElement = document.createElement(RESOURCES); Element resourceSetElement = createElementWithAttribute(document, RESOURCE_SET, PROPERTY_TAG, POLICY); Element resourceElement = createElementWithAttribute(document, RESOURCE, TYPE, POLICY); resourceElement.setTextContent(documentTools.elementToString(policy.getPolicyDocument())); resourceSetElement.appendChild(resourceElement); resourcesElement.appendChild(resourceSetElement); policyElement.appendChild(resourcesElement); Entity entity = EntityBuilderHelper.getEntityWithPathMapping(EntityTypes.POLICY_TYPE, policy.getPath(), policyNameWithPath, policy.getId(), policyElement, policy.isHasRouting(), policy); if (isRedeployableBundle) { entity.setMappingAction(MappingActions.NEW_OR_UPDATE); } else if (policy.isParentEntityShared()) { entity.setMappingAction(MappingActions.NEW_OR_EXISTING); } else { entity.setMappingAction(EntityBuilderHelper.getDefaultEntityMappingAction()); } return entity; } @Inject  PolicyEntityBuilder(DocumentTools documentTools, IdGenerator idGenerator, PolicyXMLBuilder policyXMLBuilder); }
PolicyEntityBuilder implements EntityBuilder { @VisibleForTesting Entity buildPolicyEntity(Policy policy, AnnotatedBundle annotatedBundle, Bundle bundle, Document document) { String policyName = policy.getName(); String policyNameWithPath = EntityBuilderHelper.getPath(policy.getParentFolder(), policyName); policyNameWithPath = CharacterBlacklistUtil.decodePath(policyNameWithPath); AnnotatedEntity annotatedEntity = annotatedBundle != null ? annotatedBundle.getAnnotatedEntity() : null; boolean isRedeployableBundle = false; if (annotatedEntity != null) { isRedeployableBundle = annotatedEntity.isRedeployable(); policyName = annotatedBundle.applyUniqueName(policyName, BundleType.DEPLOYMENT, policy.isParentEntityShared()); policyNameWithPath = PathUtils.extractPath(policyNameWithPath) + policyName; } PolicyTags policyTags = getPolicyTags(policy, bundle); Element policyDetailElement = createElementWithAttributesAndChildren( document, POLICY_DETAIL, ImmutableMap.of(ATTRIBUTE_ID, policy.getId(), ATTRIBUTE_GUID, policy.getGuid(), ATTRIBUTE_FOLDER_ID, policy.getParentFolder().getId()), createElementWithTextContent(document, NAME, policyName), createElementWithTextContent(document, POLICY_TYPE, policyTags == null ? PolicyType.INCLUDE.getType() : policyTags.type.getType()) ); if (policyTags != null) { Builder<String, Object> builder = ImmutableMap.<String, Object>builder().put(PROPERTY_TAG, policyTags.tag); if (policyTags.subtag != null) { builder.put(PROPERTY_SUBTAG, policyTags.subtag); } buildAndAppendPropertiesElement( builder.build(), document, policyDetailElement ); } Element policyElement = createElementWithAttributes( document, BundleElementNames.POLICY, ImmutableMap.of(ATTRIBUTE_ID, policy.getId(), ATTRIBUTE_GUID, policy.getGuid()) ); policyElement.appendChild(policyDetailElement); Element resourcesElement = document.createElement(RESOURCES); Element resourceSetElement = createElementWithAttribute(document, RESOURCE_SET, PROPERTY_TAG, POLICY); Element resourceElement = createElementWithAttribute(document, RESOURCE, TYPE, POLICY); resourceElement.setTextContent(documentTools.elementToString(policy.getPolicyDocument())); resourceSetElement.appendChild(resourceElement); resourcesElement.appendChild(resourceSetElement); policyElement.appendChild(resourcesElement); Entity entity = EntityBuilderHelper.getEntityWithPathMapping(EntityTypes.POLICY_TYPE, policy.getPath(), policyNameWithPath, policy.getId(), policyElement, policy.isHasRouting(), policy); if (isRedeployableBundle) { entity.setMappingAction(MappingActions.NEW_OR_UPDATE); } else if (policy.isParentEntityShared()) { entity.setMappingAction(MappingActions.NEW_OR_EXISTING); } else { entity.setMappingAction(EntityBuilderHelper.getDefaultEntityMappingAction()); } return entity; } @Inject  PolicyEntityBuilder(DocumentTools documentTools, IdGenerator idGenerator, PolicyXMLBuilder policyXMLBuilder); List<Entity> buildEntities(Map<String, ?> policyMap, AnnotatedBundle annotatedBundle, Bundle bundle, BundleType bundleType, Document document); List<Entity> build(Bundle bundle, BundleType bundleType, Document document); @NotNull @Override Integer getOrder(); static void resolvePossibleMissingEncapsulatedAssertionDependencies(Bundle bundle, Element encapsulatedAssertionElement); }
PolicyEntityBuilder implements EntityBuilder { @VisibleForTesting Entity buildPolicyEntity(Policy policy, AnnotatedBundle annotatedBundle, Bundle bundle, Document document) { String policyName = policy.getName(); String policyNameWithPath = EntityBuilderHelper.getPath(policy.getParentFolder(), policyName); policyNameWithPath = CharacterBlacklistUtil.decodePath(policyNameWithPath); AnnotatedEntity annotatedEntity = annotatedBundle != null ? annotatedBundle.getAnnotatedEntity() : null; boolean isRedeployableBundle = false; if (annotatedEntity != null) { isRedeployableBundle = annotatedEntity.isRedeployable(); policyName = annotatedBundle.applyUniqueName(policyName, BundleType.DEPLOYMENT, policy.isParentEntityShared()); policyNameWithPath = PathUtils.extractPath(policyNameWithPath) + policyName; } PolicyTags policyTags = getPolicyTags(policy, bundle); Element policyDetailElement = createElementWithAttributesAndChildren( document, POLICY_DETAIL, ImmutableMap.of(ATTRIBUTE_ID, policy.getId(), ATTRIBUTE_GUID, policy.getGuid(), ATTRIBUTE_FOLDER_ID, policy.getParentFolder().getId()), createElementWithTextContent(document, NAME, policyName), createElementWithTextContent(document, POLICY_TYPE, policyTags == null ? PolicyType.INCLUDE.getType() : policyTags.type.getType()) ); if (policyTags != null) { Builder<String, Object> builder = ImmutableMap.<String, Object>builder().put(PROPERTY_TAG, policyTags.tag); if (policyTags.subtag != null) { builder.put(PROPERTY_SUBTAG, policyTags.subtag); } buildAndAppendPropertiesElement( builder.build(), document, policyDetailElement ); } Element policyElement = createElementWithAttributes( document, BundleElementNames.POLICY, ImmutableMap.of(ATTRIBUTE_ID, policy.getId(), ATTRIBUTE_GUID, policy.getGuid()) ); policyElement.appendChild(policyDetailElement); Element resourcesElement = document.createElement(RESOURCES); Element resourceSetElement = createElementWithAttribute(document, RESOURCE_SET, PROPERTY_TAG, POLICY); Element resourceElement = createElementWithAttribute(document, RESOURCE, TYPE, POLICY); resourceElement.setTextContent(documentTools.elementToString(policy.getPolicyDocument())); resourceSetElement.appendChild(resourceElement); resourcesElement.appendChild(resourceSetElement); policyElement.appendChild(resourcesElement); Entity entity = EntityBuilderHelper.getEntityWithPathMapping(EntityTypes.POLICY_TYPE, policy.getPath(), policyNameWithPath, policy.getId(), policyElement, policy.isHasRouting(), policy); if (isRedeployableBundle) { entity.setMappingAction(MappingActions.NEW_OR_UPDATE); } else if (policy.isParentEntityShared()) { entity.setMappingAction(MappingActions.NEW_OR_EXISTING); } else { entity.setMappingAction(EntityBuilderHelper.getDefaultEntityMappingAction()); } return entity; } @Inject  PolicyEntityBuilder(DocumentTools documentTools, IdGenerator idGenerator, PolicyXMLBuilder policyXMLBuilder); List<Entity> buildEntities(Map<String, ?> policyMap, AnnotatedBundle annotatedBundle, Bundle bundle, BundleType bundleType, Document document); List<Entity> build(Bundle bundle, BundleType bundleType, Document document); @NotNull @Override Integer getOrder(); static void resolvePossibleMissingEncapsulatedAssertionDependencies(Bundle bundle, Element encapsulatedAssertionElement); static final String POLICY; static final String ZERO_GUID; }