Class OdfPageHandler

java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.odfweb.repository.OdfPageHandler
All Implemented Interfaces:
LogEnabled, Initializable, Component, Serviceable

Component providing methods to retrieve ODF virtual pages, such as the ODF root, level 1 and 2 metadata names, and so on.
  • Field Details

  • Constructor Details

  • Method Details

    • service

      public void service(ServiceManager serviceManager) throws ServiceException
      Specified by:
      service in interface Serviceable
      Throws:
      ServiceException
    • initialize

      public void initialize() throws Exception
      Specified by:
      initialize in interface Initializable
      Throws:
      Exception
    • getOdfRootPage

      public Page getOdfRootPage(String siteName, String sitemapName) throws AmetysRepositoryException
      Get the first ODF root page.
      Parameters:
      siteName - The site name
      sitemapName - The sitemap's name
      Returns:
      a ODF root page or null if not found.
      Throws:
      AmetysRepositoryException - if an error occurs
    • getOdfRootPage

      public Page getOdfRootPage(String siteName, String sitemapName, String catalogName) throws AmetysRepositoryException
      Get ODF root page of a specific catalog.
      Parameters:
      siteName - The site name
      sitemapName - The sitemap name
      catalogName - The catalog name
      Returns:
      the ODF root page or null if not found.
      Throws:
      AmetysRepositoryException - if an error occurs
    • getOdfRootPageIds

      public List<String> getOdfRootPageIds(String siteName, String sitemapName) throws AmetysRepositoryException
      Get the id of ODF root pages
      Parameters:
      siteName - The site name
      sitemapName - The sitemap name
      Returns:
      The ids of ODF root pages
      Throws:
      AmetysRepositoryException - if an error occurs.
    • getOdfRootPages

      public Set<Page> getOdfRootPages(String siteName, String sitemapName) throws AmetysRepositoryException
      Get the ODF root pages.
      Parameters:
      siteName - the current site.
      sitemapName - the current sitemap/language.
      Returns:
      the ODF root pages
      Throws:
      AmetysRepositoryException - if an error occurs.
    • hasOdfRootPage

      public boolean hasOdfRootPage(Site site)
      Test if the given site has at least one sitemap with an odf root page.
      Parameters:
      site - the site to test.
      Returns:
      true if the site has at least one sitemap with an odf root page, false otherwise.
    • isValidRestriction

      public boolean isValidRestriction(Page rootPage, Program program)
      Determines if the program is part of the site restrictions
      Parameters:
      rootPage - The ODF root page
      program - The program
      Returns:
      true the program is part of the site restrictions
    • clearRootCache

      public void clearRootCache()
      Clear the ODF root page cache.
    • clearRootCache

      public void clearRootCache(String siteName, String sitemapName)
      Clear the ODF root page cache for a given site and language.
      Parameters:
      siteName - the current site.
      sitemapName - the current sitemap/language.
    • isODFRootPage

      public boolean isODFRootPage(Page page)
      Determines if the page is a ODF root page
      Parameters:
      page - The page to test
      Returns:
      true if the page is a ODF root page
    • _getOdfRootPage

      protected Page _getOdfRootPage(String siteName, String sitemapName) throws AmetysRepositoryException
      Get the ODF root page.
      Parameters:
      siteName - the current site.
      sitemapName - the current sitemap/language.
      Returns:
      the ODF root page or null if not found.
      Throws:
      AmetysRepositoryException - if an error occurs.
    • _getOdfRootPages

      protected Set<Page> _getOdfRootPages(String siteName, String sitemapName) throws AmetysRepositoryException
      Get the ODF root page.
      Parameters:
      siteName - the current site.
      sitemapName - the current sitemap/language.
      Returns:
      the ODF root page or null if not found.
      Throws:
      AmetysRepositoryException - if an error occurs.
    • getCatalog

      public String getCatalog(Page rootPage)
      Get the catalog value of the ODF root page
      Parameters:
      rootPage - The ODF root page
      Returns:
      the catalog value
    • getLevel1Metadata

      public String getLevel1Metadata(String siteName, String sitemapName, String catalog)
      Get the first level metadata name.
      Parameters:
      siteName - the site name.
      sitemapName - the sitemap name.
      catalog - the current selected catalog.
      Returns:
      the first level metadata name.
    • getLevel1Metadata

      public String getLevel1Metadata(Page rootPage)
      Get the first level metadata name.
      Parameters:
      rootPage - the ODF root page.
      Returns:
      the first level metadata name.
    • getLevel2Metadata

      public String getLevel2Metadata(String siteName, String sitemapName, String catalog)
      Get the second level metadata name.
      Parameters:
      siteName - the site name.
      sitemapName - the sitemap name.
      catalog - the current selected catalog.
      Returns:
      the second level metadata name.
    • getLevel2Metadata

      public String getLevel2Metadata(Page rootPage)
      Get the second level metadata name.
      Parameters:
      rootPage - the ODF root page.
      Returns:
      the second level metadata name.
    • getLevel1Values

      Get the first level metadata values (with translated label).
      Parameters:
      siteName - the site name.
      sitemapName - the sitemap name.
      catalog - the current selected catalog.
      Returns:
      the first level metadata values.
    • getProgramLevelValue

      public String getProgramLevelValue(Program program, String levelMetaPath)
      Get the level value of a program by extracting and transforming the raw program value at the desired metadata path
      Parameters:
      program - The program
      levelMetaPath - The desired metadata path that represent a level
      Returns:
      The final level value
    • getProgramLevel1Value

      public String getProgramLevel1Value(Page rootPage, Program program)
      Get the first level value of a program by extracting and transforming the raw program value
      Parameters:
      rootPage - The root page
      program - The program
      Returns:
      The final level value or null if not found
    • getProgramLevel2Value

      public String getProgramLevel2Value(Page rootPage, Program program)
      Get the second level value of a program by extracting and transforming the raw program value
      Parameters:
      rootPage - The root page
      program - The program
      Returns:
      The final level value or null if not found
    • getLevel1PageName

      public String getLevel1PageName(Page rootPage, Program program)
      Get the name of the page of first level for a given program
      Parameters:
      rootPage - The ODF root page
      program - The program
      Returns:
      The page's name
    • getLevel2PageName

      public String getLevel2PageName(Page rootPage, Program program)
      Get the name of the page of second level for a given program
      Parameters:
      rootPage - The ODF root page
      program - The program
      Returns:
      The page's name
    • getOrgunitIdFromUaiCode

      public String getOrgunitIdFromUaiCode(Page rootPage, String uaiCode)
      Get the orgunit identifier given an uai code
      Parameters:
      rootPage - Odf root page
      uaiCode - The uai code
      Returns:
      The orgunit id or null if not found
    • getProgramsWithRestrictions

      public AmetysObjectIterable<Program> getProgramsWithRestrictions(Page rootPage, String level1, String level2, String programCode, String programName)
      Get the programs available for a ODF root page, taking account the site's restrictions
      Parameters:
      rootPage - The ODF root page
      level1 - filters results with a level1 value. Can be null.
      level2 - filters results with a level2 value. Can be null.
      programCode - expected program code. Can be null.
      programName - expected program name. Can be null.
      Returns:
      an iterator over resulting programs
    • getProgramsWithRestrictions

      public AmetysObjectIterable<Program> getProgramsWithRestrictions(Page rootPage, String level1Metadata, String level1, String level2Metadata, String level2, String programCode, String programName)
      Get the programs available for a ODF root page, taking account the site's restrictions
      Parameters:
      rootPage - The ODF root page
      level1Metadata - metadata name for first level
      level1 - filters results with a level1 value. Can be null.
      level2Metadata - metadata name for second level
      level2 - filters results with a level2 value. Can be null.
      programCode - expected program code. Can be null.
      programName - expected program name. Can be null.
      Returns:
      an iterator over resulting programs
    • getLevel1Values

      Get the first level metadata values (with translated label)
      Parameters:
      rootPage - the ODF root page.
      Returns:
      the first level metadata values. Can be empty if there is no level1 attribute on root page.
    • getLevel2Values

      Get the second level metadata values (with translated label).
      Parameters:
      siteName - the site name.
      sitemapName - the sitemap name.
      catalog - the current selected catalog.
      Returns:
      the second level metadata values.
    • getLevel2Values

      Get the second level metadata values (with translated label).
      Parameters:
      rootPage - the ODF root page.
      Returns:
      the second level metadata values. Can be empty if there is no level2 attribute on root page.
    • encodeLevelValue

      public String encodeLevelValue(String value)
      Encode level value to be use into a URI. Double-encode characters ':', '-' and '/'.
      Parameters:
      value - The raw value
      Returns:
      the encoded value
    • decodeLevelValue

      public String decodeLevelValue(String value)
      Decode level value used in a URI
      Parameters:
      value - The encoded value
      Returns:
      the decoded value
    • getPageName

      Returns the page's name of a ProgramItem. Only AbstractProgram and Course can have a page.
      Parameters:
      item - The program item
      Returns:
      The page's name
      Throws:
      IllegalArgumentException - if the program item is not a AbstractProgram nor a Course.
    • getEligibleAttributesForLevel

      Get the eligible enumerated attribute definitions for ODF page level
      Returns:
      the eligible attribute definitions
    • getCatalogs

      Get the ODF catalogs
      Returns:
      the ODF catalogs
    • getEnumeratedAttributes

      public Map<String,ModelItem> getEnumeratedAttributes(String programContentTypeId, boolean allowMultiple)
      Get the enumerated attribute definitions for the given content type. Attribute with enumerator or content attribute are considered as enumerated
      Parameters:
      programContentTypeId - The content type's id
      allowMultiple - true true to allow multiple attributes
      Returns:
      The definitions of enumerated attributes
    • computeLevelsPath

      public String computeLevelsPath(Page rootPage, Program parentProgram)
      Compute the path from the root odf page, representing the first and second level pages.
      Parameters:
      rootPage - The odf root page
      parentProgram - The program to compute
      Returns:
      the path, can be empty if no levels defined, and null if the parent program does not have values for levels attributes
    • findFirstLevelPage

      public FirstLevelPage findFirstLevelPage(Page rootPage, String level1Value)
      Get the first level page from the given root page with the level 1 value.
      Parameters:
      rootPage - The odf root page
      level1Value - The first level value
      Returns:
      a first level page
    • findSecondLevelPage

      public SecondLevelPage findSecondLevelPage(Page rootPage, String level1Value, String level2Value)
      Get the second level page from the given root page with the level 1 and level 2 values.
      Parameters:
      rootPage - The odf root page
      level1Value - The first level value
      level2Value - The second level value
      Returns:
      a second level page
    • addRedirectIfNeeded

      public Page addRedirectIfNeeded(Page page, String name)
      Add an intermediate redirect page if the called page name doesn't match the real page name.
      Parameters:
      page - The page
      name - The called page name
      Returns:
      The page maybe included in a RedirectPage
    • exploreQueuePath

      public Page exploreQueuePath(Page page, String queuePath)
      Explore the queue path if it is not empty
      Parameters:
      page - The root page to explore
      queuePath - The path
      Returns:
      The child page, or given page if queue path is empty