if (!obj.isPresent()) {
toReject.addModifiedFeature(diff);
break;
}
RevFeature feature = (RevFeature) obj.get();
DepthSearch depthSearch = new DepthSearch(stagingDatabase());
Optional<NodeRef> noderef = depthSearch.find(workingTree().getTree(), path);
RevFeatureType featureType = command(RevObjectParse.class)
.setObjectId(noderef.get().getMetadataId()).call(RevFeatureType.class).get();
ImmutableList<PropertyDescriptor> descriptors = featureType.sortedDescriptors();
Set<Entry<PropertyDescriptor, AttributeDiff>> attrDiffs = diff.getDiffs().entrySet();
boolean ok = true;
for (Iterator<Entry<PropertyDescriptor, AttributeDiff>> iterator = attrDiffs.iterator(); iterator
.hasNext();) {
Entry<PropertyDescriptor, AttributeDiff> entry = iterator.next();
AttributeDiff attrDiff = entry.getValue();
PropertyDescriptor descriptor = entry.getKey();
switch (attrDiff.getType()) {
case ADDED:
if (descriptors.contains(descriptor)) {
ok = false;
}
break;
case REMOVED:
case MODIFIED:
if (!descriptors.contains(descriptor)) {
ok = false;
break;
}
for (int i = 0; i < descriptors.size(); i++) {
if (descriptors.get(i).equals(descriptor)) {
Optional<Object> value = feature.getValues().get(i);
if (!attrDiff.canBeAppliedOn(value)) {
ok = false;
}
break;
}
}
}
}
if (!ok) {
toReject.addModifiedFeature(diff);
} else {
toApply.addModifiedFeature(diff);
}
}
List<FeatureInfo> added = patch.getAddedFeatures();
for (FeatureInfo feature : added) {
String refSpec = Ref.WORK_HEAD + ":" + feature.getPath();
obj = command(RevObjectParse.class).setRefSpec(refSpec).call();
if (obj.isPresent()) {
toReject.addAddedFeature(feature.getPath(), feature.getFeature(),
feature.getFeatureType());
} else {
toApply.addAddedFeature(feature.getPath(), feature.getFeature(),
feature.getFeatureType());
}
}
List<FeatureInfo> removed = patch.getRemovedFeatures();
for (FeatureInfo feature : removed) {
String refSpec = Ref.WORK_HEAD + ":" + feature.getPath();
obj = command(RevObjectParse.class).setRefSpec(refSpec).call();
if (!obj.isPresent()) {
toReject.addRemovedFeature(feature.getPath(), feature.getFeature(),
feature.getFeatureType());
} else {
RevFeature revFeature = (RevFeature) obj.get();
DepthSearch depthSearch = new DepthSearch(stagingDatabase());
Optional<NodeRef> noderef = depthSearch.find(workingTree().getTree(),
feature.getPath());
RevFeatureType revFeatureType = command(RevObjectParse.class)
.setObjectId(noderef.get().getMetadataId()).call(RevFeatureType.class)
.get();
RevFeature patchRevFeature = RevFeatureBuilder.build(feature.getFeature());
if (revFeature.equals(patchRevFeature)
&& revFeatureType.equals(feature.getFeatureType())) {
toApply.addRemovedFeature(feature.getPath(), feature.getFeature(),
feature.getFeatureType());
} else {
toReject.addRemovedFeature(feature.getPath(), feature.getFeature(),
feature.getFeatureType());
}
}
}
ImmutableList<FeatureTypeDiff> alteredTrees = patch.getAlteredTrees();
for (FeatureTypeDiff diff : alteredTrees) {
DepthSearch depthSearch = new DepthSearch(stagingDatabase());
Optional<NodeRef> noderef = depthSearch.find(workingTree().getTree(), diff.getPath());
ObjectId metadataId = noderef.isPresent() ? noderef.get().getMetadataId()
: ObjectId.NULL;
if (Objects.equal(metadataId, diff.getOldFeatureType())) {
toApply.addAlteredTree(diff);
} else {