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.newsletter;
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.cms.ObservationConstants;
025import org.ametys.web.cache.pageelement.AbstractSimplePageElementCachePolicy;
026import org.ametys.web.cache.pageelement.PageElementCachePolicy;
027
028/**
029 * {@link PageElementCachePolicy} for the newsletter archive service.
030 */
031public class NewsletterArchiveServiceCachePolicy extends AbstractSimplePageElementCachePolicy
032{
033    
034    private static final Set<String> _TYPES = new HashSet<>();
035    static
036    {
037        _TYPES.add("SERVICE:org.ametys.newsletter.service.ListService");
038    }
039    
040    @Override
041    public Set<String> getPageElementTypes()
042    {
043        return _TYPES;
044    }
045
046    @Override
047    protected List<String> _getRemovingCacheEventIds(String workspace)
048    {
049        // The newsletter archive service only displays newsletter content titles: only react on content events.
050        if ("default".equals(workspace))
051        {
052            return Arrays.asList(ObservationConstants.EVENT_CONTENT_ADDED,
053                                 ObservationConstants.EVENT_CONTENT_MODIFIED,
054                                 // The service displays only validated contents, even in the back-office.
055                                 ObservationConstants.EVENT_CONTENT_VALIDATED,
056                                 ObservationConstants.EVENT_CONTENT_DELETED,
057                                 ObservationConstants.EVENT_CONTENT_UNTAG_LIVE);
058        }
059        else if ("live".equals(workspace))
060        {
061            return Arrays.asList(ObservationConstants.EVENT_CONTENT_ADDED,
062                                 ObservationConstants.EVENT_CONTENT_VALIDATED,
063                                 ObservationConstants.EVENT_CONTENT_DELETED,
064                                 ObservationConstants.EVENT_CONTENT_UNTAG_LIVE);
065        }
066        
067        return Collections.emptyList();
068    }
069    
070}