//# 0 errors, 80 messages
//#
/*
    //#Maintenance.java:1:1: class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
 * Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  The ASF licenses this file to You
 * under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.  For additional information regarding
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */

package org.apache.roller.weblogger.ui.struts2.editor;

import java.util.Date;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.business.search.IndexManager;
import org.apache.roller.weblogger.business.WebloggerFactory;
import org.apache.roller.weblogger.business.UserManager;
import org.apache.roller.weblogger.pojos.WeblogPermission;
import org.apache.roller.weblogger.pojos.Weblog;
import org.apache.roller.weblogger.ui.struts2.util.UIAction;
import org.apache.roller.weblogger.util.cache.CacheManager;


/**
 * Allows user to perform maintenence operations such as flushing
 * the page cache or re-indexing the search index.
 */
public class Maintenance extends UIAction {
    
    private static Log log = LogFactory.getLog(Maintenance.class);
    //#Maintenance.java:39: method: org.apache.roller.weblogger.ui.struts2.editor.Maintenance.org.apache.roller.weblogger.ui.struts2.editor.Maintenance__static_init
    //#Maintenance.java:39: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: org.apache.roller.weblogger.ui.struts2.editor.Maintenance__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#output(org.apache.roller.weblogger.ui.struts2.editor.Maintenance__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/struts2/editor/Maintenance]
    //#output(org.apache.roller.weblogger.ui.struts2.editor.Maintenance__static_init): __Dispatch_Table.execute()Ljava/lang/String;
    //#output(org.apache.roller.weblogger.ui.struts2.editor.Maintenance__static_init): __Dispatch_Table.flushCache()Ljava/lang/String;
    //#output(org.apache.roller.weblogger.ui.struts2.editor.Maintenance__static_init): __Dispatch_Table.index()Ljava/lang/String;
    //#output(org.apache.roller.weblogger.ui.struts2.editor.Maintenance__static_init): __Dispatch_Table.requiredWeblogPermissions()S
    //#output(org.apache.roller.weblogger.ui.struts2.editor.Maintenance__static_init): log
    //#post(org.apache.roller.weblogger.ui.struts2.editor.Maintenance__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/struts2/editor/Maintenance] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.ui.struts2.editor.Maintenance__static_init): __Dispatch_Table.execute()Ljava/lang/String; == &execute
    //#post(org.apache.roller.weblogger.ui.struts2.editor.Maintenance__static_init): __Dispatch_Table.flushCache()Ljava/lang/String; == &flushCache
    //#post(org.apache.roller.weblogger.ui.struts2.editor.Maintenance__static_init): __Dispatch_Table.index()Ljava/lang/String; == &index
    //#post(org.apache.roller.weblogger.ui.struts2.editor.Maintenance__static_init): __Dispatch_Table.requiredWeblogPermissions()S == &requiredWeblogPermissions
    //#post(org.apache.roller.weblogger.ui.struts2.editor.Maintenance__static_init): init'ed(log)
    //#Maintenance.java:39: end of method: org.apache.roller.weblogger.ui.struts2.editor.Maintenance.org.apache.roller.weblogger.ui.struts2.editor.Maintenance__static_init
    
    
    public Maintenance() {
    //#Maintenance.java:42: method: void org.apache.roller.weblogger.ui.struts2.editor.Maintenance.org.apache.roller.weblogger.ui.struts2.editor.Maintenance()
    //#Maintenance.java:42: Warning: method not available
    //#    -- call on void org.apache.roller.weblogger.ui.struts2.util.UIAction()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: void org.apache.roller.weblogger.ui.struts2.editor.Maintenance()
    //#    unanalyzed callee: void org.apache.roller.weblogger.ui.struts2.util.UIAction()
    //#input(void org.apache.roller.weblogger.ui.struts2.editor.Maintenance()): this
    //#output(void org.apache.roller.weblogger.ui.struts2.editor.Maintenance()): this.actionName
    //#output(void org.apache.roller.weblogger.ui.struts2.editor.Maintenance()): this.desiredMenu
    //#output(void org.apache.roller.weblogger.ui.struts2.editor.Maintenance()): this.pageTitle
    //#post(void org.apache.roller.weblogger.ui.struts2.editor.Maintenance()): this.actionName == &"maintenance"
    //#post(void org.apache.roller.weblogger.ui.struts2.editor.Maintenance()): this.desiredMenu == &"editor"
    //#post(void org.apache.roller.weblogger.ui.struts2.editor.Maintenance()): this.pageTitle == &"maintenance.title"
        this.actionName = "maintenance";
        this.desiredMenu = "editor";
        this.pageTitle = "maintenance.title";
    }
    //#Maintenance.java:46: end of method: void org.apache.roller.weblogger.ui.struts2.editor.Maintenance.org.apache.roller.weblogger.ui.struts2.editor.Maintenance()
    
    
    // admin perms required
    public short requiredWeblogPermissions() {
        return WeblogPermission.ADMIN;
    //#Maintenance.java:51: method: short org.apache.roller.weblogger.ui.struts2.editor.Maintenance.requiredWeblogPermissions()
    //#input(short requiredWeblogPermissions()): org.apache.roller.weblogger.pojos.WeblogPermission.ADMIN
    //#output(short requiredWeblogPermissions()): return_value
    //#presumption(short requiredWeblogPermissions()): init'ed(org.apache.roller.weblogger.pojos.WeblogPermission.ADMIN)
    //#post(short requiredWeblogPermissions()): return_value == org.apache.roller.weblogger.pojos.WeblogPermission.ADMIN
    //#post(short requiredWeblogPermissions()): (soft) init'ed(return_value)
    //#Maintenance.java:51: end of method: short org.apache.roller.weblogger.ui.struts2.editor.Maintenance.requiredWeblogPermissions()
    }
    
    
    public String execute() {
        return SUCCESS;
    //#Maintenance.java:56: method: String org.apache.roller.weblogger.ui.struts2.editor.Maintenance.execute()
    //#output(String execute()): return_value
    //#post(String execute()): return_value == &"success"
    //#Maintenance.java:56: end of method: String org.apache.roller.weblogger.ui.struts2.editor.Maintenance.execute()
    }
    
    
    /**
     * Rebuild search index for weblog.
     */
    public String index() {
        
        try {
            IndexManager manager = WebloggerFactory.getWeblogger().getIndexManager();
    //#Maintenance.java:66: method: String org.apache.roller.weblogger.ui.struts2.editor.Maintenance.index()
    //#Maintenance.java:66: Warning: method not available
    //#    -- call on Weblogger org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String index()
    //#    unanalyzed callee: Weblogger org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger()
    //#Maintenance.java:66: Warning: method not available
    //#    -- call on IndexManager org.apache.roller.weblogger.business.Weblogger:getIndexManager()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String index()
    //#    unanalyzed callee: IndexManager org.apache.roller.weblogger.business.Weblogger:getIndexManager()
    //#input(String index()): log
    //#input(String index()): this
    //#output(String index()): return_value
    //#pre[1] (String index()): (soft) log != null
    //#presumption(String index()): org.apache.roller.weblogger.business.Weblogger:getIndexManager(...)@66 != null
    //#presumption(String index()): org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@66 != null
    //#post(String index()): return_value == &"success"
            manager.rebuildWebsiteIndex(getActionWeblog());
    //#Maintenance.java:67: Warning: method not available
    //#    -- call on Weblog org.apache.roller.weblogger.ui.struts2.editor.Maintenance:getActionWeblog()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String index()
    //#    unanalyzed callee: Weblog org.apache.roller.weblogger.ui.struts2.editor.Maintenance:getActionWeblog()
    //#Maintenance.java:67: Warning: method not available
    //#    -- call on void org.apache.roller.weblogger.business.search.IndexManager:rebuildWebsiteIndex(Weblog)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String index()
    //#    unanalyzed callee: void org.apache.roller.weblogger.business.search.IndexManager:rebuildWebsiteIndex(Weblog)
            
            addMessage("maintenance.message.indexed");
    //#Maintenance.java:69: Warning: method not available
    //#    -- call on void org.apache.roller.weblogger.ui.struts2.editor.Maintenance:addMessage(String)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String index()
    //#    unanalyzed callee: void org.apache.roller.weblogger.ui.struts2.editor.Maintenance:addMessage(String)
        } catch (Exception ex) {
            log.error("Error doing index rebuild", ex);
    //#Maintenance.java:71: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:error(Object, Throwable)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String index()
    //#    unanalyzed callee: void org.apache.commons.logging.Log:error(Object, Throwable)
            // TODO: i18n
            addError("Error rebuilding search index");
    //#Maintenance.java:73: Warning: method not available
    //#    -- call on void org.apache.roller.weblogger.ui.struts2.editor.Maintenance:addError(String)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String index()
    //#    unanalyzed callee: void org.apache.roller.weblogger.ui.struts2.editor.Maintenance:addError(String)
        }
        
        return SUCCESS;
    //#Maintenance.java:76: end of method: String org.apache.roller.weblogger.ui.struts2.editor.Maintenance.index()
    }

    
    /**
     * Flush page cache for weblog.
     */
    public String flushCache() {
        
        try {
            Weblog weblog = getActionWeblog();
    //#Maintenance.java:86: method: String org.apache.roller.weblogger.ui.struts2.editor.Maintenance.flushCache()
    //#Maintenance.java:86: Warning: method not available
    //#    -- call on Weblog org.apache.roller.weblogger.ui.struts2.editor.Maintenance:getActionWeblog()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String flushCache()
    //#    unanalyzed callee: Weblog org.apache.roller.weblogger.ui.struts2.editor.Maintenance:getActionWeblog()
    //#input(String flushCache()): "Error saving weblog - "._tainted
    //#input(String flushCache()): log
    //#input(String flushCache()): this
    //#output(String flushCache()): return_value
    //#pre[1] (String flushCache()): (soft) log != null
    //#presumption(String flushCache()): org.apache.roller.weblogger.business.Weblogger:getUserManager(...)@91 != null
    //#presumption(String flushCache()): org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@91 != null
    //#presumption(String flushCache()): org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@93 != null
    //#presumption(String flushCache()): org.apache.roller.weblogger.ui.struts2.editor.Maintenance:getActionWeblog(...)@101 != null
    //#presumption(String flushCache()): org.apache.roller.weblogger.ui.struts2.editor.Maintenance:getActionWeblog(...)@86 != null
    //#post(String flushCache()): return_value == &"success"
            
            // some caches are based on weblog last-modified, so update it
            weblog.setLastModified(new Date());
    //#Maintenance.java:89: Warning: method not available
    //#    -- call on void org.apache.roller.weblogger.pojos.Weblog:setLastModified(Date)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String flushCache()
    //#    unanalyzed callee: void org.apache.roller.weblogger.pojos.Weblog:setLastModified(Date)
            
            UserManager umgr = WebloggerFactory.getWeblogger().getUserManager();
    //#Maintenance.java:91: Warning: method not available
    //#    -- call on Weblogger org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String flushCache()
    //#    unanalyzed callee: Weblogger org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger()
    //#Maintenance.java:91: Warning: method not available
    //#    -- call on UserManager org.apache.roller.weblogger.business.Weblogger:getUserManager()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String flushCache()
    //#    unanalyzed callee: UserManager org.apache.roller.weblogger.business.Weblogger:getUserManager()
            umgr.saveWebsite(weblog);
    //#Maintenance.java:92: Warning: method not available
    //#    -- call on void org.apache.roller.weblogger.business.UserManager:saveWebsite(Weblog)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String flushCache()
    //#    unanalyzed callee: void org.apache.roller.weblogger.business.UserManager:saveWebsite(Weblog)
            WebloggerFactory.getWeblogger().flush();
    //#Maintenance.java:93: Warning: method not available
    //#    -- call on Weblogger org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String flushCache()
    //#    unanalyzed callee: Weblogger org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger()
    //#Maintenance.java:93: Warning: method not available
    //#    -- call on void org.apache.roller.weblogger.business.Weblogger:flush()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String flushCache()
    //#    unanalyzed callee: void org.apache.roller.weblogger.business.Weblogger:flush()
            
            // also notify cache manager
            CacheManager.invalidate(weblog);
    //#Maintenance.java:96: Warning: method not available
    //#    -- call on void org.apache.roller.weblogger.util.cache.CacheManager:invalidate(Weblog)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String flushCache()
    //#    unanalyzed callee: void org.apache.roller.weblogger.util.cache.CacheManager:invalidate(Weblog)

            addMessage("maintenance.message.flushed");
    //#Maintenance.java:98: Warning: method not available
    //#    -- call on void org.apache.roller.weblogger.ui.struts2.editor.Maintenance:addMessage(String)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String flushCache()
    //#    unanalyzed callee: void org.apache.roller.weblogger.ui.struts2.editor.Maintenance:addMessage(String)
            
        } catch (Exception ex) {
            log.error("Error saving weblog - "+getActionWeblog().getHandle(), ex);
    //#Maintenance.java:101: Warning: method not available
    //#    -- call on Weblog org.apache.roller.weblogger.ui.struts2.editor.Maintenance:getActionWeblog()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String flushCache()
    //#    unanalyzed callee: Weblog org.apache.roller.weblogger.ui.struts2.editor.Maintenance:getActionWeblog()
    //#Maintenance.java:101: Warning: method not available
    //#    -- call on String org.apache.roller.weblogger.pojos.Weblog:getHandle()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String flushCache()
    //#    unanalyzed callee: String org.apache.roller.weblogger.pojos.Weblog:getHandle()
    //#Maintenance.java:101: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:error(Object, Throwable)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String flushCache()
    //#    unanalyzed callee: void org.apache.commons.logging.Log:error(Object, Throwable)
            // TODO: i18n
            addError("Error flushing page cache");
    //#Maintenance.java:103: Warning: method not available
    //#    -- call on void org.apache.roller.weblogger.ui.struts2.editor.Maintenance:addError(String)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
    //#    method: String flushCache()
    //#    unanalyzed callee: void org.apache.roller.weblogger.ui.struts2.editor.Maintenance:addError(String)
        }

        return SUCCESS;
    //#Maintenance.java:106: end of method: String org.apache.roller.weblogger.ui.struts2.editor.Maintenance.flushCache()
    }
    
}
    //#Maintenance.java:: end of class: org.apache.roller.weblogger.ui.struts2.editor.Maintenance
