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

gov.nasa.pds.citool.CIToolValidator Maven / Gradle / Ivy

Go to download

The Legacy Catalog Tool provides functionality for ingesting PDS3 catalog files into the PDS4 infrastructure including the Registry Service.

There is a newer version: 3.1.0
Show newest version
package gov.nasa.pds.citool;

import gov.nasa.pds.citool.report.NewStandardValuesReport;
import gov.nasa.pds.citool.report.ReferentialIntegrityReport;
import gov.nasa.pds.citool.report.Report;
import gov.nasa.pds.citool.ri.NewValidValueFinder;
import gov.nasa.pds.citool.ri.RIType;
import gov.nasa.pds.citool.ri.ReferentialIntegrityValidator;
import gov.nasa.pds.citool.target.Target;
import gov.nasa.pds.citool.util.Utility;
import gov.nasa.pds.citool.validate.ReferenceFinderValidator;
import gov.nasa.pds.citool.validate.ReferenceValidator;
import gov.nasa.pds.tools.LabelParserException;
import gov.nasa.pds.tools.constants.Constants.ProblemType;
import gov.nasa.pds.tools.dict.Dictionary;
import gov.nasa.pds.tools.dict.parser.DictionaryParser;
import gov.nasa.pds.tools.label.AttributeStatement;
import gov.nasa.pds.tools.label.IncludePointer;
import gov.nasa.pds.tools.label.Label;
import gov.nasa.pds.tools.label.ManualPathResolver;
import gov.nasa.pds.tools.label.ObjectStatement;
import gov.nasa.pds.tools.label.PointerStatement;
import gov.nasa.pds.tools.label.Statement;
import gov.nasa.pds.tools.label.parser.DefaultLabelParser;
import gov.nasa.pds.tools.label.validate.Validator;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

public class CIToolValidator {
    private ManualPathResolver resolver;
    private DefaultLabelParser parser;
    private Report report;
    private URL allrefs;

    public CIToolValidator(Report report) {
        this(report, new ArrayList());
    }

    public CIToolValidator(Report report, List includePaths) {
        this.report = report;
        this.allrefs = null;
        resolver = new ManualPathResolver();
        if (!includePaths.isEmpty()) {
            resolver.setIncludePaths(includePaths);
        }
        parser = new DefaultLabelParser(true, true, true, resolver);
    }

    public Dictionary parseDictionary(List dictionaries,
            boolean aliasing)
    throws URISyntaxException, CIToolValidatorException {
        Dictionary dictionary = null;
        boolean dictionaryPassed = true;
        URL url = null;
        Iterator i = dictionaries.iterator();
        try {
            url = Utility.toURL(i.next());
            dictionary = DictionaryParser.parse(url, aliasing, true);
            report.addConfiguration("   Dictionary version     "
                    + dictionary.getVersion());
            if (dictionary.getProblems().size() != 0) {
                dictionaryPassed = false;
                report.record(dictionary.getDictionaryURI(),
                        dictionary.getProblems());
            }
            while (i.hasNext()) {
                url = Utility.toURL(i.next());
                Dictionary mergedDictionary = DictionaryParser.parse(url,
                        aliasing, true);
                dictionary.merge(mergedDictionary);
                report.addConfiguration("   Dictionary version     "
                        + mergedDictionary.getVersion());
                if (mergedDictionary.getProblems().size() != 0) {
                    dictionaryPassed = false;
                    report.record(mergedDictionary.getDictionaryURI(),
                            mergedDictionary.getProblems());
                }
            }
        } catch (LabelParserException le) {
            List problems =
                new ArrayList();
            problems.add(le);
            report.record(url.toURI(), problems);
            dictionaryPassed = false;
        } catch (IOException io) {
            report.recordSkip(url.toURI(), io);
            dictionaryPassed = false;
        }
        if (!dictionaryPassed) {
            throw new CIToolValidatorException("Dictionary did not pass");
        }
        return dictionary;
    }

    public void setAllrefs(URL url) {
        this.allrefs = url;
    }

    public Report doReferentialIntegrity(List




© 2015 - 2024 Weber Informatics LLC | Privacy Policy