X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fservices%2FCaseInsensitiveComponentFunctionNamingStrategy.java;h=d5a2b92a42306f466bd4d94a2f00dd4de536e0e8;hb=78e89544a2077001fe3d1486f38a141cda7e10a8;hp=40115a1ac393c564017d21420dae13fe20302dea;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/services/CaseInsensitiveComponentFunctionNamingStrategy.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/services/CaseInsensitiveComponentFunctionNamingStrategy.java index 40115a1ac..d5a2b92a4 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/services/CaseInsensitiveComponentFunctionNamingStrategy.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/services/CaseInsensitiveComponentFunctionNamingStrategy.java @@ -27,14 +27,16 @@ import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.common.request.UnaryRead; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.genericrelation.Dependencies; import org.simantics.db.layer0.genericrelation.IndexQueries; import org.simantics.db.service.GraphChangeListenerSupport; import org.simantics.layer0.Layer0; import org.simantics.scl.runtime.function.Function; import org.simantics.scl.runtime.function.Function1; -import org.simantics.scl.runtime.tuple.Tuple3; import org.simantics.scl.runtime.tuple.Tuple4; import org.simantics.structural.stubs.StructuralResource2; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import gnu.trove.set.hash.THashSet; @@ -44,7 +46,7 @@ import gnu.trove.set.hash.THashSet; * *

* The type of the function is expected to be: - * ReadGraph => Resource -> String -> Integer -> List<Map<String,Object>> + * ReadGraph => Resource -> String -> Integer -> List<Resource> * * @author Tuukka Lehtonen * @@ -52,6 +54,7 @@ import gnu.trove.set.hash.THashSet; */ public class CaseInsensitiveComponentFunctionNamingStrategy extends ComponentNamingStrategyBase { + private static final Logger LOGGER = LoggerFactory.getLogger(CaseInsensitiveComponentFunctionNamingStrategy.class); protected static final boolean DEBUG_INDEX_SEARCH = false | DEBUG_ALL; @SuppressWarnings("rawtypes") @@ -133,14 +136,14 @@ public class CaseInsensitiveComponentFunctionNamingStrategy extends ComponentNam synchronized (this) { - String search = "Name:" + lowercaseName + "*"; + String search = IndexQueries.escapeTerm(Dependencies.FIELD_NAME_SEARCH, lowercaseName, true) + "*"; //$NON-NLS-1$ @SuppressWarnings("unchecked") List components = (List) index.apply(graph, indexRoot, search, Integer.MAX_VALUE); Set rs = new THashSet(); for (Resource componentResult : components) { if (DEBUG_INDEX_SEARCH) - System.out.println(getClass().getSimpleName() + ": found " + componentResult); + LOGGER.info(getClass().getSimpleName() + ": found " + componentResult); String n = graph.getPossibleRelatedValue(componentResult, L0.HasName, Bindings.STRING); if (n != null && n.toLowerCase().equals(lowercaseName)) rs.add(componentResult); @@ -194,13 +197,13 @@ public class CaseInsensitiveComponentFunctionNamingStrategy extends ComponentNam Layer0 L0 = Layer0.getInstance(graph); for (Resource componentResult : components) { if (DEBUG_INDEX_SEARCH) - System.out.println(getClass().getSimpleName() + ": found " + componentResult); + LOGGER.info(getClass().getSimpleName() + ": found " + componentResult); String name = graph.getPossibleRelatedValue(componentResult, L0.HasName, Bindings.STRING); if (name != null) reserved.add(name); } - System.err.println("found " + reserved.size() + " components"); + LOGGER.warn("found " + reserved.size() + " components"); return reserved; @@ -213,7 +216,7 @@ public class CaseInsensitiveComponentFunctionNamingStrategy extends ComponentNam Resource componentType, String proposition, boolean acceptProposition) throws NamingException, DatabaseException { Resource indexRoot = graph.syncRequest(new PossibleIndexRoot(configurationRoot)); if (indexRoot == null) { - System.err.println("Could not find index root from configuration root '" + NameUtils.getSafeName(graph, configurationRoot, true) + "'"); + LOGGER.warn("Could not find index root from configuration root '" + NameUtils.getSafeName(graph, configurationRoot, true) + "'"); if(fallbackStrategy == null) fallbackStrategy = new CaseInsensitiveComponentNamingStrategy2(graph.getService(GraphChangeListenerSupport.class), generatedNameFormat); @@ -225,7 +228,7 @@ public class CaseInsensitiveComponentFunctionNamingStrategy extends ComponentNam synchronized (this) { - String search = "Name:" + proposition + "*"; + String search = Dependencies.FIELD_NAME_SEARCH + ":" + IndexQueries.escape(proposition.toLowerCase(), true) + "*"; //$NON-NLS-1$ //$NON-NLS-2$ Set reserved = graph.syncRequest(new ComponentsRequest(new Tuple4(indexRoot, index, search, getComparator())), TransientCacheAsyncListener.instance()); @@ -237,7 +240,7 @@ public class CaseInsensitiveComponentFunctionNamingStrategy extends ComponentNam cache.addRequested(result); if (DEBUG_INDEX_SEARCH) - System.out.println(getClass().getSimpleName() + ": validated instance name " + result); + LOGGER.info(getClass().getSimpleName() + ": validated instance name " + result); return result; } @@ -265,19 +268,19 @@ public class CaseInsensitiveComponentFunctionNamingStrategy extends ComponentNam if (propositionPreFilter != null) proposition = propositionPreFilter.apply(proposition); - String search = "Name:" + IndexQueries.escape( proposition ) + "*"; + String search = IndexQueries.quoteTerm(Dependencies.FIELD_NAME_SEARCH, proposition.toLowerCase()); @SuppressWarnings("unchecked") List components = (List) index.apply(graph, indexRoot, search, Integer.MAX_VALUE); if (DEBUG_INDEX_SEARCH) - System.out.println(getClass().getSimpleName() + ": found " + components.size() + LOGGER.info(getClass().getSimpleName() + ": found " + components.size() + " index results for index root " + indexRoot + " & configurationRoot " + configurationRoot + " & proposition '" + proposition + "':"); reserved.clear(); for (Resource componentResult : components) { if (DEBUG_INDEX_SEARCH) - System.out.println(getClass().getSimpleName() + ": found " + componentResult); + LOGGER.info(getClass().getSimpleName() + ": found " + componentResult); String name = graph.getPossibleRelatedValue(componentResult, L0.HasName, Bindings.STRING); if (name != null) reserved.add(name); @@ -291,11 +294,11 @@ public class CaseInsensitiveComponentFunctionNamingStrategy extends ComponentNam result.add(name); if (DEBUG_INDEX_SEARCH) - System.out.println(getClass().getSimpleName() + ": validated instance name " + proposition + " -> " + name); + LOGGER.info(getClass().getSimpleName() + ": validated instance name " + proposition + " -> " + name); } if (DEBUG_INDEX_SEARCH) - System.out.println(getClass().getSimpleName() + ": validated instance names " + propositions + " -> " + result); + LOGGER.info(getClass().getSimpleName() + ": validated instance names " + propositions + " -> " + result); return result; }