public boolean checkCondition()

in wilma-application/modules/wilma-stub-configuration-support/src/main/java/com/epam/wilma/stubconfig/condition/checker/json/JsonSchemaChecker.java [65:103]


    public boolean checkCondition(final WilmaHttpRequest request, final ParameterList parameters) {
        boolean result = true;
        String schemaString = parameters.get(SCHEMA);
        String isSchemaVolatileString = parameters.get(IS_SCHEMA_VOLATILE);
        boolean isSchemaVolatile = isSchemaVolatileString == null || isSchemaVolatileString.compareToIgnoreCase("true") == 0;

        Schema jsonSchema;
        try {
            if (!isSchemaVolatile && schemaMap.containsKey(schemaString)) {
                jsonSchema = schemaMap.get(schemaString);
            } else {  //either volatile or schema is not yet loaded
                jsonSchema = readTemplateAsJsonSchemaFromFileSystem(schemaString);
                if (!isSchemaVolatile) {
                    schemaMap.put(schemaString, jsonSchema);
                }
            }
        } catch (Exception e) {
            throw new StubConfigJsonSchemaException("Cannot load: " + schemaString + " as Json Schema to check the messages, pls fix the configuration.");
        }

        JSONObject jsonToBeValidated = null;
        try {
            InputStream stream = new ByteArrayInputStream(request.getBody().getBytes(StandardCharsets.UTF_8.name()));
            jsonToBeValidated = new JSONObject(new JSONTokener(stream));
        } catch (JSONException | IOException e) {
            //it is not a valid Json file
            result = false;
        }

        if (result) {
            try {
                jsonSchema.validate(jsonToBeValidated);
            } catch (ValidationException e) {
                //it is not a good Json file
                result = false;
            }
        }
        return result;
    }