Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ and this project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html)

## [Unreleased]

### Changed

- Needs DirXMLDev 0.79.0 (was 0.78.0). **Reads of the vault take in other Libraries**
(PointBlueTechnology/DirXMLDev#115): Compare, Plan, Deploy and capture now see the objects the driver set's
links name outside it, as the LDIF and Designer imports do, so a tree read from the vault no longer reports
`link-unresolved` for them. Deploy's verify no longer fails on a trace size limit it leaves alone. The
simulator behind Simulate is 1.10.0: entitlements a user holds are seen, and Matching, Create and Placement
run only when the engine runs them.
- **Update this branch from <env>** keeps the tree's folder name for each other Library (a read could name
`Library@services` just `Library`). Updating chosen drivers brings in the other-Library objects they link
that the tree doesn't have yet, with the folder when the tree has none for that container; the tree's
other objects stay as they are.

## [0.97.0] - 2026-11-23

### Changed
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<!-- The Point Blue libraries below are on Maven Central (com.pointbluetech.*), so Maven fetches
them. The DirXMLDev release this server is written against: bin/idmweb runs against a
DirXMLDev checkout at this tag (its classes, engine jars) and the simulator in ~/.m2. -->
<dirxmldev.version>0.78.0</dirxmldev.version>
<simulator.version>1.9.0</simulator.version>
<dirxmldev.version>0.79.0</dirxmldev.version>
<simulator.version>1.10.0</simulator.version>
<!-- the DirXML Trace Viewer's library: parser, highlighter, LDAP trace source (its release attaches the jar) -->
<!-- Directory Console's shared library console-auth: OIDC sign-in, TLS trust -->
<console.version>0.4.11</console.version>
Expand Down
71 changes: 71 additions & 0 deletions src/main/java/com/pointblue/dirxml/web/TreeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* The tree, as the page needs it: the outline, an artifact with its source and references, a
Expand Down Expand Up @@ -903,6 +904,59 @@ public synchronized String requireRevision(String revision) {
return current;
}

/**
* A partial pull swaps in the named drivers from {@code live}; their links into {@code libraries/} must still
* resolve. Each other-Library object those drivers link that {@code result} (the tree) lacks is added, with its
* folder when the tree has no Library for that DN. Objects the tree already has stay as they are: they are
* read-only references, refreshed by a whole-set pull. Returns the folders that got objects.
*/
static Set<String> addLinkedLibraryObjects(DriverSet result, DriverSet live, List<String> drivers, List<String> notes) {
Set<String> wanted = new java.util.TreeSet<>(String.CASE_INSENSITIVE_ORDER);
for (String name : drivers) {
Driver d = live.driver(name);
if (d != null) {
for (com.pointblue.dirxml.dev.model.PolicyLink l : d.links) {
if (l.ref != null && l.ref.startsWith("libraries/")) {
wanted.add(l.ref);
}
}
}
}
Set<String> aliases = new java.util.TreeSet<>();
for (Artifact a : live.library.artifacts()) {
if (a.library == null || !wanted.contains(a.path()) || result.resolve(a.path()) != null) {
continue;
}
String dn = live.libraries.get(a.library);
String have = result.libraries.get(a.library);
if (have == null && dn != null) {
result.libraries.put(a.library, dn);
notes.add("libraries/" + a.library + ": " + dn + " (another Library the update's drivers link)");
} else if (have != null && dn != null
&& !com.pointblue.dirxml.dev.model.Libraries.normDn(have).equals(com.pointblue.dirxml.dev.model.Libraries.normDn(dn))) {
notes.add(a.path() + ": the tree's folder " + a.library + " is " + have + ", the vault's object is in " + dn + "; left out");
continue;
}
if (a instanceof Policy) {
result.library.policies.add((Policy) a);
} else if (a instanceof Resource) {
result.library.resources.add((Resource) a);
} else {
continue;
}
aliases.add(a.library);
}
Set<String> dirs = new java.util.TreeSet<>();
Map<String, String> byAlias = AsCodeWriter.libraryDirs(result);
for (String alias : aliases) {
String dir = byAlias.get(alias);
if (dir != null) {
dirs.add(dir);
}
}
return dirs;
}

