Class ODFHelper

All Implemented Interfaces:
LogEnabled, PluginAware, Component, Contextualizable, Serviceable

Helper for ODF contents
  • Field Details

  • Constructor Details

  • Method Details

    • contextualize

      public void contextualize(Context context) throws ContextException
      Specified by:
      contextualize in interface Contextualizable
      Throws:
      ContextException
    • service

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

      public void setPluginInfo(String pluginName, String featureName, String id)
      Description copied from interface: PluginAware
      Sets the plugin info relative to the current component.
      Note : The feature name may be null if the targeted component in declared at plugin level.
      Specified by:
      setPluginInfo in interface PluginAware
      Parameters:
      pluginName - Unique identifier for the plugin hosting the extension
      featureName - Unique feature identifier (unique for a given pluginName)
      id - Unique identifier of this component
    • getRootContent

      Gets the root for ODF contents
      Returns:
      the root for ODF contents
    • getRootContent

      public AmetysObjectCollection getRootContent(boolean create)
      Gets the root for ODF contents
      Parameters:
      create - true to create automatically the root when missing.
      Returns:
      the root for ODF contents
    • getProgramItems

      public <C extends Content> AmetysObjectIterable<C> getProgramItems(String cTypeId, String code, String catalogName, String lang)
      Get the ProgramItems matching the given arguments
      Type Parameters:
      C - The content return type
      Parameters:
      cTypeId - The id of content type. Can be null to get program's items whatever their content type.
      code - The code. Can be null to get program's items regardless of their code
      catalogName - The search catalog. Can be null to get program's items regardless the catalog they belong to.
      lang - The search language. Can be null to get program's items regardless of their language
      Returns:
      The matching program items
    • getProgramItems

      public <C extends Content> AmetysObjectIterable<C> getProgramItems(Collection<String> cTypeIds, String code, String catalogName, String lang)
      Get the ProgramItems matching the given arguments
      Type Parameters:
      C - The content return type
      Parameters:
      cTypeIds - The id of content types. Can be empty to get program's items whatever their content type.
      code - The code. Can be null to get program's items regardless of their code
      catalogName - The search catalog. Can be null to get program's items regardless the catalog they belong to.
      lang - The search language. Can be null to get program's items regardless of their language
      Returns:
      The matching program items
    • getProgramItems

      public <C extends Content> AmetysObjectIterable<C> getProgramItems(String cTypeId, String code, String catalogName, String lang, Expression additionnalExpr, SortCriteria sortCriteria)
      Get the ProgramItems matching the given arguments
      Type Parameters:
      C - The content return type
      Parameters:
      cTypeId - The id of content type. Can be null to get program's items whatever their content type.
      code - The code. Can be null to get program's items regardless of their code
      catalogName - The search catalog. Can be null to get program's items regardless the catalog they belong to.
      lang - The search language. Can be null to get program's items regardless of their language
      additionnalExpr - An additional expression for filtering result. Can be null
      sortCriteria - criteria for sorting results
      Returns:
      The matching program items
    • getProgramItems

      public <C extends Content> AmetysObjectIterable<C> getProgramItems(Collection<String> cTypeIds, String code, String catalogName, String lang, Expression additionnalExpr, SortCriteria sortCriteria)
      Get the ProgramItems matching the given arguments
      Type Parameters:
      C - The content return type
      Parameters:
      cTypeIds - The id of content types. Can be empty to get program's items whatever their content type.
      code - The code. Can be null to get program's items regardless of their code
      catalogName - The search catalog. Can be null to get program's items regardless the catalog they belong to.
      lang - The search language. Can be null to get program's items regardless of their language
      additionnalExpr - An additional expression for filtering result. Can be null
      sortCriteria - criteria for sorting results
      Returns:
      The matching program items
    • getCoursePart

      public CoursePart getCoursePart(CoursePart srcCoursePart, String catalogName, String lang)
      Get the equivalent CoursePart of the source CoursePart in given catalog and language
      Parameters:
      srcCoursePart - The source course part
      catalogName - The name of catalog to search into
      lang - The search language
      Returns:
      The equivalent program item or null if not exists
    • getProgramItem

      public <T extends ProgramItem> T getProgramItem(T srcProgramItem, String catalogName, String lang)
      Get the equivalent ProgramItem of the source ProgramItem in given catalog and language
      Type Parameters:
      T - The type of returned object, it have to be a subclass of ProgramItem
      Parameters:
      srcProgramItem - The source program item
      catalogName - The name of catalog to search into
      lang - The search language
      Returns:
      The equivalent program item or null if not exists
    • getODFContent

      public <T extends AmetysObject> T getODFContent(String contentType, String odfContentCode, String catalogName, String lang)
      Get the equivalent Content having the same code in given catalog and language
      Type Parameters:
      T - The type of returned object, it have to be a subclass of AmetysObject
      Parameters:
      contentType - The content type to search for
      odfContentCode - The code of the ODF content
      catalogName - The name of catalog to search into
      lang - The search language
      Returns:
      The equivalent content or null if not exists
    • getChildProgramItems

      Get the child program items of a ProgramItem
      Parameters:
      programItem - The program item
      Returns:
      The child program items
    • getChildSubPrograms

      Get the child subprograms of a ProgramPart
      Parameters:
      programPart - The program part
      Returns:
      The child subprograms
    • getParentContainers

      Gets (recursively) parent containers of this program item.
      Parameters:
      programItem - The program item
      Returns:
      parent containers of this program item.
    • getParentContainers

      public Set<Container> getParentContainers(ProgramItem programItem, boolean continueIfFound)
      Gets (recursively) parent containers of this program item.
      Parameters:
      programItem - The program item
      continueIfFound - If true continue searching corresponding parents in the parent structure, otherwise only closest items are returned.
      Returns:
      parent containers of this program item.
    • getParentPrograms

      public Set<Program> getParentPrograms(CoursePart coursePart)
      Gets (recursively) parent programs of this course part.
      Parameters:
      coursePart - The course part
      Returns:
      parent programs of this course part.
    • getParentPrograms

      public Set<Program> getParentPrograms(ProgramItem programItem)
      Gets (recursively) parent programs of this program item.
      Parameters:
      programItem - The program item
      Returns:
      parent programs of this program item.
    • getParentSubPrograms

      Gets (recursively) parent subprograms of this course part.
      Parameters:
      coursePart - The course part
      Returns:
      parent subprograms of this course part.
    • getParentSubPrograms

      public Set<SubProgram> getParentSubPrograms(CoursePart coursePart, boolean continueIfFound)
      Gets (recursively) parent subprograms of this course part.
      Parameters:
      coursePart - The course part
      continueIfFound - If true continue searching corresponding parents in the parent structure, otherwise only closest items are returned.
      Returns:
      parent subprograms of this course part.
    • getParentSubPrograms

      Gets (recursively) parent subprograms of this program item.
      Parameters:
      programItem - The program item
      Returns:
      parent subprograms of this program item.
    • getParentSubPrograms

      public Set<SubProgram> getParentSubPrograms(ProgramItem programItem, boolean continueIfFound)
      Gets (recursively) parent subprograms of this program item.
      Parameters:
      programItem - The program item
      continueIfFound - If true continue searching corresponding parents in the parent structure, otherwise only closest items are returned.
      Returns:
      parent subprograms of this program item.
    • getParentAbstractPrograms

      Gets (recursively) parent abstract programs of this course part.
      Parameters:
      coursePart - The course part
      Returns:
      parent abstract programs of this course part.
    • getParentAbstractPrograms

      public Set<AbstractProgram> getParentAbstractPrograms(CoursePart coursePart, boolean continueIfFound)
      Gets (recursively) parent abstract programs of this course part.
      Parameters:
      coursePart - The course part
      continueIfFound - If true continue searching corresponding parents in the parent structure, otherwise only closest items are returned.
      Returns:
      parent abstract programs of this course part.
    • getParentAbstractPrograms

      Gets (recursively) parent abstract programs of this program item.
      Parameters:
      programItem - The program item
      Returns:
      parent abstract programs of this program item.
    • getParentAbstractPrograms

      public Set<AbstractProgram> getParentAbstractPrograms(ProgramItem programItem, boolean continueIfFound)
      Gets (recursively) parent abstract programs of this program item.
      Parameters:
      programItem - The program item
      continueIfFound - If true continue searching corresponding parents in the parent structure, otherwise only closest items are returned.
      Returns:
      parent abstract programs of this program item.
    • getProgramsFromOrgUnit

      public List<Program> getProgramsFromOrgUnit(OrgUnit orgUnit, String catalog, String lang)
      Get the child programs of an OrgUnit
      Parameters:
      orgUnit - the orgUnit, can be null
      catalog - the catalog
      lang - the lang
      Returns:
      The child programs
    • getSubOrgUnitIds

      public List<String> getSubOrgUnitIds(OrgUnit orgUnit)
      Get the current orgunit and its suborgunits recursively identifiers.
      Parameters:
      orgUnit - The orgunit at the top
      Returns:
      A List of OrgUnit ids
    • hasParentProgramItems

      public boolean hasParentProgramItems(ProgramItem programItem)
      Determines if the ProgramItem has parent program items
      Parameters:
      programItem - The program item
      Returns:
      true if has parent program items
    • getParentProgramItems

      Get the parent program items of a ProgramItem
      Parameters:
      programItem - The program item
      Returns:
      The parent program items
    • getParentProgramItem

      public ProgramItem getParentProgramItem(ProgramItem programItem, AbstractProgram parentProgram)
      Get the nearest program item parent into the given parent AbstractProgram
      Parameters:
      programItem - The program item
      parentProgram - The parent program or subprogram. If null, the nearest abstract program will be returned.
      Returns:
      The parent program item or null if not found.
    • getProgramItemInfo

      public Map<String,Object> getProgramItemInfo(String programItemId, List<String> programItemPathIds)
      Get information of the program item
      Parameters:
      programItemId - the program item id
      programItemPathIds - the list of program item ids containing in the path of the program item ... starting with itself. Can be null or empty
      Returns:
      a map of information
    • getStructureInfo

      public Map<String,Object> getStructureInfo(String contentId)
      Get information of the program item structure (type, if program has children) or orgunit (no structure for now)
      Parameters:
      contentId - the content id
      Returns:
      a map of information
    • getStructureInfo

      public Map<String,Map<String,Object>> getStructureInfo(List<String> programItemIds)
      Get information of the program item structure (type, if program has children)
      Parameters:
      programItemIds - the list of program item id
      Returns:
      a map of information
    • getOrgUnitPath

      public String getOrgUnitPath(OrgUnit orgunit, String separator)
      Get all the path of the orgunit.
      The path is built with the contents' title and code
      Parameters:
      orgunit - The orgunit
      separator - The path separator
      Returns:
      the path in parent orgunit
    • getPaths

      public List<String> getPaths(ProgramItem item, String separator)
      Get all the paths of a ODF content.
      The path is built with the contents' title and code
      Parameters:
      item - The program item
      separator - The path separator
      Returns:
      the paths in parent program items
    • getPaths

      public List<String> getPaths(ProgramItem item, String separator, Function<ProgramItem,String> mapper, boolean includeItseft)
      Get all the paths of a ODF content.
      The path is built with the mapper function.
      Parameters:
      item - The program item
      separator - The path separator
      mapper - the function to apply to each program item to build the path
      includeItseft - set to false to not include final item in path
      Returns:
      the paths in parent program items
    • getPathOfAncestors

      Get the full path to program item for highest ancestors. The path includes this final item.
      Parameters:
      item - the program item
      Returns:
      a list for each highest ancestors found. Each item of the list contains the program items to the path to this program item.
    • getPathInProgram

      public String getPathInProgram(String programItemId, String programId)
      Get the path of a ProgramItem into a Program
      The path is construct with the contents' names and the used separator is '/'.
      Parameters:
      programItemId - The id of the program item
      programId - The id of program. Can not be null.
      Returns:
      the path into the parent program or null if the item is not part of this program.
    • getPathInProgram

      public String getPathInProgram(ProgramItem item, Program parentProgram)
      Get the path of a ODF content into a Program.
      The path is construct with the contents' names and the used separator is '/'.
      Parameters:
      item - The program item
      parentProgram - The parent root (sub)program. Can not be null.
      Returns:
      the path from the parent program
    • getPathInCourse

      public String getPathInCourse(String contentId, String parentCourseId)
      Get the path of a Course or a CourseList into a Course
      The path is construct with the contents' names and the used separator is '/'.
      Parameters:
      contentId - The id of the content
      parentCourseId - The id of parent course. Can not be null.
      Returns:
      the path into the parent course or null if the item is not part of this course.
    • getPathInCourse

      public String getPathInCourse(Content courseOrList, Course parentCourse)
      Get the path of a Course or a CourseList into a Course
      The path is construct with the contents' names and the used separator is '/'.
      Parameters:
      courseOrList - The course or the course list
      parentCourse - The parent course. Can not be null.
      Returns:
      the path into the parent course or null if the item is not part of this course.
    • getOrgUnitPath

      public String getOrgUnitPath(String orgUnitId, String rootOrgUnitId)
      Get the hierarchical path of a OrgUnit from the root orgunit id.
      The path is construct with the contents' names and the used separator is '/'.
      Parameters:
      orgUnitId - The id of the orgunit
      rootOrgUnitId - The root orgunit id
      Returns:
      the path into the parent program or null if the item is not part of this program.
    • getOrgUnitPath

      public String getOrgUnitPath(String orgUnitId)
      Get the hierarchical path of a OrgUnit from the root orgunit.
      The path is construct with the contents' names and the used separator is '/'.
      Parameters:
      orgUnitId - The id of the orgunit
      Returns:
      the path into the parent program or null if the item is not part of this program.
    • hasAncestor

      public boolean hasAncestor(ProgramPart part, String parentId)
      Return true if the given ProgramPart has in its hierarchy a parent of given id
      Parameters:
      part - The program part
      parentId - The ancestor id
      Returns:
      true if the given ProgramPart has in its hierarchy a parent of given id
    • isRelationCompatible

      public boolean isRelationCompatible(Content srcContent, Content targetContent, List<I18nizableText> errors, Map<String,Object> contextualParameters)
      Check if a relation can be establish between two ODF contents
      Parameters:
      srcContent - The source content (copied or moved)
      targetContent - The target content
      errors - The list of error messages
      contextualParameters - the contextual parameters
      Returns:
      true if the relation is valid, false otherwise
    • copyProgramItem

      public <C extends ModifiableContent> C copyProgramItem(ProgramItem srcContent, String targetCatalog, boolean fullCopy, Map<String,String> copiedPrograms, Map<String,String> copiedSubPrograms, Map<String,String> copiedContainers, Map<String,String> copiedCourseLists, Map<String,String> copiedCourses, Map<String,String> copiedCourseParts) throws AmetysRepositoryException, com.opensymphony.workflow.WorkflowException
      Type Parameters:
      C - The modifiable content return type
      Parameters:
      srcContent - The program item to copy
      targetCatalog - The target catalog. Can be null. The target catalog will be the catalog of the source object.
      fullCopy - Set to true to copy the sub-structure
      copiedPrograms - the id of initial programs with their copied content
      copiedSubPrograms - the id of initial subprograms with their copied content
      copiedContainers - the id of initial containers with their copied content
      copiedCourseLists - the id of initial course lists with their copied content
      copiedCourses - the id of initial courses with their copied content
      copiedCourseParts - the id of initial course parts with their copied content
      Returns:
      The created content
      Throws:
      AmetysRepositoryException - If an error occurred during copy
      com.opensymphony.workflow.WorkflowException - If an error occurred during copy
    • copyProgramItem

      public <C extends ModifiableContent> C copyProgramItem(ProgramItem srcContent, String targetContentName, String targetContentLanguage, String targetCatalog, boolean fullCopy, Map<String,String> copiedPrograms, Map<String,String> copiedSubPrograms, Map<String,String> copiedContainers, Map<String,String> copiedCourseLists, Map<String,String> copiedCourses, Map<String,String> copiedCourseParts) throws AmetysRepositoryException, com.opensymphony.workflow.WorkflowException
      Type Parameters:
      C - The modifiable content return type
      Parameters:
      srcContent - The program item to copy
      targetContentName - The name of content to created. Can be null. If null, the new name will be get from the source object.
      targetContentLanguage - The name of content to created. Can be null. If null, the language of target content will be the same as source object.
      targetCatalog - The target catalog. Can be null. The target catalog will be the catalog of the source object.
      fullCopy - Set to true to copy the sub-structure
      copiedPrograms - the id of initial programs with their copied content
      copiedSubPrograms - the id of initial subprograms with their copied content
      copiedContainers - the id of initial containers with their copied content
      copiedCourseLists - the id of initial course lists with their copied content
      copiedCourses - the id of initial courses with their copied content
      copiedCourseParts - the id of initial course parts with their copied content
      Returns:
      The created content
      Throws:
      AmetysObjectExistsException - If a program item with same code, catalog and language already exists
      AmetysRepositoryException - If an error occurred
      com.opensymphony.workflow.WorkflowException - If an error occurred
    • copyCoursePart

      public <C extends ModifiableContent> C copyCoursePart(CoursePart srcContent, String targetContentName, String targetContentLanguage, int initWorkflowActionId, String targetCatalog, boolean fullCopy, Map<String,String> copiedPrograms, Map<String,String> copiedSubPrograms, Map<String,String> copiedContainers, Map<String,String> copiedCourseLists, Map<String,String> copiedCourses, Map<String,String> copiedCourseParts) throws AmetysRepositoryException, com.opensymphony.workflow.WorkflowException
      Copy a CoursePart
      Type Parameters:
      C - The modifiable content return type
      Parameters:
      srcContent - The course part to copy
      targetContentName - The name of content to created. Can be null. If null, the new name will be get from the source object.
      targetContentLanguage - The name of content to created. Can be null. If null, the language of target content will be the same as source object.
      initWorkflowActionId - The initial workflow action id
      fullCopy - Set to true to copy the sub-structure
      targetCatalog - The target catalog. Can be null. The target catalog will be the catalog of the source object.
      copiedPrograms - the id of initial programs with their copied content
      copiedSubPrograms - the id of initial subprograms with their copied content
      copiedContainers - the id of initial containers with their copied content
      copiedCourseLists - the id of initial course lists with their copied content
      copiedCourses - the id of initial courses with their copied content
      copiedCourseParts - the id of initial course parts with their copied content
      Returns:
      The created content
      Throws:
      AmetysObjectExistsException - If a program item with same code, catalog and language already exists
      AmetysRepositoryException - If an error occurred
      com.opensymphony.workflow.WorkflowException - If an error occurred
    • copyProgramItem

      public <C extends ModifiableContent> C copyProgramItem(ProgramItem srcContent, String targetContentName, String targetContentLanguage, int initWorkflowActionId, String targetCatalog, boolean fullCopy, Map<String,String> copiedPrograms, Map<String,String> copiedSubPrograms, Map<String,String> copiedContainers, Map<String,String> copiedCourseLists, Map<String,String> copiedCourses, Map<String,String> copiedCourseParts) throws AmetysRepositoryException, com.opensymphony.workflow.WorkflowException
      Type Parameters:
      C - The modifiable content return type
      Parameters:
      srcContent - The program item to copy
      targetContentName - The name of content to created. Can be null. If null, the new name will be get from the source object.
      targetContentLanguage - The name of content to created. Can be null. If null, the language of target content will be the same as source object.
      initWorkflowActionId - The initial workflow action id
      fullCopy - Set to true to copy the sub-structure
      targetCatalog - The target catalog. Can be null. The target catalog will be the catalog of the source object.
      copiedPrograms - the id of initial programs with their copied content
      copiedSubPrograms - the id of initial subprograms with their copied content
      copiedContainers - the id of initial containers with their copied content
      copiedCourseLists - the id of initial course lists with their copied content
      copiedCourses - the id of initial courses with their copied content
      copiedCourseParts - the id of initial course parts with their copied content
      Returns:
      The created content
      Throws:
      AmetysObjectExistsException - If a program item with same code, catalog and language already exists
      AmetysRepositoryException - If an error occurred
      com.opensymphony.workflow.WorkflowException - If an error occurred
    • copyProgramItemStructure

      protected void copyProgramItemStructure(ProgramItem srcContent, ModifiableContent targetContent, String targetContentLanguage, int initWorkflowActionId, String targetCatalogName, Map<String,String> copiedPrograms, Map<String,String> copiedSubPrograms, Map<String,String> copiedContainers, Map<String,String> copiedCourseLists, Map<String,String> copiedCourses, Map<String,String> copiedCourseParts) throws AmetysRepositoryException, com.opensymphony.workflow.WorkflowException
      Copy the structure of a ProgramItem
      Parameters:
      srcContent - the content to copy
      targetContent - the target content
      targetContentLanguage - The name of content to created. Can be null. If null, the language of target content will be the same as source object.
      initWorkflowActionId - The initial workflow action id
      targetCatalogName - The target catalog. Can be null. The target catalog will be the catalog of the source object.
      copiedPrograms - the id of initial programs with their copied content
      copiedSubPrograms - the id of initial subprograms with their copied content
      copiedContainers - the id of initial containers with their copied content
      copiedCourseLists - the id of initial course lists with their copied content
      copiedCourses - the id of initial courses with their copied content
      copiedCourseParts - the id of initial course parts with their copied content
      Throws:
      AmetysRepositoryException - If an error occurred during copy
      com.opensymphony.workflow.WorkflowException - If an error occurred during copy
    • _cleanContentMetadata

      protected void _cleanContentMetadata(ModifiableContent createdContent)
      Clean the CONTENT metadata created after a copy but whose values reference the initial content' structure
      Parameters:
      createdContent - The created content to clean
    • switchToLiveVersion

      Switch the ametys object to Live version if it has one
      Parameters:
      ao - the Ametys object
      Throws:
      NoLiveVersionException - if the content has no live version
    • switchToLiveVersionIfNeeded

      Switch to Live version if is required
      Parameters:
      ao - the Ametys object
      Throws:
      NoLiveVersionException - if the Live version is required but not exist
    • getCumulatedHours

      public Double getCumulatedHours(ProgramItem programItem)
      Count the hours accumulation in the ProgramItem
      Parameters:
      programItem - The program item on which we compute the total number of hours
      Returns:
      The hours accumulation
    • _getRequest

      protected Request _getRequest()
      Get the request
      Returns:
      the request
    • getOrgUnitByUAICode

      Get the first orgunit matching the given UAI code
      Parameters:
      uaiCode - the UAI code
      Returns:
      the orgunit or null if not found