@Test void testWritePolicyWithSubfolder(final TemporaryFolder temporaryFolder) throws DocumentParseException { PolicyWriter writer = new PolicyWriter(policyConverterRegistry, DocumentFileUtils.INSTANCE, JsonFileUtils.INSTANCE, new EntityLinkerRegistry(new HashSet<>())); Bundle bundle = new Bundle(); bundle.addEntity(ROOT_FOLDER); Folder folder = new Folder("0000000000000000ffffffffffff54", "Test"); folder.setParentFolder(ROOT_FOLDER); bundle.addEntity(folder); bundle.setFolderTree(new FolderTree(bundle.getEntities(Folder.class).values())); Policy policy = new Policy(); policy.setGuid("123"); policy.setPath("assertionPolicy"); policy.setParentFolder(folder); policy.setName("assertionPolicy"); policy.setId("asd"); policy.setPolicyXML("<wsp:Policy xmlns:wsp=\"http: " <wsp:All wsp:Usage=\"Required\"><L7p:JavaScript>\n" + " <L7p:ExecutionTimeout stringValue=\"\"/>\n" + " <L7p:Name stringValue=\"assertionPolicy\"/>\n" + " <L7p:Script stringValueReference=\"inline\"><![CDATA[var js = {};]]></L7p:Script>\n" + " </L7p:JavaScript></wsp:All>\n" + "</wsp:Policy>"); policy.setPolicyDocument(DocumentTools.INSTANCE.parse(policy.getPolicyXML()).getDocumentElement()); bundle.getPolicies().put("assertionPolicy", policy); writer.write(bundle, temporaryFolder.getRoot(), bundle); File policyFolder = new File(temporaryFolder.getRoot(), "policy"); assertTrue(policyFolder.exists()); File testFolder = new File(policyFolder, "Test"); assertTrue(testFolder.exists()); File policyFile = new File(testFolder, "assertionPolicy.assertion.js"); assertTrue(policyFile.exists()); File configFolder = new File(temporaryFolder.getRoot(), "config"); assertTrue(configFolder.exists()); File policyMetadataFile = new File(configFolder, "policies.yml"); assertTrue(policyMetadataFile.exists()); }
@Override public void write(Bundle bundle, File rootFolder, Bundle rawBundle) { File policyFolder = new File(rootFolder, "policy"); documentFileUtils.createFolder(policyFolder.toPath()); bundle.getFolderTree().stream().forEach(folder -> { if (folder.getParentFolder() != null) { Path folderFile = policyFolder.toPath().resolve(bundle.getFolderTree().getPath(folder)); documentFileUtils.createFolder(folderFile); } }); Map<String, PolicyMetadata> policyMetadataMap = new HashMap<>(); Map<String, Service> services = bundle.getEntities(Service.class); services.values().parallelStream().forEach(serviceEntity -> { writePolicy(bundle, policyFolder, serviceEntity, serviceEntity.getPolicyXML()); final PolicyMetadata policyMetadata = createPolicyMetadata(bundle, rawBundle, null, serviceEntity); policyMetadataMap.put(policyMetadata.getFullPath(), policyMetadata); }); Stream.of( bundle.getEntities(Policy.class).values().stream(), bundle.getEntities(GlobalPolicy.class).values().stream().map(Policy.class::cast).collect(toList()).stream(), bundle.getEntities(AuditPolicy.class).values().stream().map(Policy.class::cast).collect(toList()).stream() ).flatMap(s -> s) .forEach(policyEntity -> { writePolicy(bundle, policyFolder, policyEntity, policyEntity.getPolicyDocument()); final PolicyMetadata policyMetadata = createPolicyMetadata(bundle, rawBundle, policyEntity, policyEntity); policyMetadataMap.put(policyMetadata.getFullPath(), policyMetadata); }); writePolicyMetadata(policyMetadataMap, rootFolder); }
PolicyWriter implements EntityWriter { @Override public void write(Bundle bundle, File rootFolder, Bundle rawBundle) { File policyFolder = new File(rootFolder, "policy"); documentFileUtils.createFolder(policyFolder.toPath()); bundle.getFolderTree().stream().forEach(folder -> { if (folder.getParentFolder() != null) { Path folderFile = policyFolder.toPath().resolve(bundle.getFolderTree().getPath(folder)); documentFileUtils.createFolder(folderFile); } }); Map<String, PolicyMetadata> policyMetadataMap = new HashMap<>(); Map<String, Service> services = bundle.getEntities(Service.class); services.values().parallelStream().forEach(serviceEntity -> { writePolicy(bundle, policyFolder, serviceEntity, serviceEntity.getPolicyXML()); final PolicyMetadata policyMetadata = createPolicyMetadata(bundle, rawBundle, null, serviceEntity); policyMetadataMap.put(policyMetadata.getFullPath(), policyMetadata); }); Stream.of( bundle.getEntities(Policy.class).values().stream(), bundle.getEntities(GlobalPolicy.class).values().stream().map(Policy.class::cast).collect(toList()).stream(), bundle.getEntities(AuditPolicy.class).values().stream().map(Policy.class::cast).collect(toList()).stream() ).flatMap(s -> s) .forEach(policyEntity -> { writePolicy(bundle, policyFolder, policyEntity, policyEntity.getPolicyDocument()); final PolicyMetadata policyMetadata = createPolicyMetadata(bundle, rawBundle, policyEntity, policyEntity); policyMetadataMap.put(policyMetadata.getFullPath(), policyMetadata); }); writePolicyMetadata(policyMetadataMap, rootFolder); } }
PolicyWriter implements EntityWriter { @Override public void write(Bundle bundle, File rootFolder, Bundle rawBundle) { File policyFolder = new File(rootFolder, "policy"); documentFileUtils.createFolder(policyFolder.toPath()); bundle.getFolderTree().stream().forEach(folder -> { if (folder.getParentFolder() != null) { Path folderFile = policyFolder.toPath().resolve(bundle.getFolderTree().getPath(folder)); documentFileUtils.createFolder(folderFile); } }); Map<String, PolicyMetadata> policyMetadataMap = new HashMap<>(); Map<String, Service> services = bundle.getEntities(Service.class); services.values().parallelStream().forEach(serviceEntity -> { writePolicy(bundle, policyFolder, serviceEntity, serviceEntity.getPolicyXML()); final PolicyMetadata policyMetadata = createPolicyMetadata(bundle, rawBundle, null, serviceEntity); policyMetadataMap.put(policyMetadata.getFullPath(), policyMetadata); }); Stream.of( bundle.getEntities(Policy.class).values().stream(), bundle.getEntities(GlobalPolicy.class).values().stream().map(Policy.class::cast).collect(toList()).stream(), bundle.getEntities(AuditPolicy.class).values().stream().map(Policy.class::cast).collect(toList()).stream() ).flatMap(s -> s) .forEach(policyEntity -> { writePolicy(bundle, policyFolder, policyEntity, policyEntity.getPolicyDocument()); final PolicyMetadata policyMetadata = createPolicyMetadata(bundle, rawBundle, policyEntity, policyEntity); policyMetadataMap.put(policyMetadata.getFullPath(), policyMetadata); }); writePolicyMetadata(policyMetadataMap, rootFolder); } @Inject  PolicyWriter(PolicyConverterRegistry policyConverterRegistry, DocumentFileUtils documentFileUtils,
                 JsonFileUtils jsonFileUtils, EntityLinkerRegistry entityLinkerRegistry); }
