- Partial first cut of initial version of links management UI

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5917 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2007-06-11 20:54:23 +00:00
parent 1be49d2679
commit 3ad9668624
31 changed files with 2248 additions and 2 deletions

View File

@@ -41,6 +41,7 @@ import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import javax.transaction.UserTransaction;
import org.alfresco.linkvalidation.HrefValidationProgress;
import org.alfresco.model.WCMAppModel;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.repo.avm.actions.AVMRevertStoreAction;
@@ -147,6 +148,12 @@ public class AVMBrowseBean implements IContextListener
/** List of expired paths to submit */
private List<AVMNodeDescriptor> expiredNodes = Collections.<AVMNodeDescriptor>emptyList();
/** Object used by link validation service to monitor the status of a link check */
private HrefValidationProgress linkValidationMonitor;
/** Link validation state instance used by link validation dialogs */
private LinkValidationState linkValidationState;
/* component references */
private UIRichList foldersRichList;
private UIRichList filesRichList;
@@ -456,6 +463,38 @@ public class AVMBrowseBean implements IContextListener
{
this.deploymentMonitorIds = deploymentMonitorIds;
}
/**
* @return Returns the link validation monitor instance
*/
public HrefValidationProgress getLinkValidationMonitor()
{
return this.linkValidationMonitor;
}
/**
* @param monitor The link validation monitor instance to use
*/
public void setLinkValidationMonitor(HrefValidationProgress monitor)
{
this.linkValidationMonitor = monitor;
}
/**
* @return Returns the link validation state instance
*/
public LinkValidationState getLinkValidationState()
{
return this.linkValidationState;
}
/**
* @param monitor The link validation state instance to use
*/
public void setLinkValidationState(LinkValidationState state)
{
this.linkValidationState = state;
}
/**
* Returns the list of expired nodes. Used by the submit dialog to retrieve

View File

@@ -0,0 +1,74 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing
*/
package org.alfresco.web.bean.wcm;
import java.io.IOException;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean used by the AJAX callback from the RunLinkValidationDialog.
*
* @author gavinc
*/
public class LinkValidationProgressBean
{
private AVMBrowseBean avmBrowseBean;
private static Log logger = LogFactory.getLog(LinkValidationProgressBean.class);
public void getStatus() throws IOException
{
FacesContext context = FacesContext.getCurrentInstance();
ResponseWriter out = context.getResponseWriter();
if (logger.isDebugEnabled())
logger.debug("Retrieving progress status for link validation check...");
StringBuilder xml = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>");
xml.append("<link-validation-progress finished=\"");
xml.append(this.avmBrowseBean.getLinkValidationMonitor().isDone());
xml.append("\" file-count=\"");
xml.append(this.avmBrowseBean.getLinkValidationMonitor().getFileUpdateCount());
xml.append("\" link-count=\"");
xml.append(this.avmBrowseBean.getLinkValidationMonitor().getUrlUpdateCount());
xml.append("\"></link-validation-progress>");
// send the generated XML back to the callee
out.write(xml.toString());
if (logger.isDebugEnabled())
logger.debug("returning XML: " + xml.toString());
}
public void setAvmBrowseBean(AVMBrowseBean avmBrowseBean)
{
this.avmBrowseBean = avmBrowseBean;
}
}

View File

@@ -0,0 +1,136 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing
*/
package org.alfresco.web.bean.wcm;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.dialog.BaseDialogBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Implementation of the link validation report dialog.
*
* @author gavinc
*/
public class LinkValidationReportDialog extends BaseDialogBean
{
protected AVMBrowseBean avmBrowseBean;
protected AVMService avmService;
protected ActionService actionService;
private String store;
private static final Log logger = LogFactory.getLog(LinkValidationReportDialog.class);
// ------------------------------------------------------------------------------
// Dialog implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
// setup context for dialog
store = parameters.get("store");
if (logger.isDebugEnabled())
logger.debug("Showing link validation report for store '" + store + "'");
}
@SuppressWarnings("unchecked")
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
{
if (logger.isDebugEnabled())
logger.debug("Re-running link validation report for store '" + store + "'");
Map<String, String> params = new HashMap<String, String>(1);
params.put("store", this.store);
params.put("rerun", "true");
Application.getDialogManager().setupParameters(params);
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME +
AlfrescoNavigationHandler.OUTCOME_SEPARATOR +
"dialog:runLinkValidation";
}
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "rerun_report");
}
@Override
public boolean getFinishButtonDisabled()
{
return (this.avmBrowseBean.getLinkValidationState().getNumberBrokenLinks() == 0);
}
@Override
public String getCancelButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "close");
}
@Override
protected String getDefaultCancelOutcome()
{
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME +
AlfrescoNavigationHandler.OUTCOME_SEPARATOR +
"browseWebsite";
}
// ------------------------------------------------------------------------------
// Bean getters and setters
/**
* @param avmBrowseBean The AVM BrowseBean to set
*/
public void setAvmBrowseBean(AVMBrowseBean avmBrowseBean)
{
this.avmBrowseBean = avmBrowseBean;
}
public void setAvmService(AVMService avmService)
{
this.avmService = avmService;
}
/**
* @param actionService The actionService to set.
*/
public void setActionService(ActionService actionService)
{
this.actionService = actionService;
}
}

