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.cms.search.systemprop; 017 018import java.util.Date; 019import java.util.Map; 020 021import org.ametys.cms.contenttype.MetadataType; 022import org.ametys.cms.repository.Content; 023import org.ametys.cms.search.SearchField; 024import org.ametys.cms.search.model.SystemProperty; 025import org.ametys.cms.search.query.LastValidationDateQuery; 026import org.ametys.cms.search.query.Query; 027import org.ametys.cms.search.query.Query.Operator; 028import org.ametys.cms.search.solr.field.LastValidationSearchField; 029import org.ametys.core.util.DateUtils; 030import org.ametys.core.util.date.AdaptableDate; 031 032/** 033 * {@link SystemProperty} which represents the last validation date of a content. 034 */ 035public class LastValidationSystemProperty extends AbstractSystemProperty 036{ 037 @Override 038 public MetadataType getType() 039 { 040 return MetadataType.DATETIME; 041 } 042 043 @Override 044 public boolean isMultiple() 045 { 046 return false; 047 } 048 049 @Override 050 public boolean isSortable() 051 { 052 return true; 053 } 054 055 @Override 056 public Query getQuery(Object value, Operator operator, String language, Map<String, Object> contextualParameters) 057 { 058 AdaptableDate dateValue = parseDate(value); 059 return new LastValidationDateQuery(operator, dateValue); 060 } 061 062 @Override 063 public SearchField getSearchField() 064 { 065 return new LastValidationSearchField(); 066 } 067 068 @Override 069 public String getWidget() 070 { 071 return "edition.date"; 072 } 073 074 @Override 075 public Object getValue(Content content) 076 { 077 return content.getLastValidationDate(); 078 } 079 080 @Override 081 public Object getJsonValue(Content content, boolean full) 082 { 083 return DateUtils.dateToString((Date) getValue(content)); 084 } 085}