/**
* Write the vault's state into this workspace's tree, as {@code idm import-live --env} does: the whole driver set,
* or only the {@code drivers} named (the rest of the tree as it is); with an {@code overrides/} directory the
Expand Down Expand Up @@ -951,8 +1005,11 @@ public synchronized Map<String, Object> pull(DriverSet live, String envName, Lis
if (base != null) {
notes.addAll(com.pointblue.dirxml.dev.deploy.Overrides.toTreeNames(live, base.overrides.get(envName)));
notes.addAll(com.pointblue.dirxml.dev.deploy.ServerMap.toTree(live, base.overrides.get(envName), base));
// a read sees only the Libraries its links name: give each the tree's folder name (DirXMLDev #115)
com.pointblue.dirxml.dev.model.Libraries.adoptAliases(live, base);
}
DriverSet result = live;
Set<String> newLibraryDirs = new java.util.TreeSet<>();
if (drivers != null && !drivers.isEmpty()) {
if (base == null) {
throw new BadRequest("the workspace has no tree yet: take the whole driver set");
Expand Down Expand Up @@ -981,6 +1038,7 @@ public synchronized Map<String, Object> pull(DriverSet live, String envName, Lis
}
}
result.overrides.clear();
newLibraryDirs.addAll(addLinkedLibraryObjects(result, live, drivers, notes));
}
notes.addAll(com.pointblue.dirxml.dev.deploy.DriverEnvironments.keepOnImport(result, envName, base, markNew,
drivers != null && !drivers.isEmpty() ? drivers : null));
Expand Down Expand Up @@ -1013,6 +1071,19 @@ public synchronized Map<String, Object> pull(DriverSet live, String envName, Lis
}
roots.add(com.pointblue.dirxml.dev.deploy.Overrides.DIR);
roots.add(".gitattributes");
// the other-Library objects a partial pull brought in: their files and the folder's manifest, not the rest
for (String dir : newLibraryDirs) {
Path p = copy.resolve(dir);
names.add(dir + "/" + AsCodeWriter.LIBRARY_MANIFEST);
if (Files.isDirectory(p)) {
try (java.util.stream.Stream<Path> s = Files.walk(p)) {
s.filter(Files::isRegularFile)
.map(f -> copy.relativize(f).toString().replace('\\', '/'))
.filter(f -> !Files.exists(tree.resolve(f)))
.forEach(names::add);
}
}
}
for (Path side : List.of(tree, copy)) {
for (String r : roots) {
Path p = side.resolve(r);
Expand Down
148 changes: 148 additions & 0 deletions src/test/java/com/pointblue/dirxml/web/PullOtherLibrariesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package com.pointblue.dirxml.web;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import com.pointblue.dirxml.dev.ascode.AsCodeReader;
import com.pointblue.dirxml.dev.ascode.AsCodeWriter;
import com.pointblue.dirxml.dev.model.Driver;
import com.pointblue.dirxml.dev.model.DriverSet;
import com.pointblue.dirxml.dev.model.DuplicateArtifacts;
import com.pointblue.dirxml.dev.model.Policy;
import com.pointblue.dirxml.dev.model.PolicyLink;
import com.pointblue.dirxml.dev.model.PolicySet;
import com.pointblue.dirxml.dev.model.Scope;
import com.pointblue.dirxml.dev.xml.CanonicalXml;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

/**
* Update this branch from a vault whose drivers link Libraries outside the driver set (DirXMLDev #115): the tree keeps
* its folder names for them, and updating one driver brings in the other-Library objects it links that the tree lacks.
*/
public class PullOtherLibrariesTest {

@Rule
public TemporaryFolder tmp = new TemporaryFolder();

private static final String DS_DN = "cn=Set,o=system";
private static final String SHARED = "cn=Library,ou=shared,o=system";
private static final String ODD = "ou=policies,o=x";

private static Policy policy(String name, String libraryDn, String alias) {
Policy p = new Policy(name, Scope.LIBRARY, null, CanonicalXml.parse(
"<policy><rule><description>" + name + "</description><conditions/><actions/></rule></policy>").getDocumentElement());
p.meta.put(DuplicateArtifacts.LIBRARY_DN, libraryDn);
p.library = alias;
return p;
}

private static Driver driver(String name, String... refs) {
Driver d = new Driver(name);
d.dn = "cn=" + name + "," + DS_DN;
d.shimClass = "com.example.Shim";
int order = 0;
for (String ref : refs) {
d.links.add(new PolicyLink(PolicySet.SUB_EVENT, ref, order++));
}
return d;
}

/** The tree: SHARED in the folder the LDIF import named it, Library@shared, with P; AD links P, Payroll nothing. */
private Path tree() throws Exception {
DriverSet ds = new DriverSet("Set");
ds.dn = DS_DN;
ds.libraries.put("Library@shared", SHARED);
ds.library.policies.add(policy("P", SHARED, "Library@shared"));
ds.drivers.add(driver("AD", "libraries/Library@shared/P"));
ds.drivers.add(driver("Payroll"));
Path tree = tmp.newFolder("tree").toPath();
AsCodeWriter.write(ds, tree);
return tree;
}

/** The vault as a read sees it: SHARED alone, so aliased Library, and AD now links Q there; Payroll links Odd in an ou. */
private static DriverSet live() {
DriverSet live = new DriverSet("Set");
live.dn = DS_DN;
live.libraries.put("Library", SHARED);
live.libraries.put("policies", ODD);
live.library.policies.add(policy("P", SHARED, "Library"));
live.library.policies.add(policy("Q", SHARED, "Library"));
live.library.policies.add(policy("Odd", ODD, "policies"));
live.drivers.add(driver("AD", "libraries/Library/P", "libraries/Library/Q"));
live.drivers.add(driver("Payroll", "libraries/policies/Odd"));
return live;
}

@Test
@SuppressWarnings("unchecked")
public void aWholeUpdateKeepsTheTreesFolderNames() throws Exception {
Path tree = tree();
try (Watcher w = new Watcher(tree, 10_000)) {
TreeService service = new TreeService(tree, w);
Map<String, Object> plan = service.pull(live(), "QA", List.of(), true, "", new ArrayList<>());
List<String> changed = (List<String>) plan.get("changedFiles");
List<String> deleted = (List<String>) plan.get("deletedFiles");
assertFalse("no folder under the read's alias " + changed, changed.stream().anyMatch(f -> f.startsWith("libraries/Library/")));
assertFalse("the tree's folder stays " + deleted, deleted.stream().anyMatch(f -> f.startsWith("libraries/Library@shared/")));

service.pull(live(), "QA", List.of(), false, (String) plan.get("revision"), new ArrayList<>());
DriverSet now = AsCodeReader.read(tree);
assertEquals(SHARED, now.libraries.get("Library@shared"));
assertNotNull(now.resolve("libraries/Library@shared/Q"));
assertTrue(now.unresolvedLinks().toString(), now.unresolvedLinks().isEmpty());
}
}

@Test
@SuppressWarnings("unchecked")
public void updatingOneDriverBringsInWhatItLinks() throws Exception {
Path tree = tree();
byte[] p = Files.readAllBytes(tree.resolve(firstFile(tree, "libraries/Library@shared", "P")));
try (Watcher w = new Watcher(tree, 10_000)) {
TreeService service = new TreeService(tree, w);

// AD: Q joins the tree's folder for SHARED; P is left as it is
List<String> notes = new ArrayList<>();
Map<String, Object> plan = service.pull(live(), "QA", List.of("AD"), true, "", notes);
List<String> changed = (List<String>) plan.get("changedFiles");
assertTrue(changed.toString(), changed.stream().anyMatch(f -> f.startsWith("libraries/Library@shared/Q")));
assertFalse(changed.toString(), changed.stream().anyMatch(f -> f.startsWith("libraries/Library@shared/P")));
assertFalse(changed.toString(), changed.stream().anyMatch(f -> f.startsWith("libraries/policies/")));
service.pull(live(), "QA", List.of("AD"), false, (String) plan.get("revision"), new ArrayList<>());
DriverSet now = AsCodeReader.read(tree);
assertNotNull(now.resolve("libraries/Library@shared/Q"));
assertTrue(now.unresolvedLinks().toString(), now.unresolvedLinks().isEmpty());
assertEquals(new String(p), new String(Files.readAllBytes(tree.resolve(firstFile(tree, "libraries/Library@shared", "P")))));

// Payroll: a container the tree has no folder for gets one, in the manifest too
notes.clear();
plan = service.pull(live(), "QA", List.of("Payroll"), true, "", notes);
changed = (List<String>) plan.get("changedFiles");
assertTrue(changed.toString(), changed.stream().anyMatch(f -> f.startsWith("libraries/policies/Odd")));
assertTrue(notes.toString(), notes.stream().anyMatch(n -> n.startsWith("libraries/policies: " + ODD)));
service.pull(live(), "QA", List.of("Payroll"), false, (String) plan.get("revision"), new ArrayList<>());
now = AsCodeReader.read(tree);
assertEquals(ODD, now.libraries.get("policies"));
assertNotNull(now.resolve("libraries/policies/Odd"));
assertTrue(now.unresolvedLinks().toString(), now.unresolvedLinks().isEmpty());
}
}

/** The file an artifact named {@code name} was written to in {@code dir}, relative to the tree. */
private static String firstFile(Path tree, String dir, String name) throws Exception {
try (java.util.stream.Stream<Path> s = Files.list(tree.resolve(dir))) {
return tree.relativize(s.filter(f -> f.getFileName().toString().startsWith(name + "."))
.findFirst().orElseThrow(() -> new AssertionError("no file for " + name + " in " + dir))).toString();
}
}
}
Loading