View File

@@ -0,0 +1,198 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing
*/
package org.alfresco.web.bean.wcm;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.linkvalidation.HrefValidationProgress;
import org.alfresco.linkvalidation.LinkValidationAction;
import org.alfresco.linkvalidation.LinkValidationReport;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.sandbox.SandboxConstants;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.dialog.BaseDialogBean;
import org.alfresco.web.ui.common.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Implementation of the run link validation dialog.
*
* @author gavinc
*/
public class LinkValidationRunDialog extends BaseDialogBean
{
protected AVMBrowseBean avmBrowseBean;
protected AVMService avmService;
protected ActionService actionService;
private String store;
private NodeRef storeRef;
private boolean rerun = false;
private static final Log logger = LogFactory.getLog(LinkValidationRunDialog.class);
// ------------------------------------------------------------------------------
// Dialog implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
// TODO: determine whether the virtualisation server is running, if it's not
// we need to throw an exception to reflect that
// setup context for dialog
store = parameters.get("store");
String storePath = this.store + ":/";
this.storeRef = AVMNodeConverter.ToNodeRef(-1, storePath);
this.rerun = false;
String rerunParam = parameters.get("rerun");
if (rerunParam != null && rerunParam.equals("true"))
{
this.rerun = true;
}
if (logger.isDebugEnabled())
{
if (this.rerun)
logger.debug("Starting re-run link validation check for store '" + store + "'");
else
logger.debug("Starting initial link validation check for store '" + store + "'");
}
// create context required to run and monitor the link check
HrefValidationProgress monitor = new HrefValidationProgress();
Map<String, Serializable> args = new HashMap<String, Serializable>(1, 1.0f);
args.put(LinkValidationAction.PARAM_MONITOR, monitor);
this.avmBrowseBean.setLinkValidationMonitor(monitor);
// create and execute the action in the background
Action action = this.actionService.createAction(LinkValidationAction.NAME, args);
this.actionService.executeAction(action, this.storeRef, false, true);
}
@SuppressWarnings("unchecked")
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
{
return outcome;
}
// ------------------------------------------------------------------------------
// Event handlers
public String linkCheckCompleted()
{
String outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
// the link validation report should be stored as a store property
// on the store the link check was run on, retrieve it and see if
// the link check was successful.
PropertyValue val = this.avmService.getStoreProperty(this.store,
SandboxConstants.PROP_LINK_VALIDATION_REPORT);
if (val != null)
{
LinkValidationReport report = (LinkValidationReport)val.getSerializableValue();
if (report != null)
{
if (report.wasSuccessful())
{
// setup the context required by the reporting components to display the results
if (this.rerun)
{
this.avmBrowseBean.getLinkValidationState().updateState(report);
}
else
{
LinkValidationState state = new LinkValidationState(this.store, report);
this.avmBrowseBean.setLinkValidationState(state);
}
Map<String, String> params = new HashMap<String, String>(1);
params.put("store", this.store);
Application.getDialogManager().setupParameters(params);
outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME +
AlfrescoNavigationHandler.OUTCOME_SEPARATOR +
"dialog:linkValidationReport";
}
else
{
FacesContext context = FacesContext.getCurrentInstance();
String errorMsg = Application.getMessage(context, "link_validation_unknown_error");
Throwable cause = report.getError();
if (cause != null)
{
errorMsg = Application.getMessage(context, "link_validation_error") + ": " +
cause.getMessage();
}
Utils.addErrorMessage(errorMsg);
}
}
}
return outcome;
}
// ------------------------------------------------------------------------------
// Bean getters and setters
/**
* @param avmBrowseBean The AVM BrowseBean to set
*/
public void setAvmBrowseBean(AVMBrowseBean avmBrowseBean)
{
this.avmBrowseBean = avmBrowseBean;
}
public void setAvmService(AVMService avmService)
{
this.avmService = avmService;
}
/**
* @param actionService The actionService to set.
*/
public void setActionService(ActionService actionService)
{
this.actionService = actionService;
}
}

