Search in sources :

Example 1 with BranchState

use of com.b2international.index.revision.RevisionBranch.BranchState 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();
}
Also used : RevisionBranch(com.b2international.index.revision.RevisionBranch) ImmutableList(com.google.common.collect.ImmutableList) RevisionBranch(com.b2international.index.revision.RevisionBranch) BranchState(com.b2international.index.revision.RevisionBranch.BranchState)

Example 2 with BranchState

use of com.b2international.index.revision.RevisionBranch.BranchState 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));
        }
    }
}
Also used : BaseRevisionBranching(com.b2international.index.revision.BaseRevisionBranching) java.util(java.util) BranchState(com.b2international.index.revision.RevisionBranch.BranchState) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) ResourceRequests(com.b2international.snowowl.core.request.ResourceRequests) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) RevisionBranch(com.b2international.index.revision.RevisionBranch) BranchInfo(com.b2international.snowowl.core.branch.BranchInfo) ResourceURIPathResolver(com.b2international.snowowl.core.uri.ResourceURIPathResolver) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Multimaps(com.google.common.collect.Multimaps) ResourceDocument(com.b2international.snowowl.core.internal.ResourceDocument) Strings(com.google.common.base.Strings) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) Options(com.b2international.commons.options.Options) Lists(com.google.common.collect.Lists) TreeMultimap(com.google.common.collect.TreeMultimap) Versions(com.b2international.snowowl.core.version.Versions) ResourceURI(com.b2international.snowowl.core.ResourceURI) BaseResourceConverter(com.b2international.snowowl.core.request.BaseResourceConverter) Version(com.b2international.snowowl.core.version.Version) ResourceURI(com.b2international.snowowl.core.ResourceURI) RevisionBranch(com.b2international.index.revision.RevisionBranch) BranchInfo(com.b2international.snowowl.core.branch.BranchInfo) BranchState(com.b2international.index.revision.RevisionBranch.BranchState) BaseRevisionBranching(com.b2international.index.revision.BaseRevisionBranching) ResourceURIPathResolver(com.b2international.snowowl.core.uri.ResourceURIPathResolver)

Example 3 with BranchState

use of com.b2international.index.revision.RevisionBranch.BranchState in project snow-owl by b2ihealthcare.

the class BaseRevisionBranching method doMerge.

Commit doMerge(BranchMergeOperation operation) {
    String source = operation.fromPath;
    String target = operation.toPath;
    if (target.equals(source)) {
        throw new BadRequestException(String.format("Can't merge branch '%s' onto itself.", target));
    }
    RevisionBranch from = getBranch(source);
    RevisionBranch to = getBranch(target);
    BranchState changesFromState = getBranchState(from, to);
    // do nothing if from state compared to toBranch is either UP_TO_DATE or BEHIND
    if (changesFromState == BranchState.UP_TO_DATE || changesFromState == BranchState.BEHIND) {
        return null;
    }
    final InternalRevisionIndex index = revisionIndex();
    final StagingArea staging = index.prepareCommit(to.getPath()).withContext(operation.context);
    // apply changes from source ref
    staging.merge(from.ref(), to.ref(), operation.squash, operation.conflictProcessor, operation.exclusions);
    // commit changes to index
    final String commitMessage = !Strings.isNullOrEmpty(operation.commitMessage) ? operation.commitMessage : String.format("Merge %s into %s", source, target);
    return staging.commit(currentTime(), operation.author, commitMessage);
}
Also used : BranchState(com.b2international.index.revision.RevisionBranch.BranchState)

Example 4 with BranchState

use of com.b2international.index.revision.RevisionBranch.BranchState 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()));
    }
}
Also used : RevisionBranch(com.b2international.index.revision.RevisionBranch) BranchInfo(com.b2international.snowowl.core.branch.BranchInfo) BranchState(com.b2international.index.revision.RevisionBranch.BranchState) BaseRevisionBranching(com.b2international.index.revision.BaseRevisionBranching)

Aggregations

BranchState (com.b2international.index.revision.RevisionBranch.BranchState)4 RevisionBranch (com.b2international.index.revision.RevisionBranch)3 BaseRevisionBranching (com.b2international.index.revision.BaseRevisionBranching)2 BranchInfo (com.b2international.snowowl.core.branch.BranchInfo)2 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)1 Options (com.b2international.commons.options.Options)1 RepositoryManager (com.b2international.snowowl.core.RepositoryManager)1 ResourceURI (com.b2international.snowowl.core.ResourceURI)1 RepositoryContext (com.b2international.snowowl.core.domain.RepositoryContext)1 ResourceDocument (com.b2international.snowowl.core.internal.ResourceDocument)1 BaseResourceConverter (com.b2international.snowowl.core.request.BaseResourceConverter)1 ResourceRequests (com.b2international.snowowl.core.request.ResourceRequests)1 ResourceURIPathResolver (com.b2international.snowowl.core.uri.ResourceURIPathResolver)1 Version (com.b2international.snowowl.core.version.Version)1 Versions (com.b2international.snowowl.core.version.Versions)1 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Multimaps (com.google.common.collect.Multimaps)1