001/*
002 *  Copyright 2012 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.program;
017
018import java.util.Collections;
019import java.util.List;
020import java.util.Set;
021
022import javax.jcr.Node;
023
024import org.ametys.cms.data.ContentDataHelper;
025import org.ametys.odf.cdmfr.CDMFRTagsConstants;
026import org.ametys.runtime.model.exception.UndefinedItemPathException;
027
028/**
029 * This class represent the root element of a program
030 */
031public class Program extends AbstractProgram<ProgramFactory>
032{
033    /**
034     * Constructor.
035     * @param node the JCR Node backing this Content.
036     * @param parentPath the parent path in the Ametys hierarchy.
037     * @param factory the corresponding {@link ProgramFactory}.
038     */
039    public Program(Node node, String parentPath, ProgramFactory factory)
040    {
041        super(node, parentPath, factory);
042    }
043    
044    @Override
045    public Set<Program> getRootPrograms()
046    {
047        return Collections.EMPTY_SET;
048    }
049    
050    @Override
051    public List<ProgramPart> getProgramPartParents()
052    {
053        return Collections.EMPTY_LIST;
054    }
055    
056    // --------------------------------------------------------------------------------------//
057    // CDMfr
058    // --------------------------------------------------------------------------------------//
059    @Override
060    public String getCDMTagName()
061    {
062        return CDMFRTagsConstants.TAG_PROGRAM;
063    }
064    
065    /**
066     * Get the degree
067     * @return the degree or null
068     */
069    public String getDegree()
070    {
071        try
072        {
073            return ContentDataHelper.getContentIdFromContentData(this, DEGREE);
074        }
075        catch (UndefinedItemPathException e)
076        {
077            return null; // this attribute is not part of model
078        }
079    }
080}