001/*
002 *  Copyright 2010 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 */
016
017package org.ametys.plugins.odfweb.repository;
018
019import java.util.ArrayList;
020
021import org.ametys.odf.program.Program;
022import org.ametys.plugins.repository.AmetysObjectIterable;
023import org.ametys.plugins.repository.AmetysRepositoryException;
024import org.ametys.plugins.repository.CollectionIterable;
025import org.ametys.plugins.repository.data.holder.ModelLessDataHolder;
026import org.ametys.plugins.repository.data.holder.impl.DefaultModelLessDataHolder;
027import org.ametys.plugins.repository.data.repositorydata.RepositoryData;
028import org.ametys.plugins.repository.data.repositorydata.impl.MemoryRepositoryData;
029import org.ametys.plugins.repository.data.type.RepositoryModelItemType;
030import org.ametys.runtime.plugin.component.AbstractThreadSafeComponentExtensionPoint;
031import org.ametys.web.repository.page.Page;
032import org.ametys.web.repository.page.Zone;
033import org.ametys.web.repository.page.ZoneItem;
034
035/**
036 * {@link Zone} holding a {@link Program}.
037 */
038public class ProgramZone implements Zone
039{
040    private ProgramPage _page;
041    private AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> _zoneDataTypeExtensionPoint;
042    private AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> _zoneItemDataTypeExtensionPoint;
043    
044    /**
045     * Constructor
046     * @param page the parent {@link ProgramPage}.
047     * @param zoneDataTypeExtensionPoint the extension point with available data types for zones
048     * @param zoneItemDataTypeExtensionPoint the extension point with available data types for zone items
049     */
050    public ProgramZone(ProgramPage page, AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> zoneDataTypeExtensionPoint, AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> zoneItemDataTypeExtensionPoint)
051    {
052        _page = page;
053        _zoneDataTypeExtensionPoint = zoneDataTypeExtensionPoint;
054        _zoneItemDataTypeExtensionPoint = zoneItemDataTypeExtensionPoint;
055    }
056    
057    @Override
058    public Page getPage()
059    {
060        return _page;
061    }
062
063    @Override
064    public AmetysObjectIterable<? extends ZoneItem> getZoneItems() throws AmetysRepositoryException
065    {
066        ArrayList<ZoneItem> zoneItems = new ArrayList<>();
067        zoneItems.add(new ProgramZoneItem(_page, _zoneDataTypeExtensionPoint, _zoneItemDataTypeExtensionPoint));
068        return new CollectionIterable<>(zoneItems);
069    }
070
071    public ModelLessDataHolder getDataHolder()
072    {
073        RepositoryData repositoryData = new MemoryRepositoryData(getName());
074        return new DefaultModelLessDataHolder(_zoneDataTypeExtensionPoint, repositoryData);
075    }
076
077    @Override
078    public String getId() throws AmetysRepositoryException
079    {
080        return "programZone://unused?pageId=" + _page.getId();
081    }
082
083    @Override
084    public String getName() throws AmetysRepositoryException
085    {
086        return "default";
087    }
088
089    @SuppressWarnings("unchecked")
090    @Override
091    public Page getParent() throws AmetysRepositoryException
092    {
093        return _page;
094    }
095
096    @Override
097    public String getParentPath() throws AmetysRepositoryException
098    {
099        return _page.getPath();
100    }
101
102    @Override
103    public String getPath() throws AmetysRepositoryException
104    {
105        return _page.getPath() + "/default";
106    }
107}