More functionality added to links management UI

- Report now shows date/time when report was executed
 - Report now shows forms with broken links
 - Fixed items are now displayed
 - Current status stats are now correct

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5922 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2007-06-12 20:35:11 +00:00
parent 21b9367f7f
commit 9abfab20ab
12 changed files with 657 additions and 172 deletions

View File

@@ -25,12 +25,20 @@
package org.alfresco.web.bean.wcm;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.linkvalidation.LinkValidationReport;
import org.alfresco.model.WCMAppModel;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.web.bean.repository.Repository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -50,6 +58,7 @@ import org.apache.commons.logging.LogFactory;
public class LinkValidationState
{
private String store;
private Date initialCheckedCompletedAt;
private boolean checkBeenReRun = false;
private int noFilesCheckedStart = 0;
@@ -73,14 +82,11 @@ public class LinkValidationState
private List<String> brokenStaticFilesLast;
private List<String> brokenFormsLast;
private List<String> fixedStaticFiles;
private List<String> fixedFiles;
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 Map<String, List<String>> brokenFilesByForm;
private static Log logger = LogFactory.getLog(LinkValidationState.class);
@@ -90,6 +96,7 @@ public class LinkValidationState
public LinkValidationState(String store, LinkValidationReport initialReport)
{
this.store = store;
this.initialCheckedCompletedAt = new Date();
processReport(initialReport, false);
}
@@ -97,6 +104,22 @@ public class LinkValidationState
// ------------------------------------------------------------------------------
// Getters
/**
* @return The store this validation state represents
*/
public String getStore()
{
return this.store;
}
/**
* @return The date the initial check was completed
*/
public Date getInitialCheckCompletedAt()
{
return this.initialCheckedCompletedAt;
}
/**
* @return The number of files checked by the initial link check
*/
@@ -206,9 +229,9 @@ public class LinkValidationState
* @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)
public List<String> getBrokenFilesByForm(String form)
{
return this.brokenLinksByForm.get(form);
return this.brokenFilesByForm.get(form);
}
/**
@@ -221,38 +244,23 @@ public class LinkValidationState
}
/**
* @return The list of non-generated files that have been fixed since the
* @return The list of files that have been fixed since the
* initial link check
*/
public List<String> getFixedStaticFiles()
public List<String> getFixedFiles()
{
return this.fixedStaticFiles;
return this.fixedFiles;
}
/**
* @return The list of forms that have been fixed since the initial link check
* @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
@@ -279,6 +287,7 @@ public class LinkValidationState
processReport(newReport, true);
}
@Override
public String toString()
{
StringBuilder buffer = new StringBuilder(super.toString());
@@ -289,11 +298,11 @@ public class LinkValidationState
// ------------------------------------------------------------------------------
// Private Helpers
public void processReport(LinkValidationReport report, boolean updatedReport)
public void processReport(LinkValidationReport report, boolean rerunReport)
{
this.checkBeenReRun = updatedReport;
this.checkBeenReRun = rerunReport;
if (updatedReport == false)
if (rerunReport == false)
{
// setup initial counts
this.noBrokenFilesStart = report.getNumberBrokenFiles();
@@ -305,27 +314,13 @@ public class LinkValidationState
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));
}
// setup fixed lists
this.fixedFiles = new ArrayList<String>(this.noBrokenFilesStart);
this.fixedForms = new ArrayList<String>(this.noBrokenFilesStart);
// process the broken files and determine which ones are static files
// and which ones are generated
processFiles(report.getFilesWithBrokenLinks(), rerunReport, report);
}
else
{
@@ -347,27 +342,111 @@ public class LinkValidationState
this.noFixedLinks = 0;
}
// go through the list of files still broken and find which ones
// process the broken files and determine which ones are static files
// and which ones are generated
processFiles(report.getFilesWithBrokenLinks(), rerunReport, report);
// go through the list of files & forms 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)
if (this.brokenStaticFilesLast.contains(file) == false &&
this.fixedFiles.contains(file) == false)
{
this.fixedStaticFilesLast.add(file);
this.fixedStaticFiles.add(file);
this.fixedFiles.add(file);
}
}
// update the broken files info
this.brokenLinksByFile.clear();
for (String file : this.brokenStaticFilesLast)
for (String file : this.brokenFormsStart)
{
if (this.brokenFormsLast.contains(file) == false &&
this.fixedForms.contains(file) == false)
{
this.fixedForms.add(file);
}
}
}
}
protected void processFiles(List<String> files, boolean rerunReport, LinkValidationReport report)
{
AVMService avmService = Repository.getServiceRegistry(
FacesContext.getCurrentInstance()).getAVMService();
NodeService nodeService = Repository.getServiceRegistry(
FacesContext.getCurrentInstance()).getNodeService();
if (logger.isDebugEnabled())
{
if (rerunReport)
logger.debug("Processing files from updated report: " + report);
else
logger.debug("Processing files from initial report: " + report);
}
// reset the 'last' lists and the maps
this.brokenStaticFilesLast = new ArrayList<String>(this.noBrokenFilesLast);
this.brokenFormsLast = new ArrayList<String>(this.noBrokenFilesLast);
this.brokenFilesByForm = new HashMap<String, List<String>>(this.noBrokenFilesLast);
this.brokenLinksByFile = new HashMap<String, List<String>>(this.noBrokenFilesLast);
// iterate around the files and determine which ones are generated and static
for (String file : files)
{
if (avmService.hasAspect(-1, file, WCMAppModel.ASPECT_FORM_INSTANCE_DATA))
{
if (avmService.hasAspect(-1, file, WCMAppModel.ASPECT_RENDITION))
{
if (logger.isDebugEnabled())
logger.debug("Processing generated file: " + file);
// store the broken links in the file
this.brokenLinksByFile.put(file, report.getBrokenLinksForFile(file));
// find the XML that generated this file
NodeRef nodeRef = AVMNodeConverter.ToNodeRef(-1, file);
String xmlPath = (String)nodeService.getProperty(nodeRef,
WCMAppModel.PROP_PRIMARY_FORM_INSTANCE_DATA);
xmlPath = this.store + ":" + xmlPath;
if (logger.isDebugEnabled())
logger.debug("Found source XML for '" + file + "': " + xmlPath);
// store the XML as a broken form (if not already)
if (this.brokenFormsLast.contains(xmlPath) == false)
{
this.brokenFormsLast.add(xmlPath);
}
// store the list of files generated by the XML in the map
List<String> genFiles = this.brokenFilesByForm.get(xmlPath);
if (genFiles == null)
{
genFiles = new ArrayList<String>(1);
}
genFiles.add(file);
this.brokenFilesByForm.put(xmlPath, genFiles);
}
}
else
{
if (logger.isDebugEnabled())
logger.debug("Processing static file: " + file);
// the file does not have the form instance data aspect so it must
// have been added manually
this.brokenStaticFilesLast.add(file);
this.brokenLinksByFile.put(file, report.getBrokenLinksForFile(file));
}
}
// if this is the first run of the report setup the initial lists
if (rerunReport == false)
{
this.brokenStaticFilesStart = new ArrayList<String>(this.brokenStaticFilesLast.size());
this.brokenStaticFilesStart.addAll(this.brokenStaticFilesLast);
this.brokenFormsStart = new ArrayList<String>(this.brokenFormsLast.size());
this.brokenFormsStart.addAll(this.brokenFormsLast);
}
}
}