use of com.b2international.snowowl.core.branch.BranchInfo 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));
}
}
}
use of com.b2international.snowowl.core.branch.BranchInfo in project snow-owl by b2ihealthcare.
the class CodeSystemConverter method expandExtensionOfBranchState.
private void expandExtensionOfBranchState(List<CodeSystem> results) {
if (!expand().containsKey(CodeSystem.Expand.EXTENSION_OF_BRANCH_INFO)) {
return;
}
// extensionOf branches are the parent branches of the CodeSystem, so simple branch state calculation is enough
BaseRevisionBranching branching = context().service(BaseRevisionBranching.class);
for (CodeSystem result : results) {
RevisionBranch branch = branching.getBranch(result.getBranchPath());
BranchState branchState = branching.getBranchState(branch);
result.setExtensionOfBranchInfo(new BranchInfo(branch.getPath(), branchState, branch.getBaseTimestamp(), branch.getHeadTimestamp()));
}
}
Aggregations