001/*
002 *  Copyright 2017 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.repository.Content;
020import org.ametys.plugins.repository.AmetysRepositoryException;
021import org.ametys.plugins.repository.data.holder.ModelAwareDataHolder;
022import org.ametys.plugins.repository.data.holder.ModelLessDataHolder;
023import org.ametys.plugins.repository.data.holder.impl.DefaultModelLessDataHolder;
024import org.ametys.plugins.repository.data.repositorydata.RepositoryData;
025import org.ametys.plugins.repository.data.repositorydata.impl.MemoryRepositoryData;
026import org.ametys.web.data.type.ModelItemTypeExtensionPoint;
027import org.ametys.web.repository.page.Zone;
028import org.ametys.web.repository.page.ZoneItem;
029
030/**
031 * {@link ZoneItem} holding a content.
032 */
033public class OrgUnitZoneItem implements ZoneItem
034{
035    private OrgUnitPage _page;
036    private ModelItemTypeExtensionPoint _zoneDataTypeExtensionPoint;
037    private ModelItemTypeExtensionPoint _zoneItemDataTypeExtensionPoint;
038    
039    /**
040     * Constructor.
041     * @param page the parent {@link OrgUnitPage}.
042     * @param zoneDataTypeExtensionPoint the extension point with available data types for zones
043     * @param zoneItemDataTypeExtensionPoint the extension point with available data types for zone items
044     */
045    public OrgUnitZoneItem(OrgUnitPage page, ModelItemTypeExtensionPoint zoneDataTypeExtensionPoint, ModelItemTypeExtensionPoint zoneItemDataTypeExtensionPoint)
046    {
047        _page = page;
048        _zoneDataTypeExtensionPoint = zoneDataTypeExtensionPoint;
049        _zoneItemDataTypeExtensionPoint = zoneItemDataTypeExtensionPoint;
050    }
051    
052    @SuppressWarnings("unchecked")
053    @Override
054    public Content getContent() throws AmetysRepositoryException
055    {
056        Content content = _page.getSyncContent();
057        return content;
058    }
059
060    public String getViewName() throws AmetysRepositoryException
061    {
062        return "main";
063    }
064    
065    @Override
066    public String getServiceId() throws AmetysRepositoryException
067    {
068        throw new UnsupportedOperationException("getServiceId not supported on virtual organisation chart pages");
069    }
070
071    public ModelAwareDataHolder getServiceParameters() throws AmetysRepositoryException
072    {
073        throw new UnsupportedOperationException("getServiceParameters not supported on virtual organisation chart pages");
074    }
075
076    @Override
077    public ZoneType getType() throws AmetysRepositoryException
078    {
079        return ZoneType.CONTENT;
080    }
081
082    @Override
083    public Zone getZone()
084    {
085        return new OrgUnitZone(_page, _zoneDataTypeExtensionPoint, _zoneItemDataTypeExtensionPoint);
086    }
087
088    public ModelLessDataHolder getDataHolder()
089    {
090        RepositoryData repositoryData = new MemoryRepositoryData(Zone.ZONEITEM_DATA_NAME);
091        return new DefaultModelLessDataHolder(_zoneItemDataTypeExtensionPoint, repositoryData);
092    }
093
094    /**
095     * Compute the zone item id of a content for a page 
096     * @param pageId The page id
097     * @return The zoneitem id
098     */
099    public static String getZoneItemId(String pageId)
100    {
101        return "udorgunitzoneitem://unused?pageId=" + pageId;
102    }
103    
104    @Override
105    public String getId() throws AmetysRepositoryException
106    {
107        return getZoneItemId(_page.getId());
108    }
109
110    @Override
111    public String getName() throws AmetysRepositoryException
112    {
113        return "default";
114    }
115
116    @SuppressWarnings("unchecked")
117    @Override
118    public OrgUnitZone getParent() throws AmetysRepositoryException
119    {
120        return new OrgUnitZone(_page, _zoneDataTypeExtensionPoint, _zoneItemDataTypeExtensionPoint);
121    }
122
123    @Override
124    public String getParentPath() throws AmetysRepositoryException
125    {
126        return _page.getPath() + "/default";
127    }
128
129    @Override
130    public String getPath() throws AmetysRepositoryException
131    {
132        return _page.getPath() + "/default/default";
133    }
134
135    public ModelAwareDataHolder getZoneItemParametersHolder() throws AmetysRepositoryException
136    {
137        return null;
138    }
139
140    public ModelAwareDataHolder getContentViewParametersHolder(String contentViewName) throws AmetysRepositoryException
141    {
142        return null;
143    }
144
145    public ModelAwareDataHolder getServiceViewParametersHolder(String serviceViewName) throws AmetysRepositoryException
146    {
147        return null;
148    }
149}