Commit 77194e88 authored by Abhishek Kumar's avatar Abhishek Kumar
Browse files

Fixing empty definition and schema version issue

parent c63358f4
Pipeline #54629 passed with stages
in 27 minutes and 3 seconds
......@@ -20,6 +20,7 @@ public class SchemaConstants {
//Delimeters
public static final String SCHEMA_KIND_DELIMITER = ":";
public static final String SCHEMA_Version_DELIMITER = ".";
public static final String SCHEMA_KIND_REGEX="^([^.:\\r\\n\\s]+):([^.:\\r\\n\\s]+):([^.:\\r\\n\\s]+):(\\d+.\\d+.\\d+)$";
// schema
public static final String SCHEMA_KIND = "schema";
......
package org.opengroup.osdu.schema.validation;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.schema.exceptions.ApplicationException;
import org.opengroup.osdu.schema.exceptions.SchemaVersionException;
import org.opengroup.osdu.schema.util.JSONUtil;
import org.opengroup.osdu.schema.validation.handler.SchemaValidationChainOfHandlers;
import org.opengroup.osdu.schema.validation.handler.SchemaValidationHandler;
import org.opengroup.osdu.schema.validation.model.SchemaBreakingChanges;
import org.opengroup.osdu.schema.validation.model.SchemaDiff;
import org.opengroup.osdu.schema.validation.model.SchemaPatch;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
......@@ -33,9 +29,9 @@ public abstract class AbstractVersionValidator implements VersionValidator{
try {
JsonNode cleanSource = jsonUtil.getCleanJSON(oldSchema);
JsonNode cleanTarget = jsonUtil.getCleanJSON(newSchema);
JsonNode sourceDefinitions = jsonUtil.removeElement(cleanSource, "definitions").orElse(null);
JsonNode targetDefinitions = jsonUtil.removeElement(cleanTarget, "definitions").orElse(null);
JsonNode sourceDefinitions = jsonUtil.removeElement(cleanSource, "definitions").orElse(new ObjectMapper().createObjectNode());
JsonNode targetDefinitions = jsonUtil.removeElement(cleanTarget, "definitions").orElse(new ObjectMapper().createObjectNode());
List<SchemaBreakingChanges> schemaBreakingChanges = new ArrayList<>();
SchemaDiff schemaDiff = new SchemaDiff(cleanSource, cleanTarget, sourceDefinitions, targetDefinitions, getType());
......
package org.opengroup.osdu.schema.validation.handler;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.validation.SchemaVersionValidatorType;
import org.opengroup.osdu.schema.validation.handler.common.AdditionalPropertiesHandler;
import org.opengroup.osdu.schema.validation.handler.common.RemoveOperationHandler;
......@@ -12,8 +15,6 @@ import org.opengroup.osdu.schema.validation.handler.minor.ReferenceAttributeHand
public class SchemaValidationChainOfHandlers {
public static String REGEX="^([^\\s]+):([^\\s]+):([^\\s]+):\\d+.\\d+.\\d+$";
public SchemaValidationHandler getChainOfHandlers(SchemaVersionValidatorType validatorType) {
if(validatorType == SchemaVersionValidatorType.PATCH)
......@@ -60,20 +61,22 @@ public class SchemaValidationChainOfHandlers {
private boolean getPatchVersionPredicate(String oldSchema, String newSchema) {
Pattern pattern = Pattern.compile(REGEX, Pattern.CASE_INSENSITIVE);
boolean isValidOldSchemaId = pattern.matcher(oldSchema).find();
boolean isValidNewSchemaId = pattern.matcher(newSchema).find();
if((false == isValidOldSchemaId || false == isValidNewSchemaId) && oldSchema.equals(newSchema) == false)
return false;
Pattern pattern = Pattern.compile(SchemaConstants.SCHEMA_KIND_REGEX);
Matcher oldMatcher = pattern.matcher(oldSchema);
Matcher newMatcher = pattern.matcher(newSchema);
if(false == oldMatcher.find() || 4 != oldMatcher.groupCount()
|| false == newMatcher.find() || 4 != newMatcher.groupCount())
return oldSchema.equals(newSchema);
String [] oldKind = oldSchema.split("\\.");
String [] newKind = newSchema.split("\\.");
String [] oldKind = oldMatcher.group(4).split("\\.");
String [] newKind = newMatcher.group(4).split("\\.");
if(oldKind[0].equals(newKind[0]) == false)
if(!StringUtils.substringBeforeLast(oldSchema, ":").equals((StringUtils.substringBeforeLast(newSchema, ":"))))
return false;
else if(Long.valueOf(oldKind[1]) > Long.valueOf(newKind[1])
else if(Long.valueOf(oldKind[0]) != Long.valueOf(newKind[0])
|| Long.valueOf(oldKind[1]) != Long.valueOf(newKind[1])
|| Long.valueOf(oldKind[2]) > Long.valueOf(newKind[2]))
return false;
......@@ -83,20 +86,22 @@ public class SchemaValidationChainOfHandlers {
private boolean getMinorVersionPredicate(String oldSchema, String newSchema) {
Pattern pattern = Pattern.compile(REGEX, Pattern.CASE_INSENSITIVE);
boolean isValidOldSchemaId = pattern.matcher(oldSchema).find();
boolean isValidNewSchemaId = pattern.matcher(newSchema).find();
if((false == isValidOldSchemaId || false == isValidNewSchemaId) && oldSchema.equals(newSchema) == false)
return false;
Pattern pattern = Pattern.compile(SchemaConstants.SCHEMA_KIND_REGEX);
Matcher oldMatcher = pattern.matcher(oldSchema);
Matcher newMatcher = pattern.matcher(newSchema);
if(false == oldMatcher.find() || 4 != oldMatcher.groupCount()
|| false == newMatcher.find() || 4 != newMatcher.groupCount())
return oldSchema.equals(newSchema);
String [] oldKind = oldSchema.split("\\.");
String [] newKind = newSchema.split("\\.");
String [] oldKind = oldMatcher.group(4).split("\\.");
String [] newKind = newMatcher.group(4).split("\\.");
if(oldKind[0].equals(newKind[0]) == false)
if(!StringUtils.substringBeforeLast(oldSchema, ":").equals((StringUtils.substringBeforeLast(newSchema, ":"))))
return false;
else if(Long.valueOf(oldKind[1]) > Long.valueOf(newKind[1])
else if(Long.valueOf(oldKind[0]) != Long.valueOf(newKind[0])
|| Long.valueOf(oldKind[1]) > Long.valueOf(newKind[1])
|| Long.valueOf(oldKind[2]) > Long.valueOf(newKind[2]))
return false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment