Skip to content

Commit

Permalink
Merge branch 'extended-3.5' of https://github.com/Evolveum/midpoint i…
Browse files Browse the repository at this point in the history
…nto extended-3.5_
  • Loading branch information
KaterynaHonchar committed Mar 1, 2017
2 parents 608ed0a + f3b30d3 commit c8cdf36
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 41 deletions.
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2010-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.schema.util;

import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchIndexedItemsConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import org.jetbrains.annotations.NotNull;

import javax.xml.namespace.QName;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
* @author mederly
*/
public class FullTextSearchConfigurationUtil {

public static boolean isEnabled(FullTextSearchConfigurationType config) {
return config != null && !config.getIndexed().isEmpty() && !Boolean.FALSE.equals(config.isEnabled());
}

public static boolean isEnabledFor(FullTextSearchConfigurationType config, Class<? extends ObjectType> clazz) {
return isEnabled(config) && !getFullTextSearchItemPaths(config, clazz).isEmpty();
}

@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;
}

private static boolean isApplicable(FullTextSearchIndexedItemsConfigurationType indexed, List<QName> types) {
if (indexed.getObjectType().isEmpty()) {
return true;
}
for (QName type : types) {
if (QNameUtil.matchAny(type, indexed.getObjectType())) {
return true;
}
}
return false;
}
}
Expand Up @@ -17,7 +17,6 @@
package com.evolveum.midpoint.schema.util;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FullTextSearchConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.InternalsConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;

Expand Down Expand Up @@ -54,7 +53,4 @@ public static Integer getMaxModelClicks(PrismObject<SystemConfigurationType> sys
return sysconfigObject.asObjectable().getInternals().getMaxModelClicks();
}

public static boolean isFullTextSearchEnabled(FullTextSearchConfigurationType config) {
return config != null && !config.getIndexed().isEmpty() && !Boolean.FALSE.equals(config.isEnabled());
}
}
Expand Up @@ -26,25 +26,19 @@
import com.evolveum.midpoint.repo.sql.data.common.id.RObjectTextInfoId;
import com.evolveum.midpoint.repo.sql.query2.definition.NotQueryable;
import com.evolveum.midpoint.repo.sql.util.RUtil;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.util.SystemConfigurationTypeUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.schema.util.FullTextSearchConfigurationUtil;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.ForeignKey;
import org.jetbrains.annotations.NotNull;

import javax.persistence.*;
import javax.xml.namespace.QName;
import java.io.Serializable;
import java.util.*;
import java.util.Objects;
import java.util.stream.Collectors;

import static com.evolveum.midpoint.repo.sql.data.common.RObjectTextInfo.COLUMN_OWNER_OID;
import static com.evolveum.midpoint.repo.sql.data.common.RObjectTextInfo.TABLE_NAME;

/**
Expand Down Expand Up @@ -132,26 +126,10 @@ public static <T extends ObjectType> Set<RObjectTextInfo> createItemsSet(@NotNul
@NotNull RepositoryContext repositoryContext) {

FullTextSearchConfigurationType config = repositoryContext.repositoryService.getFullTextSearchConfiguration();
if (!SystemConfigurationTypeUtil.isFullTextSearchEnabled(config)) {
if (!FullTextSearchConfigurationUtil.isEnabled(config)) {
return Collections.emptySet();
}
List<QName> types =
ObjectTypes.getObjectType(object.getClass()).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 (path.isEmpty()) {
LOGGER.debug("Empty path in full time index configuration; skipping.");
} else if (!ItemPath.containsEquivalent(paths, path)) {
paths.add(path);
}
}
}
}
Set<ItemPath> paths = FullTextSearchConfigurationUtil.getFullTextSearchItemPaths(config, object.getClass());

List<PrismValue> values = new ArrayList<>();
for (ItemPath path : paths) {
Expand Down Expand Up @@ -189,18 +167,6 @@ public static <T extends ObjectType> Set<RObjectTextInfo> createItemsSet(@NotNul
return createItemsSet(repo, allWords);
}

private static boolean isApplicable(FullTextSearchIndexedItemsConfigurationType indexed, List<QName> types) {
if (indexed.getObjectType().isEmpty()) {
return true;
}
for (QName type : types) {
if (QNameUtil.matchAny(type, indexed.getObjectType())) {
return true;
}
}
return false;
}

private static Set<RObjectTextInfo> createItemsSet(RObject repo, List<String> allWords) {
Set<RObjectTextInfo> rv = new HashSet<>();
StringBuilder sb = new StringBuilder();
Expand Down

0 comments on commit c8cdf36

Please sign in to comment.