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

org.ikasan.designer.json.DesignerJsonHelper Maven / Gradle / Ivy

package org.ikasan.designer.json;

import org.ikasan.designer.pallet.DesignerItemIdentifier;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class DesignerJsonHelper {

    /**
     * Get a JSONObject based on DesignerItemIdentifier.type
     *
     * @param type
     * @param json
     * @return
     */
    public static List getIdentifierTypeItems(String type, String json) {
        ArrayList results = new ArrayList<>();
        JSONArray jsonArray = new JSONArray(json);

        jsonArray.forEach(item -> {
            if(item instanceof JSONObject) {
                String id = ((JSONObject)item).getString("id");

                try {
                    DesignerItemIdentifier designerItemIdentifier = DesignerItemIdentifier.getIdentifier(id);

                    if(designerItemIdentifier.getType().equals(type)) {
                        results.add((JSONObject)item);
                    }
                }
                catch (IllegalArgumentException e){
                    // ignore as we are not interested in this item.
                }
            }
        });

        return results;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy