Commit 748e7c1c authored by Maxime Lefrançois's avatar Maxime Lefrançois
Browse files

updated some conditions

parent ce30ef66
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -44,6 +44,10 @@ public class CMDConfigurations {
	public static final String ARG_NO_SITE_LONG = "no-site";
	public static final String ARG_NO_SITE_MAN = "Do not generate the static website";

	public static final String ARG_IGNORE_TERMS = "t";
	public static final String ARG_IGNORE_TERMS_LONG = "no-terms";
	public static final String ARG_IGNORE_TERMS_MAN = "Do not generate the website for terms";
	
	public static final String ARG_INCLUDE_MASTER = "m";
	public static final String ARG_INCLUDE_MASTER_LONG = "master";
	public static final String ARG_INCLUDE_MASTER_MAN = "Check the master branches of the remote repositories listed in the `.saref-repositories.yml` document";
@@ -66,6 +70,7 @@ public class CMDConfigurations {
				.addOption(ARG_IGNORE_EXAMPLES, ARG_IGNORE_EXAMPLES_LONG, false, ARG_IGNORE_EXAMPLES_MAN)
				.addOption(ARG_IGNORE_GIT, ARG_IGNORE_GIT_LONG, false, ARG_IGNORE_GIT_MAN)
				.addOption(ARG_NO_SITE, ARG_NO_SITE_LONG, false, ARG_NO_SITE_MAN)
				.addOption(ARG_IGNORE_TERMS, ARG_IGNORE_TERMS_LONG, false, ARG_INCLUDE_MASTER_MAN)
				.addOption(ARG_INCLUDE_MASTER, ARG_INCLUDE_MASTER_LONG, false, ARG_INCLUDE_MASTER_MAN)
				.addOption(ARG_VERBOSE, ARG_VERBOSE_LONG, false, ARG_VERBOSE_MAN);
	}
+3 −1
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ public class Main {
	static boolean ignoreGit;
	static boolean includeMaster;
	static boolean generateSite;
	static boolean ignoreTerms;
	static boolean ignoreExamples;
	static boolean verbose;
		
@@ -124,6 +125,7 @@ public class Main {
		includeMaster = cl.hasOption(ARG_INCLUDE_MASTER);
		generateSite = !cl.hasOption(ARG_NO_SITE);
		ignoreExamples = cl.hasOption(ARG_IGNORE_EXAMPLES);
		ignoreTerms = cl.hasOption(ARG_IGNORE_TERMS);
		verbose = cl.hasOption(ARG_VERBOSE);
					
		setLogAppenders();
@@ -154,7 +156,7 @@ public class Main {
		new CheckConfig().doJob(dataset, ignoreExamples);

		if (generateSite) {
			new GeneratePortal("Generate static files for the portal", streamManager).doJob(dataset, directory, verbose);
			new GeneratePortal("Generate static files for the portal", streamManager).doJob(dataset, directory, verbose, ignoreExamples, ignoreTerms);
		}


+49 −45
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ public class GeneratePortal extends JobRunner {

	}

	public void doJob(Dataset dataset, File directory, boolean verbose) {
	public void doJob(Dataset dataset, File directory, boolean verbose, boolean ignoreExamples, boolean ignoreTerms) {
		File siteDir = new File(directory, Constants.SITE_DIR);
		dataset.begin(ReadWrite.READ);
		Model config = dataset.getNamedModel(Constants.CONFIG);
@@ -110,6 +110,7 @@ public class GeneratePortal extends JobRunner {
			}
		}

		if(!ignoreTerms) {
			for (ResIterator it = config.listResourcesWithProperty(RDF.type, RDFP.Resource); it.hasNext();) {
				Resource resource = it.next();// https://saref.etsi.org/core/master/ -- https://saref.etsi.org/core/Command
				String uri = resource.getURI();
@@ -136,7 +137,9 @@ public class GeneratePortal extends JobRunner {
					logger.error(String.format("Unexpected exception while writing static files for %s", resource), ex);
				}
			}
		}

		if(!ignoreExamples) {
			for (ResIterator it = config.listResourcesWithProperty(RDF.type, EX.Example); it.hasNext();) {
				Resource resource = it.next();// https://saref.etsi.org/core/master/example/doorswitch
				String uri = resource.getURI();
@@ -163,6 +166,7 @@ public class GeneratePortal extends JobRunner {
					logger.error(String.format("Unexpected exception while writing static files for %s", resource), ex);
				}
			}
		}
		
		
		dataset.end();
+0 −9
Original line number Diff line number Diff line
@@ -155,7 +155,6 @@ public class ReadExamples extends JobRunner {
		}
		Resource reportResource = ValidationUtil.validateModel(model, shapeModel, true);
		boolean conforms = reportResource.getProperty(SH.conforms).getBoolean();
		boolean hasErrors = false;
		if (!conforms) {
			Model reportModel = reportResource.getModel();
			reportModel.setNsPrefixes(PREFIXES);
@@ -172,7 +171,6 @@ public class ReadExamples extends JobRunner {
					if (severity != null && severity.getURI().equals(SHACL_VIOLATION)) {
						logger.error(String.format("Shape violation on node %s: %s%s", focusNode, resultMessage,
								gotString));
						hasErrors = true;
					} else {
						logger.warn(String.format("Shape violation on node %s: %s%s", focusNode, resultMessage,
								gotString));
@@ -184,13 +182,11 @@ public class ReadExamples extends JobRunner {
		ResIterator it = model.listSubjectsWithProperty(RDF.type, OWL2.Ontology);
		if(!it.hasNext()) {
			logger.error("There shall be exactly one owl:Ontology");
			hasErrors = true;
		}
		while(it.hasNext()) {
			Resource ontology = it.next();
			if(onto++>1) {
				logger.error("There shall be exactly one owl:Ontology");
				hasErrors = true;
			}
			// check that this ontology is imported (without a version)
			boolean found = false;
@@ -203,18 +199,13 @@ public class ReadExamples extends JobRunner {
				} else {
					if(!uri.matches("^https://saref.etsi.org/(core|saref4[a-z]{4})/v[1-9][0-9]*\\\\.[1-9][0-9]*\\\\.[1-9][0-9]*/$")) {
						logger.error("Only SAREF ontologies with specific versions shall be imported. Their URIs conform to the regular expression `^https://saref.etsi.org/(core|saref4[a-z]{4})/v[1-9][0-9]*\\\\.[1-9][0-9]*\\\\.[1-9][0-9]*/$`");
						hasErrors = true;
					}
				}
			}
			if(!found) {
				logger.error(String.format("The current ontology shall be imported: <%s>", version.getRepository().getNamespace()));
				hasErrors = true;
			}
		}
		if(hasErrors) {
			throw new SAREFPipelineException("There were rrrors while checking the example structure");
		}
	}
	
	private void updateExampleMetadata(Version version, Model model, Resource example) throws Exception {
+16 −22
Original line number Diff line number Diff line
@@ -150,7 +150,6 @@ public class ReadOntology extends JobRunner {
		}
		Resource reportResource = ValidationUtil.validateModel(model, shapeModel, true);
		boolean conforms = reportResource.getProperty(SH.conforms).getBoolean();
		boolean hasErrors = false;
		if (!conforms) {
			Model reportModel = reportResource.getModel();
			reportModel.setNsPrefixes(PREFIXES);
@@ -167,7 +166,6 @@ public class ReadOntology extends JobRunner {
					if (severity != null && severity.getURI().equals(SHACL_VIOLATION)) {
						logger.error(String.format("Shape violation on node %s: %s%s", focusNode, resultMessage,
								gotString));
						hasErrors = true;
					} else {
						logger.warn(String.format("Shape violation on node %s: %s%s", focusNode, resultMessage,
								gotString));
@@ -180,27 +178,23 @@ public class ReadOntology extends JobRunner {
			Resource ontology = it.next();
			if(onto++>1) {
				logger.error("There shall be only one owl:Ontology");
				hasErrors = true;
			}
			if(version instanceof ReleaseVersion) {
				int source = 0;
				NodeIterator its = model.listObjectsOfProperty(ontology, DCTerms.source);
				if(!its.hasNext()) {
					logger.warn(SOURCE_ERROR);
				}
				while(its.hasNext()) {
					if(source++>1) {
						logger.warn(SOURCE_ERROR);
					}
					RDFNode s = its.next();
					if(!s.isURIResource() || !s.asResource().getURI().startsWith("http://www.etsi.org/deliver/etsi_ts/")) {
						logger.warn(SOURCE_ERROR);
					}
				}
			}
		}
		if(hasErrors) {
			throw new SAREFPipelineException("There were errors while checking the ontology structure");
//			if(version instanceof ReleaseVersion) {
//				int source = 0;
//				NodeIterator its = model.listObjectsOfProperty(ontology, DCTerms.source);
//				if(!its.hasNext()) {
//					logger.warn(SOURCE_ERROR);
//				}
//				while(its.hasNext()) {
//					if(source++>1) {
//						logger.warn(SOURCE_ERROR);
//					}
//					RDFNode s = its.next();
//					if(!s.isURIResource() || !s.asResource().getURI().startsWith("http://www.etsi.org/deliver/etsi_ts/")) {
//						logger.warn(SOURCE_ERROR);
//					}
//				}
//			}
		}
	}

Loading