// Path: src/main/java/certh/iti/mklab/easie/configuration/validator/ConfigurationValidator.java
// public class ConfigurationValidator {
// 
//     private JsonValidator VALIDATOR;
//     private JsonNode ConfigurationSchema;
// 
//     public ConfigurationValidator(String path) throws IOException {
//         this.VALIDATOR = JsonSchemaFactory.byDefault().getValidator();
//         this.ConfigurationSchema = JsonLoader.fromFile(
//                 new File(path + "/ConfigurationSchema.json")
//         );
//     }
// 
//     public ConfigurationValidator() throws IOException {
//         this.VALIDATOR = JsonSchemaFactory.byDefault().getValidator();
//         this.ConfigurationSchema = JsonLoader.fromFile(
//                 new File("ConfigurationSchema.json")
//         );
//     }
// 
//     public void validate(File ConfigurationFile) throws IOException, ProcessingException, IllegalSchemaException {
//         JsonNode Configuration = JsonLoader.fromFile(ConfigurationFile);
// 
//         ProcessingReport r1 = VALIDATOR.validate(
//                 ConfigurationSchema,
//                 Configuration
//         );
// 
//         if (!r1.isSuccess()) {
//             Iterator<ProcessingMessage> it = r1.iterator();
//             ProcessingMessage pm = it.next();
//             JSONObject o = new JSONObject(pm.asJson().toString());
//             throw new IllegalSchemaException(o.toString(4));
//         }
//     }
// 
//     public void validate(String ConfigurationFile) throws IOException, ProcessingException, IllegalSchemaException {
//         JsonNode Configuration = JsonLoader.fromString(ConfigurationFile);
// 
//         ProcessingReport r1 = VALIDATOR.validate(
//                 ConfigurationSchema,
//                 Configuration
//         );
// 
//         if (!r1.isSuccess()) {
//             Iterator<ProcessingMessage> it = r1.iterator();
//             ProcessingMessage pm = it.next();
//             JSONObject o = new JSONObject(pm.asJson().toString());
//             throw new IllegalSchemaException(o.toString(4));
//         }
//     }
// 
//     public void setConfigurationSchema(File ConfigurationSchemaFile) throws IOException {
//         this.ConfigurationSchema = JsonLoader.fromFile(ConfigurationSchemaFile);
//     }
// 
//     public void setConfigurationSchema(String ConfigurationSchema) throws IOException {
//         this.ConfigurationSchema = JsonLoader.fromString(ConfigurationSchema);
//     }
// }
// 
// Path: src/main/java/certh/iti/mklab/easie/exception/IllegalSchemaException.java
// public class IllegalSchemaException extends Exception {
//    public IllegalSchemaException(){
//       
//    }
//    
//    public IllegalSchemaException(String message){
//       super(message);
//    }
//    
//    public IllegalSchemaException(Throwable cause){
//       super(cause);
//    }
//    
//    public IllegalSchemaException(String message, Throwable cause){
//       super(message, cause);
//    }
// }


import certh.iti.mklab.easie.configuration.validator.ConfigurationValidator;
import certh.iti.mklab.easie.exception.IllegalSchemaException;
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.commons.io.IOUtils;

/*
 * Copyright 2016 vasgat.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package certh.iti.mklab.easie.configuration;


/**
 * ConfigurationFileReader Object reads a JSON file or a String and transforms
 * it to Configuration Object and validates it
 *
 * @author vasgat
 */
public class ConfigurationReader {

    private String content;

    public Configuration config;

    private File ConfigurationFile;

    /**
     * ConfigurationFileReader Object constructor that created Configuration
     * Object from a JSON file and validates it.
     *
     * @param configurationFile: Configuration
     * @throws FileNotFoundException in case of not valid file path
     * @throws IllegalConfigurationException in case of invalid Configuration
     * schema
     */
    public ConfigurationReader(String FilePath, String SchemaPath) throws FileNotFoundException, IOException, ProcessingException, IllegalSchemaException {
        content = IOUtils.toString(new FileInputStream(new File(FilePath)), "UTF-8");
        this.ConfigurationFile = new File(FilePath);        
        deserialize(SchemaPath);
    }
    
    public ConfigurationReader(String config_content) throws IOException, ProcessingException, IllegalSchemaException{
        content = config_content;
        deserialize();
    }

