Skip to content

Commit

Permalink
Partial refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
klakegg committed Nov 29, 2023
1 parent 952c811 commit 484fb63
Show file tree
Hide file tree
Showing 73 changed files with 745 additions and 1,077 deletions.
24 changes: 0 additions & 24 deletions .devcontainer/Dockerfile

This file was deleted.

38 changes: 0 additions & 38 deletions .devcontainer/devcontainer.json

This file was deleted.

3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/.idea
target
*.iml
/workspace
/validator.properties
*.html
.DS_Store
24 changes: 0 additions & 24 deletions doc/configurations.md

This file was deleted.

8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.7</version>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
Expand All @@ -117,14 +117,14 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.13.0</version>
<version>2.14.0</version>
</dependency>

<!-- Guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.1.2-jre</version>
<version>32.1.3-jre</version>
</dependency>

<!-- Guice -->
Expand Down Expand Up @@ -158,7 +158,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.5.0</version>
<version>5.6.0</version>
<scope>test</scope>
</dependency>

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/no/difi/vefa/validator/ValidationInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import no.difi.vefa.validator.model.Document;
import no.difi.vefa.validator.model.Prop;
import no.difi.vefa.validator.model.Props;
import no.difi.vefa.validator.util.Configuration;
import no.difi.xsd.vefa.validator._1.AssertionType;
import no.difi.xsd.vefa.validator._1.FileType;
import no.difi.xsd.vefa.validator._1.FlagType;
Expand Down Expand Up @@ -90,7 +91,7 @@ private ValidationInstance(ValidatorInstance validatorInstance, Document documen
if (report.getTitle() == null)
report.setTitle("Unknown document type");

if (section.getAssertion().size() > 0) {
if (!section.getAssertion().isEmpty()) {
for (AssertionType assertionType : section.getAssertion()) {
if (assertionType.getFlag().compareTo(section.getFlag()) > 0)
section.setFlag(assertionType.getFlag());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/difi/vefa/validator/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Validator implements Closeable {
* @return Validation result.
*/
public Validation validate(File file, Prop... props) throws IOException {
return validate(Document.of(file), props);
return validate(file.toPath(), props);
}

/**
Expand Down
27 changes: 11 additions & 16 deletions src/main/java/no/difi/vefa/validator/ValidatorBuilder.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package no.difi.vefa.validator;

import com.google.inject.Guice;
import com.google.inject.Module;
import com.google.inject.util.Modules;
import no.difi.vefa.validator.api.Source;
import no.difi.vefa.validator.api.Repository;
import no.difi.vefa.validator.model.Prop;
import no.difi.vefa.validator.module.PropertiesModule;
import no.difi.vefa.validator.module.SourceModule;
import no.difi.vefa.validator.module.ValidatorModule;
import no.difi.vefa.validator.util.Repositories;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* Builder supporting creation of validator.
*/
public class ValidatorBuilder {

private Source source;
private Repository repository;

private Prop[] props;

Expand Down Expand Up @@ -49,13 +45,13 @@ public ValidatorBuilder setProperties(Prop... props) {
}

/**
* Define source to use if other source then production repository to be used.
* Define repository to use.
*
* @param source Source giving access to validation rules.
* @param repository Repository giving access to validation rules.
* @return Builder object
*/
public ValidatorBuilder setSource(Source source) {
this.source = source;
public ValidatorBuilder setRepository(Repository repository) {
this.repository = repository;
return this;
}

Expand All @@ -65,10 +61,9 @@ public ValidatorBuilder setSource(Source source) {
* @return Validator ready for use.
*/
public Validator build() {
List<Module> modules = new ArrayList<>();
modules.add(PropertiesModule.with(props));
modules.add(new SourceModule(source));
if (Objects.isNull(repository))
repository = Repositories.production();

return Guice.createInjector(Modules.override(new ValidatorModule()).with(modules)).getInstance(Validator.class);
return Guice.createInjector(new ValidatorModule(repository, props)).getInstance(Validator.class);
}
}
Loading

0 comments on commit 484fb63

Please sign in to comment.