use of com.b2international.index.revision.RevisionBranch in project snow-owl by b2ihealthcare.
the class BranchSearchRequest method toBranchData.
private List<Branch> toBranchData(final BaseRevisionBranching branching, final Iterable<RevisionBranch> hits) {
final Map<String, RevisionBranch> branchesById = newHashMap();
final ImmutableList.Builder<Branch> branches = ImmutableList.builder();
for (RevisionBranch doc : hits) {
final BranchState state;
if (doc.isMain()) {
// XXX MAIN branch is always up to date
state = BranchState.UP_TO_DATE;
} else {
final String parentPath = doc.getParentPath();
if (!branchesById.containsKey(parentPath)) {
branchesById.put(parentPath, branching.getBranch(parentPath));
}
state = branching.getBranchState(doc, branchesById.get(parentPath));
}
branches.add(new Branch(doc, state, BranchPathUtils.createPath(doc.getPath()), doc.getMergeSources()));
}
return branches.build();
}
use of com.b2international.index.revision.RevisionBranch in project snow-owl by b2ihealthcare.
the class BranchSearchRequest method toCollectionResource.
@Override
protected Branches toCollectionResource(RepositoryContext context, Hits<RevisionBranch> hits) {
final BaseRevisionBranching branching = context.service(BaseRevisionBranching.class);
final List<Branch> branchHits = toBranchData(branching, hits);
expand(context, branchHits);
return new Branches(branchHits, hits.getSearchAfter(), limit(), hits.getTotal());
}
use of com.b2international.index.revision.RevisionBranch in project snow-owl by b2ihealthcare.
the class SnomedBranchRequestTest method assertBranchSegmentsValid.
// assert the low level segments
private void assertBranchSegmentsValid(final String parentPath, final String createdFirstPath, final String createdSecondPath) {
BaseRevisionBranching branching = ApplicationContext.getServiceForClass(RepositoryManager.class).get(REPOSITORY_ID).service(BaseRevisionBranching.class);
RevisionBranch parent = branching.getBranch(parentPath);
RevisionBranch createdFirst = branching.getBranch(createdFirstPath);
RevisionBranch createdSecond = branching.getBranch(createdSecondPath);
SortedSet<RevisionSegment> firstParentSegments = createdFirst.getParentSegments();
SortedSet<RevisionSegment> secondParentSegments = createdSecond.getParentSegments();
// verify that first and second has a common parent start address (END address is their base timestamp, so that will be different)
assertEquals(firstParentSegments.last().getStartAddress(), secondParentSegments.last().getStartAddress());
assertNotEquals(firstParentSegments.last().getEndAddress(), secondParentSegments.last().getEndAddress());
// and parent-parent-segments of first and second are equal
assertEquals(firstParentSegments.headSet(firstParentSegments.last()), secondParentSegments.headSet(secondParentSegments.last()));
}
use of com.b2international.index.revision.RevisionBranch in project snow-owl by b2ihealthcare.
the class BranchReopenRequest method execute.
@Override
public Boolean execute(RepositoryContext context) {
final BaseRevisionBranching branching = context.service(BaseRevisionBranching.class);
final RevisionBranch branch = branching.getBranch(getBranchPath());
try {
final RevisionBranch parentBranch = branching.getBranch(branch.getParentPath());
branching.reopen(parentBranch, branch.getName(), branch.metadata());
return true;
} catch (NotFoundException e) {
// if parent not found, convert it to BadRequestException
throw e.toBadRequestException();
}
}
use of com.b2international.index.revision.RevisionBranch in project snow-owl by b2ihealthcare.
the class CodeSystemConverter method expandUpgradeOfInfo.
private void expandUpgradeOfInfo(List<CodeSystem> results) {
if (!expand().containsKey(CodeSystem.Expand.UPGRADE_INFO)) {
return;
}
final List<ResourceURI> upgradeOfURIs = results.stream().filter(codeSystem -> codeSystem.getUpgradeOf() != null).map(codeSystem -> codeSystem.getUpgradeOf().withoutPath()).collect(Collectors.toList());
// nothing to expand, quit early
if (upgradeOfURIs.isEmpty()) {
return;
}
final List<String> upgradeOfBranches = context().service(ResourceURIPathResolver.class).resolve(context(), upgradeOfURIs);
final Map<ResourceURI, String> branchesByUpgradeOf = Maps.newHashMap();
Iterator<ResourceURI> uriIterator = upgradeOfURIs.iterator();
Iterator<String> branchIterator = upgradeOfBranches.iterator();
while (uriIterator.hasNext() && branchIterator.hasNext()) {
ResourceURI uri = uriIterator.next();
String branch = branchIterator.next();
branchesByUpgradeOf.put(uri, branch);
}
for (CodeSystem result : results) {
BaseRevisionBranching branching = context().service(RepositoryManager.class).get(result.getToolingId()).service(BaseRevisionBranching.class);
String upgradeOfCodeSystemBranchPath = branchesByUpgradeOf.get(result.getUpgradeOf().withoutPath());
if (!Strings.isNullOrEmpty(upgradeOfCodeSystemBranchPath)) {
RevisionBranch branch = branching.getBranch(result.getBranchPath());
BranchState branchState = branching.getBranchState(result.getBranchPath(), upgradeOfCodeSystemBranchPath);
BranchInfo mainInfo = new BranchInfo(branch.getPath(), branchState, branch.getBaseTimestamp(), branch.getHeadTimestamp());
List<ResourceURI> availableVersions = Lists.newArrayList();
List<BranchInfo> versionBranchInfo = Lists.newArrayList();
if (!result.getUpgradeOf().isHead()) {
long startTimestamp;
final String upgradeOfVersionBranch = context().service(ResourceURIPathResolver.class).resolve(context(), List.of(result.getUpgradeOf())).stream().findFirst().orElse("");
if (!Strings.isNullOrEmpty(upgradeOfVersionBranch)) {
startTimestamp = branching.getBranch(upgradeOfVersionBranch).getBaseTimestamp() + 1;
} else {
startTimestamp = Long.MIN_VALUE;
}
ResourceRequests.prepareSearchVersion().all().filterByResource(result.getUpgradeOf().withoutPath()).filterByResourceBranchPath(upgradeOfCodeSystemBranchPath).build().execute(context()).stream().filter(csv -> !csv.getVersionResourceURI().isHead()).forEach(csv -> {
RevisionBranch versionBranch = branching.getBranch(csv.getBranchPath());
if (versionBranch.getBaseTimestamp() > startTimestamp) {
BranchState versionBranchState = branching.getBranchState(result.getBranchPath(), versionBranch.getPath());
if (versionBranchState == BranchState.BEHIND || versionBranchState == BranchState.DIVERGED) {
availableVersions.add(csv.getVersionResourceURI());
}
versionBranchInfo.add(new BranchInfo(branch.getPath(), versionBranchState, versionBranch.getBaseTimestamp(), versionBranch.getHeadTimestamp()));
}
});
}
result.setUpgradeInfo(new UpgradeInfo(mainInfo, versionBranchInfo, availableVersions));
}
}
}
Aggregations