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.tagcloud.cache.service;
017
018import java.util.Arrays;
019import java.util.Collections;
020import java.util.List;
021import java.util.Set;
022
023import org.ametys.web.ObservationConstants;
024import org.ametys.web.cache.pageelement.AbstractSimplePageElementCachePolicy;
025import org.ametys.web.cache.pageelement.PageElementCachePolicy;
026
027/**
028 * {@link PageElementCachePolicy} for the tag cloud on words service.
029 */
030public class WordCloudServiceCachePolicy extends AbstractSimplePageElementCachePolicy
031{
032    
033    /** The word cloud service ID. */
034    public static final String SERVICE_WORD_CLOUD_ID = "org.ametys.plugins.tagcloud.services.Words";
035    
036    @Override
037    public Set<String> getPageElementTypes()
038    {
039        return Collections.singleton("SERVICE:" + SERVICE_WORD_CLOUD_ID);
040    }
041    
042    @Override
043    protected List<String> _getRemovingCacheEventIds(String workspace)
044    {
045        if ("default".equals(workspace))
046        {
047            return Arrays.asList(org.ametys.cms.ObservationConstants.EVENT_CONTENT_ADDED,
048                                 org.ametys.cms.ObservationConstants.EVENT_CONTENT_MODIFIED,
049                                 org.ametys.cms.ObservationConstants.EVENT_CONTENT_DELETED,
050                                 ObservationConstants.EVENT_PAGE_CHANGED,
051                                 ObservationConstants.EVENT_PAGE_MOVED,
052                                 ObservationConstants.EVENT_PAGE_DELETED);
053        }
054        else if ("live".equals(workspace))
055        {
056            return Arrays.asList(org.ametys.cms.ObservationConstants.EVENT_CONTENT_ADDED,
057                                 org.ametys.cms.ObservationConstants.EVENT_CONTENT_VALIDATED,
058                                 org.ametys.cms.ObservationConstants.EVENT_CONTENT_DELETED,
059                                 org.ametys.cms.ObservationConstants.EVENT_CONTENT_UNTAG_LIVE,
060                                 ObservationConstants.EVENT_PAGE_CHANGED,
061                                 ObservationConstants.EVENT_PAGE_MOVED,
062                                 ObservationConstants.EVENT_PAGE_DELETED);
063        }
064        
065        return Collections.emptyList();
066    }
067    
068}