001/* 002 * Copyright 2015 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.web.search.systemprop; 017 018import java.util.HashMap; 019import java.util.LinkedHashMap; 020import java.util.Map; 021 022import org.ametys.cms.contenttype.MetadataType; 023import org.ametys.cms.repository.Content; 024import org.ametys.cms.search.SearchField; 025import org.ametys.cms.search.model.SystemProperty; 026import org.ametys.cms.search.query.Query; 027import org.ametys.cms.search.query.Query.Operator; 028import org.ametys.cms.search.systemprop.AbstractSystemProperty; 029import org.ametys.web.repository.content.SharedContent; 030import org.ametys.web.repository.content.WebContent; 031import org.ametys.web.repository.site.Site; 032import org.ametys.web.search.query.SharedQuery; 033import org.ametys.web.search.solr.field.SharedSeachField; 034 035/** 036 * {@link SystemProperty} which represents the shared status of a Content. 037 */ 038public class SharedSystemProperty extends AbstractSystemProperty 039{ 040 041 @Override 042 public MetadataType getType() 043 { 044 return MetadataType.BOOLEAN; 045 } 046 047 @Override 048 public boolean isMultiple() 049 { 050 return false; 051 } 052 053 @Override 054 public boolean isSortable() 055 { 056 return true; 057 } 058 059 @Override 060 public String getConverter() 061 { 062 return "Ametys.plugins.web.search.SearchTool.convertSharedContent"; 063 } 064 065 @Override 066 public String getRenderer() 067 { 068 return "Ametys.plugins.web.search.SearchTool.renderSharedContent"; 069 } 070 071 @Override 072 public Integer getColumnWidth() 073 { 074 return 60; 075 } 076 077 @Override 078 public Query getQuery(Object value, Operator operator, String language, Map<String, Object> contextualParameters) 079 { 080 return new SharedQuery(parseBoolean(value)); 081 } 082 083 @Override 084 public SearchField getSearchField() 085 { 086 return new SharedSeachField(); 087 } 088 089 @Override 090 public Object getValue(Content content) 091 { 092 return content instanceof SharedContent; 093 } 094 095 @Override 096 public Object getFullValue(Content content) 097 { 098 if (content instanceof SharedContent) 099 { 100 Map<String, Object> value = new LinkedHashMap<>(); 101 102 value.put("isShared", true); 103 104 Content sharedContent = ((SharedContent) content).getInitialContent(); 105 if (sharedContent != null && sharedContent instanceof WebContent) 106 { 107 Map<String, String> orginalSite = new HashMap<>(); 108 orginalSite.put("name", ((WebContent) sharedContent).getSiteName()); 109 110 Site site = ((WebContent) sharedContent).getSite(); 111 if (site != null) 112 { 113 orginalSite.put("title", site.getTitle()); 114 } 115 116 value.put("originalSite", orginalSite); 117 } 118 119 return value; 120 } 121 else 122 { 123 return false; 124 } 125 } 126 127}