001/*
002 *  Copyright 2012 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.calendar.events;
017
018import java.util.Arrays;
019import java.util.Collections;
020import java.util.HashSet;
021import java.util.List;
022import java.util.Set;
023
024import org.ametys.web.ObservationConstants;
025import org.ametys.web.cache.pageelement.AbstractSimplePageElementCachePolicy;
026import org.ametys.web.cache.pageelement.PageElementCachePolicy;
027
028/**
029 * {@link PageElementCachePolicy} for the calendar services.
030 */
031public class CalendarServiceCachePolicy extends AbstractSimplePageElementCachePolicy
032{
033    
034    private static final Set<String> _TYPES = new HashSet<>();
035    static
036    {
037        _TYPES.add("SERVICE:org.ametys.plugins.calendar.Agenda");
038        _TYPES.add("SERVICE:org.ametys.plugins.calendar.Calendar");
039    }
040    
041    @Override
042    public Set<String> getPageElementTypes()
043    {
044        return _TYPES;
045    }
046
047    @Override
048    protected List<String> _getRemovingCacheEventIds(String workspace)
049    {
050        if ("default".equals(workspace))
051        {
052            return Arrays.asList(org.ametys.cms.ObservationConstants.EVENT_CONTENT_ADDED,
053                                 org.ametys.cms.ObservationConstants.EVENT_CONTENT_MODIFIED,
054                                 org.ametys.cms.ObservationConstants.EVENT_CONTENT_DELETED,
055                                 org.ametys.cms.ObservationConstants.EVENT_CONTENT_TAGGED,
056                                 org.ametys.cms.ObservationConstants.EVENT_TAG_ADDED,
057                                 org.ametys.cms.ObservationConstants.EVENT_TAG_DELETED,
058                                 ObservationConstants.EVENT_PAGE_DELETED,
059                                 ObservationConstants.EVENT_ZONEITEM_DELETED);
060        }
061        else if ("live".equals(workspace))
062        {
063            return Arrays.asList(org.ametys.cms.ObservationConstants.EVENT_CONTENT_ADDED,
064                                 org.ametys.cms.ObservationConstants.EVENT_CONTENT_VALIDATED,
065                                 org.ametys.cms.ObservationConstants.EVENT_CONTENT_DELETED,
066                                 org.ametys.cms.ObservationConstants.EVENT_CONTENT_TAGGED,
067                                 ObservationConstants.EVENT_CONTENT_UNPUBLISHED,
068                                 org.ametys.cms.ObservationConstants.EVENT_TAG_ADDED,
069                                 org.ametys.cms.ObservationConstants.EVENT_TAG_DELETED,
070                                 ObservationConstants.EVENT_PAGE_CHANGED,
071                                 ObservationConstants.EVENT_PAGE_MOVED,   // if the page is moved out of a validated parent
072                                 ObservationConstants.EVENT_PAGE_DELETED,
073                                 ObservationConstants.EVENT_ZONEITEM_DELETED);
074        }
075        
076        return Collections.emptyList();
077    }
078    
079}