- java.lang.Object
-
- java.lang.Enum<CoreUtils>
-
- com.erudika.para.core.utils.CoreUtils
-
- All Implemented Interfaces:
InitializeListener,Serializable,Comparable<CoreUtils>,EventListener
public enum CoreUtils extends Enum<CoreUtils> implements InitializeListener
Provides some the basic functionality for domain objects.- Author:
- Alex Bogdanovski [alex@erudika.com]
- See Also:
ParaObject
-
-
Enum Constant Summary
Enum Constants Enum Constant Description INSTANCESingleton.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract List<String>addTags(List<String> objectTags, String... tag)Adds any number of tags to the set of tags.abstract LongcountChildren(ParaObject obj, String type2)Count the total number of child objects for this object.abstract LongcountLinks(ParaObject obj, String type2)Count the total number of links between this object and another type of object.abstract voiddeleteChildren(ParaObject obj, String type2)Deletes all child objects permanently.abstract <P extends ParaObject>
List<P>findChildren(ParaObject obj, String type2, String query, Pager... pager)Searches through child objects in a one-to-many relationship.abstract <P extends ParaObject>
List<P>findLinkedObjects(ParaObject obj, String type2, String field, String query, Pager... pager)Searches through all linked objects in many-to-many relationships.abstract CachegetCache()Returns the Cache object.abstract <P extends ParaObject>
List<P>getChildren(ParaObject obj, String type2, Pager... pager)Returns all child objects linked to this object.abstract <P extends ParaObject>
List<P>getChildren(ParaObject obj, String type2, String field, String term, Pager... pager)Returns all child objects linked to this object.abstract <P extends ParaObject>
PgetCreator(ParaObject obj)The user object of the creator.abstract DAOgetDao()Returns the DAO object.abstract FileStoregetFileStore()Returns the FileStore object.static CoreUtilsgetInstance()Provides a default instance using fake DAO, Search and Cache implementations.abstract <P extends ParaObject>
List<P>getLinkedObjects(ParaObject obj, String type2, Pager... pager)Returns all objects linked to the given one.abstract List<Linker>getLinks(ParaObject obj, String type2, Pager... pager)Returns a list of all Linker objects for a given object.abstract StringgetName(String name, String id)Returns the default name property of an object.abstract StringgetObjectURI(ParaObject obj)Returns the relative path to the object, e.g.abstract <P extends ParaObject>
PgetParent(ParaObject obj)The parent object.abstract QueuegetQueue()Returns the Queue object.abstract SearchgetSearch()Returns the Search object.abstract booleanisLinked(ParaObject obj, ParaObject toObj)Checks if a given object is linked to this one.abstract booleanisLinked(ParaObject obj, String type2, String id2)Checks if this object is linked to another.abstract Stringlink(ParaObject obj, String id2)Links two objects in a many-to-many relationship.abstract Stringlink(ParaObject obj, String id2, String metadata)Links two objects in a many-to-many relationship.abstract Stringoverwrite(ParaObject obj)Creates the object again (use with caution!).abstract Stringoverwrite(String appid, ParaObject obj)Creates the object again (use with caution!).abstract List<String>removeTags(List<String> objectTags, String... tag)Removes a tag from the set of tags.abstract voidsetCache(Cache cache)Sets the Cache object.abstract voidsetDao(DAO dao)Sets the DAO object.abstract voidsetFileStore(FileStore fileStore)Sets the FileStore object.abstract voidsetQueue(Queue queue)Sets the Queue object.abstract voidsetSearch(Search search)Sets the Search object.abstract voidunlink(ParaObject obj, String type2, String id2)Unlinks an object from this one.abstract voidunlinkAll(ParaObject obj)Unlinks all objects that are linked to this one.static CoreUtilsvalueOf(String name)Returns the enum constant of this type with the specified name.static CoreUtils[]values()Returns an array containing the constants of this enum type, in the order they are declared.abstract booleanvote(ParaObject votable, String userid, Votable.VoteValue upDown)Casts a vote on a given object.abstract booleanvote(ParaObject votable, String userid, Votable.VoteValue upDown, Integer expiresAfter, Integer lockedAfter)Casts a vote on a given object.-
Methods inherited from class java.lang.Enum
compareTo, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
-
Methods inherited from interface com.erudika.para.core.listeners.InitializeListener
onInitialize
-
-
-
-
Enum Constant Detail
-
INSTANCE
public static final CoreUtils INSTANCE
Singleton.
-
-
Method Detail
-
values
public static CoreUtils[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (CoreUtils c : CoreUtils.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static CoreUtils valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
getInstance
public static CoreUtils getInstance()
Provides a default instance using fake DAO, Search and Cache implementations.- Returns:
- an instance of this class
-
setSearch
public abstract void setSearch(Search search)
Sets the Search object.- Parameters:
search-Search
-
setCache
public abstract void setCache(Cache cache)
Sets the Cache object.- Parameters:
cache-Cache
-
setQueue
public abstract void setQueue(Queue queue)
Sets the Queue object.- Parameters:
queue-Queue
-
getFileStore
public abstract FileStore getFileStore()
Returns the FileStore object.- Returns:
FileStoreobject
-
setFileStore
public abstract void setFileStore(FileStore fileStore)
Sets the FileStore object.- Parameters:
fileStore-FileStore
-
addTags
public abstract List<String> addTags(List<String> objectTags, String... tag)
Adds any number of tags to the set of tags.- Parameters:
tag- a tag, must not be null or emptyobjectTags- the object tags- Returns:
- a new list of tags
-
removeTags
public abstract List<String> removeTags(List<String> objectTags, String... tag)
Removes a tag from the set of tags.- Parameters:
tag- a tag, must not be null or emptyobjectTags- the object- Returns:
- a new list of tags
-
countChildren
public abstract Long countChildren(ParaObject obj, String type2)
Count the total number of child objects for this object.- Parameters:
type2- the type of the other objectobj- the object to execute this method on- Returns:
- the number of links
-
countLinks
public abstract Long countLinks(ParaObject obj, String type2)
Count the total number of links between this object and another type of object.- Parameters:
type2- the other type of objectobj- the object to execute this method on- Returns:
- the number of links for the given object
-
deleteChildren
public abstract void deleteChildren(ParaObject obj, String type2)
Deletes all child objects permanently.- Parameters:
obj- the object to execute this method ontype2- the children's type.
-
findChildren
public abstract <P extends ParaObject> List<P> findChildren(ParaObject obj, String type2, String query, Pager... pager)
Searches through child objects in a one-to-many relationship.- Type Parameters:
P- the type of children- Parameters:
type2- the type of children to look forobj- the object to execute this method onquery- a query stringpager- aPager- Returns:
- a list of
ParaObjectin a one-to-many relationship with this object
-
findLinkedObjects
public abstract <P extends ParaObject> List<P> findLinkedObjects(ParaObject obj, String type2, String field, String query, Pager... pager)
Searches through all linked objects in many-to-many relationships.- Type Parameters:
P- type of linked objects- Parameters:
type2- type of linked objects to search forobj- the object to execute this method onpager- aPagerfield- the name of the field to target (within a nested field "nstd")query- a query string- Returns:
- a list of linked objects matching the search query
-
getChildren
public abstract <P extends ParaObject> List<P> getChildren(ParaObject obj, String type2, Pager... pager)
Returns all child objects linked to this object.- Type Parameters:
P- the type of children- Parameters:
type2- the type of children to look forobj- the object to execute this method onpager- aPager- Returns:
- a list of
ParaObjectin a one-to-many relationship with this object
-
getChildren
public abstract <P extends ParaObject> List<P> getChildren(ParaObject obj, String type2, String field, String term, Pager... pager)
Returns all child objects linked to this object.- Type Parameters:
P- the type of children- Parameters:
type2- the type of children to look forfield- the field name to use as filterterm- the field value to use as filterobj- the object to execute this method onpager- aPager- Returns:
- a list of
ParaObjectin a one-to-many relationship with this object
-
getCreator
public abstract <P extends ParaObject> P getCreator(ParaObject obj)
The user object of the creator.- Type Parameters:
P- type of linked objects- Parameters:
obj- find the creator of this object- Returns:
- the user who created this or null if
obj.getCreatorid()is null - See Also:
User
-
getLinkedObjects
public abstract <P extends ParaObject> List<P> getLinkedObjects(ParaObject obj, String type2, Pager... pager)
Returns all objects linked to the given one. Only applicable to many-to-many relationships.- Type Parameters:
P- type of linked objects- Parameters:
type2- type of linked objects to search forobj- the object to execute this method onpager- aPager- Returns:
- a list of linked objects
-
getLinks
public abstract List<Linker> getLinks(ParaObject obj, String type2, Pager... pager)
Returns a list of all Linker objects for a given object.- Parameters:
obj- the object to execute this method ontype2- the other typepager- aPager- Returns:
- a list of Linker objects
-
getName
public abstract String getName(String name, String id)
Returns the default name property of an object.- Parameters:
name- a nameid- an id- Returns:
- a combination of name and id, unless this.name is set
-
getObjectURI
public abstract String getObjectURI(ParaObject obj)
Returns the relative path to the object, e.g. /user/1234- Parameters:
obj- an object- Returns:
- a relative path
-
getParent
public abstract <P extends ParaObject> P getParent(ParaObject obj)
The parent object.- Type Parameters:
P- type of linked objects- Parameters:
obj- find the parent of this object- Returns:
- the parent or null if
obj.getParentid()is null
-
isLinked
public abstract boolean isLinked(ParaObject obj, String type2, String id2)
Checks if this object is linked to another.- Parameters:
type2- the other typeid2- the other idobj- the object to execute this method on- Returns:
- true if the two are linked
-
isLinked
public abstract boolean isLinked(ParaObject obj, ParaObject toObj)
Checks if a given object is linked to this one.- Parameters:
toObj- the other objectobj- the object to execute this method on- Returns:
- true if linked
-
link
public abstract String link(ParaObject obj, String id2)
Links two objects in a many-to-many relationship. Only a link is created. Objects are left untouched. The type of the second object is automatically determined on read.- Parameters:
id2- link to the object with this idobj- the object to execute this method on- Returns:
- the id of the
Linkerobject that is created
-
link
public abstract String link(ParaObject obj, String id2, String metadata)
Links two objects in a many-to-many relationship. Only a link is created. Objects are left untouched. The type of the second object is automatically determined on read.- Parameters:
id2- link to the object with this idobj- the object to execute this method onmetadata- some string of metadata to be attached to the link object- Returns:
- the id of the
Linkerobject that is created
-
overwrite
public abstract String overwrite(ParaObject obj)
Creates the object again (use with caution!). Same asDAO.create(com.erudika.para.core.ParaObject).- Parameters:
obj- an object- Returns:
- the object id or null
-
overwrite
public abstract String overwrite(String appid, ParaObject obj)
Creates the object again (use with caution!). Same asDAO.create(java.lang.String, com.erudika.para.core.ParaObject).- Parameters:
appid- the app idobj- an object- Returns:
- the object id or null
-
unlink
public abstract void unlink(ParaObject obj, String type2, String id2)
Unlinks an object from this one. Only a link is deleted. Objects are left untouched.- Parameters:
type2- the other typeobj- the object to execute this method onid2- the other id
-
unlinkAll
public abstract void unlinkAll(ParaObject obj)
Unlinks all objects that are linked to this one. Deletes allLinkerobjects. Only the links are deleted. Objects are left untouched.- Parameters:
obj- the object to execute this method on
-
vote
public abstract boolean vote(ParaObject votable, String userid, Votable.VoteValue upDown)
Casts a vote on a given object.- Parameters:
votable- the object to vote onuserid- the voterupDown- up or down- Returns:
- true if the vote was successful
-
vote
public abstract boolean vote(ParaObject votable, String userid, Votable.VoteValue upDown, Integer expiresAfter, Integer lockedAfter)
Casts a vote on a given object.- Parameters:
votable- the object to vote onuserid- the voterupDown- up or downexpiresAfter- expires after secondslockedAfter- locked after seconds- Returns:
- true if the vote was successful
-
-