All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.databene.dbsanity.report.CheckAssessmentModule Maven / Gradle / Ivy

Go to download

DB Sanity is a tool for verifying a database's sanity and data integrity.

There is a newer version: 0.9.4
Show newest version
/*
 * (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.Set;

import org.databene.commons.OrderedSet;
import org.databene.commons.StringUtil;
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.dbsanity.model.SanityCheckVerdict;

/**
 * Checks the sanity checks for completeness and correctness.

* Created: 08.11.2010 12:26:39 * @since 1.0 * @author Volker Bergmann */ public class CheckAssessmentModule extends AbstractReportModule { Set checksWithoutTable; Set checksWithoutDefectType; Set checksWithError; public CheckAssessmentModule() { this.checksWithoutTable = new OrderedSet(); this.checksWithoutDefectType = new OrderedSet(); this.checksWithError = new OrderedSet(); } @Override public int getDashboardColSpan(ReportScope scope) { return (scope == ReportScope.ROOT ? 1 : 0); } @Override public void renderDashboardView(ReportScope scope, SanityCheckSuite suite, FilePrintStream out) { startModule(out); modHeader("Sanity Check Assessment", out); startModBody(out); out.println(" "); if (checksWithError.size() > 0) out.println(" "); if (checksWithoutTable.size() > 0) out.println(" "); if (checksWithoutDefectType.size() > 0) out.println(" "); if (checksWithoutTable.size() == 0 && checksWithoutDefectType.size() == 0 && checksWithError.size() == 0) out.println(" "); out.println("
" + checksWithError.size() + "Faulty checks
" + checksWithoutTable.size() + "Checks without table assignment
" + checksWithoutDefectType.size() + "Checks without defect type specification
All check definitions OK
"); endModBody(out); String href = "check_assessment.html"; modFooter(href, out); endModule(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()) { if (StringUtil.isEmpty(check.getTable())) checksWithoutTable.add(check); if (StringUtil.isEmpty(check.getDefectType())) checksWithoutDefectType.add(check); if (check.getVerdict() == SanityCheckVerdict.ERROR) checksWithError.add(check); } } private void createDetailsPage(SanityCheckSuite rootSuite) { String title = "Sanity Check Assessment"; FilePrintStream out = null; File file = new File(rootSuite.getReportFolder(), "check_assessment.html"); try { out = openNewFile(file, title); out.println(context.navBar(rootSuite.getReportFolder())); faultyCheckDiv(out, file); missingTableDiv(out, file); missingDefectTypeDiv(out); } catch (FileNotFoundException e) { throw new RuntimeException("Error writing quality assessment file: " + file, e); } finally { super.closeFile(out); } } private void faultyCheckDiv(FilePrintStream out, File file) { try { startModule(out); modHeader("Faulty Checks", out); startModBody(out); if (checksWithError.size() > 0) { out.println(" "); out.println( " " + "" + "" + ""); for (SanityCheck check : checksWithError) { out.println( " " + "" + ""); } out.println("
" + context.formatLong(checksWithError.size()) + "faulty checks
" + ReportUtil.docOrDefectFileLink(check, out.getFile()) + "
"); } else { out.println("None"); } endModBody(out); endModule(out); } catch (Exception e) { throw new RuntimeException(e); } } private void missingTableDiv(FilePrintStream out, File file) { try { startModule(out); modHeader("Missing table assignment", out); startModBody(out); if (checksWithoutTable.size() > 0) { out.println(" "); out.println(" "); for (SanityCheck check : checksWithoutTable) { out.println(" "); } out.println("
" + context.formatLong(checksWithoutTable.size()) + "Checks without table assignment
" + ReportUtil.docLink(check, out.getFile()) + "
"); } else { out.println("None"); } endModBody(out); endModule(out); } catch (Exception e) { throw new RuntimeException(e); } } private void missingDefectTypeDiv(FilePrintStream out) { startModule(out); modHeader("Missing defect type specification", out); startModBody(out); if (checksWithoutDefectType.size() > 0) { out.println(" "); out.println(" "); for (SanityCheck check : checksWithoutDefectType) out.println(" "); out.println("
" + context.formatLong(checksWithoutDefectType.size()) + "Checks without defect type specification
" + ReportUtil.docLink(check, out.getFile()) + "
"); } else { out.println("None"); } endModBody(out); endModule(out); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy