001/* 002 * Copyright 2020 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 */ 016package org.ametys.plugins.workspaces.wall; 017 018import org.apache.avalon.framework.service.ServiceException; 019import org.apache.avalon.framework.service.ServiceManager; 020 021import org.ametys.cms.data.type.indexing.IndexableElementType; 022import org.ametys.cms.model.CMSDataContext; 023import org.ametys.cms.model.properties.AbstractProperty; 024import org.ametys.cms.model.properties.Property; 025import org.ametys.cms.repository.Content; 026import org.ametys.cms.search.model.CriterionDefinitionAwareElementDefinition; 027import org.ametys.cms.search.model.CriterionDefinitionHelper; 028import org.ametys.cms.search.model.IndexationAwareElementDefinition; 029import org.ametys.cms.search.model.IndexationAwareElementDefinitionHelper; 030import org.ametys.runtime.model.type.ModelItemTypeConstants; 031 032/** 033 * {@link Property} for pinned wall content 034 * 035 */ 036public class PinProperty extends AbstractProperty<Boolean, Content> implements CriterionDefinitionAwareElementDefinition<Boolean>, IndexationAwareElementDefinition<Boolean, Content> 037{ 038 private CriterionDefinitionHelper _criterionDefinitionHelper; 039 private IndexationAwareElementDefinitionHelper _indexationAwareElementDefinitionHelper; 040 041 @Override 042 public void service(ServiceManager manager) throws ServiceException 043 { 044 super.service(manager); 045 _criterionDefinitionHelper = (CriterionDefinitionHelper) manager.lookup(CriterionDefinitionHelper.ROLE); 046 _indexationAwareElementDefinitionHelper = (IndexationAwareElementDefinitionHelper) manager.lookup(IndexationAwareElementDefinitionHelper.ROLE); 047 } 048 049 public Object getValue(Content content) 050 { 051 return content.getTags().contains(WallContentManager.WALL_CONTENT_PIN_TAG); 052 } 053 054 @Override 055 protected String getTypeId() 056 { 057 return ModelItemTypeConstants.BOOLEAN_TYPE_ID; 058 } 059 060 public IndexableElementType getDefaultCriterionType() 061 { 062 CMSDataContext context = CMSDataContext.newInstance() 063 .withModelItem(this); 064 065 String typeId = getType().getDefaultCriterionTypeId(context); 066 return _criterionDefinitionHelper.getCriterionDefinitionType(typeId); 067 } 068 069 public String getSolrSortFieldName() 070 { 071 return _indexationAwareElementDefinitionHelper.getDefaultSolrSortFieldName(this); 072 } 073}