use of com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchConfigurationType in project midpoint by Evolveum.
the class RObjectTextInfo method createItemsSet.
public static Set<RObjectTextInfo> createItemsSet(@NotNull ObjectType object, @NotNull RObject repo, @NotNull RepositoryContext repositoryContext) {
FullTextSearchConfigurationType config = repositoryContext.repositoryService.getFullTextSearchConfiguration();
if (!FullTextSearchUtil.isEnabled(config)) {
return Collections.emptySet();
}
Set<ItemPath> paths = FullTextSearchUtil.getFullTextSearchItemPaths(config, object.getClass());
List<PrismValue> values = new ArrayList<>();
for (ItemPath path : paths) {
Object o = object.asPrismObject().find(path);
if (o == null) {
// shouldn't occur
} else if (o instanceof PrismValue) {
values.add((PrismValue) o);
} else if (o instanceof Item) {
values.addAll(((Item<?, ?>) o).getValues());
} else {
throw new IllegalStateException("Unexpected value " + o + " in " + object + " at " + path);
}
}
// not a (hash) set in order to preserve order
List<String> allWords = new ArrayList<>();
for (PrismValue value : values) {
if (value == null) {
continue;
}
if (value instanceof PrismPropertyValue) {
Object realValue = value.getRealValue();
if (realValue == null) {
// skip
} else if (realValue instanceof String) {
append(allWords, (String) realValue, repositoryContext.prismContext);
} else if (realValue instanceof PolyString) {
append(allWords, (PolyString) realValue, repositoryContext.prismContext);
} else {
append(allWords, realValue.toString(), repositoryContext.prismContext);
}
}
}
int maxTextSize = repositoryContext.configuration.getTextInfoColumnSize();
LOGGER.trace("Indexing {}:\n items: {}\n values: {}\n words: {}\n max text size: {}", object, paths, values, allWords, maxTextSize);
return createItemsSet(repo, allWords, maxTextSize);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchConfigurationType in project midpoint by Evolveum.
the class FullTextSearchUtil method getFullTextSearchItemPaths.
@NotNull
public static Set<ItemPath> getFullTextSearchItemPaths(@NotNull FullTextSearchConfigurationType config, Class<? extends ObjectType> clazz) {
List<QName> types = ObjectTypes.getObjectType(clazz).thisAndSupertypes().stream().map(ot -> ot.getTypeQName()).collect(Collectors.toList());
Set<ItemPath> paths = new HashSet<>();
for (FullTextSearchIndexedItemsConfigurationType indexed : config.getIndexed()) {
if (isApplicable(indexed, types)) {
for (ItemPathType itemPathType : indexed.getItem()) {
ItemPath path = itemPathType.getItemPath();
if (!ItemPath.isEmpty(path) && !ItemPathCollectionsUtil.containsEquivalent(paths, path)) {
paths.add(path);
}
}
}
}
return paths;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchConfigurationType in project midpoint by Evolveum.
the class FullTextSearchConfigurationUtil method getFullTextSearchItemPaths.
@NotNull
public static Set<ItemPath> getFullTextSearchItemPaths(@NotNull FullTextSearchConfigurationType config, Class<? extends ObjectType> clazz) {
List<QName> types = ObjectTypes.getObjectType(clazz).thisAndSupertypes().stream().map(ot -> ot.getTypeQName()).collect(Collectors.toList());
Set<ItemPath> paths = new HashSet<>();
for (FullTextSearchIndexedItemsConfigurationType indexed : config.getIndexed()) {
if (isApplicable(indexed, types)) {
for (ItemPathType itemPathType : indexed.getItem()) {
ItemPath path = itemPathType.getItemPath();
if (!ItemPath.isNullOrEmpty(path) && !ItemPath.containsEquivalent(paths, path)) {
paths.add(path);
}
}
}
}
return paths;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchConfigurationType in project midpoint by Evolveum.
the class ObjectDeltaUpdater method handleObjectTextInfoChanges.
private void handleObjectTextInfoChanges(Class<? extends ObjectType> type, Collection<? extends ItemDelta<?, ?>> modifications, PrismObject<?> prismObject, RObject object) {
FullTextSearchConfigurationType config = repositoryService.getFullTextSearchConfiguration();
if (!FullTextSearchUtil.isObjectTextInfoRecomputationNeeded(config, type, modifications)) {
return;
}
Set<RObjectTextInfo> newInfos = RObjectTextInfo.createItemsSet((ObjectType) prismObject.asObjectable(), object, new RepositoryContext(repositoryService, prismContext, relationRegistry, extItemDictionary, repositoryConfiguration));
if (newInfos == null || newInfos.isEmpty()) {
object.getTextInfoItems().clear();
} else {
Set<String> existingTexts = object.getTextInfoItems().stream().map(info -> info.getText()).collect(Collectors.toSet());
Set<String> newTexts = newInfos.stream().map(info -> info.getText()).collect(Collectors.toSet());
object.getTextInfoItems().removeIf(existingInfo -> !newTexts.contains(existingInfo.getText()));
for (RObjectTextInfo newInfo : newInfos) {
if (!existingTexts.contains(newInfo.getText())) {
object.getTextInfoItems().add(newInfo);
}
}
}
}
Aggregations