PolicyWriter implements EntityWriter { @Override public void write(Bundle bundle, File rootFolder, Bundle rawBundle) { File policyFolder = new File(rootFolder, "policy"); documentFileUtils.createFolder(policyFolder.toPath()); bundle.getFolderTree().stream().forEach(folder -> { if (folder.getParentFolder() != null) { Path folderFile = policyFolder.toPath().resolve(bundle.getFolderTree().getPath(folder)); documentFileUtils.createFolder(folderFile); } }); Map<String, PolicyMetadata> policyMetadataMap = new HashMap<>(); Map<String, Service> services = bundle.getEntities(Service.class); services.values().parallelStream().forEach(serviceEntity -> { writePolicy(bundle, policyFolder, serviceEntity, serviceEntity.getPolicyXML()); final PolicyMetadata policyMetadata = createPolicyMetadata(bundle, rawBundle, null, serviceEntity); policyMetadataMap.put(policyMetadata.getFullPath(), policyMetadata); }); Stream.of( bundle.getEntities(Policy.class).values().stream(), bundle.getEntities(GlobalPolicy.class).values().stream().map(Policy.class::cast).collect(toList()).stream(), bundle.getEntities(AuditPolicy.class).values().stream().map(Policy.class::cast).collect(toList()).stream() ).flatMap(s -> s) .forEach(policyEntity -> { writePolicy(bundle, policyFolder, policyEntity, policyEntity.getPolicyDocument()); final PolicyMetadata policyMetadata = createPolicyMetadata(bundle, rawBundle, policyEntity, policyEntity); policyMetadataMap.put(policyMetadata.getFullPath(), policyMetadata); }); writePolicyMetadata(policyMetadataMap, rootFolder); } @Inject  PolicyWriter(PolicyConverterRegistry policyConverterRegistry, DocumentFileUtils documentFileUtils,
                 JsonFileUtils jsonFileUtils, EntityLinkerRegistry entityLinkerRegistry); @Override void write(Bundle bundle, File rootFolder, Bundle rawBundle); }
PolicyWriter implements EntityWriter { @Override public void write(Bundle bundle, File rootFolder, Bundle rawBundle) { File policyFolder = new File(rootFolder, "policy"); documentFileUtils.createFolder(policyFolder.toPath()); bundle.getFolderTree().stream().forEach(folder -> { if (folder.getParentFolder() != null) { Path folderFile = policyFolder.toPath().resolve(bundle.getFolderTree().getPath(folder)); documentFileUtils.createFolder(folderFile); } }); Map<String, PolicyMetadata> policyMetadataMap = new HashMap<>(); Map<String, Service> services = bundle.getEntities(Service.class); services.values().parallelStream().forEach(serviceEntity -> { writePolicy(bundle, policyFolder, serviceEntity, serviceEntity.getPolicyXML()); final PolicyMetadata policyMetadata = createPolicyMetadata(bundle, rawBundle, null, serviceEntity); policyMetadataMap.put(policyMetadata.getFullPath(), policyMetadata); }); Stream.of( bundle.getEntities(Policy.class).values().stream(), bundle.getEntities(GlobalPolicy.class).values().stream().map(Policy.class::cast).collect(toList()).stream(), bundle.getEntities(AuditPolicy.class).values().stream().map(Policy.class::cast).collect(toList()).stream() ).flatMap(s -> s) .forEach(policyEntity -> { writePolicy(bundle, policyFolder, policyEntity, policyEntity.getPolicyDocument()); final PolicyMetadata policyMetadata = createPolicyMetadata(bundle, rawBundle, policyEntity, policyEntity); policyMetadataMap.put(policyMetadata.getFullPath(), policyMetadata); }); writePolicyMetadata(policyMetadataMap, rootFolder); } @Inject  PolicyWriter(PolicyConverterRegistry policyConverterRegistry, DocumentFileUtils documentFileUtils,
                 JsonFileUtils jsonFileUtils, EntityLinkerRegistry entityLinkerRegistry); @Override void write(Bundle bundle, File rootFolder, Bundle rawBundle);  }