// Link extraction from a record without versions
//
{
Record record = repository.newRecord();
record.setRecordType(recordType.getName());
record.setField(nonVersionedFt.getName(), new Link(ids.newRecordId("foo1")));
record = repository.create(record);
repoSetup.waitForSepProcessing();
Set<RecordId> referrers = linkIndex.getReferrers(ids.newRecordId("foo1"), lastVTag);
assertEquals(1, referrers.size());
assertTrue(referrers.contains(record.getId()));
referrers = linkIndex.getReferrers(ids.newRecordId("bar1"), lastVTag);
assertEquals(0, referrers.size());
// Now perform an update so that there is a version
record.setField(versionedFt.getName(), Arrays.asList(new Link(ids.newRecordId("foo2")),
new Link(ids.newRecordId("foo3"))));
record = repository.update(record);
repoSetup.waitForSepProcessing();
referrers = linkIndex.getReferrers(ids.newRecordId("foo1"), lastVTag);
assertEquals(1, referrers.size());
assertTrue(referrers.contains(record.getId()));
referrers = linkIndex.getReferrers(ids.newRecordId("foo2"), lastVTag);
assertEquals(1, referrers.size());
assertTrue(referrers.contains(record.getId()));
}
//
// Link extraction from nested types
//
{
Record record = repository
.recordBuilder()
.defaultNamespace("ns")
.recordType("MyRecordType")
.field("nestedLinks",
Arrays.asList(
Arrays.asList(
new HierarchyPath(new Link(ids.newRecordId("nl1"))),
new HierarchyPath(new Link(ids.newRecordId("nl2")))
),
Arrays.asList(
new HierarchyPath(new Link(ids.newRecordId("nl3"))),
new HierarchyPath(new Link(ids.newRecordId("nl4")))
)
))
.create();
repoSetup.waitForSepProcessing();
Set<RecordId> referrers = linkIndex.getReferrers(ids.newRecordId("nl1"), lastVTag);
assertEquals(1, referrers.size());
assertTrue(referrers.contains(record.getId()));
Set<RecordId> forwardLinks = linkIndex.getForwardLinks(record.getId(), lastVTag, nestedFt.getId());
assertEquals(4, forwardLinks.size());
assertTrue(forwardLinks.contains(ids.newRecordId("nl1")));
assertTrue(forwardLinks.contains(ids.newRecordId("nl2")));
assertTrue(forwardLinks.contains(ids.newRecordId("nl3")));
assertTrue(forwardLinks.contains(ids.newRecordId("nl4")));
}
//
// Link extraction from complex types
//
{
Record record = repository
.recordBuilder()
.defaultNamespace("ns")
.recordType("MyRecordType")
.field("complexLinks",
Arrays.asList(
repository
.recordBuilder()
.defaultNamespace("ns")
.recordType("MyRecordType")
.field("link1", new Link(ids.newRecordId("cl1")))
.build(),
repository
.recordBuilder()
.defaultNamespace("ns")
.recordType("MyRecordType")
.field("link1", new Link(ids.newRecordId("cl2")))
.build()
))
.create();
repoSetup.waitForSepProcessing();