View File

@@ -0,0 +1,379 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing
*/
package org.alfresco.web.bean.wcm;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.linkvalidation.LinkValidationReport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Object used to retrieve and store the state of a link validaton process.
* The object is given an initial link validation report object (the result
* of a LinkValidationService service call) which is used by components
* to display the result of the links check.
* <p>
* Further reports can then subsequently be given to this object at which
* point a difference is calculated i.e. which links (if any) have been
* fixed. This allows components to display the progress of link fixing.
* </p>
*
* @author gavinc
*/
public class LinkValidationState
{
private String store;
private boolean checkBeenReRun = false;
private int noFilesCheckedStart = 0;
private int noFilesCheckedLast = 0;
private int noLinksCheckedStart = 0;
private int noLinksCheckedLast = 0;
private int noBrokenFilesStart = 0;
private int noBrokenFilesLast = 0;
private int noBrokenLinksStart = 0;
private int noBrokenLinksLast = 0;
private int noFixedFiles = 0;
private int noFixedLinks = 0;
private List<String> brokenStaticFilesStart;
private List<String> brokenFormsStart;
private List<String> brokenStaticFilesLast;
private List<String> brokenFormsLast;
private List<String> fixedStaticFiles;
private List<String> fixedForms;
private List<String> fixedStaticFilesLast;
private List<String> fixedFormsLast;
private Map<String, List<String>> brokenLinksByFile;
private Map<String, List<String>> brokenLinksByForm;
private static Log logger = LogFactory.getLog(LinkValidationState.class);
/**
* Default constructor
*/
public LinkValidationState(String store, LinkValidationReport initialReport)
{
this.store = store;
processReport(initialReport, false);
}
// ------------------------------------------------------------------------------
// Getters
/**
* @return The number of files checked by the initial link check
*/
public int getInitialNumberFilesChecked()
{
return this.noFilesCheckedStart;
}
/**
* @return The number of links checked by the initial link check
*/
public int getInitialNumberLinksChecked()
{
return this.noLinksCheckedStart;
}
/**
* @return The number of broken files found by the initial link check
*/
public int getInitialNumberBrokenFiles()
{
return this.noBrokenFilesStart;
}
/**
* @return The number of broken links found by the initial link check
*/
public int getInitialNumberBrokenLinks()
{
return this.noBrokenLinksStart;
}
/**
* @return The number of files checked by the latest link check
*/
public int getNumberFilesChecked()
{
return this.noFilesCheckedLast;
}
/**
* @return The number of links checked by the latest link check
*/
public int getNumberLinksChecked()
{
return this.noLinksCheckedLast;
}
/**
* @return The number of broken files found by the latest link check
*/
public int getNumberBrokenFiles()
{
return this.noBrokenFilesLast;
}
/**
* @return The number of broken links found by the latest link check
*/
public int getNumberBrokenLinks()
{
return this.noBrokenLinksLast;
}
/**
* @return The number of files fixed since the initial link check
*/
public int getNumberFixedFiles()
{
return this.noFixedFiles;
}
/**
* @return The number of links fixed since the initial link check
*/
public int getNumberFixedLinks()
{
return this.noFixedLinks;
}
/**
* @return A list of paths to non-generated files that contain broken links
*/
public List<String> getStaticFilesWithBrokenLinks()
{
return this.brokenStaticFilesLast;
}
/**
* @return A list of forms that have generated files containing broken links
*/
public List<String> getFormsWithBrokenLinks()
{
return this.brokenFormsLast;
}
/**
* @return A list of all files found (including those generated by forms) that
* contain broken links
*/
public List<String> getAllFilesWithBrokenLinks()
{
throw new UnsupportedOperationException();
}
/**
* @param form The name of a form to find broken files for
* @return The list of broken files generated by the given form
*/
public List<String> getFilesBrokenByForm(String form)
{
return this.brokenLinksByForm.get(form);
}
/**
* @param file The path to a file with broken links
* @return The list of broken links within the given file
*/
public List<String> getBrokenLinksForFile(String file)
{
return this.brokenLinksByFile.get(file);
}
/**
* @return The list of non-generated files that have been fixed since the
* initial link check
*/
public List<String> getFixedStaticFiles()
{
return this.fixedStaticFiles;
}
/**
* @return The list of forms that have been fixed since the initial link check
*/
public List<String> getFixedForms()
{
return this.fixedForms;
}
/**
* @return The list of non-generated files fixed in the last run of the link check
*/
public List<String> getStaticFilesFixedInLastRun()
{
return this.fixedStaticFilesLast;
}
/**
* @return The list of forms fixed in the last run of the link check
*/
public List<String> getFormsFixedInLastRun()
{
return this.fixedFormsLast;
}
// ------------------------------------------------------------------------------
// Implementation
/**
* Determines whether the link validation check has been re-run since
* the intial check
*
* @return true if the link check has been re-run, false otherwise
*/
public boolean hasCheckBeenReRun()
{
return this.checkBeenReRun;
}
/**
* Updates the link validation state with the result from a re-run of
* the link check
*
* @param newReport The report to compare the intial report with
*/
public void updateState(LinkValidationReport newReport)
{
// process the new report
processReport(newReport, true);
}
public String toString()
{
StringBuilder buffer = new StringBuilder(super.toString());
buffer.append(" (store=").append(this.store).append(")");
return buffer.toString();
}
// ------------------------------------------------------------------------------
// Private Helpers
public void processReport(LinkValidationReport report, boolean updatedReport)
{
this.checkBeenReRun = updatedReport;
if (updatedReport == false)
{
// setup initial counts
this.noBrokenFilesStart = report.getNumberBrokenFiles();
this.noBrokenLinksStart = report.getNumberBrokenLinks();
this.noFilesCheckedStart = report.getNumberFilesChecked();
this.noLinksCheckedStart = report.getNumberLinksChecked();
this.noBrokenFilesLast = report.getNumberBrokenFiles();
this.noBrokenLinksLast = report.getNumberBrokenLinks();
this.noFilesCheckedLast = report.getNumberFilesChecked();
this.noLinksCheckedLast = report.getNumberLinksChecked();
// setup initial lists
this.brokenStaticFilesStart = report.getFilesWithBrokenLinks();
this.brokenFormsStart = Collections.emptyList();
this.brokenStaticFilesLast = report.getFilesWithBrokenLinks();
this.brokenFormsLast = Collections.emptyList();
this.fixedStaticFiles = Collections.emptyList();
this.fixedForms = Collections.emptyList();
this.fixedFormsLast = Collections.emptyList();
this.fixedStaticFiles = Collections.emptyList();
this.fixedStaticFilesLast = Collections.emptyList();
// setup initial maps
this.brokenLinksByFile = new HashMap<String, List<String>>();
this.brokenLinksByForm = Collections.emptyMap();
// populate initial maps
for (String file : this.brokenStaticFilesLast)
{
this.brokenLinksByFile.put(file, report.getBrokenLinksForFile(file));
}
}
else
{
// update the relevant counts
this.noBrokenFilesLast = report.getNumberBrokenFiles();
this.noBrokenLinksLast = report.getNumberBrokenLinks();
this.noFilesCheckedLast = report.getNumberFilesChecked();
this.noLinksCheckedLast = report.getNumberLinksChecked();
this.noFixedFiles = this.noBrokenFilesStart - this.noBrokenFilesLast;
this.noFixedLinks = this.noBrokenLinksStart - this.noBrokenLinksLast;
if (this.noFixedFiles < 0)
{
this.noFixedFiles = 0;
}
if (this.noFixedLinks < 0)
{
this.noFixedLinks = 0;
}
// go through the list of files still broken and find which ones
// were fixed in the last re-run of the report
this.brokenStaticFilesLast = report.getFilesWithBrokenLinks();
this.fixedStaticFiles = new ArrayList<String>();
this.fixedStaticFilesLast = new ArrayList<String>();
for (String file : this.brokenStaticFilesStart)
{
if (this.brokenStaticFilesLast.contains(file) == false)
{
this.fixedStaticFilesLast.add(file);
this.fixedStaticFiles.add(file);
}
}
// update the broken files info
this.brokenLinksByFile.clear();
for (String file : this.brokenStaticFilesLast)
{
this.brokenLinksByFile.put(file, report.getBrokenLinksForFile(file));
}
}
}
}