    private void deserialize(String SchemaPath) throws IOException, ProcessingException, IllegalSchemaException {

// Path: src/main/java/certh/iti/mklab/easie/configuration/validator/ConfigurationValidator.java
// public class ConfigurationValidator {
// 
//     private JsonValidator VALIDATOR;
//     private JsonNode ConfigurationSchema;
// 
//     public ConfigurationValidator(String path) throws IOException {
//         this.VALIDATOR = JsonSchemaFactory.byDefault().getValidator();
//         this.ConfigurationSchema = JsonLoader.fromFile(
//                 new File(path + "/ConfigurationSchema.json")
//         );
//     }
// 
//     public ConfigurationValidator() throws IOException {
//         this.VALIDATOR = JsonSchemaFactory.byDefault().getValidator();
//         this.ConfigurationSchema = JsonLoader.fromFile(
//                 new File("ConfigurationSchema.json")
//         );
//     }
// 
//     public void validate(File ConfigurationFile) throws IOException, ProcessingException, IllegalSchemaException {
//         JsonNode Configuration = JsonLoader.fromFile(ConfigurationFile);
// 
//         ProcessingReport r1 = VALIDATOR.validate(
//                 ConfigurationSchema,
//                 Configuration
//         );
// 
//         if (!r1.isSuccess()) {
//             Iterator<ProcessingMessage> it = r1.iterator();
//             ProcessingMessage pm = it.next();
//             JSONObject o = new JSONObject(pm.asJson().toString());
//             throw new IllegalSchemaException(o.toString(4));
//         }
//     }
// 
//     public void validate(String ConfigurationFile) throws IOException, ProcessingException, IllegalSchemaException {
//         JsonNode Configuration = JsonLoader.fromString(ConfigurationFile);
// 
//         ProcessingReport r1 = VALIDATOR.validate(
//                 ConfigurationSchema,
//                 Configuration
//         );
// 
//         if (!r1.isSuccess()) {
//             Iterator<ProcessingMessage> it = r1.iterator();
//             ProcessingMessage pm = it.next();
//             JSONObject o = new JSONObject(pm.asJson().toString());
//             throw new IllegalSchemaException(o.toString(4));
//         }
//     }
// 
//     public void setConfigurationSchema(File ConfigurationSchemaFile) throws IOException {
//         this.ConfigurationSchema = JsonLoader.fromFile(ConfigurationSchemaFile);
//     }
// 
//     public void setConfigurationSchema(String ConfigurationSchema) throws IOException {
//         this.ConfigurationSchema = JsonLoader.fromString(ConfigurationSchema);
//     }
// }
// 
// Path: src/main/java/certh/iti/mklab/easie/exception/IllegalSchemaException.java
// public class IllegalSchemaException extends Exception {
//    public IllegalSchemaException(){
//       
//    }
//    
//    public IllegalSchemaException(String message){
//       super(message);
//    }
//    
//    public IllegalSchemaException(Throwable cause){
//       super(cause);
//    }
//    
//    public IllegalSchemaException(String message, Throwable cause){
//       super(message, cause);
//    }
// }


// Path: src/main/java/certh/iti/mklab/easie/configuration/ConfigurationReader.java
import certh.iti.mklab.easie.configuration.validator.ConfigurationValidator;
import certh.iti.mklab.easie.exception.IllegalSchemaException;
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.commons.io.IOUtils;

/*
 * Copyright 2016 vasgat.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package certh.iti.mklab.easie.configuration;


/**
 * ConfigurationFileReader Object reads a JSON file or a String and transforms
 * it to Configuration Object and validates it
 *
 * @author vasgat
 */
public class ConfigurationReader {

    private String content;

    public Configuration config;

    private File ConfigurationFile;

    /**
     * ConfigurationFileReader Object constructor that created Configuration
     * Object from a JSON file and validates it.
     *
     * @param configurationFile: Configuration
     * @throws FileNotFoundException in case of not valid file path
     * @throws IllegalConfigurationException in case of invalid Configuration
     * schema
     */
    public ConfigurationReader(String FilePath, String SchemaPath) throws FileNotFoundException, IOException, ProcessingException, IllegalSchemaException {
        content = IOUtils.toString(new FileInputStream(new File(FilePath)), "UTF-8");
        this.ConfigurationFile = new File(FilePath);        
        deserialize(SchemaPath);
    }
    
    public ConfigurationReader(String config_content) throws IOException, ProcessingException, IllegalSchemaException{
        content = config_content;
        deserialize();
    }

    private void deserialize(String SchemaPath) throws IOException, ProcessingException, IllegalSchemaException {

        ConfigurationValidator validator = new ConfigurationValidator(SchemaPath);
