return checkCompatibility(prevRestSpecPath, currSnapshotPath, compatLevel, true);
}
private CompatibilityInfoMap checkCompatibility(String prevRestModelPath, String currRestModelPath, CompatibilityLevel compatLevel, boolean isAgainstRestSpec)
{
final CompatibilityInfoMap infoMap = new CompatibilityInfoMap();
if (compatLevel == CompatibilityLevel.OFF)
{
// skip check entirely.
return infoMap;
}
final Stack<Object> path = new Stack<Object>();
path.push("");
FileInputStream prevSnapshotFile = null;
FileInputStream currSnapshotFile = null;
try
{
prevSnapshotFile = new FileInputStream(prevRestModelPath);
}
catch (FileNotFoundException e)
{
infoMap.addRestSpecInfo(CompatibilityInfo.Type.RESOURCE_NEW, path, currRestModelPath);
}
try
{
currSnapshotFile = new FileInputStream(currRestModelPath);
}
catch (FileNotFoundException e)
{
infoMap.addRestSpecInfo(CompatibilityInfo.Type.RESOURCE_MISSING, path, prevRestModelPath);
}
if (prevSnapshotFile == null || currSnapshotFile == null)
{
return infoMap;
}
AbstractSnapshot prevSnapshot = null;
AbstractSnapshot currSnapshot = null;
try
{
if (isAgainstRestSpec)
{
prevSnapshot = new RestSpec(prevSnapshotFile);
}
else
{
prevSnapshot = new Snapshot(prevSnapshotFile);
}
currSnapshot = new Snapshot(currSnapshotFile);
}
catch (IOException e)
{
infoMap.addRestSpecInfo(CompatibilityInfo.Type.OTHER_ERROR, path, e.getMessage());
}
if (prevSnapshot == null || currSnapshot == null)
{
return infoMap;
}
final DataSchemaResolver currResolver = createResolverFromSnapshot(currSnapshot, _resolverPath);
final DataSchemaResolver prevResolver;
if (isAgainstRestSpec)
{
prevResolver = currResolver;
}
else
{
prevResolver = createResolverFromSnapshot(prevSnapshot, _resolverPath);
}
final ResourceCompatibilityChecker checker = new ResourceCompatibilityChecker(prevSnapshot.getResourceSchema(), prevResolver,
currSnapshot.getResourceSchema(), currResolver);
checker.check(compatLevel);
infoMap.addAll(checker.getInfoMap());
return infoMap;
}