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 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.ModifiableModelAwareDataHolder; 024import org.ametys.plugins.repository.data.holder.impl.DefaultModelLessDataHolder; 025import org.ametys.plugins.repository.data.holder.impl.DefaultModifiableModelAwareDataHolder; 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.plugins.repository.data.type.RepositoryModelItemType; 030import org.ametys.runtime.plugin.component.AbstractThreadSafeComponentExtensionPoint; 031import org.ametys.web.repository.page.Zone; 032import org.ametys.web.repository.page.ZoneItem; 033import org.ametys.web.service.ServiceExtensionPoint; 034 035/** 036 * {@link ZoneItem} holding a Sitemap service 037 */ 038public class UGCTransitionalZoneItem implements ZoneItem 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 UGCTransitionalZoneItem(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 @SuppressWarnings("unchecked") 061 @Override 062 public Content getContent() throws AmetysRepositoryException 063 { 064 throw new UnsupportedOperationException("getContent not supported on virtual degree pages"); 065 } 066 067 @Override 068 public String getMetadataSetName() throws AmetysRepositoryException 069 { 070 return getViewName(); 071 } 072 073 public String getViewName() throws AmetysRepositoryException 074 { 075 return "main"; 076 } 077 078 @Override 079 public String getServiceId() throws AmetysRepositoryException 080 { 081 return "org.ametys.web.service.SitemapService"; 082 } 083 084 public ModelAwareDataHolder getServiceParameters() throws AmetysRepositoryException 085 { 086 ModifiableRepositoryData repositoryData = new MemoryRepositoryData(SERVICE_PARAMETERS_DATA_NAME); 087 ModifiableModelAwareDataHolder dataHolder = new DefaultModifiableModelAwareDataHolder(repositoryData, _serviceExtensionPoint.getExtension(getServiceId())); 088 _setServiceParameters(dataHolder); 089 return dataHolder; 090 } 091 092 private void _setServiceParameters(ModifiableModelAwareDataHolder dataHolder) 093 { 094 dataHolder.setValue("depth", 1L); 095 dataHolder.setValue("all", "false"); 096 dataHolder.setValue("includeInvisiblePage", true); 097 } 098 099 @Override 100 public ZoneType getType() throws AmetysRepositoryException 101 { 102 return ZoneType.SERVICE; 103 } 104 105 @Override 106 public Zone getZone() 107 { 108 return new UGCTransitionalZone(_page, _zoneDataTypeExtensionPoint, _serviceExtensionPoint, _zoneItemDataTypeExtensionPoint); 109 } 110 111 public ModelLessDataHolder getDataHolder() 112 { 113 RepositoryData repositoryData = new MemoryRepositoryData(Zone.ZONEITEM_DATA_NAME); 114 return new DefaultModelLessDataHolder(_zoneItemDataTypeExtensionPoint, repositoryData); 115 } 116 117 @Override 118 public String getId() throws AmetysRepositoryException 119 { 120 return "ugctransionalzoneitem://unused?pageId=" + _page.getId(); 121 } 122 123 @Override 124 public String getName() throws AmetysRepositoryException 125 { 126 return "default"; 127 } 128 129 @SuppressWarnings("unchecked") 130 @Override 131 public UGCTransitionalZone getParent() throws AmetysRepositoryException 132 { 133 return new UGCTransitionalZone(_page, _zoneDataTypeExtensionPoint, _serviceExtensionPoint, _zoneItemDataTypeExtensionPoint); 134 } 135 136 @Override 137 public String getParentPath() throws AmetysRepositoryException 138 { 139 return _page.getPath() + "/default"; 140 } 141 142 @Override 143 public String getPath() throws AmetysRepositoryException 144 { 145 return _page.getPath() + "/default/default"; 146 } 147}