001/*
002 *  Copyright 2021 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.plugins.odfsync.utils;
017
018import java.util.stream.Stream;
019
020import org.ametys.odf.course.CourseFactory;
021import org.ametys.odf.courselist.CourseListFactory;
022import org.ametys.odf.coursepart.CoursePartFactory;
023import org.ametys.odf.orgunit.OrgUnitFactory;
024import org.ametys.odf.person.PersonFactory;
025import org.ametys.odf.program.ContainerFactory;
026import org.ametys.odf.program.ProgramFactory;
027import org.ametys.odf.program.SubProgramFactory;
028
029/**
030 * Object to describe content workflow elements.
031 */
032public enum ContentWorkflowDescription
033{
034    /** Program workflow description */
035    PROGRAM_WF_DESCRIPTION(ProgramFactory.PROGRAM_CONTENT_TYPE, "program", 1, 4),
036    /** Subprogram workflow description */
037    SUBPROGRAM_WF_DESCRIPTION(SubProgramFactory.SUBPROGRAM_CONTENT_TYPE, "subprogram", 1, 4),
038    /** Container workflow description */
039    CONTAINER_WF_DESCRIPTION(ContainerFactory.CONTAINER_CONTENT_TYPE, "container", 1, 4),
040    /** Course list workflow description */
041    COURSELIST_WF_DESCRIPTION(CourseListFactory.COURSE_LIST_CONTENT_TYPE, "courselist", 1, 4),
042    /** Course workflow description */
043    COURSE_WF_DESCRIPTION(CourseFactory.COURSE_CONTENT_TYPE, "course", 1, 4),
044    /** Course part workflow description */
045    COURSEPART_WF_DESCRIPTION(CoursePartFactory.COURSE_PART_CONTENT_TYPE, "course-part", 1, -1),
046    /** Orgunit workflow description */
047    ORGUNIT_WF_DESCRIPTION(OrgUnitFactory.ORGUNIT_CONTENT_TYPE, "orgunit", 1, 4),
048    /** Person workflow description */
049    PERSON_WF_DESCRIPTION(PersonFactory.PERSON_CONTENT_TYPE, "person", 1, 4);
050    
051    private String _contentType;
052    private String _workflowName;
053    private int _initialActionId;
054    private int _validationActionId;
055    
056    ContentWorkflowDescription(String contentType, String workflowName, int initialActionId, int validationActionId)
057    {
058        _contentType = contentType;
059        _workflowName = workflowName;
060        _initialActionId = initialActionId;
061        _validationActionId = validationActionId;
062    }
063    
064    /**
065     * Get the content type.
066     * @return the content type ID
067     */
068    public String getContentType()
069    {
070        return _contentType;
071    }
072    
073    /**
074     * Get the workflow name.
075     * @return the workflow name
076     */
077    public String getWorkflowName()
078    {
079        return _workflowName;
080    }
081    
082    /**
083     * Get the initial action ID.
084     * @return the initial action ID
085     */
086    public int getInitialActionId()
087    {
088        return _initialActionId;
089    }
090    
091    /**
092     * Get the validation action ID.
093     * @return the validation action ID
094     */
095    public int getValidationActionId()
096    {
097        return _validationActionId;
098    }
099    
100    /**
101     * Retrieve the workflow description from the content type
102     * @param contentType The content type
103     * @return The corresponding workflow description
104     */
105    public static ContentWorkflowDescription getByContentType(String contentType)
106    {
107        return Stream.of(values())
108            .filter(wd -> wd.getContentType().equals(contentType))
109            .findFirst()
110            .orElse(null);
111    }
112}