Enum CoreUtils

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 [[email protected]]
See Also:
  • Enum Constant Details

    • INSTANCE

      public static final CoreUtils INSTANCE
      Singleton.
  • Method Details

    • values

      public static CoreUtils[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      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 name
      NullPointerException - 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
    • getDao

      public abstract DAO getDao()
      Returns the DAO object.
      Returns:
      a DAO object
    • setDao

      public abstract void setDao(DAO dao)
      Sets the DAO object.
      Parameters:
      dao - DAO
    • getSearch

      public abstract Search getSearch()
      Returns the Search object.
      Returns:
      Search object
    • setSearch

      public abstract void setSearch(Search search)
      Sets the Search object.
      Parameters:
      search - Search
    • getCache

      public abstract Cache getCache()
      Returns the Cache object.
      Returns:
      Cache object
    • setCache

      public abstract void setCache(Cache cache)
      Sets the Cache object.
      Parameters:
      cache - Cache
    • getQueue

      public abstract Queue getQueue()
      Returns the Queue object.
      Returns:
      Queue object
    • setQueue

      public abstract void setQueue(Queue queue)
      Sets the Queue object.
      Parameters:
      queue - Queue
    • getFileStore

      public abstract FileStore getFileStore()
      Returns the FileStore object.
      Returns:
      FileStore object
    • 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:
      objectTags - the object tags
      tag - a tag, must not be null or empty
      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:
      objectTags - the object
      tag - a tag, must not be null or empty
      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:
      obj - the object to execute this method on
      type2 - the type of the other object
      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:
      obj - the object to execute this method on
      type2 - the other type of object
      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 on
      type2 - 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:
      obj - the object to execute this method on
      type2 - the type of children to look for
      query - a query string
      pager - a Pager
      Returns:
      a list of ParaObject in 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:
      obj - the object to execute this method on
      type2 - type of linked objects to search for
      field - the name of the field to target (within a nested field "nstd")
      query - a query string
      pager - a Pager
      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:
      obj - the object to execute this method on
      type2 - the type of children to look for
      pager - a Pager
      Returns:
      a list of ParaObject in 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:
      obj - the object to execute this method on
      type2 - the type of children to look for
      field - the field name to use as filter
      term - the field value to use as filter
      pager - a Pager
      Returns:
      a list of ParaObject in 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:
    • 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:
      obj - the object to execute this method on
      type2 - type of linked objects to search for
      pager - a Pager
      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 on
      type2 - the other type
      pager - a Pager
      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 name
      id - 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:
      obj - the object to execute this method on
      type2 - the other type
      id2 - the other id
      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:
      obj - the object to execute this method on
      toObj - the other object
      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:
      obj - the object to execute this method on
      id2 - link to the object with this id
      Returns:
      the id of the Linker object 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:
      obj - the object to execute this method on
      id2 - link to the object with this id
      metadata - some string of metadata to be attached to the link object
      Returns:
      the id of the Linker object that is created
    • overwrite

      public abstract String overwrite(ParaObject obj)
      Creates the object again (use with caution!). Same as DAO.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 as DAO.create(java.lang.String, com.erudika.para.core.ParaObject).
      Parameters:
      appid - the app id
      obj - 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:
      obj - the object to execute this method on
      type2 - the other type
      id2 - the other id
    • unlinkAll

      public abstract void unlinkAll(ParaObject obj)
      Unlinks all objects that are linked to this one. Deletes all Linker objects. 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 on
      userid - the voter
      upDown - 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 on
      userid - the voter
      upDown - up or down
      expiresAfter - expires after seconds
      lockedAfter - locked after seconds
      Returns:
      true if the vote was successful