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 org.ametys.cms.data.holder.impl.DefaultModifiableModelAwareDataHolder;
020import org.ametys.cms.repository.Content;
021import org.ametys.plugins.repository.AmetysRepositoryException;
022import org.ametys.plugins.repository.data.holder.ModelAwareDataHolder;
023import org.ametys.plugins.repository.data.holder.ModelLessDataHolder;
024import org.ametys.plugins.repository.data.holder.ModifiableModelAwareDataHolder;
025import org.ametys.plugins.repository.data.holder.impl.DefaultModelLessDataHolder;
026import org.ametys.plugins.repository.data.repositorydata.ModifiableRepositoryData;
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.Zone;
031import org.ametys.web.repository.page.ZoneItem;
032import org.ametys.web.service.ServiceExtensionPoint;
033
034/**
035 * {@link ZoneItem} holding a Sitemap service
036 */
037public class TransitionalZoneItem implements ZoneItem
038{
039    private TransitionalPage _page;
040    private ModelItemTypeExtensionPoint _zoneDataTypeExtensionPoint;
041    private ServiceExtensionPoint _serviceExtensionPoint;
042    private ModelItemTypeExtensionPoint _zoneItemDataTypeExtensionPoint;
043    
044    /**
045     * Constructor.
046     * @param page the parent {@link TransitionalPage}.
047     * @param zoneDataTypeExtensionPoint the extension point with available data types for zones
048     * @param serviceExtensionPoint the service extension point
049     * @param zoneItemDataTypeExtensionPoint the extension point with available data types for zone items
050     */
051    public TransitionalZoneItem(TransitionalPage page, ModelItemTypeExtensionPoint zoneDataTypeExtensionPoint, ServiceExtensionPoint serviceExtensionPoint, ModelItemTypeExtensionPoint zoneItemDataTypeExtensionPoint)
052    {
053        _page = page;
054        _zoneDataTypeExtensionPoint = zoneDataTypeExtensionPoint;
055        _serviceExtensionPoint = serviceExtensionPoint;
056        _zoneItemDataTypeExtensionPoint = zoneItemDataTypeExtensionPoint;
057    }
058    
059    @SuppressWarnings("unchecked")
060    @Override
061    public Content getContent() throws AmetysRepositoryException
062    {
063        throw new UnsupportedOperationException("getContent not supported on virtual degree pages");
064    }
065
066    public String getViewName() throws AmetysRepositoryException
067    {
068        return "main";
069    }
070    
071    @Override
072    public String getServiceId() throws AmetysRepositoryException
073    {
074        return "org.ametys.web.service.SitemapService";
075    }
076
077    public ModelAwareDataHolder getServiceParameters() throws AmetysRepositoryException
078    {
079        ModifiableRepositoryData repositoryData = new MemoryRepositoryData(SERVICE_PARAMETERS_DATA_NAME);
080        ModifiableModelAwareDataHolder dataHolder = new DefaultModifiableModelAwareDataHolder(repositoryData, _serviceExtensionPoint.getExtension(getServiceId()));
081        _setServicePrameters(dataHolder);
082        return dataHolder;
083    }
084    
085    private void _setServicePrameters(ModifiableModelAwareDataHolder dataHolder)
086    {
087        dataHolder.setValue("depth", 1L);
088        dataHolder.setValue("all", "false");
089        dataHolder.setValue("includeInvisiblePage", true);
090    }
091    
092    @Override
093    public ZoneType getType() throws AmetysRepositoryException
094    {
095        return ZoneType.SERVICE;
096    }
097
098    @Override
099    public Zone getZone()
100    {
101        return new TransitionalZone(_page, _zoneDataTypeExtensionPoint, _serviceExtensionPoint, _zoneItemDataTypeExtensionPoint);
102    }
103
104    public ModelLessDataHolder getDataHolder()
105    {
106        RepositoryData repositoryData = new MemoryRepositoryData(Zone.ZONEITEM_DATA_NAME);
107        return new DefaultModelLessDataHolder(_zoneItemDataTypeExtensionPoint, repositoryData);
108    }
109
110    @Override
111    public String getId() throws AmetysRepositoryException
112    {
113        return "udtransionalzoneitem://unused?pageId=" + _page.getId();
114    }
115
116    @Override
117    public String getName() throws AmetysRepositoryException
118    {
119        return "default";
120    }
121
122    @SuppressWarnings("unchecked")
123    @Override
124    public TransitionalZone getParent() throws AmetysRepositoryException
125    {
126        return new TransitionalZone(_page, _zoneDataTypeExtensionPoint, _serviceExtensionPoint, _zoneItemDataTypeExtensionPoint);
127    }
128
129    @Override
130    public String getParentPath() throws AmetysRepositoryException
131    {
132        return _page.getPath() + "/default";
133    }
134
135    @Override
136    public String getPath() throws AmetysRepositoryException
137    {
138        return _page.getPath() + "/default/default";
139    }
140
141    public ModelAwareDataHolder getZoneItemParametersHolder() throws AmetysRepositoryException
142    {
143        return null;
144    }
145
146    public ModelAwareDataHolder getContentViewParametersHolder(String contentViewName) throws AmetysRepositoryException
147    {
148        return null;
149    }
150
151    public ModelAwareDataHolder getServiceViewParametersHolder(String serviceViewName) throws AmetysRepositoryException
152    {
153        return null;
154    }
155}