Class LinkIndexManager


  • public class LinkIndexManager
    extends java.lang.Object
    This class manages the custom Types link index.

    Its goal is to list all data (aka "referrers") in which a link to a specific data (aka the "referenced data") have been filled.
    Referrers of a Data are organized by class (e.g. Article.class, ...) and by field name that were used to link to the "referenced data" (e.g. "relatedContent", "myLink", ...)

    Example (where MyArticle is a subclass of Article, and MyCustomType a Content) :

      MyCustomType MCT1 references SmallNews SM1 and SM2 in its "myLink1" field
      MyCustomType MCT2 references SmallNews SM1 in its "myLink2" field
      
      Article A1 references SmallNews SM1 and SM2 in its "relatedContent" field
      Article A2 references SmallNews SM2 in its "relatedContent" field
      MyArticle MA1 references SmallNews SM2 in its "relatedContent" field
      MyArticle MA2 references SmallNews SM1 in its "myOtherLink" field
      
      // Access with class, with support for class hierarchy *when the specified class is an an abstract class*
      linkIndexManager.getIndexedDataSet(sm1, MyCustomType.class) ==> [ MCT1, MCT2 ] 
      linkIndexManager.getIndexedDataSet(sm2, MyCustomType.class) ==> [ MCT1 ]
       
      linkIndexManager.getIndexedDataSet(sm1, Article.class) ==> [ A1 ] 
      linkIndexManager.getIndexedDataSet(sm1, Publication.class) ==> [ A1, MA2, MCT1, MCT2 ]
      linkIndexManager.getIndexedDataSet(sm2, Article.class) ==> [ A1, A2 ] 
       
      // Access with class and fieldName
      linkIndexManager.getIndexedDataSet(sm2, Publication.class, "relatedContent") ==> [ A1, MA1 ] 
      linkIndexManager.getIndexedDataSet(sm2, MyArticle.class, "relatedContent") ==> [ MA1 ]
      linkIndexManager.getIndexedDataSet(sm2, Publication.class, "myLink1") ==> [ MCT1 ] 
     

    The structure of the internal index is as follow :

     TreeMap
       Key: The data which is referenced :
           - the Data instance for the JStore index, 
           - the DBData id for the JcmsDB index  
       Value:
         HashMap: (classMap)
           Key: Class (the class referencing the data) 
           Value: (fieldMap)
             HashMap:
               Key: String (the name of the field referencing the data)
               Value: TreeSet containing all the referencing data (aka the referrers)
     
    Version:
    $Revision: 123655 $
    Author:
    Olivier Dedieu
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ALL_FIELD_KEY  
      static java.lang.String REVISION  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void checkLinkIndex()
      Check that "all" field entries are consistent with the other fields.
      java.util.TreeMap<java.lang.String,​java.util.Map<java.lang.Class<?>,​java.util.Map<java.lang.String,​java.util.TreeSet<Data>>>> getDbIndex()
      Return the internal index used to store referrer of JcmsDB data.
      java.util.TreeMap<Data,​java.util.Map<java.lang.Class<?>,​java.util.Map<java.lang.String,​java.util.TreeSet<Data>>>> getIndex()
      Return the internal index used to store referrer of JStore data.
      <T> java.util.TreeSet<T> getIndexedDataSet​(Data data, java.lang.Class<T> clazz)
      Returns the Set of clazz instances referring this data (whatever the field they used for this reference)
      <T> java.util.TreeSet<T> getIndexedDataSet​(Data data, java.lang.Class<T> clazz, java.lang.String field)
      Returns the Set of clazz instances referring this data with the given field.
      int getLinkCount​(Data data)
      Get the count of Data (referrer) which are linking to the specified data
      java.util.Map<java.lang.Class<?>,​java.util.Map<java.lang.String,​java.util.TreeSet<Data>>> getReferrerMap​(Data data)
      Return the class map of the specified Data, by looking in the correct index depending on whether its a JStore or JcmsDB data
      java.util.Map<java.lang.Class<? extends Publication>,​java.util.Set<TypeFieldEntry>> getTypeLinkMap​(java.lang.Class<? extends Publication> clazz)
      Returns the type link map for the given class.
      java.util.Set<TypeFieldEntry> getTypeLinkSet​(java.lang.Class<? extends Publication> attachedClass, java.lang.Class<? extends Publication> assignedClass)
      Returns the set of TypeFieldEntry of assignedClass that can be assigned with attachedClass.
      void printLinkIndex​(java.io.PrintWriter pw)
      Print an XML view of the index.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LinkIndexManager

        public LinkIndexManager()
    • Method Detail

      • getTypeLinkMap

        public java.util.Map<java.lang.Class<? extends Publication>,​java.util.Set<TypeFieldEntry>> getTypeLinkMap​(java.lang.Class<? extends Publication> clazz)
        Returns the type link map for the given class. The type link map contains the class .
        Parameters:
        clazz - the class.
        Returns:
        the link link map for the given class.
        Since:
        jcms-9.0.0
      • getTypeLinkSet

        public java.util.Set<TypeFieldEntry> getTypeLinkSet​(java.lang.Class<? extends Publication> attachedClass,
                                                            java.lang.Class<? extends Publication> assignedClass)
        Returns the set of TypeFieldEntry of assignedClass that can be assigned with attachedClass.
        Parameters:
        attachedClass - the class to be attached.
        assignedClass - the class to be assigned.
        Returns:
        the set of TypeFieldEntry of assignedClass that can be assigned with attachedClass.
        Since:
        jcms-9.0.0
      • getIndex

        public java.util.TreeMap<Data,​java.util.Map<java.lang.Class<?>,​java.util.Map<java.lang.String,​java.util.TreeSet<Data>>>> getIndex()
        Return the internal index used to store referrer of JStore data.

        Using this method is NOT recommended as it returns an internal Map, which only handle JStore publication.
        Use getReferrerMap(Data) to access the complete referrer map of a data Use getIndexedDataSet(Data, Class) to access referrer of a specific class

        Returns:
        the INTERNAL index
        See Also:
        getDbIndex()
      • getDbIndex

        public java.util.TreeMap<java.lang.String,​java.util.Map<java.lang.Class<?>,​java.util.Map<java.lang.String,​java.util.TreeSet<Data>>>> getDbIndex()
        Return the internal index used to store referrer of JcmsDB data.

        Using this method is NOT recommended as it returns an internal Map, which only handle JcmsDB publication.
        Use getReferrerMap(Data) to access the complete referrer map of a data Use getIndexedDataSet(Data, Class) to access referrer of a specific class

        Returns:
        the INTERNAL index
        See Also:
        getIndex()
      • getIndexedDataSet

        public <T> java.util.TreeSet<T> getIndexedDataSet​(Data data,
                                                          java.lang.Class<T> clazz)
        Returns the Set of clazz instances referring this data (whatever the field they used for this reference)
        Type Parameters:
        T - any object type (usually something extending Data)
        Parameters:
        data - the data which is being referenced (may be a JStore or a JcmsDB data)
        clazz - the class to search the referring instances
        Returns:
        a TreeSet of Data, never return null an : empty set is returned if invalid parameters where specified or when not referrer could be found
        Since:
        jcms-3.0
      • getReferrerMap

        public java.util.Map<java.lang.Class<?>,​java.util.Map<java.lang.String,​java.util.TreeSet<Data>>> getReferrerMap​(Data data)
        Return the class map of the specified Data, by looking in the correct index depending on whether its a JStore or JcmsDB data
        Parameters:
        data - the data which is being referenced (may be a JStore or a JcmsDB data)
        Returns:
        a unmodifiable Map of the class to refererrer associated to the specified data, never null (returns an empty map)
        Since:
        jcms-10.0.4 / JCMS-7832
      • getIndexedDataSet

        public <T> java.util.TreeSet<T> getIndexedDataSet​(Data data,
                                                          java.lang.Class<T> clazz,
                                                          java.lang.String field)
        Returns the Set of clazz instances referring this data with the given field.
        Type Parameters:
        T - any object type (usually something extending Data)
        Parameters:
        data - the data
        clazz - the class to search the referring instances
        field - the name of the field which contains the reference
        Returns:
        a TreeSet of Data, never return null : an empty set is returned if invalid parameters where specified or when not referrer could be found
        Since:
        jcms-4.0
      • getLinkCount

        public int getLinkCount​(Data data)
        Get the count of Data (referrer) which are linking to the specified data
        Parameters:
        data - the data which is being referenced, (may be a JStore or a JcmsDB data)
        Returns:
        the number of instances referring this data
        Since:
        jcms-3.0
      • checkLinkIndex

        public void checkLinkIndex()
        Check that "all" field entries are consistent with the other fields.
        Since:
        jcms-5.0.5
      • printLinkIndex

        public void printLinkIndex​(java.io.PrintWriter pw)
        Print an XML view of the index.
        Parameters:
        pw - the printWriter where the XML view must be printed.
        Since:
        jcms-5.0.5