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