001/* 002 * Copyright 2022 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.web.repository.page; 018 019import java.util.Map; 020 021import org.ametys.cms.data.holder.impl.DefaultModifiableModelAwareDataHolder; 022import org.ametys.cms.repository.Content; 023import org.ametys.plugins.repository.AmetysObject; 024import org.ametys.plugins.repository.AmetysRepositoryException; 025import org.ametys.plugins.repository.data.holder.ModelAwareDataHolder; 026import org.ametys.plugins.repository.data.holder.ModelLessDataHolder; 027import org.ametys.plugins.repository.data.holder.impl.DefaultModelLessDataHolder; 028import org.ametys.plugins.repository.data.repositorydata.RepositoryData; 029import org.ametys.plugins.repository.data.repositorydata.impl.MemoryRepositoryData; 030import org.ametys.web.data.type.ModelItemTypeExtensionPoint; 031import org.ametys.web.service.Service; 032 033/** 034 * A static zone item. 035 * Currently, the static zone item handle only service zone items 036 */ 037public class StaticZoneItem implements ZoneItem 038{ 039 /** The service */ 040 protected Service _service; 041 042 /** The service parameters */ 043 protected Map<String, Object> _parameters; 044 045 /** The zone type */ 046 protected ZoneType _type; 047 048 /** The zone item data type extension point */ 049 protected ModelItemTypeExtensionPoint _zoneItemDataTypeExtensionPoint; 050 051 /** The service parameters holder */ 052 protected ModelAwareDataHolder _serviceParametersHolder; 053 054 /** 055 * The constructor for a zone item containing a service 056 * @param service the service 057 * @param parameters the service parameters 058 * @param zoneItemDataTypeExtensionPoint the extension point with available data types for zone items 059 */ 060 public StaticZoneItem(Service service, Map<String, Object> parameters, ModelItemTypeExtensionPoint zoneItemDataTypeExtensionPoint) 061 { 062 this._service = service; 063 this._parameters = parameters; 064 this._type = ZoneType.SERVICE; 065 this._zoneItemDataTypeExtensionPoint = zoneItemDataTypeExtensionPoint; 066 067 DefaultModifiableModelAwareDataHolder serviceParameters = (DefaultModifiableModelAwareDataHolder) getServiceParameters(); 068 for (String key : parameters.keySet()) 069 { 070 serviceParameters.setValue(key, parameters.get(key)); 071 } 072 } 073 074 public ZoneType getType() throws AmetysRepositoryException 075 { 076 return this._type; 077 } 078 079 public <C extends Content> C getContent() throws AmetysRepositoryException 080 { 081 throw new UnsupportedOperationException("getContent method is not supported for static zone item"); 082 } 083 084 public String getServiceId() throws AmetysRepositoryException 085 { 086 return _service.getId(); 087 } 088 089 public String getId() throws AmetysRepositoryException 090 { 091 return "wrappedzoneitem://unused?serviceId=" + getServiceId(); 092 } 093 094 public String getName() throws AmetysRepositoryException 095 { 096 return "default"; 097 } 098 099 public Zone getZone() 100 { 101 throw new UnsupportedOperationException("getZone method is not supported for static zone item"); 102 } 103 104 public String getPath() throws AmetysRepositoryException 105 { 106 throw new UnsupportedOperationException("getPath method is not supported for static zone item"); 107 } 108 109 public <A extends AmetysObject> A getParent() throws AmetysRepositoryException 110 { 111 throw new UnsupportedOperationException("getParent method is not supported for static zone item"); 112 } 113 114 public String getParentPath() throws AmetysRepositoryException 115 { 116 throw new UnsupportedOperationException("getParentPath method is not supported for static zone item"); 117 } 118 119 public ModelLessDataHolder getDataHolder() 120 { 121 RepositoryData repositoryData = new MemoryRepositoryData(Zone.ZONEITEM_DATA_NAME); 122 return new DefaultModelLessDataHolder(this._zoneItemDataTypeExtensionPoint, repositoryData); 123 } 124 125 public ModelAwareDataHolder getServiceParameters() throws AmetysRepositoryException 126 { 127 if (this._serviceParametersHolder == null) 128 { 129 MemoryRepositoryData memoryData = new MemoryRepositoryData(this._service.getId()); 130 this._serviceParametersHolder = new DefaultModifiableModelAwareDataHolder(memoryData, _service); 131 } 132 133 return this._serviceParametersHolder; 134 } 135 136 public ModelAwareDataHolder getZoneItemParametersHolder() throws AmetysRepositoryException 137 { 138 // Don't handle zone item view parameters for wrapped service 139 return null; 140 } 141 142 public ModelAwareDataHolder getContentViewParametersHolder(String contentViewName) throws AmetysRepositoryException 143 { 144 throw new UnsupportedOperationException("getContentViewParametersHolder method is not supported for static zone item"); 145 } 146 147 public ModelAwareDataHolder getServiceViewParametersHolder(String serviceViewName) throws AmetysRepositoryException 148 { 149 // Don't handle view parameters for wrapped service 150 return null; 151 } 152}