Skip to content

Commit 21ddfd2

Browse files
committed
Pull request #152: Development
Merge in ITB/json-validator from development to master * commit '34769dacabe5513f14690e8e8ddc47c4dafbda89': Quality fixes Upgrade Spring Boot to v3.5.4 and Tika to v3.2.1 Support for domain aliases
2 parents e9f14ac + 34769da commit 21ddfd2

12 files changed

Lines changed: 200 additions & 187 deletions

File tree

NOTICE.md

Lines changed: 164 additions & 164 deletions
Large diffs are not rendered by default.

jsonvalidator-common/src/main/java/eu/europa/ec/itb/json/InputHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
import eu.europa.ec.itb.validation.commons.BaseInputHelper;
2020
import eu.europa.ec.itb.validation.commons.artifact.ValidationArtifactCombinationApproach;
2121
import eu.europa.ec.itb.validation.commons.error.ValidatorException;
22-
import org.apache.tika.utils.StringUtils;
22+
import org.apache.commons.lang3.StringUtils;
2323
import org.springframework.stereotype.Component;
2424

2525
/**
2626
* Component to facilitate the validation and preparation of inputs.
27-
*
27+
* <p>
2828
* This class serves simply as a marked to include the parent component as-is.
2929
*/
3030
@Component

jsonvalidator-common/src/main/java/eu/europa/ec/itb/json/validation/JSONValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import eu.europa.ec.itb.validation.plugin.PluginManager;
3636
import eu.europa.ec.itb.validation.plugin.ValidationPlugin;
3737
import org.apache.commons.io.FileUtils;
38-
import org.apache.commons.lang3.StringUtils;
38+
import org.apache.commons.lang3.Strings;
3939
import org.apache.commons.lang3.tuple.Pair;
4040
import org.slf4j.Logger;
4141
import org.slf4j.LoggerFactory;
@@ -376,7 +376,7 @@ private Function<ValidationMessage, String> getLocationMapper() {
376376
private List<Message> validateAgainstSchema(File schemaFile) {
377377
var schemaInfo = readSchema(schemaFile.toPath());
378378
var locationMapper = getLocationMapper();
379-
return schemaInfo.getLeft().validate(getContentNode(schemaInfo.getRight())).stream().map(message -> new Message(StringUtils.removeStart(message.getMessage(), "[] "), locationMapper.apply(message))).toList();
379+
return schemaInfo.getLeft().validate(getContentNode(schemaInfo.getRight())).stream().map(message -> new Message(Strings.CS.removeStart(message.getMessage(), "[] "), locationMapper.apply(message))).toList();
380380
}
381381

382382
/**

jsonvalidator-common/src/main/java/eu/europa/ec/itb/json/validation/LocalSchemaCache.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
import eu.europa.ec.itb.json.ApplicationConfig;
2020
import eu.europa.ec.itb.json.DomainConfig;
2121
import eu.europa.ec.itb.json.DomainConfigCache;
22+
import jakarta.annotation.PostConstruct;
2223
import org.apache.commons.io.FilenameUtils;
23-
import org.apache.commons.lang3.StringUtils;
24+
import org.apache.commons.lang3.Strings;
2425
import org.slf4j.Logger;
2526
import org.slf4j.LoggerFactory;
2627
import org.springframework.beans.factory.annotation.Autowired;
2728
import org.springframework.stereotype.Component;
2829

29-
import jakarta.annotation.PostConstruct;
3030
import java.io.File;
3131
import java.io.FileReader;
3232
import java.io.IOException;
@@ -139,7 +139,7 @@ private void readSchemaIdsAndPaths(DomainConfig domainConfig) throws IOException
139139
* @return The key to use.
140140
*/
141141
private String schemaKey(DomainConfig domainConfig, String id) {
142-
return StringUtils.appendIfMissing(String.format("com.gitb.domain.%s|%s", domainConfig.getDomain(), id), "#");
142+
return Strings.CS.appendIfMissing(String.format("com.gitb.domain.%s|%s", domainConfig.getDomain(), id), "#");
143143
}
144144

145145
/**

jsonvalidator-common/src/main/java/eu/europa/ec/itb/json/validation/LocalSchemaResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.networknt.schema.resource.SchemaLoader;
2121
import com.networknt.schema.resource.UriSchemaLoader;
2222
import eu.europa.ec.itb.json.DomainConfig;
23-
import org.apache.commons.lang3.StringUtils;
23+
import org.apache.commons.lang3.Strings;
2424
import org.slf4j.Logger;
2525
import org.slf4j.LoggerFactory;
2626

@@ -56,7 +56,7 @@ public LocalSchemaResolver(DomainConfig domain, LocalSchemaCache localSchemaCach
5656
*/
5757
@Override
5858
public InputStreamSource getSchema(AbsoluteIri absoluteIri) {
59-
String idToCheck = StringUtils.appendIfMissing(absoluteIri.toString(), "#");
59+
String idToCheck = Strings.CS.appendIfMissing(absoluteIri.toString(), "#");
6060
var schema = localSchemaCache.getSchemaForId(domain, idToCheck);
6161
if (schema.isEmpty()) {
6262
LOG.debug("Schema with URI {} not found locally. Looking up remotely.", absoluteIri);

jsonvalidator-common/src/main/java/eu/europa/ec/itb/json/validation/SchemaResolutionState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
/**
2424
* Class to record the thread-specific state when resolving a given schema.
25-
*
25+
* <p>
2626
* This state is used for two reasons:
2727
* - To pass the domain in question.
2828
* - To ensure that we don't end up with cyclic dependencies that could lead to infinite lookups.

jsonvalidator-jar/src/main/java/eu/europa/ec/itb/json/standalone/ValidationRunner.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ protected void bootstrapInternal(String[] args, File parentFolder) {
118118
externalSchemaCombinationApproach = inputHelper.getValidationArtifactCombinationApproach(domainConfig, validationType, schemaCombinationApproachValue);
119119
} catch (ValidatorException e) {
120120
LOGGER_FEEDBACK.info("\nInvalid arguments provided: {}\n", e.getMessageForDisplay(new LocalisationHelper(domainConfig, Locale.ENGLISH)));
121-
LOGGER.error(String.format("Invalid arguments provided: %s", e.getMessageForLog()), e);
121+
LOGGER.error("Invalid arguments provided: {}", e.getMessageForLog(), e);
122122
inputs.clear();
123123
} catch (IllegalArgumentException e) {
124124
LOGGER_FEEDBACK.info("\nInvalid arguments provided: {}\n", e.getMessage());
125-
LOGGER.error(String.format("Invalid arguments provided: %s", e.getMessage()), e);
125+
LOGGER.error("Invalid arguments provided: {}", e.getMessage(), e);
126126
inputs.clear();
127127
} catch (Exception e) {
128128
LOGGER_FEEDBACK.info("\nAn error occurred while processing the provided arguments.\n");
@@ -177,12 +177,12 @@ protected void bootstrapInternal(String[] args, File parentFolder) {
177177
}
178178
} catch (ValidatorException e) {
179179
LOGGER_FEEDBACK.info("\nAn error occurred while executing the validation: {}", e.getMessageForDisplay(localiser));
180-
LOGGER.error(String.format("An error occurred while executing the validation: %s", e.getMessageForLog()), e);
180+
LOGGER.error("An error occurred while executing the validation: {}", e.getMessageForLog(), e);
181181
break;
182182

183183
} catch (Exception e) {
184184
LOGGER_FEEDBACK.info("\nAn error occurred while executing the validation.");
185-
LOGGER.error(String.format("An error occurred while executing the validation: %s", e.getMessage()), e);
185+
LOGGER.error("An error occurred while executing the validation: {}", e.getMessage(), e);
186186
break;
187187
}
188188
i++;

jsonvalidator-service/src/main/java/eu/europa/ec/itb/json/gitb/ValidationServiceConfig.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import eu.europa.ec.itb.json.DomainConfig;
2020
import eu.europa.ec.itb.json.DomainConfigCache;
2121
import eu.europa.ec.itb.validation.commons.ValidatorChannel;
22+
import jakarta.annotation.PostConstruct;
2223
import org.apache.commons.lang3.StringUtils;
24+
import org.apache.commons.lang3.Strings;
2325
import org.apache.cxf.Bus;
2426
import org.apache.cxf.jaxws.EndpointImpl;
2527
import org.apache.cxf.transport.servlet.CXFServlet;
@@ -29,7 +31,6 @@
2931
import org.springframework.context.annotation.Bean;
3032
import org.springframework.context.annotation.Configuration;
3133

32-
import jakarta.annotation.PostConstruct;
3334
import javax.xml.namespace.QName;
3435

3536
/**
@@ -72,11 +73,12 @@ public ServletRegistrationBean<CXFServlet> servletRegistrationBean(ApplicationCo
7273
public void publishValidationServices() {
7374
for (DomainConfig domainConfig: domainConfigCache.getAllDomainConfigurations()) {
7475
if (domainConfig.getChannels().contains(ValidatorChannel.SOAP_API)) {
75-
EndpointImpl endpoint = new EndpointImpl(cxfBus, applicationContext.getBean(ValidationServiceImpl.class, domainConfig));
76+
DomainConfig resolvedDomainConfig = domainConfigCache.getConfigForDomainName(domainConfig.getDomainName());
77+
EndpointImpl endpoint = new EndpointImpl(cxfBus, applicationContext.getBean(ValidationServiceImpl.class, resolvedDomainConfig, domainConfig));
7678
endpoint.setEndpointName(new QName("http://www.gitb.com/vs/v1/", "ValidationServicePort"));
7779
endpoint.setServiceName(new QName("http://www.gitb.com/vs/v1/", "ValidationService"));
7880
if (StringUtils.isNotBlank(config.getBaseSoapEndpointUrl())) {
79-
var url = StringUtils.appendIfMissing(config.getBaseSoapEndpointUrl(), "/");
81+
var url = Strings.CS.appendIfMissing(config.getBaseSoapEndpointUrl(), "/");
8082
endpoint.setPublishedEndpointUrl(url+domainConfig.getDomainName()+"/validation");
8183
}
8284
endpoint.publish("/"+domainConfig.getDomainName()+"/validation");

jsonvalidator-service/src/main/java/eu/europa/ec/itb/json/gitb/ValidationServiceImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class ValidationServiceImpl implements ValidationService, WebServiceConte
5757

5858
private static final Logger logger = LoggerFactory.getLogger(ValidationServiceImpl.class);
5959
private final DomainConfig domainConfig;
60+
private final DomainConfig requestedDomainConfig;
6061

6162
@Autowired
6263
private ApplicationContext ctx = null;
@@ -71,9 +72,11 @@ public class ValidationServiceImpl implements ValidationService, WebServiceConte
7172
* Constructor.
7273
*
7374
* @param domainConfig The domain configuration (each domain has its own instance).
75+
* @param requestedDomainConfig The resolved domain configuration (in case of aliases).
7476
*/
75-
public ValidationServiceImpl(DomainConfig domainConfig) {
77+
public ValidationServiceImpl(DomainConfig domainConfig, DomainConfig requestedDomainConfig) {
7678
this.domainConfig = domainConfig;
79+
this.requestedDomainConfig = requestedDomainConfig;
7780
}
7881

7982
/**
@@ -125,7 +128,7 @@ private boolean definesTypeWithExternalSchemas() {
125128

126129
/**
127130
* The validate operation is called to validate the input and produce a validation report.
128-
*
131+
* <p>
129132
* The expected input is described for the service's client through the getModuleDefinition call.
130133
*
131134
* @param validateRequest The input parameters and configuration for the validation.
@@ -142,7 +145,7 @@ public ValidationResponse validate(@WebParam(name = "ValidateRequest", targetNam
142145
boolean locationAsPointer = getInputAsBoolean(validateRequest, ValidationConstants.INPUT_LOCATION_AS_POINTER, false);
143146
boolean addInputToReport = getInputAsBoolean(validateRequest, ValidationConstants.INPUT_ADD_INPUT_TO_REPORT, true);
144147
File contentToValidate = inputHelper.validateContentToValidate(validateRequest, ValidationConstants.INPUT_CONTENT, contentEmbeddingMethod, null, tempFolderPath, domainConfig.getHttpVersion()).getFile();
145-
String validationType = inputHelper.validateValidationType(domainConfig, validateRequest, ValidationConstants.INPUT_VALIDATION_TYPE);
148+
String validationType = inputHelper.validateValidationType(requestedDomainConfig.getDomainName(), domainConfig, validateRequest, ValidationConstants.INPUT_VALIDATION_TYPE);
146149
List<FileInfo> externalSchemas = inputHelper.validateExternalArtifacts(domainConfig, validateRequest, ValidationConstants.INPUT_EXTERNAL_SCHEMAS, ValidationConstants.INPUT_EXTERNAL_SCHEMAS_SCHEMA, ValidationConstants.INPUT_EMBEDDING_METHOD, validationType, null, tempFolderPath);
147150
ValidationArtifactCombinationApproach externalSchemaCombinationApproach = validateExternalSchemaCombinationApproach(validateRequest, validationType);
148151
ValidationResponse result = new ValidationResponse();

jsonvalidator-service/src/main/java/eu/europa/ec/itb/json/rest/RestValidationController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ public ResponseEntity<StreamingResponseBody> validate(
136136
HttpServletRequest request
137137
) {
138138
DomainConfig domainConfig = validateDomain(domain);
139+
// Consider the case that we have a cross-domain alias and resolve the validation type accordingly.
140+
in.setValidationType(inputHelper.determineValidationType(in.getValidationType(), domain, domainConfig));
139141
/*
140142
* Important: We call executeValidationProcess here and not in the return statement because the StreamingResponseBody
141143
* uses a separate thread. Doing so would break the ThreadLocal used in the statistics reporting.
@@ -269,6 +271,8 @@ public Output[] validateMultiple(
269271
var outputs = new ArrayList<Output>(inputs.length);
270272
for (Input input: inputs) {
271273
Output output = new Output();
274+
// Consider the case that we have a cross-domain alias and resolve the validation type accordingly.
275+
input.setValidationType(inputHelper.determineValidationType(input.getValidationType(), domain, domainConfig));
272276
var report = executeValidationProcess(input, domainConfig);
273277
try (var bos = new ByteArrayOutputStream()) {
274278
var wrapReportDataInCDATA = Objects.requireNonNullElse(input.getWrapReportDataInCDATA(), false);

0 commit comments

Comments
 (0)