Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #577: Some code suggestion from CodeGuru #984

Merged
merged 5 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public void remove(String Key){
}

public Object get(String key) {
return store.containsKey(key)?store.get(key).value:null;
ValueNode node = store.get(key);
return node != null ? node.value : null;
}

public boolean hasExpired(String key, Instant now) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private <T> void processFailedMessages(List<T> successReturns,
map(SQSMessage::getMessageId)
.collect(toList());

LOG.debug(format("[%s] records failed processing, but exceptions are suppressed. " +
LOG.debug(format("[%d] records failed processing, but exceptions are suppressed. " +
"Failed messages %s", failedMessages.size(), messageIds));
} else {
throw new SQSBatchProcessingException(exceptions, failedMessages, successReturns);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,17 @@ public static JsonSchema getJsonSchema(String schema) {
* @return the loaded json schema
*/
public static JsonSchema getJsonSchema(String schema, boolean validateSchema) {
JsonSchema jsonSchema = schemas.get(schema);
JsonSchema jsonSchema = schemas.computeIfAbsent(schema, ValidationUtils::createJsonSchema);

if (jsonSchema != null) {
return jsonSchema;
if (validateSchema) {
validateSchema(schema, jsonSchema);
}

return jsonSchema;
}

private static JsonSchema createJsonSchema(String schema) {
JsonSchema jsonSchema;
if (schema.startsWith(CLASSPATH)) {
String filePath = schema.substring(CLASSPATH.length());
try (InputStream schemaStream = ValidationAspect.class.getResourceAsStream(filePath)) {
Expand All @@ -260,21 +265,19 @@ public static JsonSchema getJsonSchema(String schema, boolean validateSchema) {
jsonSchema = ValidationConfig.get().getFactory().getSchema(schema);
}

if (validateSchema) {
String version = ValidationConfig.get().getSchemaVersion().toString();
try {
validate(jsonSchema.getSchemaNode(),
getJsonSchema("classpath:/schemas/meta_schema_" + version));
} catch (ValidationException ve) {
throw new IllegalArgumentException("The schema " + schema + " is not valid, it does not respect the specification " + version, ve);
}
}

schemas.put(schema, jsonSchema);

return jsonSchema;
}

private static void validateSchema(String schema, JsonSchema jsonSchema) {
String version = ValidationConfig.get().getSchemaVersion().toString();
try {
validate(jsonSchema.getSchemaNode(),
getJsonSchema("classpath:/schemas/meta_schema_" + version));
} catch (ValidationException ve) {
throw new IllegalArgumentException("The schema " + schema + " is not valid, it does not respect the specification " + version, ve);
}
}

/**
*
*/
Expand Down