X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Ftechtype%2FTechTypeUtils.java;fp=org.simantics.district.network%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Ftechtype%2FTechTypeUtils.java;h=930435ba2ef6b859339311852fc1de49396688d7;hb=29af77f249a4842bfd3f9280755121c9c98b32a1;hp=377253dde3d108b433c572d6e0ddc576872b30ab;hpb=62f9a86961adc4fd44782e3c2f79852b1269810d;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network/src/org/simantics/district/network/techtype/TechTypeUtils.java b/org.simantics.district.network/src/org/simantics/district/network/techtype/TechTypeUtils.java index 377253dd..930435ba 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/techtype/TechTypeUtils.java +++ b/org.simantics.district.network/src/org/simantics/district/network/techtype/TechTypeUtils.java @@ -32,6 +32,7 @@ import org.simantics.db.layer0.request.PropertyInfoRequest; import org.simantics.db.layer0.variable.Variable; import org.simantics.district.network.ontology.DistrictNetworkResource; import org.simantics.district.network.techtype.requests.PossibleTechTypeItem; +import org.simantics.district.network.techtype.requests.PossibleTechTypeKeyName; import org.simantics.district.network.techtype.requests.PossibleTechTypeTable; import org.simantics.district.network.techtype.requests.TechTypeTableData; import org.simantics.district.network.techtype.requests.TechTypeTableKeyName; @@ -341,11 +342,86 @@ public class TechTypeUtils { } } + /** + * Find the tech type table key property name for a table. + * + * @param graph A read interface to the graph db + * @param table A tech type table resource + * @return Name of the key property + * @throws DatabaseException + */ public static String getKeyPropertyName(ReadGraph graph, Resource table) throws DatabaseException { String name = graph.syncRequest(new TechTypeTableKeyName(table), TransientCacheListener.instance()); if (name == null) name = "_" + DEFAULT_KEY_NAME; return name; } + + /** + * Get a possible tech type table key property for a component type + * + * @param graph A read interface to the graph db + * @param componentType An STR.ComponentType instance + * @return The name of a property that uses DN.TechType.Functions.techTypeCodeValueAccessor or null if not found + * @throws DatabaseException + */ + public static String getPossibleTechTypeKeyName(ReadGraph graph, Resource componentType) throws DatabaseException { + return graph.syncRequest(new PossibleTechTypeKeyName(componentType), TransientCacheListener.instance()); + } + + /** + * Get a possible tech type table from a given model, for a given component type. + * + * @param graph A read interface to the graph db + * @param model A model resource (or other index root) + * @param componentType An STR.ComponentType instance + * @return A tech type table resource or null if not found + * @throws DatabaseException + */ + public static Resource getPossibleTechTypeTable(ReadGraph graph, Resource model, Resource componentType) throws DatabaseException { + return graph.syncRequest(new PossibleTechTypeTable(model, componentType), TransientCacheListener.instance()); + } + + /** + * Get the contents of a tech type table, indexed by item code and property name. + * + * @param graph A read interface to the graph db + * @param table A tech type table resource + * @return A map from item code to a map of property values + * @throws DatabaseException + */ + public static Map> getTechTypeData(ReadGraph graph, Resource table) throws DatabaseException { + return graph.syncRequest(new TechTypeTableData(table), TransientCacheListener.instance()); + } + + /** + * Get the enabled contents of a tech type table, indexed by item code and property name. + * + * The returned map is a subset of the one returned by {@link #getTechTypeData(ReadGraph, Resource)} + * with only the items whose index is listed in the HasEnabledItems property. + * + * @param graph A read interface to the graph db + * @param table A tech type table resource + * @return A map from item code to a map of property values + * @throws DatabaseException + */ + public static Map> getEnabledTechTypeData(ReadGraph graph, Resource table) throws DatabaseException { + return graph.syncRequest(new TechTypeTableData(table, true), TransientCacheListener.instance()); + } + + /** + * Get a single tech type table item that has the given item code, or null, if not found. + * + * The returned map is a subset of the one returned by {@link #getTechTypeData(ReadGraph, Resource)} + * with only the items whose index is listed in the HasEnabledItems property. + * + * @param graph A read interface to the graph db + * @param table A tech type table resource + * @return A map of property values or null if not found + * @throws DatabaseException + */ + public static Map getPossibleTechTypeItem(ReadGraph graph, Resource table, String itemCode) throws DatabaseException { + return graph.syncRequest(new PossibleTechTypeItem(table, itemCode), TransientCacheListener.instance()); + } /** * Compare strings so that contained numbers are sorted in numerical order instead of lexicographic.