use of com.b2international.index.mapping.Mappings in project snow-owl by b2ihealthcare.
the class IndexResource method before.
@Override
protected void before() throws Throwable {
if (INIT.compareAndSet(false, true)) {
mapper = new ObjectMapper();
mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
client = Indexes.createIndexClient(UUID.randomUUID().toString(), mapper, new Mappings(), indexSettings.get());
index = new DefaultIndex(client);
revisionIndex = new DefaultRevisionIndex(index, new TimestampProvider.Default(), mapper);
}
// apply mapper changes first
objectMapperConfigurator.accept(mapper);
// then mapping changes
revisionIndex.admin().updateMappings(new Mappings(types));
// then settings changes
revisionIndex.admin().updateSettings(indexSettings.get());
// then make sure we have all indexes ready for tests
revisionIndex.admin().create();
}
use of com.b2international.index.mapping.Mappings in project snow-owl by b2ihealthcare.
the class SnomedIdentifierPlugin method registerSnomedIdentifierService.
private void registerSnomedIdentifierService(final SnomedIdentifierConfiguration conf, final Environment env, final ISnomedIdentifierReservationService reservationService) {
ISnomedIdentifierService identifierService = null;
switch(conf.getStrategy()) {
case EMBEDDED:
final Index index = Indexes.createIndex(SNOMED_IDS_INDEX, env.service(ObjectMapper.class), new Mappings(SctId.class), env.service(IndexSettings.class).forIndex(env.service(RepositoryConfiguration.class).getIndexConfiguration(), SNOMED_IDS_INDEX));
index.admin().create();
final ItemIdGenerationStrategy generationStrategy = new SequentialItemIdGenerationStrategy(reservationService);
identifierService = new DefaultSnomedIdentifierService(index, generationStrategy, reservationService, conf);
break;
case CIS:
final ObjectMapper mapper = new ObjectMapper();
identifierService = new CisSnomedIdentifierService(conf, reservationService, mapper);
break;
default:
throw new IllegalStateException(String.format("Unknown ID generation source configured: %s. ", conf.getStrategy()));
}
env.services().registerService(ISnomedIdentifierService.class, identifierService);
LOGGER.info("Snow Owl is configured to use {} based identifier service.", conf.getStrategy());
}
use of com.b2international.index.mapping.Mappings in project snow-owl by b2ihealthcare.
the class StagingArea method collectConflicts.
private void collectConflicts(RevisionBranchChangeSet fromChangeSet, List<RevisionCompareDetail> fromChangeDetails, RevisionBranchChangeSet toChangeSet, List<RevisionCompareDetail> toChangeDetails, List<Conflict> conflictsToReport, Map<Class<? extends Revision>, Multimap<String, RevisionPropertyDiff>> propertyUpdatesToApply, RevisionConflictProcessor conflictProcessor) {
List<Conflict> conflicts = newArrayList();
for (Class<? extends Revision> type : ImmutableSet.copyOf(Iterables.concat(fromChangeSet.getAddedTypes(), toChangeSet.getAddedTypes()))) {
final Set<String> newRevisionIdsOnSource = fromChangeSet.getAddedIds(type);
final Set<String> newRevisionIdsOnTarget = toChangeSet.getAddedIds(type);
final Set<String> addedInSourceAndTarget = Sets.intersection(newRevisionIdsOnSource, newRevisionIdsOnTarget);
// check for added in both source and target conflicts
if (!addedInSourceAndTarget.isEmpty()) {
addedInSourceAndTarget.forEach(revisionId -> {
conflicts.add(new AddedInSourceAndTargetConflict(ObjectId.of(type, revisionId)));
});
}
// check deleted containers on target and report them as conflicts
newRevisionIdsOnSource.forEach(newRevisionOnSource -> {
ObjectId newRevisionOnSourceId = ObjectId.of(type, newRevisionOnSource);
ObjectId requiredContainer = fromChangeSet.getContainerId(newRevisionOnSourceId);
if (requiredContainer != null && toChangeSet.isRemoved(requiredContainer)) {
conflicts.add(new AddedInSourceAndDetachedInTargetConflict(newRevisionOnSourceId, requiredContainer));
}
});
// check deleted containers on source and report them as conflicts
newRevisionIdsOnTarget.forEach(newRevisionOnTarget -> {
ObjectId newRevisionOnTargetId = ObjectId.of(type, newRevisionOnTarget);
ObjectId requiredContainer = toChangeSet.getContainerId(newRevisionOnTargetId);
if (requiredContainer != null && fromChangeSet.isRemoved(requiredContainer)) {
conflicts.add(new AddedInTargetAndDetachedInSourceConflict(requiredContainer, newRevisionOnTargetId));
}
});
}
// check property conflicts
Set<String> changedRevisionIdsToCheck = newHashSet(toChangeSet.getChangedIds());
Set<String> removedRevisionIdsToCheck = newHashSet(toChangeSet.getRemovedIds());
for (Class<? extends Revision> type : fromChangeSet.getChangedTypes()) {
final DocumentMapping mapping = index.admin().mappings().getMapping(type);
final String docType = mapping.typeAsString();
Set<String> changedRevisionIdsToMerge = newHashSet(fromChangeSet.getChangedIds(type));
// first handle changed vs. removed
Set<String> changedInSourceDetachedInTargetIds = Sets.newHashSet(Sets.intersection(changedRevisionIdsToMerge, removedRevisionIdsToCheck));
if (!changedInSourceDetachedInTargetIds.isEmpty()) {
// report any conflicts
changedInSourceDetachedInTargetIds.forEach(changedInSourceDetachedInTargetId -> {
List<RevisionPropertyDiff> sourceChanges = fromChangeDetails.stream().filter(detail -> detail.getObject().id().equals(changedInSourceDetachedInTargetId)).filter(detail -> !detail.isComponentChange()).map(change -> new RevisionPropertyDiff(change.getProperty(), change.getFromValue(), change.getValue())).collect(Collectors.toList());
Conflict conflict = conflictProcessor.handleChangedInSourceDetachedInTarget(ObjectId.of(docType, changedInSourceDetachedInTargetId), sourceChanges);
if (conflict != null) {
conflicts.add(conflict);
}
});
// register them as revised on source from the target branch point of view
revisionsToReviseOnMergeSource.putAll(type, changedInSourceDetachedInTargetIds);
changedInSourceDetachedInTargetIds.forEach(id -> fromChangeSet.removeChanged(type, id));
changedRevisionIdsToMerge.removeAll(changedInSourceDetachedInTargetIds);
}
// then handle changed vs. changed with the conflict processor
Set<String> changedInSourceAndTargetIds = Sets.intersection(changedRevisionIdsToMerge, changedRevisionIdsToCheck);
if (!changedInSourceAndTargetIds.isEmpty()) {
final Map<String, Map<String, RevisionCompareDetail>> sourcePropertyChangesByObject = indexPropertyChangesByObject(fromChangeDetails);
final Map<String, Map<String, RevisionCompareDetail>> targetPropertyChangesByObject = indexPropertyChangesByObject(toChangeDetails);
for (String changedInSourceAndTargetId : changedInSourceAndTargetIds) {
// take the prop changes from both paths
final Map<String, RevisionCompareDetail> sourcePropertyChanges = sourcePropertyChangesByObject.remove(changedInSourceAndTargetId);
final Map<String, RevisionCompareDetail> targetPropertyChanges = targetPropertyChangesByObject.remove(changedInSourceAndTargetId);
if (sourcePropertyChanges != null) {
for (Entry<String, RevisionCompareDetail> sourceChange : sourcePropertyChanges.entrySet()) {
final String changedProperty = sourceChange.getKey();
final RevisionCompareDetail sourcePropertyChange = sourceChange.getValue();
final RevisionPropertyDiff sourceChangeDiff = new RevisionPropertyDiff(changedProperty, sourcePropertyChange.getFromValue(), sourcePropertyChange.getValue());
final RevisionCompareDetail targetPropertyChange = targetPropertyChanges == null ? null : targetPropertyChanges.get(changedProperty);
if (targetPropertyChange == null) {
// this property did not change in target, just apply directly on the target object via
if (!propertyUpdatesToApply.containsKey(type)) {
propertyUpdatesToApply.put(type, HashMultimap.create());
}
propertyUpdatesToApply.get(type).put(changedInSourceAndTargetId, sourceChangeDiff);
fromChangeSet.removeChanged(type, changedInSourceAndTargetId);
} else {
RevisionPropertyDiff targetChangeDiff = new RevisionPropertyDiff(targetPropertyChange.getProperty(), targetPropertyChange.getFromValue(), targetPropertyChange.getValue());
// changed on both sides, ask conflict processor to resolve the issue or raise conflict error
RevisionPropertyDiff resolution = conflictProcessor.handleChangedInSourceAndTarget(changedInSourceAndTargetId, mapping, sourceChangeDiff, targetChangeDiff, mapper);
if (resolution == null) {
conflicts.add(new ChangedInSourceAndTargetConflict(sourcePropertyChange.getObject(), sourceChangeDiff.convert(conflictProcessor), targetChangeDiff.convert(conflictProcessor)));
} else {
if (!propertyUpdatesToApply.containsKey(type)) {
propertyUpdatesToApply.put(type, HashMultimap.create());
}
propertyUpdatesToApply.get(type).put(changedInSourceAndTargetId, resolution);
}
fromChangeSet.removeChanged(type, changedInSourceAndTargetId);
}
}
} else {
fromChangeSet.removeChanged(type, changedInSourceAndTargetId);
}
// this object has changed on both sides either by tracked field changes or due to some cascading derived field change
// revise the revision on source, since we already have one on this branch already
revisionsToReviseOnMergeSource.put(type, changedInSourceAndTargetId);
}
}
}
// after generic conflict processing execute domain specific merge rules via conflict processor
conflictProcessor.checkConflicts(this, fromChangeSet, toChangeSet).forEach(conflicts::add);
// handle domain-specific conflict filtering, like donated content, etc.
// and add all reported conflicts to conflictsToReport
conflictsToReport.addAll(conflictProcessor.filterConflicts(this, conflicts));
}
use of com.b2international.index.mapping.Mappings in project snow-owl by b2ihealthcare.
the class ReservationImplTest method whenReservingRangeOfIDs_ThenItShouldConflictWithAllIDsInThatRangeIncludingBoundaries.
@Test
public void whenReservingRangeOfIDs_ThenItShouldConflictWithAllIDsInThatRangeIncludingBoundaries() throws Exception {
final Index store = Indexes.createIndex(UUID.randomUUID().toString(), new ObjectMapper(), new Mappings(SctId.class));
store.admin().create();
final ISnomedIdentifierService identifierService = new DefaultSnomedIdentifierService(store, new ItemIdGenerationStrategy() {
int counter = 200;
@Override
public Set<String> generateItemIds(String namespace, ComponentCategory category, int quantity, int attempt) {
return IntStream.range(counter, counter + quantity).mapToObj(String::valueOf).collect(Collectors.toSet());
}
}, new SnomedIdentifierReservationServiceImpl(), new SnomedIdentifierConfiguration());
final Set<ComponentCategory> components = Collections.singleton(ComponentCategory.CONCEPT);
final Reservation range = Reservations.range(200, 300, "", components);
final Set<String> componentIds = identifierService.generate(null, ComponentCategory.CONCEPT, 300 - 200 + 1);
for (String id : componentIds) {
final SnomedIdentifier identifier = SnomedIdentifiers.create(id);
assertTrue(range.includes(identifier));
}
store.admin().delete();
}
use of com.b2international.index.mapping.Mappings in project snow-owl by b2ihealthcare.
the class DefaultSnomedIdentifierServiceTest method init.
@Before
public void init() {
store = Indexes.createIndex(UUID.randomUUID().toString(), new ObjectMapper(), new Mappings(SctId.class));
store.admin().create();
final ISnomedIdentifierReservationService reservationService = new SnomedIdentifierReservationServiceImpl();
final ItemIdGenerationStrategy idGenerationStrategy = new SequentialItemIdGenerationStrategy(reservationService);
service = new DefaultSnomedIdentifierService(store, idGenerationStrategy, reservationService, new SnomedIdentifierConfiguration());
}
Aggregations