001/*
002 *  Copyright 2019 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.odf.rncp;
017
018import java.io.IOException;
019import java.util.List;
020import java.util.Map;
021
022import org.apache.avalon.framework.configuration.ConfigurationException;
023import org.apache.avalon.framework.service.ServiceException;
024import org.apache.avalon.framework.service.ServiceManager;
025import org.xml.sax.SAXException;
026
027import org.ametys.core.ui.Callable;
028import org.ametys.core.ui.StaticClientSideElement;
029import org.ametys.odf.ODFHelper;
030import org.ametys.plugins.repository.AmetysObjectResolver;
031
032/**
033 * Client side element for abstract program RNCP sheets.
034 */
035public class RNCPAbstractProgramClientSideElement extends StaticClientSideElement
036{
037    /** The Ametys object resolver */
038    protected AmetysObjectResolver _resolver;
039
040    /** The ODF helper */
041    protected ODFHelper _odfHelper;
042
043    /** The RNCP model helper */
044    protected RNCPModelHelper _rncpModelHelper;
045
046    @Override
047    public void service(ServiceManager smanager) throws ServiceException
048    {
049        super.service(smanager);
050        _resolver = (AmetysObjectResolver) smanager.lookup(AmetysObjectResolver.ROLE);
051        _odfHelper = (ODFHelper) smanager.lookup(ODFHelper.ROLE);
052        _rncpModelHelper = (RNCPModelHelper) smanager.lookup(RNCPModelHelper.ROLE);
053    }
054    
055    /**
056     * Get the list of RNCP models.
057     * @return A JSON list with id and label of each available RNCP model
058     * @throws ConfigurationException if an error occurs
059     * @throws SAXException if an error occurs
060     * @throws IOException if an error occurs
061     */
062    @Callable
063    public List<Map<String, Object>> getModels() throws ConfigurationException, SAXException, IOException
064    {
065        return _rncpModelHelper.getModels();
066    }
067}