Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* (c) Copyright 2010 by Volker Bergmann. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, is permitted under the terms of the
* GNU General Public License (GPL).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* WITHOUT A WARRANTY OF ANY KIND. ALL EXPRESS OR IMPLIED CONDITIONS,
* REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
* HEREBY EXCLUDED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package org.databene.dbsanity.report;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
import org.databene.commons.file.FilePrintStream;
import org.databene.dbsanity.model.SanityCheck;
import org.databene.dbsanity.model.SanityCheckFile;
import org.databene.dbsanity.model.SanityCheckFolder;
import org.databene.dbsanity.model.SanityCheckSuite;
import org.databene.html.HTMLUtil;
import org.databene.jdbacl.model.DBTable;
import org.databene.jdbacl.model.Database;
/**
* Checks for tables which have no check assigned.
* Created: 08.12.2010 23:57:19
* @since 0.4
* @author Volker Bergmann
*/
public class UncheckedTablesModule extends AbstractReportModule {
List uncheckedTables;
public UncheckedTablesModule(Database database, String excludedTables) {
List tables = database.getTables();
this.uncheckedTables = new ArrayList(tables.size());
Pattern pattern = (excludedTables != null ? Pattern.compile(excludedTables) : null);
for (DBTable table : tables) {
String tableName = table.getName().toUpperCase();
if (pattern == null || !pattern.matcher(tableName).matches())
uncheckedTables.add(tableName);
}
Collections.sort(this.uncheckedTables);
}
@Override
public int getDashboardColSpan(ReportScope scope) {
return (scope == ReportScope.ROOT ? 1 : 0);
}
@Override
public void renderDashboardView(ReportScope scope, SanityCheckSuite suite,
FilePrintStream out) {
div(5, 2, out);
}
@Override
public void summary(SanityCheckSuite rootSuite) {
checkSuite(rootSuite);
createDetailsPage(rootSuite);
}
private void checkSuite(SanityCheckSuite suite) {
if (suite instanceof SanityCheckFolder) {
checkFolder((SanityCheckFolder) suite);
} else
checkFile((SanityCheckFile) suite);
}
private void checkFolder(SanityCheckFolder folder) {
for (SanityCheckSuite childSuite : folder.getChildSuites().values())
checkSuite(childSuite);
}
private void checkFile(SanityCheckFile file) {
for (SanityCheck check : file.getChecks().values()) {
String table = check.getTable();
if (table != null) {
table = table.toUpperCase();
if (uncheckedTables.contains(table))
uncheckedTables.remove(table);
}
}
}
private void createDetailsPage(SanityCheckSuite rootSuite) {
if (uncheckedTables.size() == 0)
return;
String title = "Unchecked tables";
FilePrintStream out = null;
File file = new File(rootSuite.getReportFolder(), "unchecked_tables.html");
try {
out = openNewFile(file, title);
out.println(context.navBar(rootSuite.getReportFolder()));
div(-1, 4, out);
} catch (FileNotFoundException e) {
throw new RuntimeException("Error writing unchecked tables file: " + file, e);
} finally {
super.closeFile(out);
}
}
private void div(int countLimit, int columnCount, FilePrintStream out) {
// order defect type counts in descending order
startModule(out);
modHeader(context.formatLong(uncheckedTables.size(), "No") + " unchecked tables", out);
startModBody(out);
if (uncheckedTables.size() > 0) {
// render HTML
out.println("
");
out.println("
");
out.println("
Tables
");
out.println("
");
for (int i = 0; (i < countLimit || countLimit < 0) && i < uncheckedTables.size(); i += columnCount) {
out.println("
");
for (int j = i; j < i + columnCount; j++) {
if ((j < countLimit || countLimit < 0) && j < uncheckedTables.size())
out.println("