001/*
002 *  Copyright 2016 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.userdirectory.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.ModelAwareDataHolder;
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.web.data.type.ModelItemTypeExtensionPoint;
030import org.ametys.web.repository.page.Page;
031import org.ametys.web.repository.page.SitemapElement;
032import org.ametys.web.repository.page.Zone;
033import org.ametys.web.repository.page.ZoneItem;
034import org.ametys.web.service.ServiceExtensionPoint;
035
036/**
037 * {@link Zone} holding a sitemap.
038 */
039public class TransitionalZone implements Zone
040{
041    private TransitionalPage _page;
042    private ModelItemTypeExtensionPoint _zoneDataTypeExtensionPoint;
043    private ServiceExtensionPoint _serviceExtensionPoint;
044    private ModelItemTypeExtensionPoint _zoneItemDataTypeExtensionPoint;
045    
046    /**
047     * Constructor
048     * @param page the parent {@link TransitionalPage}.
049     * @param zoneDataTypeExtensionPoint the extension point with available data types for zones
050     * @param serviceExtensionPoint the service extension point
051     * @param zoneItemDataTypeExtensionPoint the extension point with available data types for zone items
052     */
053    public TransitionalZone(TransitionalPage page, ModelItemTypeExtensionPoint zoneDataTypeExtensionPoint, ServiceExtensionPoint serviceExtensionPoint, ModelItemTypeExtensionPoint zoneItemDataTypeExtensionPoint)
054    {
055        _page = page;
056        _zoneDataTypeExtensionPoint = zoneDataTypeExtensionPoint;
057        _serviceExtensionPoint = serviceExtensionPoint;
058        _zoneItemDataTypeExtensionPoint = zoneItemDataTypeExtensionPoint;
059    }
060    
061    @Override
062    public SitemapElement getSitemapElement()
063    {
064        return _page;
065    }
066
067    @Override
068    public AmetysObjectIterable<? extends ZoneItem> getZoneItems() throws AmetysRepositoryException
069    {
070        ArrayList<ZoneItem> zoneItems = new ArrayList<>();
071        zoneItems.add(new TransitionalZoneItem(_page, _zoneDataTypeExtensionPoint, _serviceExtensionPoint, _zoneItemDataTypeExtensionPoint));
072        return new CollectionIterable<>(zoneItems);
073    }
074
075    public ModelLessDataHolder getDataHolder()
076    {
077        RepositoryData repositoryData = new MemoryRepositoryData(getName());
078        return new DefaultModelLessDataHolder(_zoneDataTypeExtensionPoint, repositoryData);
079    }
080
081    @Override
082    public String getId() throws AmetysRepositoryException
083    {
084        return "udtransitionalzone://unused?pageId=" + _page.getId();
085    }
086
087    @Override
088    public String getName() throws AmetysRepositoryException
089    {
090        return "default";
091    }
092
093    @SuppressWarnings("unchecked")
094    @Override
095    public Page getParent() throws AmetysRepositoryException
096    {
097        return _page;
098    }
099
100    @Override
101    public String getParentPath() throws AmetysRepositoryException
102    {
103        return _page.getPath();
104    }
105
106    @Override
107    public String getPath() throws AmetysRepositoryException
108    {
109        return _page.getPath() + "/default";
110    }
111    
112    public ModelAwareDataHolder getZoneParametersHolder() throws AmetysRepositoryException
113    {
114        return null;
115    }
116}