Class DMXUtils
- java.lang.Object
-
- systems.dmx.core.util.DMXUtils
-
public class DMXUtils extends Object
-
-
Constructor Summary
Constructors Constructor Description DMXUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static PlayerModel[]
assocAutoTyping(AssocModel assoc, String topicTypeUri1, String topicTypeUri2, String assocTypeUri, String roleTypeUri1, String roleTypeUri2)
static PlayerModel[]
assocAutoTyping(AssocModel assoc, String topicTypeUri1, String topicTypeUri2, String assocTypeUri, String roleTypeUri1, String roleTypeUri2, java.util.function.Predicate<PlayerModel[]> playerTest)
Retypes the given association if its players match the given topic types.static <T extends RelatedObjectModel>
TfindByAssoc(long assocId, Iterable<T> objects)
static <T extends Identifiable>
TfindById(long id, Iterable<T> items)
static <T extends DMXObjectModel>
TfindByValue(SimpleValue value, Iterable<T> objects)
static String
getConfigDir()
Returns the DMX platform's configuration directory.static List<Topic>
getParentTopics(Topic topic)
Finds all parent topics of the given topic by traversing along the child->parent relationship.static PlayerModel[]
getPlayerModels(AssocModel assoc, String topicTypeUri1, String topicTypeUri2)
static List<Long>
idList(Iterable<? extends Identifiable> items)
static int
indexOfAssoc(long assocId, Iterable<? extends RelatedObjectModel> objects)
static boolean
isDMXURL(URL url)
Checks if an URL refers to this DMX installation.static <T extends DMXObject>
List<T>loadChildTopics(List<T> objects)
static org.codehaus.jettison.json.JSONArray
toJSONArray(Iterable<? extends JSONEnabled> items)
static List
toList(org.codehaus.jettison.json.JSONArray o)
static Map
toMap(org.codehaus.jettison.json.JSONObject o)
static Map
toMap(org.codehaus.jettison.json.JSONObject o, Map map)
static <M> List<M>
toModelList(Iterable<? extends DMXObject> objects)
static String
topicNames(Iterable<? extends Topic> topics)
-
-
-
Method Detail
-
isDMXURL
public static boolean isDMXURL(URL url)
Checks if an URL refers to this DMX installation. The check relies on the "dmx.host.url" system property.
-
idList
public static List<Long> idList(Iterable<? extends Identifiable> items)
-
findById
public static <T extends Identifiable> T findById(long id, Iterable<T> items)
-
findByValue
public static <T extends DMXObjectModel> T findByValue(SimpleValue value, Iterable<T> objects)
-
findByAssoc
public static <T extends RelatedObjectModel> T findByAssoc(long assocId, Iterable<T> objects)
-
indexOfAssoc
public static int indexOfAssoc(long assocId, Iterable<? extends RelatedObjectModel> objects)
-
toMap
public static Map toMap(org.codehaus.jettison.json.JSONObject o)
-
toList
public static List toList(org.codehaus.jettison.json.JSONArray o)
-
toJSONArray
public static org.codehaus.jettison.json.JSONArray toJSONArray(Iterable<? extends JSONEnabled> items)
-
getParentTopics
public static List<Topic> getParentTopics(Topic topic)
Finds all parent topics of the given topic by traversing along the child->parent relationship. Only the leaves are returned.If the given topic has no parent topics the returned list contains only the given topic.
-
assocAutoTyping
public static PlayerModel[] assocAutoTyping(AssocModel assoc, String topicTypeUri1, String topicTypeUri2, String assocTypeUri, String roleTypeUri1, String roleTypeUri2)
-
assocAutoTyping
public static PlayerModel[] assocAutoTyping(AssocModel assoc, String topicTypeUri1, String topicTypeUri2, String assocTypeUri, String roleTypeUri1, String roleTypeUri2, java.util.function.Predicate<PlayerModel[]> playerTest)
Retypes the given association if its players match the given topic types. The given assoc model is modified in-place. Typically called from a plugin'sPreCreateAssoc
.Read the parameters as follows: if "assoc" connects a "topicTypeUri1" with a "topicTypeUri2" (regardless of 1,2 position) then retype it to "assocTypeUri" and use the role types "roleTypeUri1" and "roleTypeUri2". "roleTypeUri1" is used for the "topicTypeUri1" player, "roleTypeUri2" is used for the "topicTypeUri2" player.
Auto-typing takes place only if the given assoc is of type "Association" (that is a generic assoc without any semantics). If the given assoc is not a generic one, no retyping takes place (null is returned).
Auto-typing is supported only for topic players, and only if they are identified by-ID. If the given assoc has at least one assoc player, or if a topic player is identfied by-URI, no retyping takes place (null is returned).
- Parameters:
playerTest
- optional: a predicate tested after a type-match is detected for both players, but before actual auto-typing takes place. You can prohibit auto-typing by returningfalse
. An array of 2 assoc players is passed. [0] is the player that matches "topicTypeUri1", [1] is the player that matches "topicTypeUri2". If no predicate is given (null) no additional test is performed before auto-typing.- Returns:
- a 2-element
PlayerModel
array if auto-typing took place,null
otherwise. Convenience to access the assoc's players after retyping. Element 0 is the player of "topicTypeUri1", Element 1 is the player of "topicTypeUri2".
-
getPlayerModels
public static PlayerModel[] getPlayerModels(AssocModel assoc, String topicTypeUri1, String topicTypeUri2)
-
getConfigDir
public static String getConfigDir()
Returns the DMX platform's configuration directory. This is the directory where DMX'sconfig.properties
file resides. The path to this file is configurable by thefelix.system.properties
system property when the platform is launched.Plugins can use the configuration directory for storing external plugin-specific resource files. By convention inside that directory there are per-plugin sub directories, named according to the respective plugin's repository name. These directories are created by the administrator.
So a plugin typically accesses its resource files by e.g.:
DMXUtils.getConfigDir() + "dmx-linqa/" + fileName
- Returns:
- the DMX platform's configuration directory as derived from the
felix.system.properties
system property (as configured by administrator), ending with "/". If that system property is not set an empty string is returned, functioning as "current directory". This is the case in particular in development mode, when DMX platform is run via Maven (via Pax Runner). While development create the per-plugin configuration directory inside Pax Runner's `runner` directory, e.g.:dmx-platform/ runner/ dmx-linqa/ custom.css
-
-