001/*
002 *  Copyright 2024 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.properties;
017
018import org.apache.avalon.framework.service.ServiceException;
019import org.apache.avalon.framework.service.ServiceManager;
020
021import org.ametys.cms.model.properties.AbstractIndexableStaticProperty;
022import org.ametys.cms.model.properties.Property;
023import org.ametys.cms.repository.Content;
024import org.ametys.odf.ODFHelper;
025import org.ametys.odf.ProgramItem;
026import org.ametys.runtime.model.type.ModelItemTypeConstants;
027
028/**
029 * {@link Property} which represents the shared status of a {@link ProgramItem}.
030 */
031public class SharedProperty extends AbstractIndexableStaticProperty<Boolean, Boolean, Content>
032{
033    private ODFHelper _odfHelper;
034
035    @Override
036    public void service(ServiceManager manager) throws ServiceException
037    {
038        super.service(manager);
039        _odfHelper = (ODFHelper) manager.lookup(ODFHelper.ROLE);
040    }
041    
042    public Object getValue(Content content)
043    {
044        if (content instanceof ProgramItem programItem)
045        {
046            return _odfHelper.isShared(programItem);
047        }
048        
049        return false;
050    }
051    
052    @Override
053    protected String getTypeId()
054    {
055        return ModelItemTypeConstants.BOOLEAN_TYPE_ID;
056    }
057}