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.metadata.CompositeMetadata;
022import org.ametys.web.repository.page.Zone;
023import org.ametys.web.repository.page.ZoneItem;
024
025/**
026 * {@link ZoneItem} holding a content.
027 */
028public class OrgUnitZoneItem implements ZoneItem
029{
030    private OrgUnitPage _page;
031    
032    /**
033     * Constructor.
034     * @param page the parent {@link OrgUnitPage}.
035     */
036    public OrgUnitZoneItem(OrgUnitPage page)
037    {
038        _page = page;
039    }
040    
041    @SuppressWarnings("unchecked")
042    @Override
043    public Content getContent() throws AmetysRepositoryException
044    {
045        Content content = _page.getSyncContent();
046        return content;
047    }
048
049    @Override
050    public String getMetadataSetName() throws AmetysRepositoryException
051    {
052        return "main";
053    }
054    
055    @Override
056    public String getServiceId() throws AmetysRepositoryException
057    {
058        throw new UnsupportedOperationException("getServiceId not supported on virtual organisation chart pages");
059    }
060
061    @Override
062    public CompositeMetadata getServiceParameters() throws AmetysRepositoryException
063    {
064        throw new UnsupportedOperationException("getServiceParameters not supported on virtual organisation chart pages");
065    }
066
067    @Override
068    public ZoneType getType() throws AmetysRepositoryException
069    {
070        return ZoneType.CONTENT;
071    }
072
073    @Override
074    public Zone getZone()
075    {
076        return new OrgUnitZone(_page);
077    }
078
079    @Override
080    public CompositeMetadata getMetadataHolder()
081    {
082        return new StaticCompositeMetadata();
083    }
084
085    /**
086     * Compute the zone item id of a content for a page 
087     * @param pageId The page id
088     * @return The zoneitem id
089     */
090    public static String getZoneItemId(String pageId)
091    {
092        return "udorgunitzoneitem://unused?pageId=" + pageId;
093    }
094    
095    @Override
096    public String getId() throws AmetysRepositoryException
097    {
098        return getZoneItemId(_page.getId());
099    }
100
101    @Override
102    public String getName() throws AmetysRepositoryException
103    {
104        return "default";
105    }
106
107    @SuppressWarnings("unchecked")
108    @Override
109    public OrgUnitZone getParent() throws AmetysRepositoryException
110    {
111        return new OrgUnitZone(_page);
112    }
113
114    @Override
115    public String getParentPath() throws AmetysRepositoryException
116    {
117        return _page.getPath() + "/default";
118    }
119
120    @Override
121    public String getPath() throws AmetysRepositoryException
122    {
123        return _page.getPath() + "/default/default";
124    }
125}