All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.zenwave360.zdl.antlr.ZdlModelPostProcessor Maven / Gradle / Ivy

The newest version!
package io.github.zenwave360.zdl.antlr;

import io.github.zenwave360.zdl.antlr.JSONPath;
import io.github.zenwave360.zdl.antlr.ZdlModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ZdlModelPostProcessor {

    public static ZdlModel postProcess(ZdlModel model) {
        var aggregates = model.getAggregates();
        var entities = model.getEntities();
        var inputs = model.getInputs();
        var outputs = model.getOutputs();
        var enums = model.getEnums();
        var events = model.getEvents();

        var fields = JSONPath.get(model, "$..fields[*]", List.>of());
        for (var field : fields) {
            if(entities != null && entities.containsKey(field.get("type"))) {
                field.put("isEntity", true);
                field.put("isComplexType", true);
            }
            if(enums != null && enums.containsKey(field.get("type"))) {
                field.put("isEnum", true);
                field.put("isComplexType", true);
            }
            if(inputs != null && inputs.containsKey(field.get("type"))) {
                field.put("isInput", true);
                field.put("isComplexType", true);
            }
            if(outputs != null && outputs.containsKey(field.get("type"))) {
                field.put("isOutput", true);
                field.put("isComplexType", true);
            }
            if(events != null && events.containsKey(field.get("type"))) {
                field.put("isEvent", true);
                field.put("isComplexType", true);
            }
        }

        var allEntitiesAndEnums = new HashMap<>();
        if(aggregates != null) {
            allEntitiesAndEnums.putAll(aggregates);
        }
        if(entities != null) {
            allEntitiesAndEnums.putAll(entities);
        }
        if(enums != null) {
            allEntitiesAndEnums.putAll(enums);
        }
        if(inputs != null) {
            allEntitiesAndEnums.putAll(inputs);
        }
        if(outputs != null) {
            allEntitiesAndEnums.putAll(outputs);
        }
        model.put("allEntitiesAndEnums", allEntitiesAndEnums);

        return model;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy