Search in sources :

Example 1 with RevisionCompare

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

the class BranchCompareRequest method execute.

@Override
public BranchCompareResult execute(RepositoryContext context) {
    final RevisionIndex index = context.service(RevisionIndex.class);
    final Branch branchToCompare = RepositoryRequests.branching().prepareGet(compare).build().execute(context);
    final long compareHeadTimestamp = branchToCompare.headTimestamp();
    final RevisionCompare compareResult;
    final String baseBranchPath;
    if (base != null) {
        compareResult = index.compare(base, compare, limit, excludeComponentChanges);
        baseBranchPath = base;
    } else {
        compareResult = index.compare(compare, limit, excludeComponentChanges);
        baseBranchPath = branchToCompare.parentPath();
    }
    final BranchCompareResult.Builder result = BranchCompareResult.builder(baseBranchPath, compare, compareHeadTimestamp);
    final Set<ComponentIdentifier> changedContainers = Sets.newHashSet();
    for (RevisionCompareDetail detail : compareResult.getDetails()) {
        final ObjectId affectedId;
        if (detail.isComponentChange()) {
            affectedId = detail.getComponent();
            if (!detail.getObject().isRoot() && !excludeComponentChanges) {
                changedContainers.add(ComponentIdentifier.of(detail.getObject().type(), detail.getObject().id()));
            }
        } else {
            affectedId = detail.getObject();
        }
        final ComponentIdentifier identifier = ComponentIdentifier.of(affectedId.type(), affectedId.id());
        switch(detail.getOp()) {
            case ADD:
                result.putNewComponent(identifier);
                break;
            case CHANGE:
                result.putChangedComponent(identifier);
                break;
            case REMOVE:
                result.putDeletedComponent(identifier);
                break;
        }
    }
    return result.totalNew(compareResult.getTotalAdded()).totalChanged(compareResult.getTotalChanged()).totalDeleted(compareResult.getTotalRemoved()).build(changedContainers);
}
Also used : RevisionIndex(com.b2international.index.revision.RevisionIndex) ObjectId(com.b2international.index.revision.ObjectId) Branch(com.b2international.snowowl.core.branch.Branch) RevisionCompare(com.b2international.index.revision.RevisionCompare) ComponentIdentifier(com.b2international.snowowl.core.ComponentIdentifier) RevisionCompareDetail(com.b2international.index.revision.RevisionCompareDetail)

Aggregations

ObjectId (com.b2international.index.revision.ObjectId)1 RevisionCompare (com.b2international.index.revision.RevisionCompare)1 RevisionCompareDetail (com.b2international.index.revision.RevisionCompareDetail)1 RevisionIndex (com.b2international.index.revision.RevisionIndex)1 ComponentIdentifier (com.b2international.snowowl.core.ComponentIdentifier)1 Branch (com.b2international.snowowl.core.branch.Branch)1