001/*
002 *  Copyright 2017 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.apogee;
017
018import java.util.List;
019import java.util.Map;
020
021import org.apache.ibatis.session.SqlSession;
022
023import org.ametys.core.datasource.AbstractMyBatisDAO;
024import org.ametys.runtime.config.Config;
025
026/**
027 * Data access object to the remote DB Apogee
028 */
029public class ApogeeDAO extends AbstractMyBatisDAO
030{
031    /** Avalon ROLE */
032    public static final String ROLE = ApogeeDAO.class.getName();
033    
034    /**
035     * Returns Apogee programs matching the search criteria
036     * @param params The parameters for search criteria: DIP code, VDI code, title
037     * @return the list Apogee course lists matching the search criteria
038     */
039    public List<Map<String, Object>> searchPrograms(Map<String, Object> params)
040    {
041        String administrativeYear = Config.getInstance().getValueAsString("odf.apogee.administrative.year");
042        params.put("year", administrativeYear);
043        
044        try (SqlSession session = getSession())
045        {
046            return session.selectList("Apogee.searchPrograms", params);
047        }
048    }
049    
050    /**
051     * Returns joint org units linked to a program
052     * @param params he parameters for search criteria: Program ID
053     * @return The list of Apogee joint org units matching the program
054     */
055    public List<Map<String, Object>> getJointOrgUnits(Map<String, Object> params)
056    {
057        try (SqlSession session = getSession())
058        {
059            return session.selectList("Apogee.getJointOrgUnits", params);
060        }
061    }
062
063    /**
064     * Returns form of teaching linked to a program
065     * @param params he parameters for search criteria: Program ID
066     * @return The list of Apogee form of teaching matching the program
067     */
068    public List<Map<String, Object>> getFormOfTeachingOrg(Map<String, Object> params)
069    {
070        try (SqlSession session = getSession())
071        {
072            return session.selectList("Apogee.getFormOfTeachingOrg", params);
073        }
074    }
075    
076    /**
077     * Returns the add elements (rich texts) to a program
078     * @param params he parameters for search criteria: Program ID
079     * @return The list of Apogee add elements matching the program
080     */
081    public List<Map<String, Object>> getAddElements(Map<String, Object> params)
082    {
083        try (SqlSession session = getSession())
084        {
085            return session.selectList("Apogee.getAddElements", params);
086        }
087    }
088    
089    /**
090     * Returns Apogee organizational units matching the search criteria
091     * @param params The parameters for search criteria: cod_cmp, cod_tpc, title
092     * @return The list of Apogee organizational units matching the search criteria
093     */
094    public List<Map<String, Object>> searchOrgUnits(Map<String, Object> params)
095    {
096        try (SqlSession session = getSession())
097        {
098            return session.selectList("Apogee.searchOrgUnits", params);
099        }
100    }
101    
102    /**
103     * Returns Apogee containers matching the search criteria
104     * @param params The parameters for search criteria: code, type, title
105     * @return The list of Apogee containers matching the search criteria
106     */
107    public List<Map<String, Object>> searchContainers(Map<String, Object> params)
108    {
109        try (SqlSession session = getSession())
110        {
111            return session.selectList("Apogee.searchContainers", params);
112        }
113    }
114    
115    /**
116     * Returns Apogee subprograms matching the search criteria
117     * @param params The parameters for search criteria: "dip", "vdi", "vdi-ter", "etp-code", "vet-code", "vet-title"
118     * @return The list of Apogee subprograms matching the search criteria
119     */
120    public List<Map<String, Object>> searchSubPrograms(Map<String, Object> params)
121    {
122        String administrativeYear = Config.getInstance().getValueAsString("odf.apogee.administrative.year");
123        params.put("year", administrativeYear);
124        
125        try (SqlSession session = getSession())
126        {
127            return session.selectList("Apogee.searchSubPrograms", params);
128        }
129    }
130    
131    /**
132     * Returns the Apogee educational elements matching the search criteria
133     * @param params The parameters for search criteria: ELP code (code), ELP type (type), title (title)
134     * @return the list of Apogee educational elements matching the search criteria
135     */
136    public List<Map<String, Object>> searchCourses(Map<String, Object> params)
137    {
138        try (SqlSession session = getSession())
139        {
140            return session.selectList("Apogee.searchCourses", params);
141        }
142    }
143    
144    /**
145     * Returns the Apogee course lists matching the search criteria
146     * @param params The parameters for search criteria: ELP code (code), NEL code (cod_nel), title (title)
147     * @return the list Apogee course lists matching the search criteria
148     */
149    public List<Map<String, Object>> searchCourseLists(Map<String, Object> params)
150    {
151        try (SqlSession session = getSession())
152        {
153            return session.selectList("Apogee.searchCourseLists", params);
154        }
155    }
156}