use of com.b2international.index.revision.RevisionCompareDetail 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);
}
Aggregations