use of com.b2international.snowowl.core.validation.whitelist.ValidationWhiteList in project snow-owl by b2ihealthcare.
the class ValidationWhiteListApiTest method createWhiteList.
@Test
public void createWhiteList() throws Exception {
final String whiteListId = createWhiteLists("58", COMPONENT_ID);
assertThat(whiteListId).isNotEmpty();
final ValidationWhiteList whiteList = ValidationRequests.whiteList().prepareGet(whiteListId).buildAsync().getRequest().execute(context);
assertThat(whiteList.getRuleId()).isEqualTo("58");
assertThat(whiteList.getComponentIdentifier()).isEqualTo(COMPONENT_ID);
}
use of com.b2international.snowowl.core.validation.whitelist.ValidationWhiteList in project snow-owl by b2ihealthcare.
the class ValidationRepositoryContext method commit.
void commit() {
if (!newObjects.isEmpty() || !objectsToDelete.isEmpty()) {
final Set<String> ruleIdsAffectedByDeletion = Sets.newHashSet();
service(ValidationRepository.class).write(writer -> {
writer.putAll(newObjects);
final Multimap<String, ComponentIdentifier> addToWhitelist = HashMultimap.create();
newObjects.stream().filter(ValidationWhiteList.class::isInstance).map(ValidationWhiteList.class::cast).forEach(whitelist -> addToWhitelist.put(whitelist.getRuleId(), whitelist.getComponentIdentifier()));
if (!addToWhitelist.isEmpty()) {
ExpressionBuilder filter = Expressions.builder();
for (String ruleId : addToWhitelist.keySet()) {
filter.should(Expressions.builder().filter(Expressions.exactMatch(ValidationIssue.Fields.RULE_ID, ruleId)).filter(Expressions.matchAny(ValidationIssue.Fields.AFFECTED_COMPONENT_ID, addToWhitelist.get(ruleId).stream().map(ComponentIdentifier::getComponentId).collect(Collectors.toSet()))).build());
}
writer.bulkUpdate(new BulkUpdate<>(ValidationIssue.class, filter.build(), ValidationIssue.Scripts.WHITELIST, ImmutableMap.of("whitelisted", true)));
}
final Multimap<String, ComponentIdentifier> removeFromWhitelist = HashMultimap.create();
ValidationRequests.whiteList().prepareSearch().all().filterByIds(ImmutableSet.copyOf(objectsToDelete.get(ValidationWhiteList.class))).build().execute(this).forEach(whitelist -> removeFromWhitelist.put(whitelist.getRuleId(), whitelist.getComponentIdentifier()));
if (!removeFromWhitelist.isEmpty()) {
ExpressionBuilder filter = Expressions.builder();
for (String ruleId : removeFromWhitelist.keySet()) {
ruleIdsAffectedByDeletion.add(ruleId);
filter.should(Expressions.builder().filter(Expressions.exactMatch(ValidationIssue.Fields.RULE_ID, ruleId)).filter(Expressions.matchAny(ValidationIssue.Fields.AFFECTED_COMPONENT_ID, removeFromWhitelist.get(ruleId).stream().map(ComponentIdentifier::getComponentId).collect(Collectors.toSet()))).build());
}
writer.bulkUpdate(new BulkUpdate<>(ValidationIssue.class, filter.build(), ValidationIssue.Scripts.WHITELIST, ImmutableMap.of("whitelisted", false)));
}
final Map<Class<?>, Set<String>> docsToDelete = newHashMap();
objectsToDelete.asMap().forEach((type, ids) -> docsToDelete.put(type, ImmutableSet.copyOf(ids)));
writer.removeAll(docsToDelete);
writer.commit();
return null;
});
if (!newObjects.isEmpty()) {
final Set<String> addedWhiteLists = newHashSet();
final Set<String> affectedRuleIds = newHashSet();
newObjects.forEach((doc) -> {
if (doc instanceof ValidationWhiteList) {
ValidationWhiteList whitelistedDoc = (ValidationWhiteList) doc;
affectedRuleIds.add(whitelistedDoc.getRuleId());
addedWhiteLists.add(whitelistedDoc.getId());
}
});
if (!addedWhiteLists.isEmpty()) {
WhiteListNotification.added(addedWhiteLists, affectedRuleIds).publish(service(IEventBus.class));
}
}
if (!objectsToDelete.isEmpty()) {
final Set<String> removedWhiteLists = ImmutableSet.copyOf(objectsToDelete.get(ValidationWhiteList.class));
if (!removedWhiteLists.isEmpty()) {
WhiteListNotification.removed(removedWhiteLists, ruleIdsAffectedByDeletion).publish(service(IEventBus.class));
}
}
}
}
Aggregations