Search in sources :

Example 1 with FullTextSearchConfigurationType

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);
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismValue(com.evolveum.midpoint.prism.PrismValue) Item(com.evolveum.midpoint.prism.Item) FullTextSearchConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchConfigurationType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 2 with FullTextSearchConfigurationType

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;
}
Also used : PrismValue(com.evolveum.midpoint.prism.PrismValue) java.util(java.util) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Item(com.evolveum.midpoint.prism.Item) FullTextSearchIndexedItemsConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchIndexedItemsConfigurationType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Trace(com.evolveum.midpoint.util.logging.Trace) FullTextSearchConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchConfigurationType) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) Nullable(org.jetbrains.annotations.Nullable) QNameUtil(com.evolveum.midpoint.util.QNameUtil) PrismContext(com.evolveum.midpoint.prism.PrismContext) ItemPathCollectionsUtil(com.evolveum.midpoint.prism.path.ItemPathCollectionsUtil) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) FullTextSearchIndexedItemsConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchIndexedItemsConfigurationType) QName(javax.xml.namespace.QName) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with FullTextSearchConfigurationType

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;
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) FullTextSearchIndexedItemsConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchIndexedItemsConfigurationType) Set(java.util.Set) FullTextSearchConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchConfigurationType) Collectors(java.util.stream.Collectors) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) HashSet(java.util.HashSet) QNameUtil(com.evolveum.midpoint.util.QNameUtil) List(java.util.List) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) FullTextSearchIndexedItemsConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchIndexedItemsConfigurationType) QName(javax.xml.namespace.QName) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) HashSet(java.util.HashSet) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with FullTextSearchConfigurationType

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);
            }
        }
    }
}
Also used : PrismIdentifierGenerator(com.evolveum.midpoint.repo.sql.util.PrismIdentifierGenerator) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Session(org.hibernate.Session) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) FullTextSearchConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchConfigurationType) RObjectTextInfo(com.evolveum.midpoint.repo.sql.data.common.RObjectTextInfo) DebugUtil(com.evolveum.midpoint.util.DebugUtil) StringUtils(org.apache.commons.lang3.StringUtils) SqlRepositoryConfiguration(com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration) FullTextSearchUtil(com.evolveum.midpoint.schema.util.FullTextSearchUtil) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) EquivalenceStrategy(com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) PrismContext(com.evolveum.midpoint.prism.PrismContext) RepositoryContext(com.evolveum.midpoint.repo.sql.data.RepositoryContext) RelationRegistry(com.evolveum.midpoint.schema.RelationRegistry) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) Collection(java.util.Collection) Set(java.util.Set) PrismObject(com.evolveum.midpoint.prism.PrismObject) Collectors(java.util.stream.Collectors) ObjectUpdater(com.evolveum.midpoint.repo.sql.helpers.ObjectUpdater) Component(org.springframework.stereotype.Component) PrismEntityMapper(com.evolveum.midpoint.repo.sql.helpers.modify.PrismEntityMapper) RepoModifyOptions(com.evolveum.midpoint.repo.api.RepoModifyOptions) ManagedType(javax.persistence.metamodel.ManagedType) ExtItemDictionary(com.evolveum.midpoint.repo.sql.data.common.dictionary.ExtItemDictionary) RObjectType(com.evolveum.midpoint.repo.sql.data.common.other.RObjectType) EntityRegistry(com.evolveum.midpoint.repo.sql.helpers.modify.EntityRegistry) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) RShadow(com.evolveum.midpoint.repo.sql.data.common.RShadow) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) RepositoryContext(com.evolveum.midpoint.repo.sql.data.RepositoryContext) FullTextSearchConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchConfigurationType) RObjectTextInfo(com.evolveum.midpoint.repo.sql.data.common.RObjectTextInfo)

Aggregations

FullTextSearchConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchConfigurationType)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)3 Collectors (java.util.stream.Collectors)3 Item (com.evolveum.midpoint.prism.Item)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)2 PrismValue (com.evolveum.midpoint.prism.PrismValue)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)2 QNameUtil (com.evolveum.midpoint.util.QNameUtil)2 Trace (com.evolveum.midpoint.util.logging.Trace)2 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)2 FullTextSearchIndexedItemsConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchIndexedItemsConfigurationType)2 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)2 Set (java.util.Set)2 QName (javax.xml.namespace.QName)2 StringUtils (org.apache.commons.lang3.StringUtils)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)1