001/*
002 *  Copyright 2011 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.lock;
017
018import java.time.LocalDateTime;
019import java.util.HashMap;
020import java.util.Map;
021
022import org.apache.cocoon.environment.ObjectModelHelper;
023import org.apache.cocoon.environment.Request;
024
025import org.ametys.plugins.repository.lock.LockableAmetysObject;
026import org.ametys.web.repository.content.WebContent;
027
028/**
029 * List contents that can be unlocked, on the given site.
030 */
031public class UnlockGenerator extends org.ametys.cms.lock.UnlockGenerator
032{
033    
034    @Override
035    protected Map<LockableAmetysObject, LocalDateTime> _getLockedObjects()
036    {
037        Map<LockableAmetysObject, LocalDateTime> allLockedObjects = super._getLockedObjects();
038        
039        Map<LockableAmetysObject, LocalDateTime> lockedObjects = new HashMap<>(allLockedObjects.size());
040        
041        Request request = ObjectModelHelper.getRequest(objectModel);
042        String siteName = request.getParameter("siteName");
043        
044        // Return only objects that belong to the given site.
045        for (LockableAmetysObject object : allLockedObjects.keySet())
046        {
047            if (object instanceof WebContent)
048            {
049                WebContent webContent = (WebContent) object;
050                if (webContent.getSiteName().equals(siteName))
051                {
052                    lockedObjects.put(object, allLockedObjects.get(object));
053                }
054            }
055            else
056            {
057                lockedObjects.put(object, allLockedObjects.get(object));
058            }
059        }
060        
061        return lockedObjects;
062    }
063    
064}